[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 ); |
---|
[275] | 24 | _technique = new rampedEllipsoidTechnique(); |
---|
[262] | 25 | |
---|
| 26 | // Set ROI to flatten and estimated height after correction |
---|
[290] | 27 | _technique->setModifiedHeight(450); // 450 |
---|
[279] | 28 | |
---|
| 29 | ModificationManager::getInstance()->addTerrainToManage( new osgTerrain::Terrain() ); |
---|
[251] | 30 | } |
---|
| 31 | |
---|
| 32 | void ModificationVisitor::apply( osg::Node& node ) |
---|
| 33 | { |
---|
[252] | 34 | //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: Node found: " << node.className() << std::endl; |
---|
[255] | 35 | |
---|
| 36 | if(std::string(node.className())=="TerrainTile") |
---|
| 37 | { |
---|
[256] | 38 | //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: Tile found" << std::endl; |
---|
| 39 | osgTerrain::TerrainTile* tile = dynamic_cast<osgTerrain::TerrainTile*>(&node); |
---|
| 40 | if(tile) |
---|
| 41 | modifyTile(tile); |
---|
[255] | 42 | } |
---|
| 43 | |
---|
[251] | 44 | traverse( node ); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | void ModificationVisitor::apply( osg::PagedLOD& pNode ) |
---|
| 48 | { |
---|
[252] | 49 | //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: pagedLOD found: " << pNode.className() << std::endl; |
---|
| 50 | |
---|
| 51 | for( unsigned int i=0;i<pNode.getNumFileNames();i++) |
---|
| 52 | { |
---|
| 53 | //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: pagedLOD Child #" << i << std::endl; |
---|
| 54 | if(pNode.getFileName(i)!="") |
---|
| 55 | { |
---|
| 56 | //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: pagedLOD Child Name pre: " << pNode.getFileName(i) << std::endl; |
---|
| 57 | pNode.setFileName(i, pNode.getFileName(i)+_extensionToSet ); |
---|
| 58 | //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: pagedLOD Child Name post: " << newFileName << std::endl; |
---|
| 59 | } |
---|
| 60 | } |
---|
| 61 | |
---|
[251] | 62 | traverse( pNode ); |
---|
[255] | 63 | } |
---|
| 64 | |
---|
[256] | 65 | void ModificationVisitor::modifyTile(osgTerrain::TerrainTile* tile) |
---|
[255] | 66 | { |
---|
[258] | 67 | //OSG_NOTIFY( osg::ALWAYS ) << "ModificationVisitor::modifyTile() : Checking if tile is affected.." << std::endl; |
---|
[256] | 68 | HeightFieldLayer* hfl = dynamic_cast<HeightFieldLayer*>(tile->getElevationLayer()); |
---|
| 69 | osg::HeightField* h = hfl->getHeightField(); |
---|
[255] | 70 | |
---|
[270] | 71 | // Determine extend of the tile. |
---|
| 72 | region tileExtends( *h ); |
---|
| 73 | |
---|
[257] | 74 | // ROI to flatten |
---|
[275] | 75 | //region modificationROI = region( 48.336808, 48.370467, 11.736750, 11.835322 ); // roi_lat_min, roi_lat_max, roi_lon_min, roi_lon_max // MUC |
---|
| 76 | region modificationROI = region( 48.331808, 48.375467, 11.731750, 11.840322 ); // roi_lat_min, roi_lat_max, roi_lon_min, roi_lon_max // MUC in größer wegen Rampe. |
---|
| 77 | //region modificationROI = region( 30.0, 50.0, 9.0, 15.0 ); // roi_lat_min, roi_lat_max, roi_lon_min, roi_lon_max // Large ROI für Bluemarble. |
---|
[255] | 78 | |
---|
[257] | 79 | // Check if tile is fully or partially inside ROI: |
---|
[269] | 80 | if( tileExtends.isFullOrPartiallyInside(modificationROI) ) |
---|
| 81 | _technique->modifyHeightfield( modificationROI, h, tileExtends ); |
---|
[251] | 82 | } |
---|