Introduced the use of linear interpolation of evelvations when sampling

This commit is contained in:
Robert Osfield 2010-03-25 11:11:35 +00:00
parent 9d35ec1631
commit 304214e0df
2 changed files with 56 additions and 14 deletions

View File

@ -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() {};

View File

@ -310,7 +310,7 @@ void GeometryTechnique::generateGeometry(Locator* masterLocator, const osg::Vec3
Locator* locator = colorLayer->getLocator();
if (!locator)
{
{
osgTerrain::SwitchLayer* switchLayer = dynamic_cast<osgTerrain::SwitchLayer*>(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="<<i<<" j="<<j<<" z="<<value<<std::endl;
if (sampleRatio==1.0) validValue = elevationLayer->getValidValue(i,j,value);
else validValue = elevationLayer->getInterpolatedValidValue(ndc.x(), ndc.y(), value);
ndc.z() = value*scaleHeight;
}
if (validValue)
{
indices[iv] = vertices->size();
osg::Vec3d model;
masterLocator->convertLocalToModel(ndc, model);
@ -416,7 +411,7 @@ void GeometryTechnique::generateGeometry(Locator* masterLocator, const osg::Vec3
}
}
}
// populate primitive sets
// bool optimizeOrientations = elevations!=0;
bool swapOrientation = !(masterLocator->orientationOpenGL());