source: experimental/TerrainTest/rampedEllipsoidTechnique.cpp @ 265

Last change on this file since 265 was 265, checked in by Torben Dannhauer, 13 years ago

Prototype of rampedEllipsoidFunction works.

File size: 3.1 KB
Line 
1#include "rampedEllipsoidTechnique.h"
2
3
4
5rampedEllipsoidTechnique::rampedEllipsoidTechnique()
6{
7        _height = 0.0;
8        _rampWidthFactor = 0.1; // 10% of ROI is ramp.
9}
10
11rampedEllipsoidTechnique::~rampedEllipsoidTechnique()
12{
13}
14
15void rampedEllipsoidTechnique::modifyHeightfield(osg::Vec4d& modificationROI, osg::HeightField* h, osg::Vec4d tileExtends)
16{
17        //OSG_NOTIFY( osg::ALWAYS ) << "rampedEllipsoidTechnique::modifyHeightfield()" << std::endl;
18        //OSG_NOTIFY( osg::ALWAYS ) << "LAT: " << tileExtends[0] << " | " << tileExtends[1] << std::endl;
19        //OSG_NOTIFY( osg::ALWAYS ) << "LON: " << tileExtends[2] << " | " << tileExtends[3] << std::endl;
20
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;
29
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
33
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();
62
63
64        // Modify height value of affected vertices in the core ROI
65        for(int x=X_startRamp;x<X_endRamp;x++)
66        {
67                for(int y=Y_startRamp;y<Y_endRamp;y++)
68                {
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                       
78                }
79        }
80}
81
Note: See TracBrowser for help on using the repository browser.