source: experimental/TerrainTest/ModificationVisitor.cpp @ 273

Last change on this file since 273 was 272, checked in by Torben Dannhauer, 14 years ago
File size: 3.1 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(600);     // 450
28}
29
30void ModificationVisitor::apply( osg::Node& node )
31{
32        //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: Node found: " << node.className() << std::endl;
33
34        if(std::string(node.className())=="TerrainTile")
35        {
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);
40        }
41
42        traverse( node );
43}
44
45void ModificationVisitor::apply( osg::PagedLOD& pNode )
46{
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
60        traverse( pNode );
61}
62
63void ModificationVisitor::modifyTile(osgTerrain::TerrainTile* tile)
64{
65        //OSG_NOTIFY( osg::ALWAYS ) << "ModificationVisitor::modifyTile() : Checking if tile is affected.." << std::endl;
66        HeightFieldLayer* hfl = dynamic_cast<HeightFieldLayer*>(tile->getElevationLayer());
67        osg::HeightField* h = hfl->getHeightField();
68
69        // Determine extend of the tile.
70        region tileExtends( *h );
71
72        // ROI to flatten
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
75
76        // Check if tile is fully or partially inside ROI:
77        if( tileExtends.isFullOrPartiallyInside(modificationROI) )
78                _technique->modifyHeightfield( modificationROI, h, tileExtends );
79}
Note: See TracBrowser for help on using the repository browser.