minor updates, corrections, added documentations, etc.
This commit is contained in:
parent
49c4d52f70
commit
f36d1e007a
|
@ -24,12 +24,13 @@
|
|||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.5 2004/03/10 15:27:48 tarini
|
||||
added Normalized flag
|
||||
|
||||
|
||||
Revision 1.1 2004/03/08 16:15:48 tarini
|
||||
first version (tarini)
|
||||
|
||||
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
|
@ -61,31 +62,48 @@ public:
|
|||
/// The point type
|
||||
typedef Point3<LineScalarType> PointType;
|
||||
|
||||
/// The point type
|
||||
/// The line type
|
||||
typedef Line3<LineScalarType,NORM> LineType;
|
||||
|
||||
private:
|
||||
|
||||
/// Origingin
|
||||
/// Origin
|
||||
PointType _ori;
|
||||
|
||||
/// Directionection (not necessarily normalized)
|
||||
/// Direction (not necessarily normalized, unless so specified by NORM)
|
||||
PointType _dir;
|
||||
|
||||
public:
|
||||
|
||||
/// Members to access the origin, direction
|
||||
//@{
|
||||
/** @name Members to access the origin or direction
|
||||
Direction() cannot be assigned directly.
|
||||
Use SetDirection() or Set() instead.
|
||||
**/
|
||||
///
|
||||
inline const PointType &Origin() const { return _ori; }
|
||||
inline const PointType &Direction() const { return _dir; }
|
||||
inline PointType &Origin() { return _ori; }
|
||||
inline PointType &Direction() {
|
||||
assert(!IsNormalized()); // Directionection can't be set for NORMALIZED Lines! Use SetDirection instead!
|
||||
return _dir;
|
||||
}
|
||||
/// The empty constructor
|
||||
inline const PointType &Direction() const { return _dir; }
|
||||
/// sets the origin
|
||||
inline void SetOrigin( const PointType & ori )
|
||||
{ _ori=ori; }
|
||||
/// sets the direction
|
||||
inline void SetDirection( const PointType & dir)
|
||||
{ _dir=dir; if (NORM) _dir.Normalize(); }
|
||||
/// sets origin and direction.
|
||||
inline void Set( const PointType & ori, const PointType & dir )
|
||||
{ SetOrigin(ori); SetDirection(dir); }
|
||||
//@}
|
||||
|
||||
//@{
|
||||
/** @name Constructors
|
||||
**/
|
||||
/// The empty constructor
|
||||
Line3() {};
|
||||
/// The (origin, direction) constructor
|
||||
LineType(const PointType &ori, const PointType &dir) {SetOrigin(ori); SetDirection(dir);};
|
||||
Line3(const PointType &ori, const PointType &dir) {SetOrigin(ori); SetDirection(dir);};
|
||||
//@}
|
||||
|
||||
/// Operator to compare two lines
|
||||
inline bool operator == ( LineType const & p ) const
|
||||
{ return _ori==p._ori && _dir==p._dir; }
|
||||
|
@ -97,31 +115,29 @@ public:
|
|||
{ if (NORM) return ScalarType((p-_ori)*_dir);
|
||||
else return ScalarType((p-_ori)*_dir/_dir.SquaredNorm());
|
||||
}
|
||||
inline bool IsNormalized() const {return NORM;};
|
||||
///set the origin
|
||||
inline void SetOrigin( const PointType & ori )
|
||||
{ _ori=ori; }
|
||||
///set the direction
|
||||
inline void SetDirection( const PointType & dir)
|
||||
{ _dir=dir; if (NORM) _dir.Normalize(); }
|
||||
///set both the origina and direction.
|
||||
inline void Set( const PointType & ori, const PointType & dir )
|
||||
{ SetOrigin(ori); SetDirection(dir); }
|
||||
/// returns wheter this type is normalized or not
|
||||
static bool IsNormalized() {return NORM;};
|
||||
/// calculates the point of parameter t on the line.
|
||||
inline PointType P( const ScalarType t ) const
|
||||
{ return _ori + _dir * t; }
|
||||
/// normalizes direction field (returns a Normalized Line)
|
||||
Line3<ScalarType,true> &Normalize()
|
||||
inline Line3<ScalarType,true> &Normalize()
|
||||
{ if (!NORM) _dir.Normalize(); return *((Line3<ScalarType,true>*)this);}
|
||||
/// normalizes direction field (returns a Normalized Line) - static version
|
||||
static Line3<ScalarType,true> &Normalize(LineType &p)
|
||||
{ p.Normalize(); return *((Line3<ScalarType,true>*)(&p));}
|
||||
/// importer for different line types
|
||||
/// importer for different line types (with any scalar type or normalization beaviour)
|
||||
template <class Q, bool K>
|
||||
inline void Import( const Line3<Q,K> & b )
|
||||
{ _ori.Import( b.Origin()); _dir.Import( b.Direction());
|
||||
if ((NORM) && (!K)) _dir.Normalize();
|
||||
{ _ori.Import( b.Origin() ); _dir.Import( b.Direction() );
|
||||
if ((NORM) && (!K)) _dir.Normalize();
|
||||
//printf("(=)%c->%c ",(!NORM)?'N':'n', NORM?'N':'n');
|
||||
}
|
||||
/// constructs a new line importing it from an existing one
|
||||
template <class Q, bool K>
|
||||
static LineType Construct( const Line3<Q,K> & b )
|
||||
{ LineType res; res.Import(b); return res;
|
||||
}
|
||||
PointType ClosestPoint(const PointType & p) const{
|
||||
return P(Projection(p));
|
||||
}
|
||||
|
@ -129,6 +145,39 @@ public:
|
|||
inline void Flip(){
|
||||
_dir=-_dir;
|
||||
};
|
||||
|
||||
//@{
|
||||
/** @name Linearity for 3d lines
|
||||
(operators +, -, *, /) so a line can be set as a linear combination
|
||||
of several lines. Note that the result of any operation returns
|
||||
a non-normalized line; however, the command r0 = r1*a + r2*b is licit
|
||||
even if r0,r1,r2 are normalized lines, as the normalization will
|
||||
take place within the final assignement operation.
|
||||
**/
|
||||
inline Line3<ScalarType,false> operator + ( LineType const & p) const
|
||||
{return Line3<ScalarType,false> ( _ori+p.Origin(), _dir+p.Direction() );}
|
||||
inline Line3<ScalarType,false> operator - ( LineType const & p) const
|
||||
{return Line3<ScalarType,false> ( _ori-p.Origin(), _dir-p.Direction() );}
|
||||
inline Line3<ScalarType,false> operator * ( const ScalarType s ) const
|
||||
{return Line3<ScalarType,false> ( _ori*s, _dir*s );}
|
||||
inline Line3<ScalarType,false> operator / ( const ScalarType s ) const
|
||||
{ScalarType s0=((ScalarType)1.0)/s; return LineType( _ori*s0, _dir*s0 );}
|
||||
//@}
|
||||
|
||||
|
||||
//@{
|
||||
/** @name Automatic normalized to non-normalized
|
||||
"Line3dN r0 = r1" is equivalent to
|
||||
"Line3dN r0 = r1.Normalize()" if r1 is a Line3d
|
||||
**/
|
||||
/// copy constructor that takes opposite beaviour
|
||||
LineType (const Line3<ScalarType,!NORM > &r)
|
||||
{ Import(r); };
|
||||
/// assignment
|
||||
inline LineType & operator = ( Line3<ScalarType,!NORM> const &r)
|
||||
{ Import(r); return *this; };
|
||||
//@}
|
||||
|
||||
}; // end class definition
|
||||
|
||||
typedef Line3<short> Line3s;
|
||||
|
|
|
@ -25,8 +25,8 @@
|
|||
|
||||
$Log: not supported by cvs2svn $
|
||||
|
||||
|
||||
|
||||
Revision 1.3 2004/03/10 15:27:18 tarini
|
||||
first version
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
|
@ -59,31 +59,48 @@ public:
|
|||
/// The point type
|
||||
typedef Point3<RayScalarType> PointType;
|
||||
|
||||
/// The point type
|
||||
/// The ray type
|
||||
typedef Ray3<RayScalarType,NORM> RayType;
|
||||
|
||||
private:
|
||||
|
||||
/// Origingin
|
||||
/// Origin
|
||||
PointType _ori;
|
||||
|
||||
/// Directionection (not necessarily normalized)
|
||||
/// Direction (not necessarily normalized, unless so specified by NORM)
|
||||
PointType _dir;
|
||||
|
||||
public:
|
||||
|
||||
/// Members to access the origin, direction
|
||||
//@{
|
||||
/** @name Members to access the origin or direction
|
||||
Direction() cannot be assigned directly.
|
||||
Use SetDirection() or Set() instead.
|
||||
**/
|
||||
///
|
||||
inline const PointType &Origin() const { return _ori; }
|
||||
inline const PointType &Direction() const { return _dir; }
|
||||
inline PointType &Origin() { return _ori; }
|
||||
inline PointType &Direction() {
|
||||
assert(!IsNormalized()); // Directionection can't be set for NORMALIZED Rays! Use SetDirection instead!
|
||||
return _dir;
|
||||
}
|
||||
/// The empty constructor
|
||||
inline const PointType &Direction() const { return _dir; }
|
||||
/// sets the origin
|
||||
inline void SetOrigin( const PointType & ori )
|
||||
{ _ori=ori; }
|
||||
/// sets the direction
|
||||
inline void SetDirection( const PointType & dir)
|
||||
{ _dir=dir; if (NORM) _dir.Normalize(); }
|
||||
/// sets origin and direction.
|
||||
inline void Set( const PointType & ori, const PointType & dir )
|
||||
{ SetOrigin(ori); SetDirection(dir); }
|
||||
//@}
|
||||
|
||||
//@{
|
||||
/** @name Constructors
|
||||
**/
|
||||
/// The empty constructor
|
||||
Ray3() {};
|
||||
/// The (origin, direction) constructor
|
||||
RayType(const PointType &ori, const PointType &dir) {SetOrigin(ori); SetDirection(dir);};
|
||||
//@}
|
||||
|
||||
/// Operator to compare two rays
|
||||
inline bool operator == ( RayType const & p ) const
|
||||
{ return _ori==p._ori && _dir==p._dir; }
|
||||
|
@ -95,16 +112,8 @@ public:
|
|||
{ if (NORM) return ScalarType((p-_ori)*_dir);
|
||||
else return ScalarType((p-_ori)*_dir/_dir.SquaredNorm());
|
||||
}
|
||||
inline bool IsNormalized() const {return NORM;};
|
||||
///set the origin
|
||||
inline void SetOrigin( const PointType & ori )
|
||||
{ _ori=ori; }
|
||||
///set the direction
|
||||
inline void SetDirection( const PointType & dir)
|
||||
{ _dir=dir; if (NORM) _dir.Normalize(); }
|
||||
///set both the origina and direction.
|
||||
inline void Set( const PointType & ori, const PointType & dir )
|
||||
{ SetOrigin(ori); SetDirection(dir); }
|
||||
/// returns wheter this type is normalized or not
|
||||
static bool IsNormalized() {return NORM;};
|
||||
/// calculates the point of parameter t on the ray.
|
||||
inline PointType P( const ScalarType t ) const
|
||||
{ return _ori + _dir * t; }
|
||||
|
@ -114,12 +123,18 @@ public:
|
|||
/// normalizes direction field (returns a Normalized Ray) - static version
|
||||
static Ray3<ScalarType,true> &Normalize(RayType &p)
|
||||
{ p.Normalize(); return *((Ray3<ScalarType,true>*)(&p));}
|
||||
/// importer for different ray types
|
||||
/// importer for different ray types (with any scalar type or normalization beaviour)
|
||||
template <class Q, bool K>
|
||||
inline void Import( const Ray3<Q,K> & b )
|
||||
{ _ori.Import( b.Origin() ); _dir.Import( b.Direction() );
|
||||
if ((NORM) && (!K)) _dir.Normalize();
|
||||
if ((NORM) && (!K)) _dir.Normalize();
|
||||
//printf("(=)%c->%c ",(!NORM)?'N':'n', NORM?'N':'n');
|
||||
}
|
||||
/// constructs a new ray importing it from an existing one
|
||||
template <class Q, bool K>
|
||||
static RayType Construct( const Ray3<Q,K> & b )
|
||||
{ RayType res; res.Import(b); return res;
|
||||
}
|
||||
PointType ClosestPoint(const PointType & p) const{
|
||||
return P(Projection(p));
|
||||
}
|
||||
|
@ -127,6 +142,39 @@ public:
|
|||
inline void Flip(){
|
||||
_dir=-_dir;
|
||||
};
|
||||
|
||||
//@{
|
||||
/** @name Linearity for 3d rays
|
||||
(operators +, -, *, /) so a ray can be set as a linear combination
|
||||
of several rays. Note that the result of any operation returns
|
||||
a non-normalized ray; however, the command r0 = r1*a + r2*b is licit
|
||||
even if r0,r1,r2 are normalized rays, as the normalization will
|
||||
take place within the final assignement operation.
|
||||
**/
|
||||
inline Ray3<ScalarType,false> operator + ( RayType const & p) const
|
||||
{return Ray3<ScalarType,false> ( _ori+p.Origin(), _dir+p.Direction() );}
|
||||
inline Ray3<ScalarType,false> operator - ( RayType const & p) const
|
||||
{return Ray3<ScalarType,false> ( _ori-p.Origin(), _dir-p.Direction() );}
|
||||
inline Ray3<ScalarType,false> operator * ( const ScalarType s ) const
|
||||
{return Ray3<ScalarType,false> ( _ori*s, _dir*s );}
|
||||
inline Ray3<ScalarType,false> operator / ( const ScalarType s ) const
|
||||
{ScalarType s0=((ScalarType)1.0)/s; return RayType( _ori*s0, _dir*s0 );}
|
||||
//@}
|
||||
|
||||
|
||||
//@{
|
||||
/** @name Automatic normalized to non-normalized
|
||||
"Ray3dN r0 = r1" is equivalent to
|
||||
"Ray3dN r0 = r1.Normalize()" if r1 is a Ray3d
|
||||
**/
|
||||
/// copy constructor that takes opposite beaviour
|
||||
RayType (const Ray3<ScalarType,!NORM > &r)
|
||||
{ Import(r); };
|
||||
/// assignment
|
||||
inline RayType & operator = ( Ray3<ScalarType,!NORM> const &r)
|
||||
{ Import(r); return *this; };
|
||||
//@}
|
||||
|
||||
}; // end class definition
|
||||
|
||||
typedef Ray3<short> Ray3s;
|
||||
|
|
|
@ -24,11 +24,10 @@
|
|||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
|
||||
Revision 1.1 2004/03/08 19:46:47 tarini
|
||||
First Version (tarini)
|
||||
|
||||
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
|
@ -78,13 +77,13 @@ public:
|
|||
Segment3() {};
|
||||
/// The (a,b) constructor
|
||||
SegmentType(const PointType &a, const PointType &b) { _p0=a; _p1=b; };
|
||||
/// Operator to compare two bounding box
|
||||
/// Operator to compare segments
|
||||
inline bool operator == ( SegmentType const & p ) const
|
||||
{ return _p0==p._p0 && _p1==p._p1; }
|
||||
/// Operator to dispare two bounding box
|
||||
/// Operator to dispare segments
|
||||
inline bool operator != ( SegmentType const & p ) const
|
||||
{ return _p0!=p._p0 || _p1!=p._p1; }
|
||||
/// initializes the bounding box
|
||||
/// initializes the segment with its extrema
|
||||
void Set( const PointType &a, const PointType &b)
|
||||
{ _p0=a; _p1=b;}
|
||||
/// calculates the point of parameter t on the segment.
|
||||
|
@ -101,20 +100,36 @@ public:
|
|||
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
|
||||
/// returns segment length
|
||||
SegmentType &Length()
|
||||
{ return (_p0 - _p1).Norm(); }
|
||||
/// return squared lenght
|
||||
/// return segment squared lenght
|
||||
SegmentType &SquaredLength()
|
||||
{ return (_p0 - _p1).SquaredNorm(); }
|
||||
/// flips: a-b becomes b-a
|
||||
void Flip()
|
||||
{ PointType t=_p0; _p0=_p1; _p1=t; }
|
||||
template <class Q>
|
||||
/// importer for different line types
|
||||
template <class Q>
|
||||
inline void Import( const Segment3<Q> & b )
|
||||
{ _p0.Import( b._p0); _p1.Import( b._p1);
|
||||
{ _p0.Import( b.P0() ); _p1.Import( b.P1() );
|
||||
}
|
||||
/// copy constructor (builds a new segment importing an existing one)
|
||||
template <class Q>
|
||||
static SegmentType Construct( const Segment3<Q> & b )
|
||||
{ return SegmentType(PointType::Construct(b.P0()), PointType::Construct(b.P1()));}
|
||||
|
||||
//@{
|
||||
/** @name Linearity for 3d segments (operators +, -, *, /) **/
|
||||
inline SegmentType operator + ( SegmentType const & p) const
|
||||
{return SegmentType( _p0+p.P0(), _p1+p.P1() );}
|
||||
inline SegmentType operator - ( SegmentType const & p) const
|
||||
{return SegmentType( _p0-p.P0(), _p1-p.P1() );}
|
||||
inline SegmentType operator * ( const ScalarType s ) const
|
||||
{return SegmentType( _p0*s, _p1*s );}
|
||||
inline SegmentType operator / ( const ScalarType s ) const
|
||||
{ScalarType s0=((ScalarType)1.0)/s; return SegmentType( _p0*s0, _p1*s0 );}
|
||||
//@}
|
||||
|
||||
}; // end class definition
|
||||
|
||||
|
@ -129,8 +144,9 @@ template <class ScalarType>
|
|||
Point3<ScalarType> ClosestPoint( Segment3<ScalarType> s, const Point3<ScalarType> & p)
|
||||
{
|
||||
ScalarType t = s.Projection(p);
|
||||
clamp (); if (s<0) s=0;
|
||||
return r.P(t);
|
||||
if (s<0) return s.P0();
|
||||
if (s>1) return s.P0();
|
||||
return s.P(t);
|
||||
}
|
||||
|
||||
/*@}*/
|
||||
|
|
Loading…
Reference in New Issue