First Version (tarini)
This commit is contained in:
parent
7a5b65928b
commit
43f74f4627
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.1 2004/03/08 16:15:48 tarini
|
||||
first version (tarini)
|
||||
|
||||
|
||||
|
||||
****************************************************************************/
|
||||
|
@ -79,14 +82,14 @@ public:
|
|||
Line3() {};
|
||||
/// The (origin, direction) constructor
|
||||
LineType(const PointType &ori, const PointType &dir) { _ori=ori; _dir=dir; };
|
||||
/// Operator to compare two bounding box
|
||||
/// Operator to compare two lines
|
||||
inline bool operator == ( LineType const & p ) const
|
||||
{ return _ori==p._ori && _dir==p._dir; }
|
||||
/// Operator to dispare two bounding box
|
||||
/// Operator to dispare two lines
|
||||
inline bool operator != ( LineType const & p ) const
|
||||
{ return _ori!=p._ori || _dir!=p._dir; }
|
||||
/// initializes the bounding box
|
||||
inline PointType Projection( const PointType &p ) const
|
||||
/// Projects a point on the line
|
||||
inline ScalarType Projection( const PointType &p ) const
|
||||
{ ScalarType l = dire.SquaredNorm();
|
||||
return ScalarType((p-_ori)*_dir/l); }
|
||||
///set up of the line.
|
||||
|
@ -100,7 +103,11 @@ public:
|
|||
{ _dir.Normalize(); return *this;}
|
||||
static LineType &Normalize(LineType &p)
|
||||
{ p.Normalize(); return p;}
|
||||
|
||||
/// importer for different line types
|
||||
template <class Q>
|
||||
inline void Import( const Line3<Q> & b )
|
||||
{ _ori.Import( b._ori); _dir.Import( b._dir);
|
||||
}
|
||||
}; // end class definition
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,122 @@
|
|||
/****************************************************************************
|
||||
* 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_RAY3
|
||||
#define __VCGLIB_RAY3
|
||||
|
||||
#include <vcg/space/point3.h>
|
||||
|
||||
namespace vcg {
|
||||
|
||||
/** \addtogroup space */
|
||||
/*@{*/
|
||||
/**
|
||||
Templated class for 3D ray.
|
||||
This is the class for a semi-line in 3D space. A ray is stored just as origin and direction (Point3).
|
||||
@param RayScalarType (template parameter) Specifies the type of scalar used to represent coords.
|
||||
*/
|
||||
template <class RayScalarType >
|
||||
class Ray3
|
||||
{
|
||||
public:
|
||||
|
||||
/// The scalar type
|
||||
typedef RayScalarType ScalarType;
|
||||
|
||||
/// The point type
|
||||
typedef Point3<RayScalarType> PointType;
|
||||
|
||||
/// The point type
|
||||
typedef Ray3<RayScalarType> RayType;
|
||||
|
||||
private:
|
||||
|
||||
/// Origin
|
||||
PointType _ori;
|
||||
|
||||
/// Direction (not necessarily normalized)
|
||||
PointType _dir;
|
||||
|
||||
public:
|
||||
|
||||
/// Members to access the origin, direction
|
||||
inline const PointType &Ori() const { return _ori; }
|
||||
inline const PointType &Dir() const { return _dir; }
|
||||
inline PointType &Ori() { return _ori; }
|
||||
inline PointType &Dir() { return _dir; }
|
||||
/// The empty constructor
|
||||
Ray3() {};
|
||||
/// The (a,b) constructor
|
||||
RayType(const PointType &a, const PointType &b) { _p0=a; _p1=b; };
|
||||
/// Operator to compare two rays
|
||||
inline bool operator == ( LineType const & p ) const
|
||||
{ return _ori==p._ori && _dir==p._dir; }
|
||||
/// Operator to dispare two rays
|
||||
inline bool operator != ( LineType const & p ) const
|
||||
{ return _ori!=p._ori || _dir!=p._dir; }
|
||||
/// Projects a point on the ray (returns distance)
|
||||
/// projection exists iff result > 0
|
||||
inline ScalarType Projection( const PointType &p ) const
|
||||
{ ScalarType l = dire.SquaredNorm();
|
||||
return ScalarType((p-_ori)*_dir/l); }
|
||||
///set up of the line.
|
||||
void Set( const PointType & ori, const PointType & dir )
|
||||
{ _ori = ori; _dir=dir }
|
||||
/// calculates the point of parameter t on the ray.
|
||||
/// if t>0, point is on the ray
|
||||
inline PointType P( const ScalarType t ) const
|
||||
{ return orig + dire * t; }
|
||||
/// normalizes direction field
|
||||
LineType &Normalize()
|
||||
{ _dir.Normalize(); return *this;}
|
||||
static LineType &Normalize(LineType &p)
|
||||
{ p.Normalize(); return p;}
|
||||
/// importer for different Ray types
|
||||
template <class Q>
|
||||
inline void Import( const Ray3<Q> & b )
|
||||
{ _ori.Import( b._ori); _dir.Import( b._dir);
|
||||
}
|
||||
|
||||
}; // end class definition
|
||||
|
||||
|
||||
|
||||
typedef Ray3<short> Ray3s;
|
||||
typedef Ray3<int> Ray3i;
|
||||
typedef Ray3<float> Ray3f;
|
||||
typedef Ray3<double> Ray3d;
|
||||
|
||||
|
||||
/*@}*/
|
||||
|
||||
} // end namespace
|
||||
#endif
|
|
@ -0,0 +1,129 @@
|
|||
/****************************************************************************
|
||||
* 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 <vcg/space/point3.h>
|
||||
#include <vcg/space/box3.h>
|
||||
|
||||
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 SegmentScalarType >
|
||||
class Segment3
|
||||
{
|
||||
public:
|
||||
|
||||
/// The scalar type
|
||||
typedef SegmentScalarType ScalarType;
|
||||
|
||||
/// The point type
|
||||
typedef Point3<SegmentScalarType> PointType;
|
||||
|
||||
/// The point type
|
||||
typedef Segment3<SegmentScalarType> 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<ScalarType> BBox( ) const
|
||||
{ Box3<ScalarType> 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 <class Q>
|
||||
/// importer for different line types
|
||||
inline void Import( const Segment3<Q> & b )
|
||||
{ _p0.Import( b._p0); _p1.Import( b._p1);
|
||||
}
|
||||
|
||||
}; // end class definition
|
||||
|
||||
|
||||
|
||||
typedef Segment3<short> Segment3s;
|
||||
typedef Segment3<int> Segment3i;
|
||||
typedef Segment3<float> Segment3f;
|
||||
typedef Segment3<double> Segment3d;
|
||||
|
||||
|
||||
/*@}*/
|
||||
|
||||
} // end namespace
|
||||
#endif
|
Loading…
Reference in New Issue