From e082008d8a6075a416f83fec37f073c54c8a5eee Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 11 Mar 2004 16:14:25 +0000 Subject: [PATCH] Moved osgTerrain::DataSet from the osgdem example into osgTerrain. Added various improvements. --- Make/makedirdefs | 8 +- examples/osgdem/GNUmakefile | 1 - examples/osgdem/osgdem.cpp | 48 +++++- .../DataSet.h => include/osgTerrain/DataSet | 10 ++ .../osgdem => src/osgTerrain}/DataSet.cpp | 155 +++++++++++++++++- src/osgTerrain/GNUmakefile | 3 +- 6 files changed, 207 insertions(+), 18 deletions(-) rename examples/osgdem/DataSet.h => include/osgTerrain/DataSet (99%) rename {examples/osgdem => src/osgTerrain}/DataSet.cpp (94%) diff --git a/Make/makedirdefs b/Make/makedirdefs index 22ceb7c99..3bfd4d620 100644 --- a/Make/makedirdefs +++ b/Make/makedirdefs @@ -16,12 +16,16 @@ SRC_DIRS = \ osgSim\ osgGL2\ osgFX\ - osgTerrain\ osgProducer\ + +ifeq ($(GDAL_INSTALLED),yes) +SRC_DIRS += osgTerrain +endif + +SRC_DIRS += \ osgPlugins\ ../examples - ################################################################ # Directories traversed in the TOPDIR/src/osgPlugins directory diff --git a/examples/osgdem/GNUmakefile b/examples/osgdem/GNUmakefile index df7325073..52b9a49bb 100644 --- a/examples/osgdem/GNUmakefile +++ b/examples/osgdem/GNUmakefile @@ -2,7 +2,6 @@ TOPDIR = ../.. include $(TOPDIR)/Make/makedefs CXXFILES =\ - DataSet.cpp\ osgdem.cpp\ LIBS += -losgProducer -lProducer -losgTerrain -losgFX -losgGL2 -losgText -losgGA -losgDB -losgUtil -losg -lgdal $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) diff --git a/examples/osgdem/osgdem.cpp b/examples/osgdem/osgdem.cpp index db31c90d6..2ae9dd65b 100644 --- a/examples/osgdem/osgdem.cpp +++ b/examples/osgdem/osgdem.cpp @@ -29,10 +29,34 @@ #include #include -#include "DataSet.h" +#include #include +char *SanitizeSRS( const char *pszUserInput ) + +{ + OGRSpatialReferenceH hSRS; + char *pszResult = NULL; + + CPLErrorReset(); + + hSRS = OSRNewSpatialReference( NULL ); + if( OSRSetFromUserInput( hSRS, pszUserInput ) == OGRERR_NONE ) + OSRExportToWkt( hSRS, &pszResult ); + else + { + CPLError( CE_Failure, CPLE_AppDefined, + "Translating source or target SRS failed:\n%s", + pszUserInput ); + exit( 1 ); + } + + OSRDestroySpatialReference( hSRS ); + + return pszResult; +} + int main( int argc, char **argv ) { @@ -58,22 +82,22 @@ int main( int argc, char **argv ) } // create DataSet. - osg::ref_ptr dataset = new DataSet; + osg::ref_ptr dataset = new osgTerrain::DataSet; std::string filename; while (arguments.read("-d",filename)) { - if (!filename.empty()) dataset->addSource(new DataSet::Source(DataSet::Source::HEIGHT_FIELD,filename)); + if (!filename.empty()) dataset->addSource(new osgTerrain::DataSet::Source(osgTerrain::DataSet::Source::HEIGHT_FIELD,filename)); } while (arguments.read("-t",filename)) { - if (!filename.empty()) dataset->addSource(new DataSet::Source(DataSet::Source::IMAGE,filename)); + if (!filename.empty()) dataset->addSource(new osgTerrain::DataSet::Source(osgTerrain::DataSet::Source::IMAGE,filename)); } while (arguments.read("-m",filename)) { - if (!filename.empty()) dataset->addSource(new DataSet::Source(DataSet::Source::MODEL,filename)); + if (!filename.empty()) dataset->addSource(new osgTerrain::DataSet::Source(osgTerrain::DataSet::Source::MODEL,filename)); } float x,y,w,h; @@ -104,7 +128,10 @@ int main( int argc, char **argv ) while (arguments.read("-l",numLevels)) {} float verticalScale; - while (arguments.read("-v",verticalScale)) {} + while (arguments.read("-v",verticalScale)) + { + dataset->setVerticalScale(verticalScale); + } // if user request help write it out to cout. @@ -114,8 +141,13 @@ int main( int argc, char **argv ) return 1; } - - if (true) + std::string def; + while (arguments.read("-s_srs",def)) + { + dataset->setDestinationCoordinateSystem(SanitizeSRS(def.c_str()) ); + } + + if (false) { // set up the coordinate system OGRSpatialReference oSRS; diff --git a/examples/osgdem/DataSet.h b/include/osgTerrain/DataSet similarity index 99% rename from examples/osgdem/DataSet.h rename to include/osgTerrain/DataSet index 78ace039a..b990663ee 100644 --- a/examples/osgdem/DataSet.h +++ b/include/osgTerrain/DataSet @@ -26,6 +26,9 @@ #include +namespace osgTerrain +{ + class DataSet : public osg::Referenced { public: @@ -770,6 +773,9 @@ class DataSet : public osg::Referenced void loadSources(); + void setVerticalScale(float verticalScale) { _verticalScale=verticalScale; } + float getVerticalScale() const { return _verticalScale; } + void setDestinationCoordinateSystem(const std::string& wellKnownText) { _coordinateSystem = new osgTerrain::CoordinateSystem(wellKnownText); } void setDestinationCoordinateSystem(osgTerrain::CoordinateSystem* cs) { _coordinateSystem = cs; } @@ -813,6 +819,8 @@ class DataSet : public osg::Referenced QuadMap _quadMap; + float _verticalScale; + osg::ref_ptr _coordinateSystem; osg::Matrixd _geoTransform; osg::BoundingBox _extents; @@ -825,4 +833,6 @@ class DataSet : public osg::Referenced }; +} + #endif diff --git a/examples/osgdem/DataSet.cpp b/src/osgTerrain/DataSet.cpp similarity index 94% rename from examples/osgdem/DataSet.cpp rename to src/osgTerrain/DataSet.cpp index 36f31cb43..e168b5799 100644 --- a/examples/osgdem/DataSet.cpp +++ b/src/osgTerrain/DataSet.cpp @@ -11,7 +11,6 @@ * OpenSceneGraph Public License for more details. */ -#include "DataSet.h" #include #include @@ -23,14 +22,86 @@ #include #include +#include + +// GDAL includes #include -#include "cpl_string.h" +#include #include - -#include - #include +// standard library includes +#include +#include + + +using namespace osgTerrain; + + +enum CoordinateSystemType +{ + GEOGRAPHIC, + PROJECTED, + LOCAL +}; + +CoordinateSystemType getCoordinateSystemType(const osgTerrain::CoordinateSystem* lhs) +{ + // set up LHS SpatialReference + char* projection_string = strdup(lhs->getProjectionRef().c_str()); + char* importString = projection_string; + + OGRSpatialReference lhsSR; + lhsSR.importFromWkt(&importString); + + free(projection_string); + + if (lhsSR.IsGeographic()) return GEOGRAPHIC; + if (lhsSR.IsProjected()) return PROJECTED; + if (lhsSR.IsLocal()) return LOCAL; + return PROJECTED; +} + +double getAngularUnits(const osgTerrain::CoordinateSystem* lhs) +{ + // set up LHS SpatialReference + char* projection_string = strdup(lhs->getProjectionRef().c_str()); + char* importString = projection_string; + + OGRSpatialReference lhsSR; + lhsSR.importFromWkt(&importString); + + free(projection_string); + + char* str; + double result = lhsSR.GetAngularUnits(&str); + std::cout<<"lhsSR.GetAngularUnits("<getProjectionRef().c_str()); + char* importString = projection_string; + + OGRSpatialReference lhsSR; + lhsSR.importFromWkt(&importString); + + free(projection_string); + + char* str; + double result = lhsSR.GetLinearUnits(&str); + std::cout<<"lhsSR.GetLinearUnits("<GetUnitType()) std::cout << "bandSelected->GetUnitType()=" << bandSelected->GetUnitType()<GetUnitType()= null" <GetNoDataValue(&success); if (success) @@ -522,6 +604,8 @@ void DataSet::SourceData::readHeightField(DestinationData& destination) std::cout<<"We have no Scale"<padfSrcNoDataReal[i] = noDataValue; + psWO->padfSrcNoDataImag[i] = 0.0; + psWO->padfDstNoDataReal[i] = new_noDataValue; + psWO->padfDstNoDataImag[i] = 0.0; + + GDALRasterBandH band = GDALGetRasterBand(hDstDS,i+1); + GDALSetRasterNoDataValue( band, new_noDataValue); + } + } + +#if 0 + psWO->papszWarpOptions = (char**)CPLMalloc(2*sizeof(char*)); + psWO->papszWarpOptions[0] = strdup("INIT_DEST=NO_DATA"); + psWO->papszWarpOptions[1] = 0; +#endif + +#if 0 + psWO->pfnSrcValidityMaskFunc = (GDALMaskFunc)GDALWarpNoDataMasker; +#endif + } + + /* -------------------------------------------------------------------- */ /* Initialize and execute the warp. */ /* -------------------------------------------------------------------- */ diff --git a/src/osgTerrain/GNUmakefile b/src/osgTerrain/GNUmakefile index 091af9534..622e008b4 100644 --- a/src/osgTerrain/GNUmakefile +++ b/src/osgTerrain/GNUmakefile @@ -4,6 +4,7 @@ include $(TOPDIR)/Make/makedefs CXXFILES = \ CoordinateSystem.cpp\ + DataSet.cpp\ Terrain.cpp\ Renderer.cpp\ GeoMipMapRenderer.cpp\ @@ -11,7 +12,7 @@ CXXFILES = \ DEF += -DOSGTERRAIN_LIBRARY -LIBS += -losgDB -losg $(GL_LIBS) $(OTHER_LIBS) +LIBS += -losgDB -losg -lgdal $(GL_LIBS) $(OTHER_LIBS) TARGET_BASENAME = osgTerrain LIB = $(LIB_PREFIX)$(TARGET_BASENAME).$(LIB_EXT)