[264] | 1 | #include "rampedEllipsoidTechnique.h" |
---|
| 2 | |
---|
| 3 | |
---|
| 4 | |
---|
| 5 | rampedEllipsoidTechnique::rampedEllipsoidTechnique() |
---|
| 6 | { |
---|
| 7 | _height = 0.0; |
---|
[266] | 8 | _rampWidthFactor = 0.4; // 10% of ROI is ramp. |
---|
[264] | 9 | } |
---|
| 10 | |
---|
| 11 | rampedEllipsoidTechnique::~rampedEllipsoidTechnique() |
---|
| 12 | { |
---|
| 13 | } |
---|
| 14 | |
---|
| 15 | void rampedEllipsoidTechnique::modifyHeightfield(osg::Vec4d& modificationROI, osg::HeightField* h, osg::Vec4d tileExtends) |
---|
| 16 | { |
---|
[265] | 17 | //OSG_NOTIFY( osg::ALWAYS ) << "rampedEllipsoidTechnique::modifyHeightfield()" << std::endl; |
---|
[264] | 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 | |
---|
[265] | 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; |
---|
[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 |
---|
| 35 | Y_startRamp = round((modificationROI[0]-tileExtends[0]) / h->getYInterval()); |
---|
| 36 | Y_startCore = round((coreROI[0]-tileExtends[0]) / h->getYInterval()); |
---|
| 37 | Y_endCore = round((coreROI[1]-tileExtends[0]) / h->getYInterval()); |
---|
| 38 | Y_endRamp = round((modificationROI[1]-tileExtends[0]) / h->getYInterval()); |
---|
| 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 |
---|
| 46 | X_startRamp = round((modificationROI[2]-tileExtends[2]) / h->getXInterval()); |
---|
| 47 | X_startCore = round((coreROI[2]-tileExtends[2]) / h->getXInterval()); |
---|
| 48 | X_endCore = round((coreROI[3]-tileExtends[2]) / h->getXInterval()); |
---|
| 49 | X_endRamp = round((modificationROI[3]-tileExtends[2]) / h->getXInterval()); |
---|
| 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) |
---|
| 63 | double vertex_lat = y*h->getYInterval()+tileExtends[0]; |
---|
| 64 | double vertex_lon = x*h->getXInterval()+tileExtends[2]; |
---|
| 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 | { |
---|
[266] | 79 | double delta_s = abs(modificationROI[0]-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; |
---|
[265] | 84 | } |
---|
[266] | 85 | if(X_startRamp<=x && x<X_startCore) // Vertex is inside X start ramp |
---|
| 86 | { |
---|
| 87 | double delta_s = abs(modificationROI[2]-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[1]-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[3]-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 | } |
---|
[265] | 109 | |
---|
[266] | 110 | // Set height to calculated value |
---|
| 111 | h->setHeight( x, y, destination_height); |
---|
[264] | 112 | } |
---|
| 113 | } |
---|
| 114 | } |
---|
| 115 | |
---|