[272] | 1 | /* -*-c++-*- osgVisual - Copyright (C) 2009-2011 Torben Dannhauer |
---|
| 2 | * |
---|
| 3 | * This library is based on OpenSceneGraph, open source and may be redistributed and/or modified under |
---|
| 4 | * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or |
---|
| 5 | * (at your option) any later version. The full license is in LICENSE file |
---|
| 6 | * included with this distribution, and on the openscenegraph.org website. |
---|
| 7 | * |
---|
| 8 | * osgVisual requires for some proprietary modules a license from the correspondig manufacturer. |
---|
| 9 | * You have to aquire licenses for all used proprietary modules. |
---|
| 10 | * |
---|
| 11 | * This library is distributed in the hope that it will be useful, |
---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 14 | * OpenSceneGraph Public License for more details. |
---|
| 15 | */ |
---|
| 16 | |
---|
[251] | 17 | #include "ModificationVisitor.h" |
---|
| 18 | |
---|
[256] | 19 | using namespace osgTerrain; |
---|
| 20 | |
---|
[252] | 21 | ModificationVisitor::ModificationVisitor(std::string extensionToSet) : _extensionToSet(extensionToSet) |
---|
[251] | 22 | { |
---|
| 23 | setTraversalMode( osg::NodeVisitor::TRAVERSE_ALL_CHILDREN ); |
---|
[265] | 24 | _technique = new rampedEllipsoidTechnique(); |
---|
[262] | 25 | |
---|
| 26 | // Set ROI to flatten and estimated height after correction |
---|
[265] | 27 | _technique->setModifiedHeight(600); // 450 |
---|
[251] | 28 | } |
---|
| 29 | |
---|
| 30 | void ModificationVisitor::apply( osg::Node& node ) |
---|
| 31 | { |
---|
[252] | 32 | //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: Node found: " << node.className() << std::endl; |
---|
[255] | 33 | |
---|
| 34 | if(std::string(node.className())=="TerrainTile") |
---|
| 35 | { |
---|
[256] | 36 | //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: Tile found" << std::endl; |
---|
| 37 | osgTerrain::TerrainTile* tile = dynamic_cast<osgTerrain::TerrainTile*>(&node); |
---|
| 38 | if(tile) |
---|
| 39 | modifyTile(tile); |
---|
[255] | 40 | } |
---|
| 41 | |
---|
[251] | 42 | traverse( node ); |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | void ModificationVisitor::apply( osg::PagedLOD& pNode ) |
---|
| 46 | { |
---|
[252] | 47 | //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: pagedLOD found: " << pNode.className() << std::endl; |
---|
| 48 | |
---|
| 49 | for( unsigned int i=0;i<pNode.getNumFileNames();i++) |
---|
| 50 | { |
---|
| 51 | //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: pagedLOD Child #" << i << std::endl; |
---|
| 52 | if(pNode.getFileName(i)!="") |
---|
| 53 | { |
---|
| 54 | //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: pagedLOD Child Name pre: " << pNode.getFileName(i) << std::endl; |
---|
| 55 | pNode.setFileName(i, pNode.getFileName(i)+_extensionToSet ); |
---|
| 56 | //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: pagedLOD Child Name post: " << newFileName << std::endl; |
---|
| 57 | } |
---|
| 58 | } |
---|
| 59 | |
---|
[251] | 60 | traverse( pNode ); |
---|
[255] | 61 | } |
---|
| 62 | |
---|
[256] | 63 | void ModificationVisitor::modifyTile(osgTerrain::TerrainTile* tile) |
---|
[255] | 64 | { |
---|
[258] | 65 | //OSG_NOTIFY( osg::ALWAYS ) << "ModificationVisitor::modifyTile() : Checking if tile is affected.." << std::endl; |
---|
[256] | 66 | HeightFieldLayer* hfl = dynamic_cast<HeightFieldLayer*>(tile->getElevationLayer()); |
---|
| 67 | osg::HeightField* h = hfl->getHeightField(); |
---|
[255] | 68 | |
---|
[270] | 69 | // Determine extend of the tile. |
---|
| 70 | region tileExtends( *h ); |
---|
| 71 | |
---|
[257] | 72 | // ROI to flatten |
---|
[269] | 73 | //region modificationROI = region( 48.336808, 48.370467, 11.736750, 11.835322 ); // roi_lat_min, roi_lat_max, roi_lon_min, roi_lon_max |
---|
| 74 | region modificationROI = region( 48.331808, 48.375467, 11.731750, 11.840322 ); // roi_lat_min, roi_lat_max, roi_lon_min, roi_lon_max |
---|
[255] | 75 | |
---|
[257] | 76 | // Check if tile is fully or partially inside ROI: |
---|
[269] | 77 | if( tileExtends.isFullOrPartiallyInside(modificationROI) ) |
---|
| 78 | _technique->modifyHeightfield( modificationROI, h, tileExtends ); |
---|
[251] | 79 | } |
---|