From Jason Beverage,

"I've attached fixes to DataSet that should fix the problems that Maya was seeing yesterday.  The issue was that the new interpolation code I submitted didn't use the SourceData's georef, it was assuming that the GDALDataSet had a proper geo-ref.  I've made the getInterpolatedValue method a member of SourceData and now it uses the georef the SourceData's georef.

I also forward declared the GDALRasterBand class in the DataSet header."
This commit is contained in:
Robert Osfield
2006-07-31 20:56:22 +00:00
parent 564ee34f76
commit 5c4446dd5e
2 changed files with 24 additions and 14 deletions

View File

@@ -41,6 +41,7 @@
// forward declare so we can avoid tieing osgTerrain to GDAL.
class GDALDataset;
class GDALRasterBand;
namespace osgTerrain
{
@@ -248,6 +249,8 @@ class OSGTERRAIN_EXPORT DataSet : public osg::Referenced
virtual void readHeightField(DestinationData& destination);
virtual void readModels(DestinationData& destination);
float getInterpolatedValue(GDALRasterBand *band, double x, double y);
Source* _source;
bool _hasGCPs;

View File

@@ -212,22 +212,32 @@ bool areCoordinateSystemEquivalent(const osg::CoordinateSystemNode* lhs,const os
return result ? true : false;
}
float getInterpolatedValue(GDALRasterBand *band, double x, double y)
DataSet::SourceData::~SourceData()
{
if (_gdalDataset) GDALClose(_gdalDataset);
}
float DataSet::SourceData::getInterpolatedValue(GDALRasterBand *band, double x, double y)
{
double geoTransform[6];
band->GetDataset()->GetGeoTransform(geoTransform);
geoTransform[0] = _geoTransform(3,0);
geoTransform[1] = _geoTransform(0,0);
geoTransform[2] = _geoTransform(1,0);
geoTransform[3] = _geoTransform(3,1);
geoTransform[4] = _geoTransform(0,1);
geoTransform[5] = _geoTransform(1,1);
double invTransform[6];
GDALInvGeoTransform(geoTransform, invTransform);
double r, c;
GDALApplyGeoTransform(invTransform, x, y, &c, &r);
int numRows = band->GetYSize();
int numCols = band->GetXSize();
int rowMin = osg::maximum((int)floor(r), 0);
int rowMax = osg::maximum(osg::minimum((int)ceil(r), numRows-1), 0);
int rowMax = osg::maximum(osg::minimum((int)ceil(r), (int)(_numValuesY-1)), 0);
int colMin = osg::maximum((int)floor(c), 0);
int colMax = osg::maximum(osg::minimum((int)ceil(c), numCols-1), 0);
int colMax = osg::maximum(osg::minimum((int)ceil(c), (int)(_numValuesX-1)), 0);
if (rowMin > rowMax) rowMin = rowMax;
if (colMin > colMax) colMin = colMax;
@@ -256,13 +266,10 @@ float getInterpolatedValue(GDALRasterBand *band, double x, double y)
double w01 = (1.0 - y_rem) * x_rem * (double)lrHeight;
double w10 = y_rem * (1.0 - x_rem) * (double)ulHeight;
double w11 = y_rem * x_rem * (double)urHeight;
float result = (float)(w00 + w01 + w10 + w11);
return result;
}
DataSet::SourceData::~SourceData()
{
if (_gdalDataset) GDALClose(_gdalDataset);
float result = (float)(w00 + w01 + w10 + w11);
return result;
}
DataSet::SourceData* DataSet::SourceData::readData(Source* source)