Added support for decoration of the osgTerrain::DataSet generated databases

with a CoordinateSystemNode which reflect the coordinate system of the
database.

Added support for reading and writing CoordianteSystemNode into the .osg
and .ive formats.
This commit is contained in:
Robert Osfield 2004-05-02 21:50:15 +00:00
parent a709c0a474
commit fced94fab3
16 changed files with 363 additions and 6 deletions

View File

@ -93,7 +93,7 @@ class SG_EXPORT CoordinateSystemNode : public Group
/** Set the CoordinateSystem reference string, should be stored in OpenGIS Well Know Text form.*/ /** Set the CoordinateSystem reference string, should be stored in OpenGIS Well Know Text form.*/
void setCoordnateSystem(const std::string& WKT) { _WKT = WKT; } void setCoordinateSystem(const std::string& WKT) { _WKT = WKT; }
/** Get the CoordinateSystem reference string.*/ /** Get the CoordinateSystem reference string.*/
const std::string& getCoordinateSystem() const { return _WKT; } const std::string& getCoordinateSystem() const { return _WKT; }

View File

@ -36,6 +36,7 @@ class Impostor;
class ClearNode; class ClearNode;
class OccluderNode; class OccluderNode;
class Sequence; class Sequence;
class CoordinateSystemNode;
/** Visitor for type safe operations on osg::Node's. /** Visitor for type safe operations on osg::Node's.
Based on GOF's Visitor pattern. The NodeVisitor Based on GOF's Visitor pattern. The NodeVisitor
@ -221,6 +222,8 @@ class SG_EXPORT NodeVisitor : public virtual Referenced
virtual void apply(Projection& node) { apply((Group&)node); } virtual void apply(Projection& node) { apply((Group&)node); }
virtual void apply(CoordinateSystemNode& node) { apply((Group&)node); }
virtual void apply(ClipNode& node) { apply((Group&)node); } virtual void apply(ClipNode& node) { apply((Group&)node); }
virtual void apply(LightSource& node) { apply((Group&)node); } virtual void apply(LightSource& node) { apply((Group&)node); }

View File

@ -91,13 +91,16 @@ class OSGTERRAIN_EXPORT DataSet : public osg::Referenced
struct DestinationData : public osg::Referenced, SpatialProperties struct DestinationData : public osg::Referenced, SpatialProperties
{ {
DestinationData(): DestinationData(DataSet* dataSet):
_dataSet(dataSet),
_minDistance(0.0), _minDistance(0.0),
_maxDistance(FLT_MAX) {} _maxDistance(FLT_MAX) {}
typedef std::vector< osg::ref_ptr<osg::Node> > ModelList; typedef std::vector< osg::ref_ptr<osg::Node> > ModelList;
DataSet* _dataSet;
float _minDistance; float _minDistance;
float _maxDistance; float _maxDistance;
@ -903,6 +906,9 @@ class OSGTERRAIN_EXPORT DataSet : public osg::Referenced
void setUseLocalTileTransform(bool flag) { _useLocalTileTransform = flag; } void setUseLocalTileTransform(bool flag) { _useLocalTileTransform = flag; }
bool getUseLocalTileTransform() const { return _useLocalTileTransform; } bool getUseLocalTileTransform() const { return _useLocalTileTransform; }
void setDecorateGeneratedSceneGraphWithCoordinateSystemNode(bool flag) { _decorateWithCoordinateSystemNode = flag; }
bool getDecorateGeneratedSceneGraphWithCoordinateSystemNode() const { return _decorateWithCoordinateSystemNode; }
CompositeDestination* createDestinationGraph(CompositeDestination* parent, CompositeDestination* createDestinationGraph(CompositeDestination* parent,
@ -937,6 +943,8 @@ class OSGTERRAIN_EXPORT DataSet : public osg::Referenced
void _equalizeRow(Row& row); void _equalizeRow(Row& row);
void _writeRow(Row& row); void _writeRow(Row& row);
osg::CoordinateSystemNode* decorateWithCoordinateSystemNode(osg::Node* subgraph);
void init(); void init();
osg::ref_ptr<CompositeSource> _sourceGraph; osg::ref_ptr<CompositeSource> _sourceGraph;
@ -949,8 +957,8 @@ class OSGTERRAIN_EXPORT DataSet : public osg::Referenced
float _radiusToMaxVisibleDistanceRatio; float _radiusToMaxVisibleDistanceRatio;
float _verticalScale; float _verticalScale;
osg::ref_ptr<osg::CoordinateSystemNode> _destinationCoordinateSystem; osg::ref_ptr<osg::CoordinateSystemNode> _destinationCoordinateSystem;
osg::ref_ptr<osg::CoordinateSystemNode> _intermediateCoordinateSystem; osg::ref_ptr<osg::CoordinateSystemNode> _intermediateCoordinateSystem;
bool _convertFromGeographicToGeocentric; bool _convertFromGeographicToGeocentric;
osg::ref_ptr<osg::EllipsoidModel> _ellipsoidModel; osg::ref_ptr<osg::EllipsoidModel> _ellipsoidModel;
@ -964,6 +972,8 @@ class OSGTERRAIN_EXPORT DataSet : public osg::Referenced
GeometryType _geometryType; GeometryType _geometryType;
TextureType _textureType; TextureType _textureType;
bool _useLocalTileTransform; bool _useLocalTileTransform;
bool _decorateWithCoordinateSystemNode;
osg::ref_ptr<osg::Node> _rootNode; osg::ref_ptr<osg::Node> _rootNode;

View File

@ -365,7 +365,7 @@ bool Field::getFloat(double& f) const
getFieldType(); getFieldType();
if (_fieldType==REAL || _fieldType==INTEGER) if (_fieldType==REAL || _fieldType==INTEGER)
{ {
f = (float)atof(_fieldCache); f = atof(_fieldCache);
return true; return true;
} }
else else

View File

@ -0,0 +1,76 @@
/**********************************************************************
*
* FILE: CoordinateSystemNode.cpp
*
* DESCRIPTION: Read/Write osg::CoordinateSystemNode in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 9.4.2003
*
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
#include "CoordinateSystemNode.h"
#include "EllipsoidModel.h"
#include "Group.h"
using namespace ive;
void CoordinateSystemNode::write(DataOutputStream* out)
{
// Write CoordinateSystemNode's identification.
out->writeInt(IVECOORDINATESYSTEMNODE);
// If the osg class is inherited by any other class we should also write this to file.
osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){
((ive::Group*)(group))->write(out);
}
else
throw Exception("CoordinateSystemNode::write(): Could not cast this osg::CoordinateSystemNode to an osg::Group.");
// Write CoordinateSystemNode's properties.
out->writeString(getCoordinateSystem());
out->writeBool(getEllipsoidModel()!=0);
if(getEllipsoidModel())
{
((ive::EllipsoidModel*)(getEllipsoidModel()))->write(out);
}
}
void CoordinateSystemNode::read(DataInputStream* in){
// Peek on CoordinateSystemNode's identification.
int id = in->peekInt();
if(id == IVECOORDINATESYSTEMNODE)
{
// Read CoordinateSystemNode's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){
((ive::Group*)(group))->read(in);
}
else
throw Exception("CoordinateSystemNode::read(): Could not cast this osg::CoordinateSystemNode to an osg::Group.");
// Read CoordinateSystemNode's properties
// Read coord string
setCoordinateSystem( in->readString());
bool readEllopsoidModel = in->readBool();
if (readEllopsoidModel)
{
osg::EllipsoidModel* em = new osg::EllipsoidModel();
((ive::EllipsoidModel*)(em))->read(in);
setEllipsoidModel(em);
}
}
else{
throw Exception("CoordinateSystemNode::read(): Expected CoordinateSystemNode identification.");
}
}

View File

@ -0,0 +1,15 @@
#ifndef IVE_COORDINATESYSTEMNODE
#define IVE_COORDINATESYSTEMNODE 1
#include <osg/CoordinateSystemNode>
#include "ReadWrite.h"
namespace ive{
class CoordinateSystemNode : public osg::CoordinateSystemNode, public ReadWrite {
public:
void write(DataOutputStream* out);
void read(DataInputStream* in);
};
}
#endif

View File

@ -47,6 +47,7 @@
#include "Switch.h" #include "Switch.h"
#include "OccluderNode.h" #include "OccluderNode.h"
#include "Impostor.h" #include "Impostor.h"
#include "CoordinateSystemNode.h"
#include "LightPointNode.h" #include "LightPointNode.h"
#include "MultiSwitch.h" #include "MultiSwitch.h"
@ -826,6 +827,10 @@ osg::Node* DataInputStream::readNode()
node = new osg::PagedLOD(); node = new osg::PagedLOD();
((ive::PagedLOD*)(node))->read(this); ((ive::PagedLOD*)(node))->read(this);
} }
else if(nodeTypeID== IVECOORDINATESYSTEMNODE){
node = new osg::CoordinateSystemNode();
((ive::CoordinateSystemNode*)(node))->read(this);
}
else if(nodeTypeID== IVESWITCH){ else if(nodeTypeID== IVESWITCH){
node = new osg::Switch(); node = new osg::Switch();
((ive::Switch*)(node))->read(this); ((ive::Switch*)(node))->read(this);

View File

@ -49,6 +49,7 @@
#include "Switch.h" #include "Switch.h"
#include "OccluderNode.h" #include "OccluderNode.h"
#include "Impostor.h" #include "Impostor.h"
#include "CoordinateSystemNode.h"
#include "LightPointNode.h" #include "LightPointNode.h"
#include "MultiSwitch.h" #include "MultiSwitch.h"
@ -611,6 +612,9 @@ void DataOutputStream::writeNode(const osg::Node* node)
else if(dynamic_cast<const osg::Switch*>(node)){ else if(dynamic_cast<const osg::Switch*>(node)){
((ive::Switch*)(node))->write(this); ((ive::Switch*)(node))->write(this);
} }
else if(dynamic_cast<const osg::CoordinateSystemNode*>(node)){
((ive::CoordinateSystemNode*)(node))->write(this);
}
else if(dynamic_cast<const osgSim::MultiSwitch*>(node)){ else if(dynamic_cast<const osgSim::MultiSwitch*>(node)){
((ive::MultiSwitch*)(node))->write(this); ((ive::MultiSwitch*)(node))->write(this);
} }

View File

@ -0,0 +1,62 @@
/**********************************************************************
*
* FILE: EllipsoidModel.cpp
*
* DESCRIPTION: Read/Write osg::EllipsoidModel in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 23.4.2003
*
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
#include "Object.h"
#include "EllipsoidModel.h"
#include "ConvexPlanarPolygon.h"
using namespace ive;
void EllipsoidModel::write(DataOutputStream* out){
// Write EllipsoidModel's identification.
out->writeInt(IVEELLIPSOIDMODEL);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("EllipsoidModel::write(): Could not cast this osg::EllipsoidModel to an osg::Object.");
// Write EllipsoidModel's properties.
out->writeDouble(getRadiusEquator());
out->writeDouble(getRadiusPolar());
}
void EllipsoidModel::read(DataInputStream* in){
// Peek on EllipsoidModel's identification.
int id = in->peekInt();
if(id == IVEELLIPSOIDMODEL){
// Read EllipsoidModel's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("EllipsoidModel::read(): Could not cast this osg::EllipsoidModel to an osg::Object.");
// Read EllipsoidModel's properties
setRadiusEquator(in->readDouble());
setRadiusPolar(in->readDouble());
}
else{
throw Exception("EllipsoidModel::read(): Expected EllipsoidModel identification.");
}
}

View File

@ -0,0 +1,15 @@
#ifndef IVE_ELLIPSOIDMODEL
#define IVE_ELLIPSOIDMODEL 1
#include <osg/CoordinateSystemNode>
#include "ReadWrite.h"
namespace ive{
class EllipsoidModel : public osg::EllipsoidModel, public ReadWrite {
public:
void write(DataOutputStream* out);
void read(DataInputStream* in);
};
}
#endif

View File

@ -9,6 +9,7 @@ CXXFILES =\
BlendFunc.cpp\ BlendFunc.cpp\
ConvexPlanarOccluder.cpp\ ConvexPlanarOccluder.cpp\
ConvexPlanarPolygon.cpp\ ConvexPlanarPolygon.cpp\
CoordinateSystemNode.cpp\
ClusterCullingCallback.cpp\ ClusterCullingCallback.cpp\
CullFace.cpp\ CullFace.cpp\
DataInputStream.cpp\ DataInputStream.cpp\
@ -20,6 +21,7 @@ CXXFILES =\
DrawElementsUShort.cpp\ DrawElementsUShort.cpp\
DrawElementsUInt.cpp\ DrawElementsUInt.cpp\
Drawable.cpp\ Drawable.cpp\
EllipsoidModel.cpp\
Exception.cpp\ Exception.cpp\
Geode.cpp\ Geode.cpp\
Geometry.cpp\ Geometry.cpp\

View File

@ -29,6 +29,8 @@ namespace ive {
#define IVECONVEXPLANARPOLYGON 0x00000020 #define IVECONVEXPLANARPOLYGON 0x00000020
#define IVEPAGEDLOD 0x00000021 #define IVEPAGEDLOD 0x00000021
#define IVEDOFTRANSFORM 0x00000022 #define IVEDOFTRANSFORM 0x00000022
#define IVECOORDINATESYSTEMNODE 0x00000023
#define IVEELLIPSOIDMODEL 0x00000024
// Node callbacks // Node callbacks
#define IVENODECALLBACK 0x00000050 #define IVENODECALLBACK 0x00000050

View File

@ -0,0 +1,60 @@
#include "osg/CoordinateSystemNode"
#include "osgDB/Registry"
#include "osgDB/Input"
#include "osgDB/Output"
using namespace osg;
using namespace osgDB;
// forward declare functions to use later.
bool CoordinateSystemNode_readLocalData(Object& obj, Input& fr);
bool CoordinateSystemNode_writeLocalData(const Object& obj, Output& fw);
// register the read and write functions with the osgDB::Registry.
RegisterDotOsgWrapperProxy g_CoordinateSystemNodeProxy
(
new osg::CoordinateSystemNode,
"CoordinateSystemNode",
"Object Node CoordinateSystemNode Group",
&CoordinateSystemNode_readLocalData,
&CoordinateSystemNode_writeLocalData
);
bool CoordinateSystemNode_readLocalData(Object& obj, Input& fr)
{
bool iteratorAdvanced = false;
CoordinateSystemNode& csn = static_cast<CoordinateSystemNode&>(obj);
if (fr.matchSequence("CoordinateSystem %s"))
{
const char* str = fr[1].getStr();
if (str) csn.setCoordinateSystem(str);
iteratorAdvanced = true;
fr+=2;
}
static ref_ptr<EllipsoidModel> s_ellipsoidModel = new EllipsoidModel;
EllipsoidModel* em = static_cast<EllipsoidModel*>(fr.readObjectOfType(*s_ellipsoidModel));
if (em) csn.setEllipsoidModel(em);
return iteratorAdvanced;
}
bool CoordinateSystemNode_writeLocalData(const Object& obj, Output& fw)
{
const CoordinateSystemNode& csn = static_cast<const CoordinateSystemNode&>(obj);
fw.indent()<<"CoordinateSystem "<<fw.wrapString(csn.getCoordinateSystem())<<std::endl;
if (csn.getEllipsoidModel())
{
fw.writeObject(*csn.getEllipsoidModel());
}
return true;
}

View File

@ -0,0 +1,67 @@
#include "osg/CoordinateSystemNode"
#include "osg/Notify"
#include "osgDB/Registry"
#include "osgDB/Input"
#include "osgDB/Output"
using namespace osg;
using namespace osgDB;
// forward declare functions to use later.
bool EllipsoidModel_readLocalData(Object& obj, Input& fr);
bool EllipsoidModel_writeLocalData(const Object& obj, Output& fw);
// register the read and write functions with the osgDB::Registry.
RegisterDotOsgWrapperProxy g_EllipsoidModelFuncProxy
(
new osg::EllipsoidModel,
"EllipsoidModel",
"Object EllipsoidModel",
&EllipsoidModel_readLocalData,
&EllipsoidModel_writeLocalData,
DotOsgWrapper::READ_AND_WRITE
);
bool EllipsoidModel_readLocalData(Object& obj, Input& fr)
{
bool iteratorAdvanced = false;
EllipsoidModel& em = static_cast<EllipsoidModel&>(obj);
if (fr.matchSequence("RadiusEquator %f"))
{
double radius;
fr[1].getFloat(radius);
em.setRadiusEquator(radius);
fr += 2;
iteratorAdvanced = true;
}
if (fr.matchSequence("RadiusPolar %f"))
{
double radius;
fr[1].getFloat(radius);
em.setRadiusPolar(radius);
fr += 2;
iteratorAdvanced = true;
}
return iteratorAdvanced;
}
bool EllipsoidModel_writeLocalData(const Object& obj, Output& fw)
{
const EllipsoidModel& em = static_cast<const EllipsoidModel&>(obj);
int prec = fw.precision();
fw.precision(15);
fw.indent()<<"RadiusEquator "<<em.getRadiusEquator()<<std::endl;
fw.indent()<<"RadiusPolar "<<em.getRadiusPolar()<<std::endl;
fw.precision(prec);
return true;
}

View File

@ -7,13 +7,15 @@ CXXFILES =\
Billboard.cpp\ Billboard.cpp\
BlendFunc.cpp\ BlendFunc.cpp\
ClipPlane.cpp\ ClipPlane.cpp\
ClearNode.cpp\
ColorMask.cpp\ ColorMask.cpp\
CoordinateSystemNode.cpp\
ConvexPlanarOccluder.cpp\ ConvexPlanarOccluder.cpp\
CullFace.cpp\ CullFace.cpp\
ClipNode.cpp\ ClipNode.cpp\
Depth.cpp\ Depth.cpp\
Drawable.cpp\ Drawable.cpp\
ClearNode.cpp\ EllipsoidModel.cpp\
Fog.cpp\ Fog.cpp\
FragmentProgram.cpp\ FragmentProgram.cpp\
FrontFace.cpp\ FrontFace.cpp\

View File

@ -2754,6 +2754,8 @@ DataSet::DataSet()
_textureType = COMPRESSED_TEXTURE; _textureType = COMPRESSED_TEXTURE;
_useLocalTileTransform = true; _useLocalTileTransform = true;
_decorateWithCoordinateSystemNode = true;
setEllipsoidModel(new osg::EllipsoidModel()); setEllipsoidModel(new osg::EllipsoidModel());
} }
@ -3343,6 +3345,11 @@ void DataSet::_writeRow(Row& row)
{ {
osg::ref_ptr<osg::Node> node = cd->createPagedLODScene(); osg::ref_ptr<osg::Node> node = cd->createPagedLODScene();
if (_decorateWithCoordinateSystemNode)
{
node = decorateWithCoordinateSystemNode(node.get());
}
//std::string filename = cd->_name + _tileExtension; //std::string filename = cd->_name + _tileExtension;
std::string filename = _tileBasename+_tileExtension; std::string filename = _tileBasename+_tileExtension;
@ -3368,6 +3375,27 @@ void DataSet::createDestination(unsigned int numLevels)
} }
osg::CoordinateSystemNode* DataSet::decorateWithCoordinateSystemNode(osg::Node* subgraph)
{
// don't decorate if no coord system is set.
if (_destinationCoordinateSystem->getCoordinateSystem().empty())
return subgraph;
osg::CoordinateSystemNode* csn = new osg::CoordinateSystemNode;
// copy the destinate coordinate system string.
csn->setCoordinateSystem(_destinationCoordinateSystem->getCoordinateSystem());
// set the ellipsoid model if geocentric coords are used.
if (getConvertFromGeographicToGeocentric()) csn->setEllipsoidModel(getEllipsoidModel());
// add the a subgraph.
csn->addChild(subgraph);
return csn;
}
void DataSet::writeDestination() void DataSet::writeDestination()
{ {
if (_destinationGraph.valid()) if (_destinationGraph.valid())
@ -3379,6 +3407,12 @@ void DataSet::writeDestination()
{ {
populateDestinationGraphFromSources(); populateDestinationGraphFromSources();
_rootNode = _destinationGraph->createScene(); _rootNode = _destinationGraph->createScene();
if (_decorateWithCoordinateSystemNode)
{
_rootNode = decorateWithCoordinateSystemNode(_rootNode.get());
}
osgDB::writeNodeFile(*_rootNode,filename); osgDB::writeNodeFile(*_rootNode,filename);
} }
else // _databaseType==PagedLOD_DATABASE else // _databaseType==PagedLOD_DATABASE