Added normal generation in polygonal tile generation, and add --wtk option

for setting coord systems in osgdem
This commit is contained in:
Robert Osfield
2004-03-29 22:26:51 +00:00
parent 7bea5842fa
commit a1b46de936
4 changed files with 75 additions and 31 deletions

View File

@@ -174,6 +174,12 @@ int main( int argc, char **argv )
currentCS = !def.empty() ? SanitizeSRS(def.c_str()) : "";
std::cout<<"--cs "<<currentCS<<std::endl;
}
else if (arguments.read(pos, "--wtk",def))
{
argumentRead = true;
currentCS = def;
std::cout<<"--wtk "<<currentCS<<std::endl;
}
else if (arguments.read(pos, "--identity"))
{
geoTransformSet = false;

View File

@@ -28,9 +28,16 @@ class CoordinateSystem : public osg::Object
{
public:
enum Type
{
GEOCENTRIC,
GEOGRAPHIC,
PROJECTED
};
CoordinateSystem();
CoordinateSystem(const std::string& projectionRef);
CoordinateSystem(const std::string& WTK, Type type=GEOCENTRIC);
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
CoordinateSystem(const CoordinateSystem&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
@@ -40,20 +47,25 @@ class CoordinateSystem : public osg::Object
inline bool operator == (const CoordinateSystem& cs) const
{
if (this == &cs) return true;
if (_projectionRef == cs._projectionRef) return true;
return false;
if (_type!=cs._type) return false;
if (_WKT != cs._WKT) return false;
return true;
}
inline bool operator != (const CoordinateSystem& cs) const
{
return !(*this==cs);
}
/** Set the CoordinateSystem projection reference string, should be stored in OpenGIS Well Know Text form.*/
void setProjectionRef(const std::string& projectionRef) { _projectionRef = projectionRef; }
void setType(Type type) { _type = type; }
Type getType() const { return _type; }
/** Get the CoordinateSystem projection reference string.*/
const std::string& getProjectionRef() const { return _projectionRef; }
/** Set the CoordinateSystem reference string, should be stored in OpenGIS Well Know Text form.*/
void setWKT(const std::string& WKT) { _WKT = WKT; }
/** Get the CoordinateSystem reference string.*/
const std::string& getWKT() const { return _WKT; }
/** CoordinateTransformation is a helper class for transforming between two different CoodinateSystems.
@@ -86,9 +98,9 @@ class CoordinateSystem : public osg::Object
protected:
virtual ~CoordinateSystem() {}
std::string _projectionRef;
Type _type;
std::string _WKT;
};

View File

@@ -15,18 +15,20 @@
using namespace osgTerrain;
CoordinateSystem::CoordinateSystem()
CoordinateSystem::CoordinateSystem():
_type(GEOGRAPHIC)
{
}
CoordinateSystem::CoordinateSystem(const std::string& projectionRef):
_projectionRef(projectionRef)
CoordinateSystem::CoordinateSystem(const std::string& WKT, Type type):
_type(type),
_WKT(WKT)
{
}
CoordinateSystem::CoordinateSystem(const CoordinateSystem& cs,const osg::CopyOp& copyop):
Object(cs,copyop),
_projectionRef(cs._projectionRef)
_WKT(cs._WKT)
{
}

View File

@@ -50,13 +50,19 @@ enum CoordinateSystemType
CoordinateSystemType getCoordinateSystemType(const osgTerrain::CoordinateSystem* lhs)
{
// set up LHS SpatialReference
char* projection_string = strdup(lhs->getProjectionRef().c_str());
char* projection_string = strdup(lhs->getWKT().c_str());
char* importString = projection_string;
OGRSpatialReference lhsSR;
lhsSR.importFromWkt(&importString);
free(projection_string);
std::cout<<"getCoordinateSystemType("<<projection_string<<")"<<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;
if (lhsSR.IsGeographic()) return GEOGRAPHIC;
if (lhsSR.IsProjected()) return PROJECTED;
@@ -67,7 +73,7 @@ CoordinateSystemType getCoordinateSystemType(const osgTerrain::CoordinateSystem*
double getAngularUnits(const osgTerrain::CoordinateSystem* lhs)
{
// set up LHS SpatialReference
char* projection_string = strdup(lhs->getProjectionRef().c_str());
char* projection_string = strdup(lhs->getWKT().c_str());
char* importString = projection_string;
OGRSpatialReference lhsSR;
@@ -85,7 +91,7 @@ double getAngularUnits(const osgTerrain::CoordinateSystem* lhs)
double getLinearUnits(const osgTerrain::CoordinateSystem* lhs)
{
// set up LHS SpatialReference
char* projection_string = strdup(lhs->getProjectionRef().c_str());
char* projection_string = strdup(lhs->getWKT().c_str());
char* importString = projection_string;
OGRSpatialReference lhsSR;
@@ -120,7 +126,7 @@ bool areCoordinateSystemEquivilant(const osgTerrain::CoordinateSystem* lhs,const
if (*lhs == *rhs) return true;
// set up LHS SpatialReference
char* projection_string = strdup(lhs->getProjectionRef().c_str());
char* projection_string = strdup(lhs->getWKT().c_str());
char* importString = projection_string;
OGRSpatialReference lhsSR;
@@ -129,7 +135,7 @@ bool areCoordinateSystemEquivilant(const osgTerrain::CoordinateSystem* lhs,const
free(projection_string);
// set up RHS SpatialReference
projection_string = strdup(rhs->getProjectionRef().c_str());
projection_string = strdup(rhs->getWKT().c_str());
importString = projection_string;
OGRSpatialReference rhsSR;
@@ -143,8 +149,8 @@ bool areCoordinateSystemEquivilant(const osgTerrain::CoordinateSystem* lhs,const
int result2 = lhsSR.IsSameGeogCS(&rhsSR);
std::cout<<"areCoordinateSystemEquivilant "<<std::endl
<<"LHS = "<<lhs->getProjectionRef()<<std::endl
<<"RHS = "<<rhs->getProjectionRef()<<std::endl
<<"LHS = "<<lhs->getWKT()<<std::endl
<<"RHS = "<<rhs->getWKT()<<std::endl
<<"result = "<<result<<" result2 = "<<result2<<std::endl;
#endif
return result;
@@ -301,8 +307,8 @@ const DataSet::SpatialProperties& DataSet::SourceData::computeSpatialProperties(
/* destination coordinate system. */
/* -------------------------------------------------------------------- */
void *hTransformArg =
GDALCreateGenImgProjTransformer( _gdalDataSet,_cs->getProjectionRef().c_str(),
NULL, cs->getProjectionRef().c_str(),
GDALCreateGenImgProjTransformer( _gdalDataSet,_cs->getWKT().c_str(),
NULL, cs->getWKT().c_str(),
TRUE, 0.0, 1 );
if (!hTransformArg)
@@ -783,8 +789,8 @@ DataSet::Source* DataSet::Source::doReproject(const std::string& filename, osgTe
/* destination coordinate system. */
/* -------------------------------------------------------------------- */
void *hTransformArg =
GDALCreateGenImgProjTransformer( _sourceData->_gdalDataSet,_sourceData->_cs->getProjectionRef().c_str(),
NULL, cs->getProjectionRef().c_str(),
GDALCreateGenImgProjTransformer( _sourceData->_gdalDataSet,_sourceData->_cs->getWKT().c_str(),
NULL, cs->getWKT().c_str(),
TRUE, 0.0, 1 );
if (!hTransformArg)
@@ -853,21 +859,21 @@ DataSet::Source* DataSet::Source::doReproject(const std::string& filename, osgTe
/* -------------------------------------------------------------------- */
/* Write out the projection definition. */
/* -------------------------------------------------------------------- */
GDALSetProjection( hDstDS, cs->getProjectionRef().c_str() );
GDALSetProjection( hDstDS, cs->getWKT().c_str() );
GDALSetGeoTransform( hDstDS, adfDstGeoTransform );
// Set up the transformer along with the new datasets.
hTransformArg =
GDALCreateGenImgProjTransformer( _sourceData->_gdalDataSet,_sourceData->_cs->getProjectionRef().c_str(),
hDstDS, cs->getProjectionRef().c_str(),
GDALCreateGenImgProjTransformer( _sourceData->_gdalDataSet,_sourceData->_cs->getWKT().c_str(),
hDstDS, cs->getWKT().c_str(),
TRUE, 0.0, 1 );
GDALTransformerFunc pfnTransformer = GDALGenImgProjTransform;
std::cout<<"Setting projection "<<cs->getProjectionRef()<<std::endl;
std::cout<<"Setting projection "<<cs->getWKT()<<std::endl;
/* -------------------------------------------------------------------- */
/* Copy the color table, if required. */
@@ -1835,6 +1841,9 @@ osg::Geometry* DataSet::DestinationTile::createDrawablePolygonal()
color[0].set(255,255,255,255);
osg::Vec3Array* n = new osg::Vec3Array(numVertices);
unsigned int vi=0;
unsigned int r,c;
for(r=0;r<numRows;++r)
@@ -1842,13 +1851,24 @@ osg::Geometry* DataSet::DestinationTile::createDrawablePolygonal()
for(c=0;c<numColumns;++c)
{
v[vi] = grid->getVertex(c,r);
if (n) (*n)[vi] = grid->getNormal(c,r);
t[vi].x() = (float)(c)/(float)(numColumns);
t[vi].y() = (float)(r)/(float)(numRows);
++vi;
}
}
geometry->setVertexArray(&v);
if (n)
{
geometry->setNormalArray(n);
geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
}
geometry->setColorArray(&color);
geometry->setColorBinding(osg::Geometry::BIND_OVERALL);
geometry->setTexCoordArray(0,&t);
@@ -1905,6 +1925,7 @@ osg::Geometry* DataSet::DestinationTile::createDrawablePolygonal()
skirtDrawElements[ei++] = (r)*numColumns+c;
skirtDrawElements[ei++] = vi;
v[vi] = v[(r)*numColumns+c]+skirtVector;
if (n) (*n)[vi] = (*n)[r*numColumns+c];
t[vi++] = t[(r)*numColumns+c];
}
// create right skirt vertices
@@ -1914,6 +1935,7 @@ osg::Geometry* DataSet::DestinationTile::createDrawablePolygonal()
skirtDrawElements[ei++] = (r)*numColumns+c;
skirtDrawElements[ei++] = vi;
v[vi] = v[(r)*numColumns+c]+skirtVector;
if (n) (*n)[vi] = (*n)[(r)*numColumns+c];
t[vi++] = t[(r)*numColumns+c];
}
// create top skirt vertices
@@ -1923,6 +1945,7 @@ osg::Geometry* DataSet::DestinationTile::createDrawablePolygonal()
skirtDrawElements[ei++] = (r)*numColumns+c;
skirtDrawElements[ei++] = vi;
v[vi] = v[(r)*numColumns+c]+skirtVector;
if (n) (*n)[vi] = (*n)[(r)*numColumns+c];
t[vi++] = t[(r)*numColumns+c];
}
// create left skirt vertices
@@ -1932,6 +1955,7 @@ osg::Geometry* DataSet::DestinationTile::createDrawablePolygonal()
skirtDrawElements[ei++] = (r)*numColumns+c;
skirtDrawElements[ei++] = vi;
v[vi] = v[(r)*numColumns+c]+skirtVector;
if (n) (*n)[vi] = (*n)[(r)*numColumns+c];
t[vi++] = t[(r)*numColumns+c];
}
skirtDrawElements[ei++] = 0;
@@ -2623,7 +2647,7 @@ void DataSet::computeDestinationGraphFromSources(unsigned int numLevels)
if (sd->_cs.valid())
{
_coordinateSystem = sd->_cs;
std::cout<<"Setting coordinate system to "<<_coordinateSystem->getProjectionRef()<<std::endl;
std::cout<<"Setting coordinate system to "<<_coordinateSystem->getWKT()<<std::endl;
break;
}
}