| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | #include <osgVolume/Volume> |
|---|
| 15 | #include <OpenThreads/ScopedLock> |
|---|
| 16 | |
|---|
| 17 | using namespace osgVolume; |
|---|
| 18 | |
|---|
| 19 | Volume::Volume() |
|---|
| 20 | { |
|---|
| 21 | } |
|---|
| 22 | |
|---|
| 23 | Volume::Volume(const Volume& ts, const osg::CopyOp& copyop): |
|---|
| 24 | osg::Group(ts,copyop) |
|---|
| 25 | { |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | Volume::~Volume() |
|---|
| 30 | { |
|---|
| 31 | OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex); |
|---|
| 32 | |
|---|
| 33 | for(VolumeTileSet::iterator itr = _volumeTileSet.begin(); |
|---|
| 34 | itr != _volumeTileSet.end(); |
|---|
| 35 | ++itr) |
|---|
| 36 | { |
|---|
| 37 | const_cast<VolumeTile*>(*itr)->_volume = 0; |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | _volumeTileSet.clear(); |
|---|
| 41 | _volumeTileMap.clear(); |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | void Volume::traverse(osg::NodeVisitor& nv) |
|---|
| 45 | { |
|---|
| 46 | Group::traverse(nv); |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | VolumeTile* Volume::getVolumeTile(const TileID& tileID) |
|---|
| 50 | { |
|---|
| 51 | OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex); |
|---|
| 52 | |
|---|
| 53 | VolumeTileMap::iterator itr = _volumeTileMap.find(tileID); |
|---|
| 54 | if (itr != _volumeTileMap.end()) return 0; |
|---|
| 55 | |
|---|
| 56 | return itr->second; |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | const VolumeTile* Volume::getVolumeTile(const TileID& tileID) const |
|---|
| 60 | { |
|---|
| 61 | OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex); |
|---|
| 62 | |
|---|
| 63 | VolumeTileMap::const_iterator itr = _volumeTileMap.find(tileID); |
|---|
| 64 | if (itr != _volumeTileMap.end()) return 0; |
|---|
| 65 | |
|---|
| 66 | return itr->second; |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | void Volume::dirtyRegisteredVolumeTiles() |
|---|
| 70 | { |
|---|
| 71 | OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex); |
|---|
| 72 | |
|---|
| 73 | for(VolumeTileSet::iterator itr = _volumeTileSet.begin(); |
|---|
| 74 | itr != _volumeTileSet.end(); |
|---|
| 75 | ++itr) |
|---|
| 76 | { |
|---|
| 77 | (const_cast<VolumeTile*>(*itr))->setDirty(true); |
|---|
| 78 | } |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | static unsigned int s_maxNumVolumeTiles = 0; |
|---|
| 82 | void Volume::registerVolumeTile(VolumeTile* volumeTile) |
|---|
| 83 | { |
|---|
| 84 | if (!volumeTile) return; |
|---|
| 85 | |
|---|
| 86 | OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex); |
|---|
| 87 | |
|---|
| 88 | if (volumeTile->getTileID().valid()) |
|---|
| 89 | { |
|---|
| 90 | _volumeTileMap[volumeTile->getTileID()] = volumeTile; |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | _volumeTileSet.insert(volumeTile); |
|---|
| 94 | |
|---|
| 95 | if (_volumeTileSet.size() > s_maxNumVolumeTiles) s_maxNumVolumeTiles = _volumeTileSet.size(); |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | void Volume::unregisterVolumeTile(VolumeTile* volumeTile) |
|---|
| 101 | { |
|---|
| 102 | if (!volumeTile) return; |
|---|
| 103 | |
|---|
| 104 | OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex); |
|---|
| 105 | |
|---|
| 106 | if (volumeTile->getTileID().valid()) |
|---|
| 107 | { |
|---|
| 108 | _volumeTileMap.erase(volumeTile->getTileID()); |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | _volumeTileSet.erase(volumeTile); |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | } |
|---|