[272] | 1 | /* -*-c++-*- osgVisual - Copyright (C) 2009-2011 Torben Dannhauer |
---|
| 2 | * |
---|
| 3 | * This library is based on OpenSceneGraph, open source and may be redistributed and/or modified under |
---|
| 4 | * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or |
---|
| 5 | * (at your option) any later version. The full license is in LICENSE file |
---|
| 6 | * included with this distribution, and on the openscenegraph.org website. |
---|
| 7 | * |
---|
| 8 | * osgVisual requires for some proprietary modules a license from the correspondig manufacturer. |
---|
| 9 | * You have to aquire licenses for all used proprietary modules. |
---|
| 10 | * |
---|
| 11 | * This library is distributed in the hope that it will be useful, |
---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 14 | * OpenSceneGraph Public License for more details. |
---|
| 15 | */ |
---|
| 16 | |
---|
[264] | 17 | #include "rampedEllipsoidTechnique.h" |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | rampedEllipsoidTechnique::rampedEllipsoidTechnique() |
---|
| 21 | { |
---|
| 22 | _height = 0.0; |
---|
[266] | 23 | _rampWidthFactor = 0.4; // 10% of ROI is ramp. |
---|
[264] | 24 | } |
---|
| 25 | |
---|
| 26 | rampedEllipsoidTechnique::~rampedEllipsoidTechnique() |
---|
| 27 | { |
---|
| 28 | } |
---|
| 29 | |
---|
[269] | 30 | void rampedEllipsoidTechnique::modifyHeightfield(region& modificationROI, osg::HeightField* h, region tileExtends) |
---|
[264] | 31 | { |
---|
[290] | 32 | //OSG_NOTIFY( osg::ALWAYS ) << "rampedEllipsoidTechnique::modifyHeightfield()" << std::endl; |
---|
[269] | 33 | //OSG_NOTIFY( osg::ALWAYS ) << "LAT: " << tileExtends._lat_min << " | " << tileExtends._lat_max << std::endl; |
---|
| 34 | //OSG_NOTIFY( osg::ALWAYS ) << "LON: " << tileExtends._lon_min << " | " << tileExtends._lon_max << std::endl; |
---|
[264] | 35 | |
---|
[265] | 36 | // Determine modificationROI without ramp |
---|
[269] | 37 | double deltaLatPerSide = modificationROI.delta_lat() * _rampWidthFactor / 2.0; |
---|
| 38 | double deltaLonPerSide = modificationROI.delta_lon() * _rampWidthFactor / 2.0; |
---|
| 39 | region coreROI = modificationROI; |
---|
| 40 | coreROI._lat_min+=deltaLatPerSide; |
---|
| 41 | coreROI._lat_max-=deltaLatPerSide; |
---|
| 42 | coreROI._lon_min+=deltaLonPerSide; |
---|
| 43 | coreROI._lon_max-=deltaLonPerSide; |
---|
[264] | 44 | |
---|
[265] | 45 | // Calculate colum start/end and row start/end of affected vertices |
---|
| 46 | int Y_start=0, Y_startRamp=0, Y_startCore=0, Y_endCore=0, Y_endRamp=0, Y_end=h->getNumRows(); // Lat |
---|
| 47 | int X_start=0, X_startRamp=0, X_startCore=0, X_endCore=0, X_endRamp=0, X_end=h->getNumColumns(); // Lon |
---|
[264] | 48 | |
---|
[266] | 49 | // Lat |
---|
[269] | 50 | Y_startRamp = round((modificationROI._lat_min-tileExtends._lat_min) / h->getYInterval()); |
---|
| 51 | Y_startCore = round((coreROI._lat_min-tileExtends._lat_min) / h->getYInterval()); |
---|
| 52 | Y_endCore = round((coreROI._lat_max-tileExtends._lat_min) / h->getYInterval()); |
---|
| 53 | Y_endRamp = round((modificationROI._lat_max-tileExtends._lat_min) / h->getYInterval()); |
---|
[266] | 54 | |
---|
[265] | 55 | clampValue(Y_startRamp, Y_start, Y_end); |
---|
| 56 | clampValue(Y_startCore, Y_start, Y_end); |
---|
| 57 | clampValue(Y_endCore, Y_start, Y_end); |
---|
| 58 | clampValue(Y_endRamp, Y_start, Y_end); |
---|
[290] | 59 | //OSG_NOTIFY( osg::ALWAYS ) << "Y_startRamp:" << Y_startRamp << " Y_startCore:" << Y_startCore << " Y_endCore:" << Y_endCore << " Y_endRamp:" << Y_endRamp << std::endl; |
---|
[264] | 60 | |
---|
[266] | 61 | // Lon |
---|
[269] | 62 | X_startRamp = round((modificationROI._lon_min-tileExtends._lon_min) / h->getXInterval()); |
---|
| 63 | X_startCore = round((coreROI._lon_min-tileExtends._lon_min) / h->getXInterval()); |
---|
| 64 | X_endCore = round((coreROI._lon_max-tileExtends._lon_min) / h->getXInterval()); |
---|
| 65 | X_endRamp = round((modificationROI._lon_max-tileExtends._lon_min) / h->getXInterval()); |
---|
[266] | 66 | |
---|
[265] | 67 | clampValue(X_startRamp, X_start, X_end); |
---|
| 68 | clampValue(X_startCore, X_start, X_end); |
---|
| 69 | clampValue(X_endCore, X_start, X_end); |
---|
| 70 | clampValue(X_endRamp, X_start, X_end); |
---|
[290] | 71 | //OSG_NOTIFY( osg::ALWAYS ) << "X_startRamp:" << X_startRamp << " X_startCore:" << X_startCore << " X_endCore:" << X_endCore << " X_endRamp:" << X_endRamp << std::endl; |
---|
[264] | 72 | |
---|
[265] | 73 | // Modify height value of affected vertices in the core ROI |
---|
| 74 | for(int x=X_startRamp;x<X_endRamp;x++) |
---|
[264] | 75 | { |
---|
[265] | 76 | for(int y=Y_startRamp;y<Y_endRamp;y++) |
---|
[264] | 77 | { |
---|
[266] | 78 | // Calculate vertex position in global coordinate system (lat/lon) |
---|
[269] | 79 | double vertex_lat = y*h->getYInterval()+tileExtends._lat_min; |
---|
| 80 | double vertex_lon = x*h->getXInterval()+tileExtends._lon_min; |
---|
[266] | 81 | // Calculate vertex delta h: h_dest - h_org |
---|
| 82 | double height_org = h->getHeight(x,y); |
---|
| 83 | double delta_h = _height - height_org; |
---|
[287] | 84 | // preset offset value to max and let every ramp function try to lower it... |
---|
[289] | 85 | double current_vertex_delta = std::numeric_limits<double>::max(); |
---|
[266] | 86 | |
---|
| 87 | // Calculate vertex height according to the region it is in. |
---|
[290] | 88 | //// Estimated height in the core ROI |
---|
| 89 | double destination_height = _height; |
---|
| 90 | //// Startramp |
---|
| 91 | if(Y_startRamp<=y && y<=Y_startCore && Y_startRamp != Y_startCore) // Vertex is inside Y start ramp |
---|
[265] | 92 | { |
---|
[269] | 93 | double delta_s = abs(modificationROI._lat_min-vertex_lat); |
---|
[266] | 94 | double gradient = delta_h/deltaLatPerSide; |
---|
[289] | 95 | double calculated_height = delta_s*gradient + height_org; |
---|
| 96 | double local_test_delta = abs(calculated_height-height_org); |
---|
| 97 | if(local_test_delta<current_vertex_delta) |
---|
| 98 | { |
---|
| 99 | current_vertex_delta = local_test_delta; |
---|
| 100 | destination_height = calculated_height; |
---|
| 101 | } |
---|
[265] | 102 | } |
---|
[290] | 103 | if(X_startRamp<=x && x<=X_startCore && X_startRamp != X_startCore) // Vertex is inside X start ramp |
---|
[266] | 104 | { |
---|
[269] | 105 | double delta_s = abs(modificationROI._lon_min-vertex_lon); |
---|
[266] | 106 | double gradient = delta_h/deltaLonPerSide; |
---|
[289] | 107 | double calculated_height = delta_s*gradient + height_org; |
---|
| 108 | double local_test_delta = abs(calculated_height-height_org); |
---|
| 109 | if(local_test_delta<current_vertex_delta) |
---|
| 110 | { |
---|
| 111 | current_vertex_delta = local_test_delta; |
---|
| 112 | destination_height = calculated_height; |
---|
| 113 | } |
---|
[266] | 114 | } |
---|
[290] | 115 | //// End ramp |
---|
| 116 | if(Y_endCore<=y && y<=Y_endRamp && Y_endCore != Y_endRamp) // Vertex is inside Y end ramp |
---|
[266] | 117 | { |
---|
[269] | 118 | double delta_s = abs(modificationROI._lat_max-vertex_lat); |
---|
[266] | 119 | double gradient = delta_h/deltaLatPerSide; |
---|
[289] | 120 | double calculated_height = delta_s*gradient + height_org; |
---|
| 121 | double local_test_delta = abs(calculated_height-height_org); |
---|
| 122 | if(local_test_delta<current_vertex_delta) |
---|
| 123 | { |
---|
| 124 | current_vertex_delta = local_test_delta; |
---|
| 125 | destination_height = calculated_height; |
---|
| 126 | } |
---|
[266] | 127 | } |
---|
[290] | 128 | if (X_endCore<=x && x<=X_endRamp && X_endCore != X_endRamp) // Vertex is inside X end ramp |
---|
[266] | 129 | { |
---|
[269] | 130 | double delta_s = abs(modificationROI._lon_max-vertex_lon); |
---|
[266] | 131 | double gradient = delta_h/deltaLonPerSide; |
---|
[289] | 132 | double calculated_height = delta_s*gradient + height_org; |
---|
| 133 | double local_test_delta = abs(calculated_height-height_org); |
---|
| 134 | if(local_test_delta<current_vertex_delta) |
---|
| 135 | { |
---|
| 136 | current_vertex_delta = local_test_delta; |
---|
| 137 | destination_height = calculated_height; |
---|
| 138 | } |
---|
[266] | 139 | } |
---|
[265] | 140 | |
---|
[266] | 141 | // Set height to calculated value |
---|
[290] | 142 | //OSG_NOTIFY( osg::ALWAYS ) << "rampedEllipsoidTechnique: X,Y:"<<x<<","<<y<<" destination_height=" << destination_height << std::endl; |
---|
[266] | 143 | h->setHeight( x, y, destination_height); |
---|
[264] | 144 | } |
---|
| 145 | } |
---|
| 146 | } |
---|
| 147 | |
---|