From Farshid Lashkari, removal of redundent spaces at the end of lines.
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
/* -*-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
|
||||
* 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
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
@@ -33,7 +33,7 @@ class IntersectionVisitor;
|
||||
class Intersector : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
enum CoordinateFrame
|
||||
{
|
||||
WINDOW,
|
||||
@@ -45,33 +45,33 @@ class Intersector : public osg::Referenced
|
||||
Intersector(CoordinateFrame cf=MODEL):
|
||||
_coordinateFrame(cf),
|
||||
_disabledCount(0) {}
|
||||
|
||||
|
||||
|
||||
|
||||
void setCoordinateFrame(CoordinateFrame cf) { _coordinateFrame = cf; }
|
||||
|
||||
|
||||
CoordinateFrame getCoordinateFrame() const { return _coordinateFrame; }
|
||||
|
||||
|
||||
virtual Intersector* clone(osgUtil::IntersectionVisitor& iv) = 0;
|
||||
|
||||
|
||||
virtual bool enter(const osg::Node& node) = 0;
|
||||
|
||||
|
||||
virtual void leave() = 0;
|
||||
|
||||
|
||||
virtual void intersect(osgUtil::IntersectionVisitor& iv, osg::Drawable* drawable) = 0;
|
||||
|
||||
|
||||
virtual void reset() { _disabledCount = 0; }
|
||||
|
||||
|
||||
virtual bool containsIntersections() = 0;
|
||||
|
||||
|
||||
inline bool disabled() const { return _disabledCount!=0; }
|
||||
|
||||
|
||||
inline void incrementDisabledCount() { ++_disabledCount; }
|
||||
|
||||
|
||||
inline void decrementDisabledCount() { if (_disabledCount>0) --_disabledCount; }
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
CoordinateFrame _coordinateFrame;
|
||||
unsigned int _disabledCount;
|
||||
|
||||
@@ -83,38 +83,38 @@ class Intersector : public osg::Referenced
|
||||
class OSGUTIL_EXPORT IntersectorGroup : public Intersector
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
IntersectorGroup();
|
||||
|
||||
/** Add an Intersector. */
|
||||
void addIntersector(Intersector* intersector);
|
||||
|
||||
|
||||
typedef std::vector< osg::ref_ptr<Intersector> > Intersectors;
|
||||
|
||||
/** Get the list of intersector. */
|
||||
Intersectors& getIntersectors() { return _intersectors; }
|
||||
|
||||
/** Clear the list of intersectors.*/
|
||||
/** Clear the list of intersectors.*/
|
||||
void clear();
|
||||
|
||||
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();
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
Intersectors _intersectors;
|
||||
|
||||
|
||||
};
|
||||
|
||||
/** InteresectionVisitor is used to testing for intersections with the scene, traversing the scene using generic osgUtil::Intersector's to test against the scene.
|
||||
@@ -136,7 +136,7 @@ class OSGUTIL_EXPORT IntersectionVisitor : public osg::NodeVisitor
|
||||
|
||||
|
||||
IntersectionVisitor(Intersector* intersector=0, ReadCallback* readCallback=0);
|
||||
|
||||
|
||||
META_NodeVisitor("osgUtil","IntersectionVisitor")
|
||||
|
||||
virtual void reset();
|
||||
@@ -144,7 +144,7 @@ class OSGUTIL_EXPORT IntersectionVisitor : public osg::NodeVisitor
|
||||
|
||||
/** Set the intersector that will be used to intersect with the scene, and to store any hits that occur.*/
|
||||
void setIntersector(Intersector* intersector);
|
||||
|
||||
|
||||
/** Get the intersector that will be used to intersect with the scene, and to store any hits that occur.*/
|
||||
Intersector* getIntersector() { return _intersectorStack.empty() ? 0 : _intersectorStack.front().get(); }
|
||||
|
||||
@@ -154,10 +154,10 @@ class OSGUTIL_EXPORT IntersectionVisitor : public osg::NodeVisitor
|
||||
|
||||
/** Set whether the intersectors should use KdTrees when they are found on the scene graph.*/
|
||||
void setUseKdTreeWhenAvailable(bool useKdTrees) { _useKdTreesWhenAvailable = useKdTrees; }
|
||||
|
||||
|
||||
/** Set whether the intersectors should use KdTrees.*/
|
||||
bool getUseKdTreeWhenAvailable() const { return _useKdTreesWhenAvailable; }
|
||||
|
||||
|
||||
void setDoDummyTraversal(bool dummy) { _dummyTraversal = dummy; }
|
||||
bool getDoDummyTraversal() const { return _dummyTraversal; }
|
||||
|
||||
@@ -170,8 +170,8 @@ class OSGUTIL_EXPORT IntersectionVisitor : public osg::NodeVisitor
|
||||
|
||||
/** Get the const read callback.*/
|
||||
const ReadCallback* getReadCallback() const { return _readCallback.get(); }
|
||||
|
||||
|
||||
|
||||
|
||||
void pushWindowMatrix(osg::RefMatrix* matrix) { _windowStack.push_back(matrix); _eyePointDirty = true; }
|
||||
void pushWindowMatrix(osg::Viewport* viewport) { _windowStack.push_back(new osg::RefMatrix( viewport->computeWindowMatrix()) ); _eyePointDirty = true; }
|
||||
void popWindowMatrix() { _windowStack.pop_back(); _eyePointDirty = true; }
|
||||
@@ -189,7 +189,7 @@ class OSGUTIL_EXPORT IntersectionVisitor : public osg::NodeVisitor
|
||||
const osg::RefMatrix* getViewMatrix() const { return _viewStack.empty() ? 0 : _viewStack.back().get(); }
|
||||
|
||||
void pushModelMatrix(osg::RefMatrix* matrix) { _modelStack.push_back(matrix); _eyePointDirty = true; }
|
||||
void popModelMatrix() { _modelStack.pop_back(); _eyePointDirty = true; }
|
||||
void popModelMatrix() { _modelStack.pop_back(); _eyePointDirty = true; }
|
||||
osg::RefMatrix* getModelMatrix() { return _modelStack.empty() ? 0 : _modelStack.back().get(); }
|
||||
const osg::RefMatrix* getModelMatrix() const { return _modelStack.empty() ? 0 : _modelStack.back().get(); }
|
||||
|
||||
@@ -199,13 +199,13 @@ class OSGUTIL_EXPORT IntersectionVisitor : public osg::NodeVisitor
|
||||
|
||||
/** Get the reference eye point.*/
|
||||
const osg::Vec3& getReferenceEyePoint() const { return _referenceEyePoint; }
|
||||
|
||||
|
||||
/** Set the coordinate frame of the reference eye point.*/
|
||||
void setReferenceEyePointCoordinateFrame(Intersector::CoordinateFrame cf) { _referenceEyePointCoordinateFrame = cf; }
|
||||
|
||||
/** Get the coordinate frame of the reference eye point.*/
|
||||
Intersector::CoordinateFrame getReferenceEyePointCoordinateFrame() const { return _referenceEyePointCoordinateFrame; }
|
||||
|
||||
|
||||
|
||||
/** Get the eye point in the local coordinate frame a given traversal point.*/
|
||||
virtual osg::Vec3 getEyePoint() const;
|
||||
@@ -215,7 +215,7 @@ class OSGUTIL_EXPORT IntersectionVisitor : public osg::NodeVisitor
|
||||
USE_HIGHEST_LEVEL_OF_DETAIL,
|
||||
USE_EYE_POINT_FOR_LOD_LEVEL_SELECTION
|
||||
};
|
||||
|
||||
|
||||
/** Set the LOD selection scheme.*/
|
||||
void setLODSelectionMode(LODSelectionMode mode) { _lodSelectionMode = mode; }
|
||||
|
||||
@@ -237,9 +237,9 @@ class OSGUTIL_EXPORT IntersectionVisitor : public osg::NodeVisitor
|
||||
virtual void apply(osg::Transform& transform);
|
||||
virtual void apply(osg::Projection& projection);
|
||||
virtual void apply(osg::Camera& camera);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
inline bool enter(const osg::Node& node) { return _intersectorStack.empty() ? false : _intersectorStack.back()->enter(node); }
|
||||
inline void leave() { _intersectorStack.back()->leave(); }
|
||||
inline void intersect(osg::Drawable* drawable) { _intersectorStack.back()->intersect(*this, drawable); }
|
||||
@@ -251,9 +251,9 @@ class OSGUTIL_EXPORT IntersectionVisitor : public osg::NodeVisitor
|
||||
|
||||
bool _useKdTreesWhenAvailable;
|
||||
bool _dummyTraversal;
|
||||
|
||||
|
||||
osg::ref_ptr<ReadCallback> _readCallback;
|
||||
|
||||
|
||||
typedef std::list< osg::ref_ptr<osg::RefMatrix> > MatrixStack;
|
||||
MatrixStack _windowStack;
|
||||
MatrixStack _projectionStack;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
/* -*-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
|
||||
* 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
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
@@ -27,22 +27,22 @@ class OSGUTIL_EXPORT LineSegmentIntersector : public Intersector
|
||||
|
||||
/** Construct a LineSegmentIntersector the runs between the specified start and end points in MODEL coordinates. */
|
||||
LineSegmentIntersector(const osg::Vec3d& start, const osg::Vec3d& end);
|
||||
|
||||
|
||||
/** Construct a LineSegmentIntersector the runs between the specified start and end points in the specified coordinate frame. */
|
||||
LineSegmentIntersector(CoordinateFrame cf, const osg::Vec3d& start, const osg::Vec3d& end);
|
||||
|
||||
|
||||
/** Convenience constructor for supporting picking in WINDOW, or PROJECTION coordinates
|
||||
* In WINDOW coordinates creates a start value of (x,y,0) and end value of (x,y,1).
|
||||
* In PROJECTION coordinates (clip space cube) creates a start value of (x,y,-1) and end value of (x,y,1).
|
||||
* In VIEW and MODEL coordinates creates a start value of (x,y,0) and end value of (x,y,1).*/
|
||||
LineSegmentIntersector(CoordinateFrame cf, double x, double y);
|
||||
|
||||
|
||||
struct Intersection
|
||||
{
|
||||
Intersection():
|
||||
ratio(-1.0),
|
||||
primitiveIndex(0) {}
|
||||
|
||||
|
||||
bool operator < (const Intersection& rhs) const { return ratio < rhs.ratio; }
|
||||
|
||||
typedef std::vector<unsigned int> IndexList;
|
||||
@@ -57,22 +57,22 @@ class OSGUTIL_EXPORT LineSegmentIntersector : public Intersector
|
||||
IndexList indexList;
|
||||
RatioList ratioList;
|
||||
unsigned int primitiveIndex;
|
||||
|
||||
|
||||
const osg::Vec3d& getLocalIntersectPoint() const { return localIntersectionPoint; }
|
||||
osg::Vec3d getWorldIntersectPoint() const { return matrix.valid() ? localIntersectionPoint * (*matrix) : localIntersectionPoint; }
|
||||
|
||||
|
||||
const osg::Vec3& getLocalIntersectNormal() const { return localIntersectionNormal; }
|
||||
osg::Vec3 getWorldIntersectNormal() const { return matrix.valid() ? osg::Matrix::transform3x3(osg::Matrix::inverse(*matrix),localIntersectionNormal) : localIntersectionNormal; }
|
||||
};
|
||||
|
||||
|
||||
typedef std::multiset<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()); }
|
||||
|
||||
|
||||
inline void setStart(const osg::Vec3d& start) { _start = start; }
|
||||
inline const osg::Vec3d& getStart() const { return _start; }
|
||||
|
||||
@@ -82,19 +82,19 @@ class OSGUTIL_EXPORT LineSegmentIntersector : public Intersector
|
||||
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 !_intersections.empty(); }
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
bool intersects(const osg::BoundingSphere& bs);
|
||||
bool intersectAndClip(osg::Vec3d& s, osg::Vec3d& e,const osg::BoundingBox& bb);
|
||||
|
||||
@@ -102,9 +102,9 @@ class OSGUTIL_EXPORT LineSegmentIntersector : public Intersector
|
||||
|
||||
osg::Vec3d _start;
|
||||
osg::Vec3d _end;
|
||||
|
||||
|
||||
Intersections _intersections;
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
/* -*-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
|
||||
* 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
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
@@ -26,25 +26,25 @@ namespace osgUtil
|
||||
class OSGUTIL_EXPORT PlaneIntersector : public Intersector
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
/** Construct a PolytopeIntersector using speified polytope in MODEL coordinates.*/
|
||||
PlaneIntersector(const osg::Plane& plane, const osg::Polytope& boundingPolytope=osg::Polytope());
|
||||
|
||||
|
||||
/** Construct a PolytopeIntersector using speified polytope in specified coordinate frame.*/
|
||||
PlaneIntersector(CoordinateFrame cf, const osg::Plane& plane, const osg::Polytope& boundingPolytope=osg::Polytope());
|
||||
|
||||
struct Intersection
|
||||
{
|
||||
Intersection() {}
|
||||
|
||||
|
||||
bool operator < (const Intersection& rhs) const
|
||||
{
|
||||
if (polyline < rhs.polyline) return true;
|
||||
if (rhs.polyline < polyline) return false;
|
||||
|
||||
|
||||
if (nodePath < rhs.nodePath) return true;
|
||||
if (rhs.nodePath < nodePath ) return false;
|
||||
|
||||
|
||||
return (drawable < rhs.drawable);
|
||||
}
|
||||
|
||||
@@ -56,34 +56,34 @@ class OSGUTIL_EXPORT PlaneIntersector : public Intersector
|
||||
osg::ref_ptr<osg::Drawable> drawable;
|
||||
Polyline polyline;
|
||||
Attributes attributes;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
typedef std::vector<Intersection> Intersections;
|
||||
|
||||
|
||||
inline void insertIntersection(const Intersection& intersection) { getIntersections().push_back(intersection); }
|
||||
|
||||
inline Intersections& getIntersections() { return _parent ? _parent->_intersections : _intersections; }
|
||||
|
||||
|
||||
|
||||
void setRecordHeightsAsAttributes(bool flag) { _recordHeightsAsAttributes = flag; }
|
||||
|
||||
|
||||
bool getRecordHeightsAsAttributes() const { return _recordHeightsAsAttributes; }
|
||||
|
||||
void setEllipsoidModel(osg::EllipsoidModel* em) { _em = em; }
|
||||
|
||||
|
||||
const osg::EllipsoidModel* getEllipsoidModel() const { return _em.get(); }
|
||||
|
||||
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 !_intersections.empty(); }
|
||||
@@ -91,15 +91,15 @@ class OSGUTIL_EXPORT PlaneIntersector : public Intersector
|
||||
protected:
|
||||
|
||||
PlaneIntersector* _parent;
|
||||
|
||||
|
||||
bool _recordHeightsAsAttributes;
|
||||
osg::ref_ptr<osg::EllipsoidModel> _em;
|
||||
|
||||
osg::Plane _plane;
|
||||
osg::Polytope _polytope;
|
||||
|
||||
|
||||
Intersections _intersections;
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
/* -*-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
|
||||
* 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
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
@@ -71,9 +71,9 @@ class OSGUTIL_EXPORT PolytopeIntersector : public Intersector
|
||||
osg::Vec3 intersectionPoints[MaxNumIntesectionPoints];
|
||||
unsigned int primitiveIndex; ///< primitive index
|
||||
};
|
||||
|
||||
|
||||
typedef std::set<Intersection> Intersections;
|
||||
|
||||
|
||||
inline void insertIntersection(const Intersection& intersection) { getIntersections().insert(intersection); }
|
||||
|
||||
inline Intersections& getIntersections() { return _parent ? _parent->_intersections : _intersections; }
|
||||
@@ -100,13 +100,13 @@ class OSGUTIL_EXPORT PolytopeIntersector : public Intersector
|
||||
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 !_intersections.empty(); }
|
||||
@@ -121,7 +121,7 @@ class OSGUTIL_EXPORT PolytopeIntersector : public Intersector
|
||||
osg::Plane _referencePlane; ///< plane to use for sorting intersections
|
||||
|
||||
Intersections _intersections;
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
/* -*-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
|
||||
* 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
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
@@ -32,23 +32,23 @@ namespace LineSegmentIntersectorUtils
|
||||
_index(index),
|
||||
_normal(normal),
|
||||
_r1(r1),
|
||||
_v1(v1),
|
||||
_v1(v1),
|
||||
_r2(r2),
|
||||
_v2(v2),
|
||||
_v2(v2),
|
||||
_r3(r3),
|
||||
_v3(v3) {}
|
||||
|
||||
unsigned int _index;
|
||||
const osg::Vec3 _normal;
|
||||
float _r1;
|
||||
const osg::Vec3* _v1;
|
||||
const osg::Vec3* _v1;
|
||||
float _r2;
|
||||
const osg::Vec3* _v2;
|
||||
const osg::Vec3* _v2;
|
||||
float _r3;
|
||||
const osg::Vec3* _v3;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
TriangleIntersection& operator = (const TriangleIntersection&) { return *this; }
|
||||
};
|
||||
|
||||
@@ -246,18 +246,18 @@ Intersector* LineSegmentIntersector::clone(osgUtil::IntersectionVisitor& iv)
|
||||
osg::Matrix matrix;
|
||||
switch (_coordinateFrame)
|
||||
{
|
||||
case(WINDOW):
|
||||
case(WINDOW):
|
||||
if (iv.getWindowMatrix()) matrix.preMult( *iv.getWindowMatrix() );
|
||||
if (iv.getProjectionMatrix()) matrix.preMult( *iv.getProjectionMatrix() );
|
||||
if (iv.getViewMatrix()) matrix.preMult( *iv.getViewMatrix() );
|
||||
if (iv.getModelMatrix()) matrix.preMult( *iv.getModelMatrix() );
|
||||
break;
|
||||
case(PROJECTION):
|
||||
case(PROJECTION):
|
||||
if (iv.getProjectionMatrix()) matrix.preMult( *iv.getProjectionMatrix() );
|
||||
if (iv.getViewMatrix()) matrix.preMult( *iv.getViewMatrix() );
|
||||
if (iv.getModelMatrix()) matrix.preMult( *iv.getModelMatrix() );
|
||||
break;
|
||||
case(VIEW):
|
||||
case(VIEW):
|
||||
if (iv.getViewMatrix()) matrix.preMult( *iv.getViewMatrix() );
|
||||
if (iv.getModelMatrix()) matrix.preMult( *iv.getModelMatrix() );
|
||||
break;
|
||||
@@ -304,7 +304,7 @@ void LineSegmentIntersector::intersect(osgUtil::IntersectionVisitor& iv, osg::Dr
|
||||
++itr)
|
||||
{
|
||||
osg::KdTree::LineSegmentIntersection& lsi = *(itr);
|
||||
|
||||
|
||||
// get ratio in s,e range
|
||||
double ratio = lsi.ratio;
|
||||
|
||||
@@ -320,26 +320,26 @@ void LineSegmentIntersector::intersect(osgUtil::IntersectionVisitor& iv, osg::Dr
|
||||
hit.primitiveIndex = lsi.primitiveIndex;
|
||||
|
||||
hit.localIntersectionPoint = _start*(1.0-remap_ratio) + _end*remap_ratio;
|
||||
|
||||
|
||||
// OSG_NOTICE<<"KdTree: ratio="<<hit.ratio<<" ("<<hit.localIntersectionPoint<<")"<<std::endl;
|
||||
|
||||
|
||||
hit.localIntersectionNormal = lsi.intersectionNormal;
|
||||
|
||||
|
||||
hit.indexList.reserve(3);
|
||||
hit.ratioList.reserve(3);
|
||||
if (lsi.r0!=0.0f)
|
||||
if (lsi.r0!=0.0f)
|
||||
{
|
||||
hit.indexList.push_back(lsi.p0);
|
||||
hit.ratioList.push_back(lsi.r0);
|
||||
}
|
||||
|
||||
if (lsi.r1!=0.0f)
|
||||
|
||||
if (lsi.r1!=0.0f)
|
||||
{
|
||||
hit.indexList.push_back(lsi.p1);
|
||||
hit.ratioList.push_back(lsi.r1);
|
||||
}
|
||||
|
||||
if (lsi.r2!=0.0f)
|
||||
if (lsi.r2!=0.0f)
|
||||
{
|
||||
hit.indexList.push_back(lsi.p2);
|
||||
hit.ratioList.push_back(lsi.r2);
|
||||
@@ -348,7 +348,7 @@ void LineSegmentIntersector::intersect(osgUtil::IntersectionVisitor& iv, osg::Dr
|
||||
insertIntersection(hit);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -409,7 +409,7 @@ void LineSegmentIntersector::intersect(osgUtil::IntersectionVisitor& iv, osg::Dr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
insertIntersection(hit);
|
||||
|
||||
}
|
||||
@@ -419,14 +419,14 @@ void LineSegmentIntersector::intersect(osgUtil::IntersectionVisitor& iv, osg::Dr
|
||||
void LineSegmentIntersector::reset()
|
||||
{
|
||||
Intersector::reset();
|
||||
|
||||
|
||||
_intersections.clear();
|
||||
}
|
||||
|
||||
bool LineSegmentIntersector::intersects(const osg::BoundingSphere& bs)
|
||||
{
|
||||
// if bs not valid then return true based on the assumption that an invalid sphere is yet to be defined.
|
||||
if (!bs.valid()) return true;
|
||||
if (!bs.valid()) return true;
|
||||
|
||||
osg::Vec3d sm = _start - bs._center;
|
||||
double c = sm.length2()-bs._radius*bs._radius;
|
||||
@@ -582,9 +582,9 @@ bool LineSegmentIntersector::intersectAndClip(osg::Vec3d& s, osg::Vec3d& e,const
|
||||
s = s+(e-s)*(bb_max.z()-s.z())/(e.z()-s.z());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// OSG_NOTICE<<"clampped segment "<<s<<" "<<e<<std::endl;
|
||||
|
||||
|
||||
// if (s==e) return false;
|
||||
|
||||
return true;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
/* -*-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
|
||||
* 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
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace PlaneIntersectorUtils
|
||||
{
|
||||
typedef std::vector<osg::Vec4d> Polyline;
|
||||
Polyline _polyline;
|
||||
|
||||
|
||||
void reverse()
|
||||
{
|
||||
unsigned int s=0;
|
||||
@@ -37,32 +37,32 @@ namespace PlaneIntersectorUtils
|
||||
{
|
||||
std::swap(_polyline[s],_polyline[e]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
class PolylineConnector
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
typedef std::map<osg::Vec4d, osg::ref_ptr<RefPolyline> > PolylineMap;
|
||||
typedef std::vector< osg::ref_ptr<RefPolyline> > PolylineList;
|
||||
|
||||
|
||||
PolylineList _polylines;
|
||||
PolylineMap _startPolylineMap;
|
||||
PolylineMap _endPolylineMap;
|
||||
osg::ref_ptr<osg::EllipsoidModel> _em;
|
||||
|
||||
|
||||
|
||||
void add(const osg::Vec3d& v1, const osg::Vec3d& v2)
|
||||
{
|
||||
add(osg::Vec4d(v1,0.0), osg::Vec4d(v2,0.0));
|
||||
}
|
||||
|
||||
|
||||
void add(const osg::Vec4d& v1, const osg::Vec4d& v2)
|
||||
{
|
||||
if (v1==v2) return;
|
||||
|
||||
|
||||
PolylineMap::iterator v1_start_itr = _startPolylineMap.find(v1);
|
||||
PolylineMap::iterator v1_end_itr = _endPolylineMap.find(v1);
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace PlaneIntersectorUtils
|
||||
unsigned int v2_connections = 0;
|
||||
if (v2_start_itr != _startPolylineMap.end()) ++v2_connections;
|
||||
if (v2_end_itr != _endPolylineMap.end()) ++v2_connections;
|
||||
|
||||
|
||||
if (v1_connections==0) // v1 is no connected to anything.
|
||||
{
|
||||
if (v2_connections==0)
|
||||
@@ -130,15 +130,15 @@ namespace PlaneIntersectorUtils
|
||||
OSG_NOTICE<<"v1="<<v1<<" must connect to a start and an end - must have a loop!!!!!."<<std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
// v1 and v2 connect to existing lines, now need to fuse them together.
|
||||
bool v1_connected_to_start = v1_start_itr != _startPolylineMap.end();
|
||||
bool v1_connected_to_end = v1_end_itr != _endPolylineMap.end();
|
||||
|
||||
|
||||
bool v2_connected_to_start = v2_start_itr != _startPolylineMap.end();
|
||||
bool v2_connected_to_end = v2_end_itr != _endPolylineMap.end();
|
||||
|
||||
|
||||
if (v1_connected_to_start)
|
||||
{
|
||||
if (v2_connected_to_start)
|
||||
@@ -175,7 +175,7 @@ namespace PlaneIntersectorUtils
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void newline(const osg::Vec4d& v1, const osg::Vec4d& v2)
|
||||
{
|
||||
RefPolyline* polyline = new RefPolyline;
|
||||
@@ -184,7 +184,7 @@ namespace PlaneIntersectorUtils
|
||||
_startPolylineMap[v1] = polyline;
|
||||
_endPolylineMap[v2] = polyline;
|
||||
}
|
||||
|
||||
|
||||
void insertAtStart(const osg::Vec4d& v, PolylineMap::iterator v_start_itr)
|
||||
{
|
||||
// put v1 at the start of its poyline
|
||||
@@ -198,7 +198,7 @@ namespace PlaneIntersectorUtils
|
||||
_startPolylineMap.erase(v_start_itr);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void insertAtEnd(const osg::Vec4d& v, PolylineMap::iterator v_end_itr)
|
||||
{
|
||||
// put v1 at the end of its poyline
|
||||
@@ -229,11 +229,11 @@ namespace PlaneIntersectorUtils
|
||||
|
||||
// reverse the first polyline
|
||||
poly1->reverse();
|
||||
|
||||
|
||||
// add the second polyline to the first
|
||||
poly1->_polyline.insert( poly1->_polyline.end(),
|
||||
poly2->_polyline.begin(), poly2->_polyline.end() );
|
||||
|
||||
|
||||
_startPolylineMap[poly1->_polyline.front()] = poly1;
|
||||
_endPolylineMap[poly1->_polyline.back()] = poly1;
|
||||
|
||||
@@ -243,17 +243,17 @@ namespace PlaneIntersectorUtils
|
||||
{
|
||||
osg::ref_ptr<RefPolyline> end_poly = end_itr->second;
|
||||
osg::ref_ptr<RefPolyline> start_poly = start_itr->second;
|
||||
|
||||
|
||||
PolylineMap::iterator end_start_poly_itr = _endPolylineMap.find(start_poly->_polyline.back());
|
||||
|
||||
|
||||
// add start_poly to end of end_poly
|
||||
end_poly->_polyline.insert( end_poly->_polyline.end(),
|
||||
start_poly->_polyline.begin(), start_poly->_polyline.end() );
|
||||
|
||||
|
||||
// reassign the end of the start poly so that it now points to the merged end_poly
|
||||
end_start_poly_itr->second = end_poly;
|
||||
|
||||
|
||||
|
||||
// remove entries for the end of the end_poly and the start of the start_poly
|
||||
_endPolylineMap.erase(end_itr);
|
||||
_startPolylineMap.erase(start_itr);
|
||||
@@ -284,11 +284,11 @@ namespace PlaneIntersectorUtils
|
||||
|
||||
// reverse the first polyline
|
||||
poly2->reverse();
|
||||
|
||||
|
||||
// add the second polyline to the first
|
||||
poly1->_polyline.insert( poly1->_polyline.end(),
|
||||
poly2->_polyline.begin(), poly2->_polyline.end() );
|
||||
|
||||
|
||||
_startPolylineMap[poly1->_polyline.front()] = poly1;
|
||||
_endPolylineMap[poly1->_polyline.back()] = poly1;
|
||||
|
||||
@@ -347,7 +347,7 @@ namespace PlaneIntersectorUtils
|
||||
OSG_NOTICE<<"supposed to be doing a fuse..."<<std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
struct TriangleIntersector
|
||||
@@ -401,7 +401,7 @@ namespace PlaneIntersectorUtils
|
||||
osg::Plane& plane = *itr;
|
||||
double ds = distance(plane,vs);
|
||||
double de = distance(plane,ve);
|
||||
|
||||
|
||||
if (ds<0.0)
|
||||
{
|
||||
if (de<0.0)
|
||||
@@ -409,14 +409,14 @@ namespace PlaneIntersectorUtils
|
||||
// OSG_NOTICE<<"Discard segment "<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// OSG_NOTICE<<"Trim start vs="<<vs;
|
||||
|
||||
double div = 1.0/(de-ds);
|
||||
vs = vs*(de*div) - ve*(ds*div);
|
||||
|
||||
// OSG_NOTICE<<" after vs="<<vs<<std::endl;
|
||||
|
||||
|
||||
}
|
||||
else if (de<0.0)
|
||||
{
|
||||
@@ -426,14 +426,14 @@ namespace PlaneIntersectorUtils
|
||||
ve = ve*(ds*div) - vs*(de*div);
|
||||
|
||||
// OSG_NOTICE<<" after ve="<<ve<<std::endl;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
// OSG_NOTICE<<"Segment fine"<<std::endl;
|
||||
|
||||
_polylineConnector.add(vs,ve);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -443,25 +443,25 @@ namespace PlaneIntersectorUtils
|
||||
double d1 = _plane.distance(v1);
|
||||
double d2 = _plane.distance(v2);
|
||||
double d3 = _plane.distance(v3);
|
||||
|
||||
|
||||
unsigned int numBelow = 0;
|
||||
unsigned int numAbove = 0;
|
||||
unsigned int numOnPlane = 0;
|
||||
if (d1<0) ++numBelow;
|
||||
else if (d1>0) ++numAbove;
|
||||
else ++numOnPlane;
|
||||
|
||||
|
||||
if (d2<0) ++numBelow;
|
||||
else if (d2>0) ++numAbove;
|
||||
else ++numOnPlane;
|
||||
|
||||
|
||||
if (d3<0) ++numBelow;
|
||||
else if (d3>0) ++numAbove;
|
||||
else ++numOnPlane;
|
||||
|
||||
|
||||
// trivially discard triangles that are completely one side of the plane
|
||||
if (numAbove==3 || numBelow==3) return;
|
||||
|
||||
|
||||
_hit = true;
|
||||
|
||||
if (numOnPlane==3)
|
||||
@@ -487,15 +487,15 @@ namespace PlaneIntersectorUtils
|
||||
|
||||
osg::Vec4d v[2];
|
||||
unsigned int numIntersects = 0;
|
||||
|
||||
|
||||
osg::Vec4d p1(v1, v1.z());
|
||||
osg::Vec4d p2(v2, v2.z());
|
||||
osg::Vec4d p3(v3, v3.z());
|
||||
|
||||
|
||||
if (_em.valid())
|
||||
{
|
||||
double latitude, longitude, height;
|
||||
|
||||
|
||||
if (_matrix.valid())
|
||||
{
|
||||
osg::Vec3d tp = v1 * (*_matrix);
|
||||
@@ -550,7 +550,7 @@ namespace PlaneIntersectorUtils
|
||||
{
|
||||
OSG_NOTICE<<"!!! too many intersecting edges found !!!"<<std::endl;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
add(v[0],v[1]);
|
||||
@@ -600,18 +600,18 @@ Intersector* PlaneIntersector::clone(osgUtil::IntersectionVisitor& iv)
|
||||
osg::Matrix matrix;
|
||||
switch (_coordinateFrame)
|
||||
{
|
||||
case(WINDOW):
|
||||
case(WINDOW):
|
||||
if (iv.getWindowMatrix()) matrix.preMult( *iv.getWindowMatrix() );
|
||||
if (iv.getProjectionMatrix()) matrix.preMult( *iv.getProjectionMatrix() );
|
||||
if (iv.getViewMatrix()) matrix.preMult( *iv.getViewMatrix() );
|
||||
if (iv.getModelMatrix()) matrix.preMult( *iv.getModelMatrix() );
|
||||
break;
|
||||
case(PROJECTION):
|
||||
case(PROJECTION):
|
||||
if (iv.getProjectionMatrix()) matrix.preMult( *iv.getProjectionMatrix() );
|
||||
if (iv.getViewMatrix()) matrix.preMult( *iv.getViewMatrix() );
|
||||
if (iv.getModelMatrix()) matrix.preMult( *iv.getModelMatrix() );
|
||||
break;
|
||||
case(VIEW):
|
||||
case(VIEW):
|
||||
if (iv.getViewMatrix()) matrix.preMult( *iv.getViewMatrix() );
|
||||
if (iv.getModelMatrix()) matrix.preMult( *iv.getModelMatrix() );
|
||||
break;
|
||||
@@ -664,7 +664,7 @@ void PlaneIntersector::intersect(osgUtil::IntersectionVisitor& iv, osg::Drawable
|
||||
if (ti._hit)
|
||||
{
|
||||
Intersections& intersections = getIntersections();
|
||||
|
||||
|
||||
for(PlaneIntersectorUtils::PolylineConnector::PolylineList::iterator pitr = ti._polylineConnector._polylines.begin();
|
||||
pitr != ti._polylineConnector._polylines.end();
|
||||
++pitr)
|
||||
@@ -676,10 +676,10 @@ void PlaneIntersector::intersect(osgUtil::IntersectionVisitor& iv, osg::Drawable
|
||||
Intersection& new_intersection = intersections[pos];
|
||||
|
||||
new_intersection.matrix = iv.getModelMatrix();
|
||||
|
||||
|
||||
new_intersection.polyline.reserve((*pitr)->_polyline.size());
|
||||
if (_recordHeightsAsAttributes) new_intersection.attributes.reserve((*pitr)->_polyline.size());
|
||||
|
||||
|
||||
for(PlaneIntersectorUtils::RefPolyline::Polyline::iterator vitr = (*pitr)->_polyline.begin();
|
||||
vitr != (*pitr)->_polyline.end();
|
||||
++vitr)
|
||||
@@ -700,6 +700,6 @@ void PlaneIntersector::intersect(osgUtil::IntersectionVisitor& iv, osg::Drawable
|
||||
void PlaneIntersector::reset()
|
||||
{
|
||||
Intersector::reset();
|
||||
|
||||
|
||||
_intersections.clear();
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace PolytopeIntersectorUtils
|
||||
typedef osg::Polytope::PlaneList PlaneList;
|
||||
|
||||
/// a line defined by the intersection of two planes
|
||||
struct PlanesLine
|
||||
struct PlanesLine
|
||||
{
|
||||
PlanesLine(PlaneMask m, Vec3_type p, Vec3_type d) :
|
||||
mask(m), pos(p), dir(d) {}
|
||||
@@ -108,7 +108,7 @@ namespace PolytopeIntersectorUtils
|
||||
{
|
||||
const osg::Plane& plane=*it;
|
||||
if (selector_mask & inside_mask) continue;
|
||||
|
||||
|
||||
for (CandList_t::iterator pointIt=_candidates.begin(); pointIt!=_candidates.end(); ++pointIt)
|
||||
{
|
||||
PlaneMask& mask=pointIt->first;
|
||||
@@ -161,7 +161,7 @@ namespace PolytopeIntersectorUtils
|
||||
const bool d1IsNegative = (d1<0.0f);
|
||||
const bool d2IsNegative = (d2<0.0f);
|
||||
if (d1IsNegative && d2IsNegative) return; // line outside
|
||||
|
||||
|
||||
if (!d1IsNegative && !d2IsNegative)
|
||||
{
|
||||
inside_mask |= selector_mask;
|
||||
@@ -311,16 +311,16 @@ namespace PolytopeIntersectorUtils
|
||||
Vec3_type p=line.dir^e2;
|
||||
const value_type a=e1*p;
|
||||
if (osg::absolute(a)<eps()) continue;
|
||||
|
||||
|
||||
const value_type f=1.0f/a;
|
||||
const Vec3_type s=(line.pos-v1);
|
||||
const value_type u=f*(s*p);
|
||||
if (u<0.0f || u>1.0f) continue;
|
||||
|
||||
|
||||
const Vec3_type q=s^e1;
|
||||
const value_type v=f*(line.dir*q);
|
||||
if (v<0.0f || u+v>1.0f) continue;
|
||||
|
||||
|
||||
const value_type t=f*(e2*q);
|
||||
|
||||
_candidates.push_back(CandList_t::value_type(line.mask, line.pos+line.dir*t));
|
||||
@@ -344,10 +344,11 @@ namespace PolytopeIntersectorUtils
|
||||
++_index;
|
||||
return;
|
||||
}
|
||||
|
||||
this->operator()(v1,v2,v3,treatVertexDataAsTemporary);
|
||||
|
||||
|
||||
--_index;
|
||||
|
||||
|
||||
this->operator()(v1,v3,v4,treatVertexDataAsTemporary);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user