Added beginnings of osgUtil::PlaneIntersector and osgSim::ElevationSlice
This commit is contained in:
98
include/osgSim/ElevationSlice
Normal file
98
include/osgSim/ElevationSlice
Normal file
@@ -0,0 +1,98 @@
|
||||
/* -*-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 OSGSIM_ELEVATIONSLICE
|
||||
#define OSGSIM_ELEVATIONSLICE 1
|
||||
|
||||
#include <osgUtil/IntersectionVisitor>
|
||||
|
||||
// include so we can get access to the DatabaseCacheReadCallback
|
||||
#include <osgSim/LineOfSight>
|
||||
|
||||
namespace osgSim {
|
||||
|
||||
/** Helper class for setting up and aquiring height above terrain intersections with terrain.*/
|
||||
class OSGSIM_EXPORT ElevationSlice
|
||||
{
|
||||
public :
|
||||
|
||||
|
||||
ElevationSlice();
|
||||
|
||||
/** Set the start point of the slice.*/
|
||||
void setStartPoint(const osg::Vec3d& startPoint) { _startPoint = startPoint; }
|
||||
|
||||
/** Get the start point of the slice.*/
|
||||
const osg::Vec3d& getStartPoint() const { return _startPoint; }
|
||||
|
||||
/** Set the end point of the slice.*/
|
||||
void setEndPoint(const osg::Vec3d& endPoint) { _endPoint = endPoint; }
|
||||
|
||||
/** Get the end point of the slice.*/
|
||||
const osg::Vec3d& getEndPoint() const { return _endPoint; }
|
||||
|
||||
|
||||
typedef std::vector<osg::Vec3d> Vec3dList;
|
||||
|
||||
/** Get the intersections in the form of a vector of Vec3d. */
|
||||
const Vec3dList& getIntersections() const { return _intersections; }
|
||||
|
||||
typedef std::pair<double,double> DistanceHeight;
|
||||
typedef std::vector<DistanceHeight> DistanceHeightList;
|
||||
|
||||
/** Get the intersections in the form a vector of pair<double,double> representing distance along the slice and height. */
|
||||
const DistanceHeightList& getDistanceHeightIntersections() const { return _distanceHeightIntersections; }
|
||||
|
||||
|
||||
/** Compute the intersections with the specified scene graph, the results are stored in vectors of Vec3d.
|
||||
* Note, if the topmost node is a CoordinateSystemNode then the input points are assumed to be geocentric,
|
||||
* with the up vector defined by the EllipsoidModel attached to the CoordinateSystemNode.
|
||||
* If the topmost node is not a CoordinateSystemNode then a local coordinates frame is assumed, with a local up vector. */
|
||||
void computeIntersections(osg::Node* scene);
|
||||
|
||||
/** Compute the vertical distance between the specified scene graph and a single HAT point. .*/
|
||||
static Vec3dList computeElevationSlice(osg::Node* scene, const osg::Vec3d& startPoint, const osg::Vec3d& endPoint);
|
||||
|
||||
|
||||
/** Clear the database cache.*/
|
||||
void clearDatabaseCache() { if (_dcrc.valid()) _dcrc->clearDatabaseCache(); }
|
||||
|
||||
/** Set the ReadCallback that does the reading of external PagedLOD models, and caching of loaded subgraphs.
|
||||
* Note, if you have mulitple LineOfSight or ElevationSlice objects in use at one time then you should share a single
|
||||
* DatabaseCacheReadCallback between all of them. */
|
||||
void setDatabaseCacheReadCallback(DatabaseCacheReadCallback* dcrc);
|
||||
|
||||
/** Get the ReadCallback that does the reading of external PagedLOD models, and caching of loaded subgraphs.*/
|
||||
DatabaseCacheReadCallback* getDatabaseCacheReadCallback() { return _dcrc.get(); }
|
||||
|
||||
/** Get the IntersectionVistor that does the intersection traversal over the scene.
|
||||
* Note, if you want to customized the traversal then you can use the IntersectionVisitor's method to alter its behavior. */
|
||||
osgUtil::IntersectionVisitor& getIntersectionVisitor() { return _intersectionVisitor; }
|
||||
|
||||
protected :
|
||||
|
||||
|
||||
osg::Vec3d _startPoint;
|
||||
osg::Vec3d _endPoint;
|
||||
Vec3dList _intersections;
|
||||
DistanceHeightList _distanceHeightIntersections;
|
||||
|
||||
osg::ref_ptr<DatabaseCacheReadCallback> _dcrc;
|
||||
osgUtil::IntersectionVisitor _intersectionVisitor;
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -215,6 +215,67 @@ class OSGUTIL_EXPORT PolytopeIntersector : public Intersector
|
||||
|
||||
};
|
||||
|
||||
/** Concrent class for implementing polytope intersections with the scene graph.
|
||||
* To be used in conjunction with IntersectionVisitor. */
|
||||
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 (nodePath < rhs.nodePath) return true;
|
||||
if (rhs.nodePath < nodePath ) return false;
|
||||
return (drawable < rhs.drawable);
|
||||
}
|
||||
|
||||
osg::NodePath nodePath;
|
||||
osg::ref_ptr<osg::Drawable> drawable;
|
||||
};
|
||||
|
||||
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()); }
|
||||
|
||||
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:
|
||||
|
||||
PlaneIntersector* _parent;
|
||||
|
||||
osg::Plane _plane;
|
||||
osg::Polytope _polytope;
|
||||
|
||||
Intersections _intersections;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/** Concrent class for passing multiple intersectors through the scene graph.
|
||||
* To be used in conjunction with IntersectionVisitor. */
|
||||
class OSGUTIL_EXPORT IntersectorGroup : public Intersector
|
||||
|
||||
Reference in New Issue
Block a user