LineOfSight
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 OSGSIM_LINEOFSIGHT
#define OSGSIM_LINEOFSIGHT 1
#include <osgUtil/IntersectionVisitor>
#include <osgSim/Export>
namespace osgSim {
class OSGSIM_EXPORT DatabaseCacheReadCallback : public osgUtil::IntersectionVisitor::ReadCallback
{
public:
DatabaseCacheReadCallback();
void setMaximumNumOfFilesToCache(unsigned int maxNumFilesToCache) { _maxNumFilesToCache = maxNumFilesToCache; }
unsigned int getMaximumNumOfFilesToCache() const { return _maxNumFilesToCache; }
void clearDatabaseCache();
void pruneUnusedDatabaseCache();
virtual osg::ref_ptr<osg::Node> readNodeFile(const std::string& filename);
protected:
typedef std::map<std::string, osg::ref_ptr<osg::Node> > FileNameSceneMap;
unsigned int _maxNumFilesToCache;
OpenThreads::Mutex _mutex;
FileNameSceneMap _filenameSceneMap;
};
class OSGSIM_EXPORT LineOfSight
{
public :
LineOfSight();
void clear();
unsigned int addLOS(const osg::Vec3d& start, const osg::Vec3d& end);
unsigned int getNumLOS() const { return _LOSList.size(); }
void setStartPoint(unsigned int i, const osg::Vec3d& start) { _LOSList[i]._start = start; }
const osg::Vec3d& getStartPoint(unsigned int i) const { return _LOSList[i]._start; }
void setEndPoint(unsigned int i, const osg::Vec3d& end) { _LOSList[i]._end = end; }
const osg::Vec3d& getEndPoint(unsigned int i) const { return _LOSList[i]._end; }
typedef std::vector<osg::Vec3d> Intersections;
const Intersections& getIntersections(unsigned int i) const { return _LOSList[i]._intersections; }
void computeIntersections(osg::Node* scene, osg::Node::NodeMask traversalMask=0xffffffff);
static Intersections computeIntersections(osg::Node* scene, const osg::Vec3d& start, const osg::Vec3d& end, osg::Node::NodeMask traversalMask=0xffffffff);
void clearDatabaseCache() { if (_dcrc.valid()) _dcrc->clearDatabaseCache(); }
void setDatabaseCacheReadCallback(DatabaseCacheReadCallback* dcrc);
DatabaseCacheReadCallback* getDatabaseCacheReadCallback() { return _dcrc.get(); }
protected :
struct LOS
{
LOS(const osg::Vec3d& start, const osg::Vec3d& end):
_start(start),
_end(end) {}
osg::Vec3d _start;
osg::Vec3d _end;
Intersections _intersections;
};
typedef std::vector<LOS> LOSList;
LOSList _LOSList;
osg::ref_ptr<DatabaseCacheReadCallback> _dcrc;
osgUtil::IntersectionVisitor _intersectionVisitor;
};
}
#endif
IntersectionVisitor
OpenThreads::Mutex
This class provides an object-oriented thread mutex interface.
Definition Mutex:31
osgSim::DatabaseCacheReadCallback
Definition LineOfSight:24
osgSim::DatabaseCacheReadCallback::DatabaseCacheReadCallback
DatabaseCacheReadCallback()
osgSim::DatabaseCacheReadCallback::getMaximumNumOfFilesToCache
unsigned int getMaximumNumOfFilesToCache() const
Definition LineOfSight:29
osgSim::DatabaseCacheReadCallback::_mutex
OpenThreads::Mutex _mutex
Definition LineOfSight:42
osgSim::DatabaseCacheReadCallback::clearDatabaseCache
void clearDatabaseCache()
osgSim::DatabaseCacheReadCallback::_filenameSceneMap
FileNameSceneMap _filenameSceneMap
Definition LineOfSight:43
osgSim::DatabaseCacheReadCallback::pruneUnusedDatabaseCache
void pruneUnusedDatabaseCache()
osgSim::DatabaseCacheReadCallback::setMaximumNumOfFilesToCache
void setMaximumNumOfFilesToCache(unsigned int maxNumFilesToCache)
Definition LineOfSight:28
osgSim::DatabaseCacheReadCallback::_maxNumFilesToCache
unsigned int _maxNumFilesToCache
Definition LineOfSight:41
osgSim::DatabaseCacheReadCallback::readNodeFile
virtual osg::ref_ptr< osg::Node > readNodeFile(const std::string &filename)
osgSim::DatabaseCacheReadCallback::FileNameSceneMap
std::map< std::string, osg::ref_ptr< osg::Node > > FileNameSceneMap
Definition LineOfSight:39
osgSim::LineOfSight::_intersectionVisitor
osgUtil::IntersectionVisitor _intersectionVisitor
Definition LineOfSight:123
osgSim::LineOfSight::Intersections
std::vector< osg::Vec3d > Intersections
Definition LineOfSight:81
osgSim::LineOfSight::setDatabaseCacheReadCallback
void setDatabaseCacheReadCallback(DatabaseCacheReadCallback *dcrc)
osgSim::LineOfSight::getIntersections
const Intersections & getIntersections(unsigned int i) const
Definition LineOfSight:84
osgSim::LineOfSight::LineOfSight
LineOfSight()
osgSim::LineOfSight::getStartPoint
const osg::Vec3d & getStartPoint(unsigned int i) const
Definition LineOfSight:73
osgSim::LineOfSight::getDatabaseCacheReadCallback
DatabaseCacheReadCallback * getDatabaseCacheReadCallback()
Definition LineOfSight:103
osgSim::LineOfSight::addLOS
unsigned int addLOS(const osg::Vec3d &start, const osg::Vec3d &end)
osgSim::LineOfSight::_dcrc
osg::ref_ptr< DatabaseCacheReadCallback > _dcrc
Definition LineOfSight:122
osgSim::LineOfSight::setStartPoint
void setStartPoint(unsigned int i, const osg::Vec3d &start)
Definition LineOfSight:70
osgSim::LineOfSight::computeIntersections
static Intersections computeIntersections(osg::Node *scene, const osg::Vec3d &start, const osg::Vec3d &end, osg::Node::NodeMask traversalMask=0xffffffff)
osgSim::LineOfSight::LOSList
std::vector< LOS > LOSList
Definition LineOfSight:119
osgSim::LineOfSight::_LOSList
LOSList _LOSList
Definition LineOfSight:120
osgSim::LineOfSight::getEndPoint
const osg::Vec3d & getEndPoint(unsigned int i) const
Definition LineOfSight:79
osgSim::LineOfSight::computeIntersections
void computeIntersections(osg::Node *scene, osg::Node::NodeMask traversalMask=0xffffffff)
osgSim::LineOfSight::setEndPoint
void setEndPoint(unsigned int i, const osg::Vec3d &end)
Definition LineOfSight:76
osgSim::LineOfSight::clear
void clear()
osgSim::LineOfSight::clearDatabaseCache
void clearDatabaseCache()
Definition LineOfSight:95
osgSim::LineOfSight::getNumLOS
unsigned int getNumLOS() const
Definition LineOfSight:67
osgUtil::IntersectionVisitor
Definition IntersectionVisitor:152
osg::Node
Definition Node:72
osg::Node::NodeMask
unsigned int NodeMask
Definition Node:363
osg::Vec3d
Definition Vec3d:30
osg::ref_ptr
Definition ref_ptr:32
osgSim
Definition BlinkSequence:27
Export
OSGSIM_EXPORT
#define OSGSIM_EXPORT
Definition osgSim/Export:38
osgSim::LineOfSight::LOS::LOS
LOS(const osg::Vec3d &start, const osg::Vec3d &end)
Definition LineOfSight:109
osgSim::LineOfSight::LOS::_end
osg::Vec3d _end
Definition LineOfSight:115
osgSim::LineOfSight::LOS::_start
osg::Vec3d _start
Definition LineOfSight:114
osgSim::LineOfSight::LOS::_intersections
Intersections _intersections
Definition LineOfSight:116
osgUtil::IntersectionVisitor::ReadCallback
Definition IntersectionVisitor:161