From 304214e0df2334a2aaba85ea394f05330cca5ec3 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 25 Mar 2010 11:11:35 +0000 Subject: [PATCH] Introduced the use of linear interpolation of evelvations when sampling --- include/osgTerrain/Layer | 47 ++++++++++++++++++++++++++++ src/osgTerrain/GeometryTechnique.cpp | 23 ++++++-------- 2 files changed, 56 insertions(+), 14 deletions(-) diff --git a/include/osgTerrain/Layer b/include/osgTerrain/Layer index f8058dfa1..11f9dd931 100644 --- a/include/osgTerrain/Layer +++ b/include/osgTerrain/Layer @@ -191,6 +191,53 @@ class OSGTERRAIN_EXPORT Layer : public osg::Object return false; } + inline bool getInterpolatedValidValue(double ndc_x, double ndc_y, float& value) + { + unsigned int i,j; + double ir, jr; + computeIndices(ndc_x, ndc_y, i, j, ir, jr); + value = 0.0f; + double div = 0.0f; + float v,r; + + r = (1.0f-ir)*(1.0f-jr); + if (r>0.0 && getValidValue(i,j,v)) + { + value += v*r; + div += r; + } + + r = (ir)*(1.0f-jr); + if (r>0.0 && getValidValue(i+1,j,v)) + { + value += v*r; + div += r; + } + + r = (ir)*(jr); + if (r>0.0 && getValidValue(i+1,j+1,v)) + { + value += v*r; + div += r; + } + + r = (1.0f-ir)*(jr); + if (r>0.0 && getValidValue(i,j+1,v)) + { + value += v*r; + div += r; + } + + if (div != 0.0) + { + value /= div; + return true; + } + + value = 0.0; + return false; + } + /** increment the modified count."*/ virtual void dirty() {}; diff --git a/src/osgTerrain/GeometryTechnique.cpp b/src/osgTerrain/GeometryTechnique.cpp index 883d9264d..30bd8cd5e 100644 --- a/src/osgTerrain/GeometryTechnique.cpp +++ b/src/osgTerrain/GeometryTechnique.cpp @@ -310,7 +310,7 @@ void GeometryTechnique::generateGeometry(Locator* masterLocator, const osg::Vec3 Locator* locator = colorLayer->getLocator(); if (!locator) - { + { osgTerrain::SwitchLayer* switchLayer = dynamic_cast(colorLayer); if (switchLayer) { @@ -321,8 +321,8 @@ void GeometryTechnique::generateGeometry(Locator* masterLocator, const osg::Vec3 locator = switchLayer->getLayer(switchLayer->getActiveLayer())->getLocator(); } } - } - + } + TexCoordLocatorPair& tclp = layerToTexCoordMap[colorLayer]; tclp.first = new osg::Vec2Array; tclp.first->reserve(numVertices); @@ -355,25 +355,20 @@ void GeometryTechnique::generateGeometry(Locator* masterLocator, const osg::Vec3 { unsigned int iv = j*numColumns + i; osg::Vec3d ndc( ((double)i)/(double)(numColumns-1), ((double)j)/(double)(numRows-1), 0.0); - + bool validValue = true; - - - unsigned int i_equiv = i_sampleFactor==1.0 ? i : (unsigned int) (double(i)*i_sampleFactor); - unsigned int j_equiv = i_sampleFactor==1.0 ? j : (unsigned int) (double(j)*j_sampleFactor); - if (elevationLayer) { float value = 0.0f; - validValue = elevationLayer->getValidValue(i_equiv,j_equiv, value); - // OSG_INFO<<"i="<