source: experimental/TerrainTest/ModificationVisitor.cpp @ 264

Last change on this file since 264 was 262, checked in by Torben Dannhauer, 13 years ago

introduced abstract "terrainModficationTechnique" base class. this class will be derived by every terrainTechnique, e.g. ellipsoidTechnique

File size: 2.5 KB
Line 
1#include "ModificationVisitor.h"
2
3using namespace osgTerrain;
4
5ModificationVisitor::ModificationVisitor(std::string extensionToSet) : _extensionToSet(extensionToSet)
6{
7        setTraversalMode( osg::NodeVisitor::TRAVERSE_ALL_CHILDREN );
8        _technique = new ellipsoidTechnique();
9
10        // Set ROI to flatten and estimated height after correction
11        _technique->setModifiedHeight(450);
12}
13
14void ModificationVisitor::apply( osg::Node& node )
15{
16        //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: Node found: " << node.className() << std::endl;
17
18        if(std::string(node.className())=="TerrainTile")
19        {
20                //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: Tile found" << std::endl;
21                osgTerrain::TerrainTile* tile = dynamic_cast<osgTerrain::TerrainTile*>(&node);
22                if(tile)
23                        modifyTile(tile);
24        }
25
26        traverse( node );
27}
28
29void ModificationVisitor::apply( osg::PagedLOD& pNode )
30{
31        //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: pagedLOD found: " << pNode.className() << std::endl;
32
33        for( unsigned int i=0;i<pNode.getNumFileNames();i++)
34        {
35                //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: pagedLOD Child #" << i << std::endl;
36                if(pNode.getFileName(i)!="")
37                {
38                        //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: pagedLOD Child Name pre: " << pNode.getFileName(i) << std::endl;
39                        pNode.setFileName(i, pNode.getFileName(i)+_extensionToSet );
40                        //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: pagedLOD Child Name post: " << newFileName << std::endl;
41                }
42        }
43
44        traverse( pNode );
45}
46
47void ModificationVisitor::modifyTile(osgTerrain::TerrainTile* tile)
48{
49        //OSG_NOTIFY( osg::ALWAYS ) << "ModificationVisitor::modifyTile() : Checking if tile is affected.." << std::endl;
50        HeightFieldLayer* hfl = dynamic_cast<HeightFieldLayer*>(tile->getElevationLayer());
51        osg::HeightField* h = hfl->getHeightField();
52
53        // ROI to flatten
54        osg::Vec4d modificationROI = osg::Vec4d( 48.336808, 48.370467, 11.736750, 11.835322 );          // roi_lat_min, roi_lat_max, roi_lon_min, roi_lon_max
55
56        // Determine extend of the tile.
57        double lat_min = h->getOrigin()[1];
58        double lat_max = lat_min + h->getNumRows() * h->getYInterval();
59        double lon_min = h->getOrigin()[0];
60        double lon_max = lon_min + h->getNumColumns() * h->getXInterval();
61
62        // Check if tile is fully or partially inside ROI:
63        if(lat_max>modificationROI[0] && lat_min<modificationROI[1]                     // lat inside ROI?
64                && lon_max>modificationROI[2] && lon_min<modificationROI[3] )   // lon inside ROI?
65        {
66                _technique->modifyHeightfield( modificationROI, h, osg::Vec4d(lat_min, lat_max, lon_min, lon_max) );
67        }
68}
Note: See TracBrowser for help on using the repository browser.