source: experimental/TerrainTest/ModificationVisitor.cpp @ 271

Last change on this file since 271 was 270, checked in by Torben Dannhauer, 13 years ago
File size: 2.3 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        // Determine extend of the tile.
54        region tileExtends( *h );
55
56        // ROI to flatten
57        //region modificationROI = region( 48.336808, 48.370467, 11.736750, 11.835322 );                // roi_lat_min, roi_lat_max, roi_lon_min, roi_lon_max
58        region modificationROI = region( 48.331808, 48.375467, 11.731750, 11.840322 );          // roi_lat_min, roi_lat_max, roi_lon_min, roi_lon_max
59
60        // Check if tile is fully or partially inside ROI:
61        if( tileExtends.isFullOrPartiallyInside(modificationROI) )
62                _technique->modifyHeightfield( modificationROI, h, tileExtends );
63}
Note: See TracBrowser for help on using the repository browser.