dd996a3289
forcing users to use osgDB::readRef*File() methods. The later is preferable as it closes a potential threading bug when using paging databases in conjunction with the osgDB::Registry Object Cache. This threading bug occurs when one thread gets an object from the Cache via an osgDB::read*File() call where only a pointer to the object is passed back, so taking a reference to the object is delayed till it gets reassigned to a ref_ptr<>, but at the same time another thread calls a flush of the Object Cache deleting this object as it's referenceCount is now zero. Using osgDB::readREf*File() makes sure the a ref_ptr<> is passed back and the referenceCount never goes to zero. To ensure the OSG builds when OSG_PROVIDE_READFILE is to OFF the many cases of osgDB::read*File() usage had to be replaced with a ref_ptr<> osgDB::readRef*File() usage. The avoid this change causing lots of other client code to be rewritten to handle the use of ref_ptr<> in place of C pointer I introduced a serious of templte methods in various class to adapt ref_ptr<> to the underly C pointer to be passed to old OSG API's, example of this is found in include/osg/Group: bool addChild(Node* child); // old method which can only be used with a Node* tempalte<class T> bool addChild(const osg::ref_ptr<T>& child) { return addChild(child.get()); } // adapter template method These changes together cover 149 modified files, so it's a large submission. This extent of changes are warrent to make use of the Object Cache and multi-threaded loaded more robust. git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@15164 16af8721-9629-0410-8352-f15c8da7e697
130 lines
5.3 KiB
C++
130 lines
5.3 KiB
C++
/* -*-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;
|
|
};
|
|
|
|
/** Helper class for setting up and acquiring line of sight intersections with terrain.
|
|
* By default assigns a osgSim::DatabaseCacheReadCallback that enables automatic loading
|
|
* of external PagedLOD tiles to ensure that the highest level of detail is used in intersections.
|
|
* This automatic loading of tiles is done by the intersection traversal that is done within
|
|
* the computeIntersections(..) method, so can result in long intersection times when external
|
|
* tiles have to be loaded.
|
|
* The external loading of tiles can be disabled by removing the read callback, this is done by
|
|
* calling the setDatabaseCacheReadCallback(DatabaseCacheReadCallback*) method with a value of 0.*/
|
|
class OSGSIM_EXPORT LineOfSight
|
|
{
|
|
public :
|
|
|
|
LineOfSight();
|
|
|
|
/** Clear the internal LOS List so it contains no line of sight tests.*/
|
|
void clear();
|
|
|
|
/** Add a line of sight test, consisting of start and end point. Returns the index number of the newly adding LOS test.*/
|
|
unsigned int addLOS(const osg::Vec3d& start, const osg::Vec3d& end);
|
|
|
|
/** Get the number of line of sight tests.*/
|
|
unsigned int getNumLOS() const { return _LOSList.size(); }
|
|
|
|
/** Set the start point of single line of sight test.*/
|
|
void setStartPoint(unsigned int i, const osg::Vec3d& start) { _LOSList[i]._start = start; }
|
|
|
|
/** Get the start point of single line of sight test.*/
|
|
const osg::Vec3d& getStartPoint(unsigned int i) const { return _LOSList[i]._start; }
|
|
|
|
/** Set the end point of single line of sight test.*/
|
|
void setEndPoint(unsigned int i, const osg::Vec3d& end) { _LOSList[i]._end = end; }
|
|
|
|
/** Get the end point of single line of sight test.*/
|
|
const osg::Vec3d& getEndPoint(unsigned int i) const { return _LOSList[i]._end; }
|
|
|
|
typedef std::vector<osg::Vec3d> Intersections;
|
|
|
|
/** Get the intersection points for a single line of sight test.*/
|
|
const Intersections& getIntersections(unsigned int i) const { return _LOSList[i]._intersections; }
|
|
|
|
/** Compute the LOS intersections with the specified scene graph.
|
|
* The results are all stored in the form of Intersections list, one per LOS test.*/
|
|
void computeIntersections(osg::Node* scene, osg::Node::NodeMask traversalMask=0xffffffff);
|
|
|
|
/** Compute the intersection between the specified scene graph and a single LOS start,end pair. Returns an IntersectionList, of all the points intersected.*/
|
|
static Intersections computeIntersections(osg::Node* scene, const osg::Vec3d& start, const osg::Vec3d& end, osg::Node::NodeMask traversalMask=0xffffffff);
|
|
|
|
|
|
/** 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 multiple LineOfSight or HeightAboveTerrain 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(); }
|
|
|
|
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
|