PolytopeIntersector
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library 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
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGUTIL_POLYTOPEINTERSECTOR
#define OSGUTIL_POLYTOPEINTERSECTOR 1
#include <osgUtil/IntersectionVisitor>
namespace osgUtil
{
class OSGUTIL_EXPORT PolytopeIntersector : public Intersector
{
public:
PolytopeIntersector(const osg::Polytope& polytope);
PolytopeIntersector(CoordinateFrame cf, const osg::Polytope& polytope);
PolytopeIntersector(CoordinateFrame cf, double xMin, double yMin, double xMax, double yMax);
osg::Polytope& getPolytope() { return _polytope;}
const osg::Polytope& getPolytope() const { return _polytope;}
typedef osg::Plane::Vec3_type Vec3_type;
struct Intersection
{
Intersection():
distance(0.0),
maxDistance(0.0),
numIntersectionPoints(0),
primitiveIndex(0) {}
bool operator < (const Intersection& rhs) const
{
if (distance < rhs.distance) return true;
if (rhs.distance < distance) return false;
if (primitiveIndex < rhs.primitiveIndex) return true;
if (rhs.primitiveIndex < primitiveIndex) return false;
if (nodePath < rhs.nodePath) return true;
if (rhs.nodePath < nodePath ) return false;
return (drawable < rhs.drawable);
}
enum { MaxNumIntesectionPoints=6 };
double distance;
double maxDistance;
osg::NodePath nodePath;
osg::ref_ptr<osg::Drawable> drawable;
osg::ref_ptr<osg::RefMatrix> matrix;
Vec3_type localIntersectionPoint;
unsigned int numIntersectionPoints;
Vec3_type intersectionPoints[MaxNumIntesectionPoints];
unsigned int primitiveIndex;
};
typedef std::set<Intersection> Intersections;
inline void insertIntersection(const Intersection& intersection) { getIntersections().insert(intersection); }
inline Intersections& getIntersections() { return _parent ? _parent->_intersections : _intersections; }
inline Intersection getFirstIntersection() { Intersections& intersections = getIntersections(); return intersections.empty() ? Intersection() : *(intersections.begin()); }
enum {
POINT_PRIMITIVES = (1<<0),
LINE_PRIMITIVES = (1<<1),
TRIANGLE_PRIMITIVES = (1<<2),
ALL_PRIMITIVES = ( POINT_PRIMITIVES | LINE_PRIMITIVES | TRIANGLE_PRIMITIVES )
};
void setPrimitiveMask(unsigned int mask) { _primitiveMask = mask; }
unsigned int getPrimitiveMask() const { return _primitiveMask; }
inline void setReferencePlane(const osg::Plane& plane) { _referencePlane = plane; }
inline const osg::Plane& getReferencePlane() const { return _referencePlane; }
#ifdef OSG_USE_DEPRECATED_API
enum {
DimZero = POINT_PRIMITIVES,
DimOne = LINE_PRIMITIVES,
DimTwo = TRIANGLE_PRIMITIVES,
AllDims = ALL_PRIMITIVES
};
inline void setDimensionMask(unsigned int mask) { setPrimitiveMask(mask); }
inline unsigned int getDimensionMask() const { return getPrimitiveMask(); }
#endif
public:
virtual Intersector* clone(osgUtil::IntersectionVisitor& iv);
virtual bool enter(const osg::Node& node);
virtual void leave();
virtual void intersect(osgUtil::IntersectionVisitor& iv, osg::Drawable* drawable);
virtual void reset();
virtual bool containsIntersections() { return !getIntersections().empty(); }
protected:
PolytopeIntersector* _parent;
osg::Polytope _polytope;
unsigned int _primitiveMask;
osg::Plane _referencePlane;
Intersections _intersections;
};
}
#endif
IntersectionVisitor
osgUtil::IntersectionVisitor
Definition IntersectionVisitor:152
osgUtil::Intersector::CoordinateFrame
CoordinateFrame
Definition IntersectionVisitor:38
osgUtil::Intersector::Intersector
Intersector(CoordinateFrame cf=MODEL, IntersectionLimit il=NO_LIMIT)
Definition IntersectionVisitor:53
osgUtil::PolytopeIntersector::_referencePlane
osg::Plane _referencePlane
plane to use for sorting intersections
Definition PolytopeIntersector:149
osgUtil::PolytopeIntersector::PolytopeIntersector
PolytopeIntersector(CoordinateFrame cf, double xMin, double yMin, double xMax, double yMax)
osgUtil::PolytopeIntersector::enter
virtual bool enter(const osg::Node &node)
osgUtil::PolytopeIntersector::reset
virtual void reset()
osgUtil::PolytopeIntersector::Intersections
std::set< Intersection > Intersections
Definition PolytopeIntersector:81
osgUtil::PolytopeIntersector::setPrimitiveMask
void setPrimitiveMask(unsigned int mask)
Definition PolytopeIntersector:99
osgUtil::PolytopeIntersector::PolytopeIntersector
PolytopeIntersector(const osg::Polytope &polytope)
osgUtil::PolytopeIntersector::_primitiveMask
unsigned int _primitiveMask
mask which dimensions should be checked
Definition PolytopeIntersector:148
osgUtil::PolytopeIntersector::Vec3_type
osg::Plane::Vec3_type Vec3_type
Definition PolytopeIntersector:47
osgUtil::PolytopeIntersector::setReferencePlane
void setReferencePlane(const osg::Plane &plane)
Definition PolytopeIntersector:109
osgUtil::PolytopeIntersector::getPrimitiveMask
unsigned int getPrimitiveMask() const
Definition PolytopeIntersector:102
osgUtil::PolytopeIntersector::getPolytope
const osg::Polytope & getPolytope() const
Definition PolytopeIntersector:44
osgUtil::PolytopeIntersector::getFirstIntersection
Intersection getFirstIntersection()
Definition PolytopeIntersector:87
osgUtil::PolytopeIntersector::_intersections
Intersections _intersections
Definition PolytopeIntersector:151
osgUtil::PolytopeIntersector::getReferencePlane
const osg::Plane & getReferencePlane() const
Definition PolytopeIntersector:111
osgUtil::PolytopeIntersector::_parent
PolytopeIntersector * _parent
Definition PolytopeIntersector:144
osgUtil::PolytopeIntersector::_polytope
osg::Polytope _polytope
Definition PolytopeIntersector:146
osgUtil::PolytopeIntersector::containsIntersections
virtual bool containsIntersections()
Definition PolytopeIntersector:140
osgUtil::PolytopeIntersector::TRIANGLE_PRIMITIVES
@ TRIANGLE_PRIMITIVES
check for lines
Definition PolytopeIntersector:94
osgUtil::PolytopeIntersector::LINE_PRIMITIVES
@ LINE_PRIMITIVES
check for points
Definition PolytopeIntersector:93
osgUtil::PolytopeIntersector::POINT_PRIMITIVES
@ POINT_PRIMITIVES
Definition PolytopeIntersector:92
osgUtil::PolytopeIntersector::ALL_PRIMITIVES
@ ALL_PRIMITIVES
check for triangles and other primitives like quad, polygons that can be decomposed into triangles
Definition PolytopeIntersector:95
osgUtil::PolytopeIntersector::insertIntersection
void insertIntersection(const Intersection &intersection)
Definition PolytopeIntersector:83
osgUtil::PolytopeIntersector::PolytopeIntersector
PolytopeIntersector(CoordinateFrame cf, const osg::Polytope &polytope)
osgUtil::PolytopeIntersector::intersect
virtual void intersect(osgUtil::IntersectionVisitor &iv, osg::Drawable *drawable)
osgUtil::PolytopeIntersector::leave
virtual void leave()
osgUtil::PolytopeIntersector::getPolytope
osg::Polytope & getPolytope()
Definition PolytopeIntersector:41
osgUtil::PolytopeIntersector::getIntersections
Intersections & getIntersections()
Definition PolytopeIntersector:85
osgUtil::PolytopeIntersector::clone
virtual Intersector * clone(osgUtil::IntersectionVisitor &iv)
osg::Drawable
Definition Drawable:89
osg::Node
Definition Node:72
osg::Plane
A plane class. It can be used to represent an infinite plane.
Definition Plane:34
osg::Plane::Vec3_type
Vec3d Vec3_type
Definition Plane:46
osg::Polytope
Definition Polytope:26
osg::ref_ptr
Definition ref_ptr:32
osgUtil
Definition NodeVisitor:25
osg::NodePath
std::vector< Node * > NodePath
Definition Node:47
OSGUTIL_EXPORT
#define OSGUTIL_EXPORT
Definition osgUtil/Export:40
osgUtil::PolytopeIntersector::Intersection
Definition PolytopeIntersector:50
osgUtil::PolytopeIntersector::Intersection::localIntersectionPoint
Vec3_type localIntersectionPoint
center of all intersection points
Definition PolytopeIntersector:75
osgUtil::PolytopeIntersector::Intersection::matrix
osg::ref_ptr< osg::RefMatrix > matrix
Definition PolytopeIntersector:74
osgUtil::PolytopeIntersector::Intersection::numIntersectionPoints
unsigned int numIntersectionPoints
Definition PolytopeIntersector:76
osgUtil::PolytopeIntersector::Intersection::primitiveIndex
unsigned int primitiveIndex
primitive index
Definition PolytopeIntersector:78
osgUtil::PolytopeIntersector::Intersection::MaxNumIntesectionPoints
@ MaxNumIntesectionPoints
Definition PolytopeIntersector:68
osgUtil::PolytopeIntersector::Intersection::distance
double distance
distance from reference plane
Definition PolytopeIntersector:70
osgUtil::PolytopeIntersector::Intersection::intersectionPoints
Vec3_type intersectionPoints[MaxNumIntesectionPoints]
Definition PolytopeIntersector:77
osgUtil::PolytopeIntersector::Intersection::nodePath
osg::NodePath nodePath
Definition PolytopeIntersector:72
osgUtil::PolytopeIntersector::Intersection::maxDistance
double maxDistance
maximum distance of intersection points from reference plane
Definition PolytopeIntersector:71
osgUtil::PolytopeIntersector::Intersection::drawable
osg::ref_ptr< osg::Drawable > drawable
Definition PolytopeIntersector:73
osgUtil::PolytopeIntersector::Intersection::Intersection
Intersection()
Definition PolytopeIntersector:51