source: experimental/TerrainTest/ModificationVisitor.cpp @ 269

Last change on this file since 269 was 269, checked in by Torben Dannhauer, 13 years ago
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 rampedEllipsoidTechnique();
9
10        // Set ROI to flatten and estimated height after correction
11        _technique->setModifiedHeight(600);     // 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        //region modificationROI = region( 48.336808, 48.370467, 11.736750, 11.835322 );                // roi_lat_min, roi_lat_max, roi_lon_min, roi_lon_max
55        region modificationROI = region( 48.331808, 48.375467, 11.731750, 11.840322 );          // roi_lat_min, roi_lat_max, roi_lon_min, roi_lon_max
56
57        // Determine extend of the tile.
58        region tileExtends;
59        tileExtends._lat_min = h->getOrigin()[1];
60        tileExtends._lat_max = tileExtends._lat_min + h->getNumRows() * h->getYInterval();
61        tileExtends._lon_min = h->getOrigin()[0];
62        tileExtends._lon_max = tileExtends._lon_min + h->getNumColumns() * h->getXInterval();
63
64        // Check if tile is fully or partially inside ROI:
65        if( tileExtends.isFullOrPartiallyInside(modificationROI) )
66                _technique->modifyHeightfield( modificationROI, h, tileExtends );
67}
Note: See TracBrowser for help on using the repository browser.