[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 | |
---|
[257] | 53 | // ROI to flatten |
---|
[262] | 54 | osg::Vec4d modificationROI = osg::Vec4d( 48.336808, 48.370467, 11.736750, 11.835322 ); // roi_lat_min, roi_lat_max, roi_lon_min, roi_lon_max |
---|
[255] | 55 | |
---|
[257] | 56 | // Determine extend of the tile. |
---|
| 57 | double lat_min = h->getOrigin()[1]; |
---|
[258] | 58 | double lat_max = lat_min + h->getNumRows() * h->getYInterval(); |
---|
[257] | 59 | double lon_min = h->getOrigin()[0]; |
---|
[258] | 60 | double lon_max = lon_min + h->getNumColumns() * h->getXInterval(); |
---|
[255] | 61 | |
---|
[257] | 62 | // Check if tile is fully or partially inside ROI: |
---|
[262] | 63 | if(lat_max>modificationROI[0] && lat_min<modificationROI[1] // lat inside ROI? |
---|
| 64 | && lon_max>modificationROI[2] && lon_min<modificationROI[3] ) // lon inside ROI? |
---|
[257] | 65 | { |
---|
[262] | 66 | _technique->modifyHeightfield( modificationROI, h, osg::Vec4d(lat_min, lat_max, lon_min, lon_max) ); |
---|
[257] | 67 | } |
---|
[251] | 68 | } |
---|