/* -*-c++-*- osgVisual - Copyright (C) 2009-2011 Torben Dannhauer * * This library is based on OpenSceneGraph, open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * (at your option) any later version. The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. * * osgVisual requires for some proprietary modules a license from the correspondig manufacturer. * You have to aquire licenses for all used proprietary modules. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. */ #include "rampedEllipsoidTechnique.h" rampedEllipsoidTechnique::rampedEllipsoidTechnique() { _height = 0.0; _rampWidthFactor = 0.4; // 10% of ROI is ramp. } rampedEllipsoidTechnique::~rampedEllipsoidTechnique() { } void rampedEllipsoidTechnique::modifyHeightfield(region& modificationROI, osg::HeightField* h, region tileExtends) { //OSG_NOTIFY( osg::ALWAYS ) << "rampedEllipsoidTechnique::modifyHeightfield()" << std::endl; //OSG_NOTIFY( osg::ALWAYS ) << "LAT: " << tileExtends._lat_min << " | " << tileExtends._lat_max << std::endl; //OSG_NOTIFY( osg::ALWAYS ) << "LON: " << tileExtends._lon_min << " | " << tileExtends._lon_max << std::endl; // Determine modificationROI without ramp double deltaLatPerSide = modificationROI.delta_lat() * _rampWidthFactor / 2.0; double deltaLonPerSide = modificationROI.delta_lon() * _rampWidthFactor / 2.0; region coreROI = modificationROI; coreROI._lat_min+=deltaLatPerSide; coreROI._lat_max-=deltaLatPerSide; coreROI._lon_min+=deltaLonPerSide; coreROI._lon_max-=deltaLonPerSide; // Calculate colum start/end and row start/end of affected vertices int Y_start=0, Y_startRamp=0, Y_startCore=0, Y_endCore=0, Y_endRamp=0, Y_end=h->getNumRows(); // Lat int X_start=0, X_startRamp=0, X_startCore=0, X_endCore=0, X_endRamp=0, X_end=h->getNumColumns(); // Lon // Lat Y_startRamp = round((modificationROI._lat_min-tileExtends._lat_min) / h->getYInterval()); Y_startCore = round((coreROI._lat_min-tileExtends._lat_min) / h->getYInterval()); Y_endCore = round((coreROI._lat_max-tileExtends._lat_min) / h->getYInterval()); Y_endRamp = round((modificationROI._lat_max-tileExtends._lat_min) / h->getYInterval()); clampValue(Y_startRamp, Y_start, Y_end); clampValue(Y_startCore, Y_start, Y_end); clampValue(Y_endCore, Y_start, Y_end); clampValue(Y_endRamp, Y_start, Y_end); //OSG_NOTIFY( osg::ALWAYS ) << "Y_startRamp:" << Y_startRamp << " Y_startCore:" << Y_startCore << " Y_endCore:" << Y_endCore << " Y_endRamp:" << Y_endRamp << std::endl; // Lon X_startRamp = round((modificationROI._lon_min-tileExtends._lon_min) / h->getXInterval()); X_startCore = round((coreROI._lon_min-tileExtends._lon_min) / h->getXInterval()); X_endCore = round((coreROI._lon_max-tileExtends._lon_min) / h->getXInterval()); X_endRamp = round((modificationROI._lon_max-tileExtends._lon_min) / h->getXInterval()); clampValue(X_startRamp, X_start, X_end); clampValue(X_startCore, X_start, X_end); clampValue(X_endCore, X_start, X_end); clampValue(X_endRamp, X_start, X_end); //OSG_NOTIFY( osg::ALWAYS ) << "X_startRamp:" << X_startRamp << " X_startCore:" << X_startCore << " X_endCore:" << X_endCore << " X_endRamp:" << X_endRamp << std::endl; // Modify height value of affected vertices in the core ROI for(int x=X_startRamp;xgetYInterval()+tileExtends._lat_min; double vertex_lon = x*h->getXInterval()+tileExtends._lon_min; // Calculate vertex delta h: h_dest - h_org double height_org = h->getHeight(x,y); double delta_h = _height - height_org; // preset offset value to max and let every ramp function try to lower it... double current_vertex_delta = std::numeric_limits::max(); // Calculate vertex height according to the region it is in. //// Estimated height in the core ROI double destination_height = _height; //// Startramp if(Y_startRamp<=y && y<=Y_startCore && Y_startRamp != Y_startCore) // Vertex is inside Y start ramp { double delta_s = abs(modificationROI._lat_min-vertex_lat); double gradient = delta_h/deltaLatPerSide; double calculated_height = delta_s*gradient + height_org; double local_test_delta = abs(calculated_height-height_org); if(local_test_delta