root/OpenSceneGraph/trunk/src/osgTerrain/TerrainTechnique.cpp @ 13041

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

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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 <osgTerrain/TerrainTechnique>
15#include <osgTerrain/TerrainTile>
16
17using namespace osgTerrain;
18
19/////////////////////////////////////////////////////////////////////////////////////
20//
21// TerrainNeighbours
22//
23TerrainNeighbours::TerrainNeighbours()
24{
25}
26
27TerrainNeighbours::~TerrainNeighbours()
28{
29    clear();
30}
31
32void TerrainNeighbours::addNeighbour(TerrainTile* tile)
33{
34    OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_neighboursMutex);
35    _neighbours.insert(tile);
36}
37
38void TerrainNeighbours::removeNeighbour(TerrainTile* tile)
39{
40    OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_neighboursMutex);
41    _neighbours.erase(tile);
42}
43
44void TerrainNeighbours::clear()
45{
46    OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_neighboursMutex);
47    _neighbours.clear();
48}
49
50
51bool TerrainNeighbours::containsNeighbour(TerrainTile* tile) const
52{
53    OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_neighboursMutex);
54    return _neighbours.count(tile)!=0;
55}
56
57/////////////////////////////////////////////////////////////////////////////////////
58//
59// TerrainTechnique
60//
61TerrainTechnique::TerrainTechnique():
62    _terrainTile(0)
63{
64    setThreadSafeRefUnref(true);
65}
66
67TerrainTechnique::TerrainTechnique(const TerrainTechnique& TerrainTechnique,const osg::CopyOp& copyop):
68    osg::Object(TerrainTechnique,copyop),
69    _terrainTile(0)
70{
71}
72
73TerrainTechnique::~TerrainTechnique()
74{
75}
76
77void TerrainTechnique::setTerrainTile(TerrainTile* tile)
78{
79    if (_terrainTile==tile) return;
80
81    _neighbours.clear();
82
83    _terrainTile = tile;
84}
85
86void TerrainTechnique::init(int dirtyMask, bool assumeMultiThreaded)
87{
88    OSG_NOTICE<<className()<<"::init(..) not implementated yet"<<std::endl;
89}
90
91void TerrainTechnique::update(osgUtil::UpdateVisitor* uv)
92{
93    OSG_NOTICE<<className()<<"::update(..) not implementated yet"<<std::endl;
94    if (_terrainTile) _terrainTile->osg::Group::traverse(*uv);
95}
96
97void TerrainTechnique::cull(osgUtil::CullVisitor* cv)
98{
99    OSG_NOTICE<<className()<<"::cull(..) not implementated yet"<<std::endl;
100    if (_terrainTile) _terrainTile->osg::Group::traverse(*cv);
101}
102
103void TerrainTechnique::cleanSceneGraph()
104{
105    OSG_NOTICE<<className()<<"::cleanSceneGraph(..) not implementated yet"<<std::endl;
106}
107
108void TerrainTechnique::traverse(osg::NodeVisitor& nv)
109{
110    if (!_terrainTile) return;
111
112    // if app traversal update the frame count.
113    if (nv.getVisitorType()==osg::NodeVisitor::UPDATE_VISITOR)
114    {
115        if (_terrainTile->getDirty()) _terrainTile->init(_terrainTile->getDirtyMask(), false);
116
117        osgUtil::UpdateVisitor* uv = dynamic_cast<osgUtil::UpdateVisitor*>(&nv);
118        if (uv)
119        {
120            update(uv);
121            return;
122        }
123
124    }
125    else if (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR)
126    {
127        osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv);
128        if (cv)
129        {
130            cull(cv);
131            return;
132        }
133    }
134
135    if (_terrainTile->getDirty())
136    {
137        _terrainTile->init(_terrainTile->getDirtyMask(), false);
138    }
139
140    // otherwise fallback to the Group::traverse()
141    _terrainTile->osg::Group::traverse(nv);
142}
Note: See TracBrowser for help on using the browser.