Moved osgTerrain::DataSet from the osgdem example into osgTerrain. Added
various improvements.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -29,10 +29,34 @@
|
||||
#include <osgProducer/Viewer>
|
||||
#include <osg/Switch>
|
||||
|
||||
#include "DataSet.h"
|
||||
#include <osgTerrain/DataSet>
|
||||
|
||||
#include <ogr_spatialref.h>
|
||||
|
||||
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> dataset = new DataSet;
|
||||
osg::ref_ptr<osgTerrain::DataSet> 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;
|
||||
|
||||
@@ -26,6 +26,9 @@
|
||||
|
||||
#include <gdal_priv.h>
|
||||
|
||||
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<osgTerrain::CoordinateSystem> _coordinateSystem;
|
||||
osg::Matrixd _geoTransform;
|
||||
osg::BoundingBox _extents;
|
||||
@@ -825,4 +833,6 @@ class DataSet : public osg::Referenced
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -11,7 +11,6 @@
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#include "DataSet.h"
|
||||
|
||||
#include <osg/Geode>
|
||||
#include <osg/ShapeDrawable>
|
||||
@@ -23,14 +22,86 @@
|
||||
#include <osgDB/WriteFile>
|
||||
#include <osgDB/FileNameUtils>
|
||||
|
||||
#include <osgTerrain/DataSet>
|
||||
|
||||
// GDAL includes
|
||||
#include <gdal_priv.h>
|
||||
#include "cpl_string.h"
|
||||
#include <cpl_string.h>
|
||||
#include <gdalwarper.h>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include <ogr_spatialref.h>
|
||||
|
||||
// standard library includes
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
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("<<str<<") "<<result<<std::endl;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
double getLinearUnits(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.GetLinearUnits(&str);
|
||||
std::cout<<"lhsSR.GetLinearUnits("<<str<<") "<<result<<std::endl;
|
||||
|
||||
std::cout<<"lhsSR.IsGeographic() "<<lhsSR.IsGeographic()<<std::endl;
|
||||
std::cout<<"lhsSR.IsProjected() "<<lhsSR.IsProjected()<<std::endl;
|
||||
std::cout<<"lhsSR.IsLocal() "<<lhsSR.IsLocal()<<std::endl;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool areCoordinateSystemEquivilant(const osgTerrain::CoordinateSystem* lhs,const osgTerrain::CoordinateSystem* rhs)
|
||||
{
|
||||
// if ptr's equal the return true
|
||||
@@ -489,6 +560,17 @@ void DataSet::SourceData::readHeightField(DestinationData& destination)
|
||||
|
||||
bool xyInDegrees = false;
|
||||
|
||||
CoordinateSystemType cst = getCoordinateSystemType(_cs.get());
|
||||
if (cst==GEOGRAPHIC)
|
||||
{
|
||||
xyInDegrees = true;
|
||||
}
|
||||
|
||||
|
||||
if (bandSelected->GetUnitType()) std::cout << "bandSelected->GetUnitType()=" << bandSelected->GetUnitType()<<std::endl;
|
||||
else std::cout << "bandSelected->GetUnitType()= null" <<std::endl;
|
||||
|
||||
|
||||
int success = 0;
|
||||
float noDataValue = bandSelected->GetNoDataValue(&success);
|
||||
if (success)
|
||||
@@ -522,6 +604,8 @@ void DataSet::SourceData::readHeightField(DestinationData& destination)
|
||||
std::cout<<"We have no Scale"<<std::endl;
|
||||
scale = xyInDegrees ? 1.0f/111319.0f : 1.0f;
|
||||
}
|
||||
|
||||
std::cout<<"********* getLinearUnits = "<<getLinearUnits(_cs.get())<<std::endl;
|
||||
|
||||
// read data into temporary array
|
||||
float* heightData = new float [ destWidth*destHeight ];
|
||||
@@ -765,12 +849,71 @@ DataSet::Source* DataSet::Source::doReproject(const std::string& filename, osgTe
|
||||
psWO->panSrcBands = (int *) CPLMalloc(psWO->nBandCount*sizeof(int));
|
||||
psWO->panDstBands = (int *) CPLMalloc(psWO->nBandCount*sizeof(int));
|
||||
|
||||
for(int i = 0; i < psWO->nBandCount; i++ )
|
||||
int i;
|
||||
for(i = 0; i < psWO->nBandCount; i++ )
|
||||
{
|
||||
psWO->panSrcBands[i] = i+1;
|
||||
psWO->panDstBands[i] = i+1;
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* Setup no datavalue */
|
||||
/* -----------------------------------------------------`--------------- */
|
||||
|
||||
|
||||
// check to see if no value values exist in source datasets.
|
||||
int numNoDataValues = 0;
|
||||
for(i = 0; i < _sourceData->_gdalDataSet->GetRasterCount(); i++ )
|
||||
{
|
||||
int success = 0;
|
||||
GDALRasterBand* band = _sourceData->_gdalDataSet->GetRasterBand(i+1);
|
||||
band->GetNoDataValue(&success);
|
||||
if (success) ++numNoDataValues;
|
||||
}
|
||||
|
||||
if (numNoDataValues)
|
||||
{
|
||||
// no data values exist, so populate the no data arrays.
|
||||
|
||||
psWO->padfSrcNoDataReal = (double*) CPLMalloc(psWO->nBandCount*sizeof(double));
|
||||
psWO->padfSrcNoDataImag = (double*) CPLMalloc(psWO->nBandCount*sizeof(double));
|
||||
|
||||
psWO->padfDstNoDataReal = (double*) CPLMalloc(psWO->nBandCount*sizeof(double));
|
||||
psWO->padfDstNoDataImag = (double*) CPLMalloc(psWO->nBandCount*sizeof(double));
|
||||
|
||||
for(i = 0; i < _sourceData->_gdalDataSet->GetRasterCount(); i++ )
|
||||
{
|
||||
int success = 0;
|
||||
GDALRasterBand* band = _sourceData->_gdalDataSet->GetRasterBand(i+1);
|
||||
double noDataValue = band->GetNoDataValue(&success);
|
||||
double new_noDataValue = 0.0;
|
||||
if (success)
|
||||
{
|
||||
std::cout<<"\tassinging no data value "<<noDataValue<<" to band "<<i+1<<std::endl;
|
||||
|
||||
psWO->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. */
|
||||
/* -------------------------------------------------------------------- */
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user