Ignore:
Timestamp:
Feb 27, 2011, 8:11:34 PM (14 years ago)
Author:
Torben Dannhauer
Message:

Prototype of rampedEllipsoidFunction works.

Location:
experimental/TerrainTest
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • experimental/TerrainTest/ModificationVisitor.cpp

    r262 r265  
    66{
    77        setTraversalMode( osg::NodeVisitor::TRAVERSE_ALL_CHILDREN );
    8         _technique = new ellipsoidTechnique();
     8        _technique = new rampedEllipsoidTechnique();
    99
    1010        // Set ROI to flatten and estimated height after correction
    11         _technique->setModifiedHeight(450);
     11        _technique->setModifiedHeight(600);     // 450
    1212}
    1313
  • experimental/TerrainTest/ModificationVisitor.h

    r264 r265  
    2121        void modifyTile(osgTerrain::TerrainTile* tile);
    2222        std::string _extensionToSet;
    23         osg::ref_ptr<ellipsoidTechnique> _technique;
     23        osg::ref_ptr<rampedEllipsoidTechnique> _technique;
    2424
    2525};
  • experimental/TerrainTest/ellipsoidTechnique.cpp

    r264 r265  
    2121
    2222       
    23         // Dertermine loop variables..
     23        // Determine loop variables..
    2424        if(tileExtends[0]<modificationROI[0])
    2525                startY = (modificationROI[0] - tileExtends[0]) / h->getYInterval();
  • experimental/TerrainTest/rampedEllipsoidTechnique.cpp

    r264 r265  
    66{
    77        _height = 0.0;
    8         _rampWidth_percent = 10.0;
     8        _rampWidthFactor = 0.1; // 10% of ROI is ramp.
    99}
    1010
     
    1515void rampedEllipsoidTechnique::modifyHeightfield(osg::Vec4d& modificationROI, osg::HeightField* h, osg::Vec4d tileExtends)
    1616{
    17         //OSG_NOTIFY( osg::ALWAYS ) << "ellipsoidTechnique::modifyHeightfield()" << std::endl;
     17        //OSG_NOTIFY( osg::ALWAYS ) << "rampedEllipsoidTechnique::modifyHeightfield()" << std::endl;
    1818        //OSG_NOTIFY( osg::ALWAYS ) << "LAT: " << tileExtends[0] << " | " << tileExtends[1] << std::endl;
    1919        //OSG_NOTIFY( osg::ALWAYS ) << "LON: " << tileExtends[2] << " | " << tileExtends[3] << std::endl;
    2020
    21         // calculate colum start/end and row start/end of affected vertices
    22         int startX=0, startY=0, endX=h->getNumColumns(), endY=h->getNumRows();
     21        // Determine modificationROI without ramp
     22        double deltaLatPerSide = (modificationROI[1] - modificationROI[0]) * _rampWidthFactor / 2.0;
     23        double deltaLonPerSide = (modificationROI[3] - modificationROI[2]) * _rampWidthFactor / 2.0;
     24        osg::Vec4d coreROI = modificationROI;
     25        coreROI[0]+=deltaLatPerSide;
     26        coreROI[1]-=deltaLatPerSide;
     27        coreROI[2]+=deltaLonPerSide;
     28        coreROI[3]-=deltaLonPerSide;
    2329
    24        
    25         // Dertermine loop variables..
    26         if(tileExtends[0]<modificationROI[0])
    27                 startY = (modificationROI[0] - tileExtends[0]) / h->getYInterval();
    28         if(tileExtends[1]>modificationROI[1])
    29                 endY = (modificationROI[1] - tileExtends[0]) / h->getYInterval();
     30        // Calculate colum start/end and row start/end of affected vertices
     31        int Y_start=0, Y_startRamp=0, Y_startCore=0, Y_endCore=0, Y_endRamp=0, Y_end=h->getNumRows();           // Lat
     32        int X_start=0, X_startRamp=0, X_startCore=0, X_endCore=0, X_endRamp=0, X_end=h->getNumColumns();        // Lon
    3033
    31         if(tileExtends[2]<modificationROI[2])
    32                 startX = (modificationROI[2] - tileExtends[2]) / h->getXInterval();
    33         if(tileExtends[3]>modificationROI[3])
    34                 endX = (modificationROI[3] - tileExtends[2]) / h->getXInterval();
     34        Y_startRamp = (modificationROI[0]-tileExtends[0]) / h->getYInterval();
     35        Y_startCore = (coreROI[0]-tileExtends[0]) / h->getYInterval();
     36        Y_endCore   = (coreROI[1]-tileExtends[0]) / h->getYInterval();
     37        Y_endRamp   = (modificationROI[1]-tileExtends[0]) / h->getYInterval();
     38        clampValue(Y_startRamp, Y_start, Y_end);
     39        clampValue(Y_startCore, Y_start, Y_end);
     40        clampValue(Y_endCore, Y_start, Y_end);
     41        clampValue(Y_endRamp, Y_start, Y_end);
     42
     43        X_startRamp = (modificationROI[2]-tileExtends[2]) / h->getXInterval();
     44        X_startCore = (coreROI[2]-tileExtends[2]) / h->getXInterval();
     45        X_endCore   = (coreROI[3]-tileExtends[2]) / h->getXInterval();
     46        X_endRamp   = (modificationROI[3]-tileExtends[2]) / h->getXInterval();
     47        clampValue(X_startRamp, X_start, X_end);
     48        clampValue(X_startCore, X_start, X_end);
     49        clampValue(X_endCore, X_start, X_end);
     50        clampValue(X_endRamp, X_start, X_end);
     51
     52        // Determine loop variables..
     53        //if(tileExtends[0]<modificationROI[0])
     54        //      startY = (modificationROI[0] - tileExtends[0]) / h->getYInterval();
     55        //if(tileExtends[1]>modificationROI[1])
     56        //      endY = (modificationROI[1] - tileExtends[0]) / h->getYInterval();
     57
     58        //if(tileExtends[2]<modificationROI[2])
     59        //      startX = (modificationROI[2] - tileExtends[2]) / h->getXInterval();
     60        //if(tileExtends[3]>modificationROI[3])
     61        //      endX = (modificationROI[3] - tileExtends[2]) / h->getXInterval();
    3562
    3663
    37         // Modify height value of affected vertices
    38         for(int x=startX;x<endX;x++)
     64        // Modify height value of affected vertices in the core ROI
     65        for(int x=X_startRamp;x<X_endRamp;x++)
    3966        {
    40                 for(int y=startY;y<endY;y++)
     67                for(int y=Y_startRamp;y<Y_endRamp;y++)
    4168                {
    42                         h->setHeight( x, y, _height);
     69                        if( Y_startCore<=y && y<Y_endCore && X_startCore<=x && x<X_endCore )    // If vertex is inside core: Apply final height
     70                        {
     71                                h->setHeight( x, y, _height);
     72                        }
     73                        else    //  vertex is inside ramp but not inside core: apply ramp height
     74                        {
     75                                h->setHeight( x, y, _height-50.0);
     76                        }
     77                       
    4378                }
    4479        }
  • experimental/TerrainTest/rampedEllipsoidTechnique.h

    r264 r265  
    1212        void modifyHeightfield(osg::Vec4d& modificationROI, osg::HeightField* h, osg::Vec4d tileExtends);
    1313        void setModifiedHeight(double height) {_height=height;}
    14         void setRampWidth_percent(double rampWidth_percent) {_rampWidth_percent=rampWidth_percent;}
     14        void setRampWidthFactor(double rampWidthFactor) {_rampWidthFactor=rampWidthFactor;}
    1515
    1616private:
    1717        double _height;
    18         double _rampWidth_percent;
     18        double _rampWidthFactor;
    1919};
  • experimental/TerrainTest/terrainModificationTechnique.h

    r264 r265  
    2323         * @param modificationROI This vector contains the extents of the region of interest which should be modified: lat min, lat_max, long_min, long_max
    2424         * @param h : Heightfield of the tile which should be modified
    25          * @param tileExtends : This vector contains the extents of the tile: lat min, lat_max, long_min, long_max
     25         * @param tileExtends : This vector contains the extents of the tile: lat_min, lat_max, long_min, long_max
    2626         */
    2727        virtual void modifyHeightfield(osg::Vec4d& modificationROI, osg::HeightField* h, osg::Vec4d tileExtends)=0;
    2828
     29protected:
     30        void clampValue(double& value, double min, double max){if(value<min)value=min;if(value>max)value=max;}
     31        void clampValue(int& value, int min, int max){if(value<min)value=min;if(value>max)value=max;}
    2932};
Note: See TracChangeset for help on using the changeset viewer.