Changeset 275 for experimental
- Timestamp:
- Mar 20, 2011, 1:14:16 PM (14 years ago)
- Location:
- experimental/TerrainTest
- Files:
-
- 1 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
experimental/TerrainTest/ModificationManager.cpp
r272 r275 17 17 #include "ModificationManager.h" 18 18 19 #define USE_TERRAIN_PROTO_WORKAROUND USE_TERRAIN_PROTO_WORKAROUND 19 20 20 21 22 void ModificationManager::addTerrainToManage(osgTerrain::Terrain* terrain) 23 { 24 if(terrain) 25 managedTerrain.push_back(terrain); 26 } 27 28 bool ModificationManager::removeTerrainToManage(osgTerrain::Terrain* terrain) 29 { 30 for(unsigned int i=0;i<managedTerrain.size();i++) 31 { 32 if(managedTerrain[i] == terrain) 33 { 34 managedTerrain.erase(managedTerrain.begin()+i); 35 return true; 36 } 37 } 38 return false; 39 } 40 41 void ModificationManager::setGeometryTechniquePrototype( osgTerrain::GeometryTechnique* geomTechnique, osgTerrain::Terrain* terrain ) 42 { 43 if(!geomTechnique) // Remove the installed geometry technique 44 { 45 terrain->setTerrainTechniquePrototype( NULL ); 46 #ifdef USE_TERRAIN_PROTO_WORKAROUND 47 osgTerrain::TerrainTile::setTileLoadedCallback(NULL); 48 #endif 49 return; 50 } 51 52 53 terrain->setTerrainTechniquePrototype( geomTechnique ); 54 #ifdef USE_TERRAIN_PROTO_WORKAROUND 55 osg::ref_ptr<osgTerrain::myTileLoadedCallback> tlcb = new osgTerrain::myTileLoadedCallback( terrain); 56 osgTerrain::TerrainTile::setTileLoadedCallback(tlcb); 57 #endif 58 59 60 } 61 -
experimental/TerrainTest/ModificationManager.h
r272 r275 17 17 18 18 #include "region.h" 19 #include "myTileLoadedCallback.h" 20 #include "terrainModificationTechnique.h" 21 #include <osgTerrain/Terrain> 22 #include <osgTerrain/GeometryTechnique> 19 23 #include <osg/observer_ptr> 24 #include <vector> 20 25 21 26 27 28 29 /** 30 * \brief This class provides a management interface to control terrain modification. 31 * 32 * It is possible to modify preprocessed VirtualPLanetBuilder (VPB) Databases on the fly. 33 * The modification can be performed in two ways: 34 * a) Modifying only the tile data and using the standard geometryTechnique to mesh the drawable. 35 * b) Using an userdefined geometryTechnique to create other meshes than the regular triangle mesh. 36 * 37 * Currently the changes are made on run time but in the pseudo loader. This way the modification does not affect the frame rate but only the delay in the tile delivery to the rendering thread. 38 * 39 * @author Torben Dannhauer 40 * @date Mrz 2011 41 */ 22 42 class ModificationManager 23 43 { 24 44 public: 45 //! Destructor: Must be public to ensure the singleton can be cleand up at the end of the programm. 25 46 ~ModificationManager(){}; 26 47 48 /** 49 * \brief This function returns a reference to the singleton instance of the terrain manager. 50 * 51 * @return Reference to the singleton instance of the terrain manager. 52 */ 27 53 static ModificationManager* getInstance() {static ModificationManager instance; return &instance;} 28 54 29 //void addRoi(); 55 /** 56 * \brief This function adds a terrain class to the manager to be managed and accessible to terrain modifications. 57 * 58 * @param terrain : Terrain to manage. 59 */ 60 void addTerrainToManage(osgTerrain::Terrain* terrain); 30 61 31 private: 32 ModificationManager(){}; 33 34 ModificationManager(const ModificationManager& cc) {}; 62 /** 63 * \brief This functions removes a terrain class from the manager to stop it's managing. 64 * 65 * @param terrain : Terrain to remove. 66 * @return : True of the specified terrain was managed and is now removed. If the specified terrain was not managed it will return false. 67 */ 68 bool removeTerrainToManage(osgTerrain::Terrain* terrain); 35 69 36 70 37 71 72 //void addRoi(region modificationROI, terrainModificationTechnique* technique=NULL); 73 //bool removeRoi(region modificationROI); 74 75 void setGeometryTechniquePrototype( osgTerrain::GeometryTechnique* geomTechnique, osgTerrain::Terrain* terrain=NULL ); 76 77 78 private: 79 //! Constructor: Private to avoid that this class can be instantiated - it should only be usable as singleton. 80 ModificationManager(){}; 81 82 //! Copy-Constructor: Private to avoid that someone can create an class instance by copying the singleton instance. 83 ModificationManager(const ModificationManager& cc) {}; 84 85 //! Vector of all managed terrain pointers. 86 std::vector<osgTerrain::Terrain*> managedTerrain; 87 38 88 }; -
experimental/TerrainTest/ModificationVisitor.cpp
r274 r275 22 22 { 23 23 setTraversalMode( osg::NodeVisitor::TRAVERSE_ALL_CHILDREN ); 24 _technique = new ellipsoidTechnique();24 _technique = new rampedEllipsoidTechnique(); 25 25 26 26 // Set ROI to flatten and estimated height after correction … … 71 71 72 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 73 //region modificationROI = region( 48.336808, 48.370467, 11.736750, 11.835322 ); // roi_lat_min, roi_lat_max, roi_lon_min, roi_lon_max // MUC 74 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. 75 //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. 75 76 76 77 // Check if tile is fully or partially inside ROI: -
experimental/TerrainTest/ModificationVisitor.h
r274 r275 23 23 24 24 #include "ellipsoidTechnique.h" 25 #include " ellipsoidTechnique.h"25 #include "rampedEllipsoidTechnique.h" 26 26 27 27 … … 36 36 void modifyTile(osgTerrain::TerrainTile* tile); 37 37 std::string _extensionToSet; 38 osg::ref_ptr< ellipsoidTechnique> _technique;38 osg::ref_ptr<rampedEllipsoidTechnique> _technique; 39 39 40 40 }; -
experimental/TerrainTest/Plugins terrainmod/Plugins terrainmod.vcproj
r274 r275 192 192 </File> 193 193 <File 194 RelativePath="..\myTerrainTechnique.cpp" 195 > 196 </File> 197 <File 194 198 RelativePath="..\rampedEllipsoidTechnique.cpp" 195 199 > … … 226 230 </File> 227 231 <File 232 RelativePath="..\myTerrainTechnique.h" 233 > 234 </File> 235 <File 236 RelativePath="..\myTileLoadedCallback.h" 237 > 238 </File> 239 <File 228 240 RelativePath="..\rampedEllipsoidTechnique.h" 229 241 > -
experimental/TerrainTest/TerrainTest.vcproj
r250 r275 346 346 </File> 347 347 <File 348 RelativePath=".\myTileLoadedCallback.cpp"349 >350 </File>351 <File352 348 RelativePath=".\osgterrain.cpp" 353 349 > -
experimental/TerrainTest/myTerrainTechnique.cpp
r255 r275 32 32 h->setHeight( 0,0, 1000); 33 33 34 /* 34 35 ImageLayer* il = dynamic_cast<ImageLayer*>( getTerrainTile()->getColorLayer(0) ); 35 36 osg::Image* img = il->getImage(); 36 37 //img->setInternalTextureFormat( GL_RGBA ); 37 38 38 /*if( img->getPixelFormat() == GL_RGBA )39 if( img->getPixelFormat() == GL_RGBA ) 39 40 OSG_ALWAYS << "Format ist RGBA" << std::endl; 40 if( img->getPixelFormat() == GL_RGB )41 if( img->getPixelFormat() == GL_RGB ) 41 42 OSG_ALWAYS << "Format ist RGB" << std::endl; 42 43 if( img->getPixelFormat() == GL_COMPRESSED_RGB_S3TC_DXT1_EXT ) … … 44 45 45 46 46 47 //osg::ref_ptr<osg::Image> img2 = new osg::Image();48 //img2->setInternalTextureFormat( GL_RGBA );49 //OSG_ALWAYS << "test: " << std::hex << img->getPixelFormat() << std::endl;50 51 47 GeometryTechnique::init(dirtyMask, assumeMultiThreaded); 52 48 53 //getTerrainTile()->getLocator()-> 54 55 OpenThreads::Thread::microSleep( 50000 ); 49 //OpenThreads::Thread::microSleep( 50000 ); / To simulate some complex tile modification. 56 50 } 57 58 void myTerrainTechnique::ConvertImage(osg::ref_ptr<osg::Image> a_toImage, osg::ref_ptr<osg::Image> a_fromImage, GLenum a_pixelFormat, GLenum a_dataType)59 {60 GLenum dataType = a_fromImage -> getDataType();61 62 //setInternalTextureFormat( 0); // tmp63 a_toImage -> allocateImage(64 a_fromImage -> s(),65 a_fromImage -> t(),66 a_fromImage -> r(),67 a_pixelFormat, a_dataType, a_fromImage -> getPacking());68 69 //// Wenn Quelle und Ziel RGBA sind70 //if( a_toImage -> getPixelFormat() == GL_RGBA && a_fromImage -> getPixelFormat() == GL_RGBA)71 //{72 // unsigned nr = a_fromImage->t();73 // unsigned nc = a_fromImage->s();74 // for (unsigned r = 0; r < nr; ++r)75 // {76 // for (unsigned c = 0; c < nc; ++c)77 // {78 // unsigned char * fromPixelData = a_fromImage -> data(c, nr-r-1);79 // unsigned char * toPixelData = a_toImage -> data(c, nr-r-1);80 81 // // Copy r, g, b, a.82 // for( int component = 0; component < 4; ++ component)83 // {84 // My_OSG_Library::OSG_PixelComponent pixelComponent( a_fromImage -> getDataType(), fromPixelData, component /* r, g, b, a */);85 // pixelComponent.Store( a_toImage -> getDataType(), toPixelData, component);86 // }87 // }88 // }89 //}90 //else91 // Wenn Quelle RGB ist und Ziel RGBA92 //if( a_toImage -> getPixelFormat() == GL_RGBA && a_fromImage -> getPixelFormat() == GL_RGB)93 //{94 // unsigned nr = a_fromImage -> t();95 // unsigned nc = a_fromImage -> s();96 // for (unsigned r = 0; r < nr; ++r)97 // {98 // for (unsigned c = 0; c < nc; ++c)99 // {100 // unsigned char * fromPixelData = a_fromImage -> data(c, nr-r-1);101 // unsigned char * toPixelData = a_toImage -> data(c, nr-r-1);102 103 // // Copy r, g, b.104 // for( int component = 0; component < 3; ++ component)105 // {106 // My_OSG_Library::OSG_PixelComponent pixelComponent( a_fromImage -> getDataType(), fromPixelData, component /* r, g, b */);107 // pixelComponent.Store( a_toImage -> getDataType(), toPixelData, component);108 // }109 110 // // Initialize alpha to opaque.111 // My_OSG_Library::OSG_PixelComponent::One().Store( a_toImage -> getDataType(), toPixelData, 3);112 // }113 // }114 //}115 } -
experimental/TerrainTest/myTerrainTechnique.h
r172 r275 20 20 21 21 virtual void init(int dirtyMask, bool assumeMultiThreaded); 22 23 void ConvertImage(osg::ref_ptr<osg::Image> a_toImage, osg::ref_ptr<osg::Image> a_fromImage, GLenum a_pixelFormat, GLenum a_dataType);24 22 }; 25 23 -
experimental/TerrainTest/myTileLoadedCallback.h
r165 r275 1 1 #pragma once 2 2 #include <osgTerrain/TerrainTile> 3 #include "myTerrainTechnique.h" 4 3 5 4 6 namespace osgTerrain { 5 6 class Terrain;7 7 8 8 class myTileLoadedCallback : public TerrainTile::TileLoadedCallback 9 9 { 10 10 public: 11 myTileLoadedCallback(osgTerrain::Terrain* terrain); 12 virtual bool deferExternalLayerLoading() const; 13 virtual void loaded(osgTerrain::TerrainTile* tile, const osgDB::ReaderWriter::Options* options) const; 14 15 protected: 16 virtual ~myTileLoadedCallback(); 11 //! Constructor: Nothing to do. 12 myTileLoadedCallback() {}; 17 13 18 osg::ref_ptr<osgTerrain::Terrain> _terrain; 19 14 //! Destructor: Nothing to do. 15 virtual ~myTileLoadedCallback() {}; 16 17 /** 18 * \brief This function must be implemented. 19 * 20 * @return : Extrnal layer loding status. 21 */ 22 virtual bool deferExternalLayerLoading() const {return true;} 23 24 /** 25 * \brief This function is performed after every tile loading. 26 * 27 * It is used to install a custom geometryTechnique on every tile, because VPB databases older VPB 0.10 have a hardcoded geometryTechnique which ignores the GeometryTechniquePrototype of osgTerrain. 28 * 29 * @param tile : Loaded tile. 30 * @param options : Reader writer optins. Defined as interface, but in this class not used. 31 */ 32 virtual void loaded(osgTerrain::TerrainTile* tile, const osgDB::ReaderWriter::Options* options) const {tile->setTerrainTechnique( new osgTerrain::myTerrainTechnique() );}; 20 33 }; 21 34 22 } 35 } // Namespace end. -
experimental/TerrainTest/osgterrain.cpp
r171 r275 232 232 //terrain->setTerrainTechniquePrototype( myT ); 233 233 234 //// Manually set the terrain technque for a tile ( his example, the first found tile) works, but then the whole database has to be processed235 //osgTerrain::TerrainTile* tile = findTopMostNodeOfType<osgTerrain::TerrainTile>(rootnode);236 //if(tile)237 //{238 // tile->setTerrainTechnique( myT );239 //}240 234 241 235 // Use Tile load Callback 242 osg::ref_ptr<osgTerrain::myTileLoadedCallback> tlcb = new osgTerrain::myTileLoadedCallback( terrain);236 osg::ref_ptr<osgTerrain::myTileLoadedCallback> tlcb = new osgTerrain::myTileLoadedCallback(); 243 237 osgTerrain::TerrainTile::setTileLoadedCallback(tlcb); 244 238 -
experimental/TerrainTest/rampedEllipsoidTechnique.cpp
r274 r275 57 57 clampValue(Y_endCore, Y_start, Y_end); 58 58 clampValue(Y_endRamp, Y_start, Y_end); 59 OSG_NOTIFY( osg::ALWAYS ) << "Y_startRamp:" << Y_startRamp << " Y_startCore:" << Y_startCore << " Y_endCore:" << Y_endCore << " Y_endRamp:" << Y_endRamp << std::endl;59 //OSG_NOTIFY( osg::ALWAYS ) << "Y_startRamp:" << Y_startRamp << " Y_startCore:" << Y_startCore << " Y_endCore:" << Y_endCore << " Y_endRamp:" << Y_endRamp << std::endl; 60 60 61 61 // Lon … … 69 69 clampValue(X_endCore, X_start, X_end); 70 70 clampValue(X_endRamp, X_start, X_end); 71 OSG_NOTIFY( osg::ALWAYS ) << "X_startRamp:" << X_startRamp << " X_startCore:" << X_startCore << " X_endCore:" << X_endCore << " X_endRamp:" << X_endRamp << std::endl;71 //OSG_NOTIFY( osg::ALWAYS ) << "X_startRamp:" << X_startRamp << " X_startCore:" << X_startCore << " X_endCore:" << X_endCore << " X_endRamp:" << X_endRamp << std::endl; 72 72 73 73 // Modify height value of affected vertices in the core ROI … … 125 125 126 126 // Set height to calculated value 127 OSG_NOTIFY( osg::ALWAYS ) << "rampedEllipsoidTechnique: destination_height=" << destination_height << std::endl;127 //OSG_NOTIFY( osg::ALWAYS ) << "rampedEllipsoidTechnique: destination_height=" << destination_height << std::endl; 128 128 h->setHeight( x, y, destination_height); 129 129 }
Note: See TracChangeset
for help on using the changeset viewer.