[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 ); |
---|
| 8 | } |
---|
| 9 | |
---|
| 10 | void ModificationVisitor::apply( osg::Node& node ) |
---|
| 11 | { |
---|
[252] | 12 | //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: Node found: " << node.className() << std::endl; |
---|
[255] | 13 | |
---|
| 14 | if(std::string(node.className())=="TerrainTile") |
---|
| 15 | { |
---|
[256] | 16 | //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: Tile found" << std::endl; |
---|
| 17 | osgTerrain::TerrainTile* tile = dynamic_cast<osgTerrain::TerrainTile*>(&node); |
---|
| 18 | if(tile) |
---|
| 19 | modifyTile(tile); |
---|
[255] | 20 | } |
---|
| 21 | |
---|
[251] | 22 | traverse( node ); |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | void ModificationVisitor::apply( osg::PagedLOD& pNode ) |
---|
| 26 | { |
---|
[252] | 27 | //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: pagedLOD found: " << pNode.className() << std::endl; |
---|
| 28 | |
---|
| 29 | for( unsigned int i=0;i<pNode.getNumFileNames();i++) |
---|
| 30 | { |
---|
| 31 | //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: pagedLOD Child #" << i << std::endl; |
---|
| 32 | if(pNode.getFileName(i)!="") |
---|
| 33 | { |
---|
| 34 | //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: pagedLOD Child Name pre: " << pNode.getFileName(i) << std::endl; |
---|
| 35 | pNode.setFileName(i, pNode.getFileName(i)+_extensionToSet ); |
---|
| 36 | //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: pagedLOD Child Name post: " << newFileName << std::endl; |
---|
| 37 | } |
---|
| 38 | } |
---|
| 39 | |
---|
[251] | 40 | traverse( pNode ); |
---|
[255] | 41 | } |
---|
| 42 | |
---|
[256] | 43 | void ModificationVisitor::modifyTile(osgTerrain::TerrainTile* tile) |
---|
[255] | 44 | { |
---|
[257] | 45 | //OSG_NOTIFY( osg::ALWAYS ) << "ModificationVisitor::modifyTile()" << std::endl; |
---|
[256] | 46 | HeightFieldLayer* hfl = dynamic_cast<HeightFieldLayer*>(tile->getElevationLayer()); |
---|
| 47 | osg::HeightField* h = hfl->getHeightField(); |
---|
[255] | 48 | |
---|
[257] | 49 | // ROI to flatten |
---|
| 50 | double dest_lat_min = 48.336808; |
---|
| 51 | double dest_lat_max = 48.370467; |
---|
| 52 | double dest_lon_min = 11.736750; |
---|
| 53 | double dest_lon_max = 11.835322; |
---|
[255] | 54 | |
---|
[257] | 55 | // Determine extend of the tile. |
---|
| 56 | int rows = h->getNumRows(); |
---|
| 57 | int cols = h->getNumColumns(); |
---|
| 58 | double lat_min = h->getOrigin()[1]; |
---|
| 59 | double lat_max = lat_min + rows * h->getYInterval(); |
---|
| 60 | double lon_min = h->getOrigin()[0]; |
---|
| 61 | double lon_max = lon_min + cols * h->getXInterval(); |
---|
[255] | 62 | |
---|
[257] | 63 | // Check if tile is fully or partially inside ROI: |
---|
| 64 | if(lat_max>dest_lat_min && lat_min<dest_lat_max // lat inside ROI |
---|
| 65 | && lon_max>dest_lon_min && lon_min<dest_lon_max ) // lon inside ROI |
---|
| 66 | { |
---|
| 67 | OSG_NOTIFY( osg::ALWAYS ) << "ModificationVisitor::modifyTile() :: affected Tile" << std::endl; |
---|
| 68 | OSG_NOTIFY( osg::ALWAYS ) << "LAT: " << lat_min << " | " << lat_max << std::endl; |
---|
| 69 | OSG_NOTIFY( osg::ALWAYS ) << "LON: " << lon_min << " | " << lon_max << std::endl; |
---|
[256] | 70 | |
---|
[257] | 71 | |
---|
| 72 | // calculate colum start/end and row start/end of affected vertices |
---|
| 73 | int startX=0,startY=0,endX=cols,endY=rows; |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | // modify height value of affected vertices |
---|
| 77 | h->setHeight( 0,0, 600); |
---|
| 78 | |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | |
---|
| 87 | //OSG_NOTIFY( osg::ALWAYS ) << "Origin: " << h->getOrigin()[0] << " | " << h->getOrigin()[1] << std::endl; |
---|
| 88 | //OSG_NOTIFY( osg::ALWAYS ) << "X-Intervall: " << h->getXInterval() << std::endl; |
---|
| 89 | //OSG_NOTIFY( osg::ALWAYS ) << "Y-Intervall: " << h->getYInterval() << std::endl; |
---|
| 90 | //if(dest_lat_min<=lat_min && lat_max<=dest_lat_max && dest_lon_min<=lon_min && lon_max<=dest_lon_max) |
---|
| 91 | //{ |
---|
| 92 | // OSG_NOTIFY( osg::ALWAYS ) << "ModificationVisitor::modifyTile() :: affected Tile" << std::endl; |
---|
| 93 | // OSG_NOTIFY( osg::ALWAYS ) << "LAT: " << lat_min << " | " << lat_max << std::endl; |
---|
| 94 | // OSG_NOTIFY( osg::ALWAYS ) << "LON: " << lon_min << " | " << lon_max << std::endl; |
---|
| 95 | |
---|
| 96 | // h->setHeight( 0,0, 1000); |
---|
| 97 | //} |
---|
| 98 | //OpenThreads::Thread::microSleep( 50000 ); |
---|
[251] | 99 | } |
---|