[251] | 1 | #include "ModificationVisitor.h" |
---|
| 2 | |
---|
[256] | 3 | using namespace osgTerrain; |
---|
| 4 | |
---|
[252] | 5 | ModificationVisitor::ModificationVisitor(std::string extensionToSet) : _extensionToSet(extensionToSet) |
---|
[251] | 6 | { |
---|
| 7 | setTraversalMode( osg::NodeVisitor::TRAVERSE_ALL_CHILDREN ); |
---|
[265] | 8 | _technique = new rampedEllipsoidTechnique(); |
---|
[262] | 9 | |
---|
| 10 | // Set ROI to flatten and estimated height after correction |
---|
[265] | 11 | _technique->setModifiedHeight(600); // 450 |
---|
[251] | 12 | } |
---|
| 13 | |
---|
| 14 | void ModificationVisitor::apply( osg::Node& node ) |
---|
| 15 | { |
---|
[252] | 16 | //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: Node found: " << node.className() << std::endl; |
---|
[255] | 17 | |
---|
| 18 | if(std::string(node.className())=="TerrainTile") |
---|
| 19 | { |
---|
[256] | 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); |
---|
[255] | 24 | } |
---|
| 25 | |
---|
[251] | 26 | traverse( node ); |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | void ModificationVisitor::apply( osg::PagedLOD& pNode ) |
---|
| 30 | { |
---|
[252] | 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 | |
---|
[251] | 44 | traverse( pNode ); |
---|
[255] | 45 | } |
---|
| 46 | |
---|
[256] | 47 | void ModificationVisitor::modifyTile(osgTerrain::TerrainTile* tile) |
---|
[255] | 48 | { |
---|
[258] | 49 | //OSG_NOTIFY( osg::ALWAYS ) << "ModificationVisitor::modifyTile() : Checking if tile is affected.." << std::endl; |
---|
[256] | 50 | HeightFieldLayer* hfl = dynamic_cast<HeightFieldLayer*>(tile->getElevationLayer()); |
---|
| 51 | osg::HeightField* h = hfl->getHeightField(); |
---|
[255] | 52 | |
---|
[270] | 53 | // Determine extend of the tile. |
---|
| 54 | region tileExtends( *h ); |
---|
| 55 | |
---|
[257] | 56 | // ROI to flatten |
---|
[269] | 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 |
---|
[255] | 59 | |
---|
[257] | 60 | // Check if tile is fully or partially inside ROI: |
---|
[269] | 61 | if( tileExtends.isFullOrPartiallyInside(modificationROI) ) |
---|
| 62 | _technique->modifyHeightfield( modificationROI, h, tileExtends ); |
---|
[251] | 63 | } |
---|