From 5c4446dd5ecc0993c429f5c94ef90c322a90ea1f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 31 Jul 2006 20:56:22 +0000 Subject: [PATCH] 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." --- include/osgTerrain/DataSet | 3 +++ src/osgTerrain/DataSet.cpp | 35 +++++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/include/osgTerrain/DataSet b/include/osgTerrain/DataSet index 75cc24a5f..b49377916 100644 --- a/include/osgTerrain/DataSet +++ b/include/osgTerrain/DataSet @@ -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; diff --git a/src/osgTerrain/DataSet.cpp b/src/osgTerrain/DataSet.cpp index 550acc8ba..d1c7ce584 100644 --- a/src/osgTerrain/DataSet.cpp +++ b/src/osgTerrain/DataSet.cpp @@ -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)