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
RevLine 
[264]1#include "rampedEllipsoidTechnique.h"
2
3
4
5rampedEllipsoidTechnique::rampedEllipsoidTechnique()
6{
7        _height = 0.0;
[266]8        _rampWidthFactor = 0.4; // 10% of ROI is ramp.
[264]9}
10
11rampedEllipsoidTechnique::~rampedEllipsoidTechnique()
12{
13}
14
[269]15void rampedEllipsoidTechnique::modifyHeightfield(region& modificationROI, osg::HeightField* h, region tileExtends)
[264]16{
[265]17        //OSG_NOTIFY( osg::ALWAYS ) << "rampedEllipsoidTechnique::modifyHeightfield()" << std::endl;
[269]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;
[264]20
[265]21        // Determine modificationROI without ramp
[269]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;
[264]29
[265]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
[264]33
[266]34        // Lat
[269]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());
[266]39
[265]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);
[264]44
[266]45        // Lon
[269]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());
[266]50
[265]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);
[264]55
[265]56
57        // Modify height value of affected vertices in the core ROI
58        for(int x=X_startRamp;x<X_endRamp;x++)
[264]59        {
[265]60                for(int y=Y_startRamp;y<Y_endRamp;y++)
[264]61                {
[266]62                        // Calculate vertex position in global coordinate system (lat/lon)
[269]63                        double vertex_lat = y*h->getYInterval()+tileExtends._lat_min;
64                        double vertex_lon = x*h->getXInterval()+tileExtends._lon_min;
[266]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.
[265]72                        if( Y_startCore<=y && y<Y_endCore && X_startCore<=x && x<X_endCore )    // If vertex is inside core: Apply final height
73                        {
[266]74                                        if(_height<destination_height)
75                                        destination_height = _height;
[265]76                        }
[266]77                        if(Y_startRamp<=y && y<Y_startCore) // Vertex is inside Y start ramp
[265]78                        {
[269]79                                double delta_s = abs(modificationROI._lat_min-vertex_lat);
[266]80                                double gradient = delta_h/deltaLatPerSide;
81                                double dest = delta_s*gradient + height_org;
82                                if(dest<destination_height)
83                                        destination_height = dest;                     
[265]84                        }
[266]85                        if(X_startRamp<=x && x<X_startCore)     // Vertex is inside X start ramp
86                        {
[269]87                                double delta_s = abs(modificationROI._lon_min-vertex_lon);
[266]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                        {
[269]95                                double delta_s = abs(modificationROI._lat_max-vertex_lat);
[266]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                        {
[269]103                                double delta_s = abs(modificationROI._lon_max-vertex_lon);
[266]104                                double gradient = delta_h/deltaLonPerSide;
105                                double dest = delta_s*gradient + height_org;
106                                if(dest<destination_height)
107                                        destination_height = dest;
108                        }
[265]109                       
[266]110                        // Set height to calculated value
111                        h->setHeight( x, y, destination_height);
[264]112                }
113        }
114}
115
Note: See TracBrowser for help on using the repository browser.