source: experimental/TerrainTest/ModificationVisitor.cpp @ 324

Last change on this file since 324 was 290, checked in by Torben Dannhauer, 14 years ago
File size: 3.4 KB
Line 
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
17#include "ModificationVisitor.h"
18
19using namespace osgTerrain;
20
21ModificationVisitor::ModificationVisitor(std::string extensionToSet) : _extensionToSet(extensionToSet)
22{
23        setTraversalMode( osg::NodeVisitor::TRAVERSE_ALL_CHILDREN );
24        _technique = new rampedEllipsoidTechnique();
25
26        // Set ROI to flatten and estimated height after correction
27        _technique->setModifiedHeight(450);     // 450
28
29        ModificationManager::getInstance()->addTerrainToManage( new osgTerrain::Terrain() );
30}
31
32void ModificationVisitor::apply( osg::Node& node )
33{
34        //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: Node found: " << node.className() << std::endl;
35
36        if(std::string(node.className())=="TerrainTile")
37        {
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);
42        }
43
44        traverse( node );
45}
46
47void ModificationVisitor::apply( osg::PagedLOD& pNode )
48{
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
62        traverse( pNode );
63}
64
65void ModificationVisitor::modifyTile(osgTerrain::TerrainTile* tile)
66{
67        //OSG_NOTIFY( osg::ALWAYS ) << "ModificationVisitor::modifyTile() : Checking if tile is affected.." << std::endl;
68        HeightFieldLayer* hfl = dynamic_cast<HeightFieldLayer*>(tile->getElevationLayer());
69        osg::HeightField* h = hfl->getHeightField();
70
71        // Determine extend of the tile.
72        region tileExtends( *h );
73
74        // ROI to flatten
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.
78
79        // Check if tile is fully or partially inside ROI:
80        if( tileExtends.isFullOrPartiallyInside(modificationROI) )
81                _technique->modifyHeightfield( modificationROI, h, tileExtends );
82}
Note: See TracBrowser for help on using the repository browser.