source: experimental/TerrainTest/rampedEllipsoidTechnique.cpp @ 271

Last change on this file since 271 was 269, checked in by Torben Dannhauer, 13 years ago
File size: 4.6 KB
Line 
1#include "rampedEllipsoidTechnique.h"
2
3
4
5rampedEllipsoidTechnique::rampedEllipsoidTechnique()
6{
7        _height = 0.0;
8        _rampWidthFactor = 0.4; // 10% of ROI is ramp.
9}
10
11rampedEllipsoidTechnique::~rampedEllipsoidTechnique()
12{
13}
14
15void rampedEllipsoidTechnique::modifyHeightfield(region& modificationROI, osg::HeightField* h, region tileExtends)
16{
17        //OSG_NOTIFY( osg::ALWAYS ) << "rampedEllipsoidTechnique::modifyHeightfield()" << std::endl;
18        //OSG_NOTIFY( osg::ALWAYS ) << "LAT: " << tileExtends._lat_min << " | " << tileExtends._lat_max << std::endl;
19        //OSG_NOTIFY( osg::ALWAYS ) << "LON: " << tileExtends._lon_min << " | " << tileExtends._lon_max << std::endl;
20
21        // Determine modificationROI without ramp
22        double deltaLatPerSide = modificationROI.delta_lat() * _rampWidthFactor / 2.0;
23        double deltaLonPerSide = modificationROI.delta_lon() * _rampWidthFactor / 2.0;
24        region coreROI = modificationROI;
25        coreROI._lat_min+=deltaLatPerSide;
26        coreROI._lat_max-=deltaLatPerSide;
27        coreROI._lon_min+=deltaLonPerSide;
28        coreROI._lon_max-=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        // Lat
35        Y_startRamp = round((modificationROI._lat_min-tileExtends._lat_min) / h->getYInterval());
36        Y_startCore = round((coreROI._lat_min-tileExtends._lat_min) / h->getYInterval());
37        Y_endCore   = round((coreROI._lat_max-tileExtends._lat_min) / h->getYInterval());
38        Y_endRamp   = round((modificationROI._lat_max-tileExtends._lat_min) / h->getYInterval());
39
40        clampValue(Y_startRamp, Y_start, Y_end);
41        clampValue(Y_startCore, Y_start, Y_end);
42        clampValue(Y_endCore, Y_start, Y_end);
43        clampValue(Y_endRamp, Y_start, Y_end);
44
45        // Lon
46        X_startRamp = round((modificationROI._lon_min-tileExtends._lon_min) / h->getXInterval());
47        X_startCore = round((coreROI._lon_min-tileExtends._lon_min) / h->getXInterval());
48        X_endCore   = round((coreROI._lon_max-tileExtends._lon_min) / h->getXInterval());
49        X_endRamp   = round((modificationROI._lon_max-tileExtends._lon_min) / h->getXInterval());
50
51        clampValue(X_startRamp, X_start, X_end);
52        clampValue(X_startCore, X_start, X_end);
53        clampValue(X_endCore, X_start, X_end);
54        clampValue(X_endRamp, X_start, X_end);
55
56
57        // Modify height value of affected vertices in the core ROI
58        for(int x=X_startRamp;x<X_endRamp;x++)
59        {
60                for(int y=Y_startRamp;y<Y_endRamp;y++)
61                {
62                        // Calculate vertex position in global coordinate system (lat/lon)
63                        double vertex_lat = y*h->getYInterval()+tileExtends._lat_min;
64                        double vertex_lon = x*h->getXInterval()+tileExtends._lon_min;
65                        // Calculate vertex delta h: h_dest - h_org
66                        double height_org = h->getHeight(x,y);
67                        double delta_h = _height - height_org;
68                        // preset offsetvalue to max and let every region try to lower it...
69                        double destination_height = std::numeric_limits<double>::max();
70
71                        // Calculate vertex height according to the region it is in.
72                        if( Y_startCore<=y && y<Y_endCore && X_startCore<=x && x<X_endCore )    // If vertex is inside core: Apply final height
73                        {
74                                        if(_height<destination_height)
75                                        destination_height = _height;
76                        }
77                        if(Y_startRamp<=y && y<Y_startCore) // Vertex is inside Y start ramp
78                        {
79                                double delta_s = abs(modificationROI._lat_min-vertex_lat);
80                                double gradient = delta_h/deltaLatPerSide;
81                                double dest = delta_s*gradient + height_org;
82                                if(dest<destination_height)
83                                        destination_height = dest;                     
84                        }
85                        if(X_startRamp<=x && x<X_startCore)     // Vertex is inside X start ramp
86                        {
87                                double delta_s = abs(modificationROI._lon_min-vertex_lon);
88                                double gradient = delta_h/deltaLonPerSide;
89                                double dest = delta_s*gradient + height_org;
90                                if(dest<destination_height)
91                                        destination_height = dest;
92                        }
93                        if(Y_endCore<=y && y<Y_endRamp)  // Vertex is inside Y end ramp
94                        {
95                                double delta_s = abs(modificationROI._lat_max-vertex_lat);
96                                double gradient = delta_h/deltaLatPerSide;
97                                double dest = delta_s*gradient + height_org;
98                                if(dest<destination_height)
99                                        destination_height = dest;
100                        }
101                        if (X_endCore<=x && x<X_endRamp) // Vertex is inside X end ramp
102                        {
103                                double delta_s = abs(modificationROI._lon_max-vertex_lon);
104                                double gradient = delta_h/deltaLonPerSide;
105                                double dest = delta_s*gradient + height_org;
106                                if(dest<destination_height)
107                                        destination_height = dest;
108                        }
109                       
110                        // Set height to calculated value
111                        h->setHeight( x, y, destination_height);
112                }
113        }
114}
115
Note: See TracBrowser for help on using the repository browser.