/**************************************************************************** * VCGLib o o * * Visual and Computer Graphics Library o o * * _ O _ * * Copyright(C) 2004 \/)\/ * * Visual Computing Lab /\/| * * ISTI - Italian National Research Council | * * \ * * All rights reserved. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * * for more details. * * * ****************************************************************************/ /**************************************************************************** History $Log: not supported by cvs2svn $ ****************************************************************************/ #ifndef __VCGLIB_SEGMENT3 #define __VCGLIB_SEGMENT3 #include #include namespace vcg { /** \addtogroup space */ /*@{*/ /** Templated class for 3D segment. This is the class for a segment in 3D space. A Segment is stored just as its two extrema (Point3). @param SegmentScalarType (template parameter) Specifies the type of scalar used to represent coords. */ template class Segment3 { public: /// The scalar type typedef SegmentScalarType ScalarType; /// The point type typedef Point3 PointType; /// The point type typedef Segment3 SegmentType; private: /// _extrema PointType _p0,_p1; public: /// Members to access either extrema inline const PointType &P0() const { return _p0; } inline const PointType &P1() const { return _p1; } inline PointType &P0() { return _p0; } inline PointType &P1() { return _p1; } /// The empty constructor Segment3() {}; /// The (a,b) constructor SegmentType(const PointType &a, const PointType &b) { _p0=a; _p1=b; }; /// Operator to compare two bounding box inline bool operator == ( SegmentType const & p ) const { return _p0==p._p0 && _p1==p._p1; } /// Operator to dispare two bounding box inline bool operator != ( SegmentType const & p ) const { return _p0!=p._p0 || _p1!=p._p1; } /// initializes the bounding box void Set( const PointType &a, const PointType &b) { _p0=a; _p1=b;} /// calculates the point of parameter t on the segment. /// if t is in [0..1] returned point is inside the segment inline PointType P( const ScalarType t ) const { return _p0 + (_p1 - _p0) * t; } /// return the middle point inline PointType MidPoint( ) const { return ( _p0 + _p1) / ScalarType(2.0) ; } /// return the bounding box inline Box3 BBox( ) const { Box3 t; if (_p0[0]<_p1[0]) { t.min[0]=_p0[0];t.max[0]=_p1[0];} else { t.min[0]=_p1[0];t.max[0]=_p0[0];} if (_p0[1]<_p1[1]) { t.min[1]=_p0[1];t.max[1]=_p1[1];} else { t.min[1]=_p1[1];t.max[1]=_p0[1];} if (_p0[2]<_p1[2]) { t.min[2]=_p0[2];t.max[2]=_p1[2];} else { t.min[2]=_p1[2];t.max[2]=_p0[2];} return t; } /// return lenght SegmentType &Length() { return (_p0 - _p1).Norm(); } /// return squared lenght SegmentType &SquaredLength() { return (_p0 - _p1).SquaredNorm(); } /// flips: a-b becomes b-a void Flip() { PointType t=_p0; _p0=_p1; _p1=t; } template /// importer for different line types inline void Import( const Segment3 & b ) { _p0.Import( b._p0); _p1.Import( b._p1); } }; // end class definition typedef Segment3 Segment3s; typedef Segment3 Segment3i; typedef Segment3 Segment3f; typedef Segment3 Segment3d; /*@}*/ } // end namespace #endif