1 /* -*-c++-*- */
2 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
3  * Copyright 2008-2010 Pelican Mapping
4  * http://osgearth.org
5  *
6  * osgEarth is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>
18  */
19 #include "DRoamNode"
20 #include "CubeManifold"
21 #include "GeodeticManifold"
22 #include <osgEarth/Cube>
23 #include <osgEarthDrivers/tms/TMSOptions>
24 
25 using namespace osgEarth::Drivers;
26 
27 #undef USE_GEODETIC_MANIFOLD
28 
DRoamNode(Map * map)29 DRoamNode::DRoamNode( Map* map ) :
30 _map( map )
31 {
32     this->setCullCallback( new MyCullCallback );
33     this->setUpdateCallback( new MyUpdateCallback );
34 
35     // TODO: provide the ellipsoid in the ctor (like with MapNode->Map)
36     this->setCoordinateSystem( "EPSG:4326" );
37     this->setFormat( "WKT" );
38     this->setEllipsoidModel( new osg::EllipsoidModel );
39 
40 #ifdef USE_GEODETIC_MANIFOLD
41     _manifold = new GeodeticManifold();
42 #else
43     _manifold = new CubeManifold();
44 #endif
45     _mesh = new MeshManager( _manifold.get(), _map.get() );
46 
47     _mesh->_maxActiveLevel = MAX_ACTIVE_LEVEL;
48 
49     this->setInitialBound( _manifold->initialBound() );
50 
51     this->addChild( _mesh->_amrGeode.get() );
52 
53     this->getOrCreateStateSet()->setMode( GL_LIGHTING, 0 );
54 }
55 
DRoamNode(const DRoamNode & rhs,const osg::CopyOp & op)56 DRoamNode::DRoamNode( const DRoamNode& rhs, const osg::CopyOp& op ) :
57 osg::CoordinateSystemNode( rhs, op ),
58 _manifold( rhs._manifold.get() )
59 {
60     //nop
61 }
62 
63 void
cull(osg::NodeVisitor * nv)64 DRoamNode::cull( osg::NodeVisitor* nv )
65 {
66     osgUtil::CullVisitor* cv = static_cast<osgUtil::CullVisitor*>( nv );
67 
68     // reset the drawable set list. we will populate it by traversing the
69     // manifold and collecting drawables that are visible. The new drawables
70     // list does not actually take effect until the next frame. So yes, the culling is
71     // one frame out of sync with the draw. We should probably think of a way to fix that.
72     //_mesh->_activeDrawables.clear();
73 
74     _mesh->_amrDrawList.clear();
75 
76     _manifold->cull( static_cast<osgUtil::CullVisitor*>( nv ) );
77 
78     // I know is not strictly kosher to modify the scene graph from the CULL traversal. But
79     // we need frame-coherence, and both the Geode and all Geometry's are marked with DYNAMIC
80     // data variance .. so hopefully this is safe.
81     _mesh->_amrGeom->setDrawList( _mesh->_amrDrawList );
82     _mesh->_amrGeode->dirtyBound();
83 }
84 
85 void
update(osg::NodeVisitor * nv)86 DRoamNode::update( osg::NodeVisitor* nv )
87 {
88     _mesh->update();
89 }
90