Ignore:
Timestamp:
Mar 20, 2011, 1:14:16 PM (14 years ago)
Author:
Torben Dannhauer
Message:
 
Location:
experimental/TerrainTest
Files:
1 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • experimental/TerrainTest/ModificationManager.cpp

    r272 r275  
    1717#include "ModificationManager.h"
    1818
     19#define USE_TERRAIN_PROTO_WORKAROUND USE_TERRAIN_PROTO_WORKAROUND
    1920
    2021
     22void ModificationManager::addTerrainToManage(osgTerrain::Terrain* terrain)
     23{
     24        if(terrain)
     25                managedTerrain.push_back(terrain);
     26}
     27
     28bool 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
     41void 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  
    1717
    1818#include "region.h"
     19#include "myTileLoadedCallback.h"
     20#include "terrainModificationTechnique.h"
     21#include <osgTerrain/Terrain>
     22#include <osgTerrain/GeometryTechnique>
    1923#include <osg/observer_ptr>
     24#include <vector>
    2025
    2126
     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 */
    2242class ModificationManager
    2343{
    2444public:
     45        //! Destructor: Must be public to ensure the singleton can be cleand up at the end of the programm.
    2546        ~ModificationManager(){};
    2647
     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         */
    2753        static ModificationManager* getInstance() {static ModificationManager instance; return &instance;}
    2854
    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);
    3061
    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);
    3569
    3670
    3771
     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
     78private:
     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
    3888};
  • experimental/TerrainTest/ModificationVisitor.cpp

    r274 r275  
    2222{
    2323        setTraversalMode( osg::NodeVisitor::TRAVERSE_ALL_CHILDREN );
    24         _technique = new ellipsoidTechnique();
     24        _technique = new rampedEllipsoidTechnique();
    2525
    2626        // Set ROI to flatten and estimated height after correction
     
    7171
    7272        // 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.
    7576
    7677        // Check if tile is fully or partially inside ROI:
  • experimental/TerrainTest/ModificationVisitor.h

    r274 r275  
    2323
    2424#include "ellipsoidTechnique.h"
    25 #include "ellipsoidTechnique.h"
     25#include "rampedEllipsoidTechnique.h"
    2626
    2727
     
    3636        void modifyTile(osgTerrain::TerrainTile* tile);
    3737        std::string _extensionToSet;
    38         osg::ref_ptr<ellipsoidTechnique> _technique;
     38        osg::ref_ptr<rampedEllipsoidTechnique> _technique;
    3939
    4040};
  • experimental/TerrainTest/Plugins terrainmod/Plugins terrainmod.vcproj

    r274 r275  
    192192                        </File>
    193193                        <File
     194                                RelativePath="..\myTerrainTechnique.cpp"
     195                                >
     196                        </File>
     197                        <File
    194198                                RelativePath="..\rampedEllipsoidTechnique.cpp"
    195199                                >
     
    226230                        </File>
    227231                        <File
     232                                RelativePath="..\myTerrainTechnique.h"
     233                                >
     234                        </File>
     235                        <File
     236                                RelativePath="..\myTileLoadedCallback.h"
     237                                >
     238                        </File>
     239                        <File
    228240                                RelativePath="..\rampedEllipsoidTechnique.h"
    229241                                >
  • experimental/TerrainTest/TerrainTest.vcproj

    r250 r275  
    346346                        </File>
    347347                        <File
    348                                 RelativePath=".\myTileLoadedCallback.cpp"
    349                                 >
    350                         </File>
    351                         <File
    352348                                RelativePath=".\osgterrain.cpp"
    353349                                >
  • experimental/TerrainTest/myTerrainTechnique.cpp

    r255 r275  
    3232        h->setHeight( 0,0, 1000);
    3333
     34         /*
    3435         ImageLayer* il = dynamic_cast<ImageLayer*>( getTerrainTile()->getColorLayer(0) );
    3536         osg::Image* img = il->getImage();
    3637         //img->setInternalTextureFormat( GL_RGBA );
    3738
    38         /* if( img->getPixelFormat() == GL_RGBA )
     39          if( img->getPixelFormat() == GL_RGBA )
    3940                 OSG_ALWAYS << "Format ist RGBA" << std::endl;
    40          if( img->getPixelFormat() == GL_RGB )
     41          if( img->getPixelFormat() == GL_RGB )
    4142                 OSG_ALWAYS << "Format ist RGB" << std::endl;
    4243          if( img->getPixelFormat() == GL_COMPRESSED_RGB_S3TC_DXT1_EXT )
     
    4445
    4546         
    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 
    5147    GeometryTechnique::init(dirtyMask, assumeMultiThreaded);
    5248
    53         //getTerrainTile()->getLocator()->
    54 
    55         OpenThreads::Thread::microSleep( 50000 );
     49        //OpenThreads::Thread::microSleep( 50000 );     / To simulate some complex tile modification.
    5650}
    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); // tmp
    63         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 sind
    70         //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         //else
    91         // Wenn Quelle RGB ist und Ziel RGBA
    92         //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  
    2020
    2121        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);
    2422};
    2523
  • experimental/TerrainTest/myTileLoadedCallback.h

    r165 r275  
    11#pragma once
    22#include <osgTerrain/TerrainTile>
     3#include "myTerrainTechnique.h"
     4
    35
    46namespace osgTerrain {
    5 
    6 class Terrain;
    77
    88class  myTileLoadedCallback : public TerrainTile::TileLoadedCallback
    99{
    1010public:
    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() {};
    1713
    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() );};
    2033};
    2134
    22 }
     35}       // Namespace end.
  • experimental/TerrainTest/osgterrain.cpp

    r171 r275  
    232232        //terrain->setTerrainTechniquePrototype( myT );
    233233
    234         //// Manually set the terrain technque for a tile ( his example, the first found tile) works, but then the whole database has to be processed
    235         //osgTerrain::TerrainTile* tile = findTopMostNodeOfType<osgTerrain::TerrainTile>(rootnode);
    236         //if(tile)
    237         //{
    238         //      tile->setTerrainTechnique( myT );
    239         //}
    240234
    241235        // 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();
    243237        osgTerrain::TerrainTile::setTileLoadedCallback(tlcb);
    244238
  • experimental/TerrainTest/rampedEllipsoidTechnique.cpp

    r274 r275  
    5757        clampValue(Y_endCore, Y_start, Y_end);
    5858        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;
    6060
    6161        // Lon
     
    6969        clampValue(X_endCore, X_start, X_end);
    7070        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;
    7272
    7373        // Modify height value of affected vertices in the core ROI
     
    125125                       
    126126                        // 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;
    128128                        h->setHeight( x, y, destination_height);
    129129                }
Note: See TracChangeset for help on using the changeset viewer.