root/OpenSceneGraph/trunk/src/osgVolume/Volume.cpp @ 13041

Revision 13041, 3.1 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#include <osgVolume/Volume>
15#include <OpenThreads/ScopedLock>
16
17using namespace osgVolume;
18
19Volume::Volume()
20{
21}
22
23Volume::Volume(const Volume& ts, const osg::CopyOp& copyop):
24    osg::Group(ts,copyop)
25{
26}
27
28
29Volume::~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
44void Volume::traverse(osg::NodeVisitor& nv)
45{
46    Group::traverse(nv);
47}
48
49VolumeTile* 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
59const 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
69void 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
81static unsigned int s_maxNumVolumeTiles = 0;
82void 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    // OSG_NOTICE<<"Volume::registerVolumeTile "<<volumeTile<<" total number of VolumeTile "<<_volumeTileSet.size()<<" max = "<<s_maxNumVolumeTiles<<std::endl;
98}
99
100void 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    // OSG_NOTICE<<"Volume::unregisterVolumeTile "<<volumeTile<<" total number of VolumeTile "<<_volumeTileSet.size()<<" max = "<<s_maxNumVolumeTiles<<std::endl;
114}
Note: See TracBrowser for help on using the browser.