source: experimental/TerrainTest/ModificationVisitor.cpp @ 260

Last change on this file since 260 was 260, 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 ellipsoidTechnique();
9}
10
11void ModificationVisitor::apply( osg::Node& node )
12{
13        //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: Node found: " << node.className() << std::endl;
14
15        if(std::string(node.className())=="TerrainTile")
16        {
17                //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: Tile found" << std::endl;
18                osgTerrain::TerrainTile* tile = dynamic_cast<osgTerrain::TerrainTile*>(&node);
19                if(tile)
20                        modifyTile(tile);
21        }
22
23        traverse( node );
24}
25
26void ModificationVisitor::apply( osg::PagedLOD& pNode )
27{
28        //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: pagedLOD found: " << pNode.className() << std::endl;
29
30        for( unsigned int i=0;i<pNode.getNumFileNames();i++)
31        {
32                //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: pagedLOD Child #" << i << std::endl;
33                if(pNode.getFileName(i)!="")
34                {
35                        //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: pagedLOD Child Name pre: " << pNode.getFileName(i) << std::endl;
36                        pNode.setFileName(i, pNode.getFileName(i)+_extensionToSet );
37                        //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: pagedLOD Child Name post: " << newFileName << std::endl;
38                }
39        }
40
41        traverse( pNode );
42}
43
44void ModificationVisitor::modifyTile(osgTerrain::TerrainTile* tile)
45{
46        //OSG_NOTIFY( osg::ALWAYS ) << "ModificationVisitor::modifyTile() : Checking if tile is affected.." << std::endl;
47        HeightFieldLayer* hfl = dynamic_cast<HeightFieldLayer*>(tile->getElevationLayer());
48        osg::HeightField* h = hfl->getHeightField();
49
50        // ROI to flatten
51        double roi_lat_min = 48.336808;
52        double roi_lat_max = 48.370467;
53        double roi_lon_min = 11.736750;
54        double roi_lon_max = 11.835322;
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>roi_lat_min && lat_min<roi_lat_max                   // lat inside ROI
64                && lon_max>roi_lon_min && lon_min<roi_lon_max ) // lon inside ROI
65        {
66                technique->modifyHeightfield(h, lat_min, lat_max, lon_min, lon_max);
67        }
68}
Note: See TracBrowser for help on using the repository browser.