From b7746ff56ec6de2a69ad18446e7fdd4214394969 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 3 May 2004 12:04:25 +0000 Subject: [PATCH] Added support for automatically finding CoordinateSystemNode's in the scene graph and then using them to set up the CoordinateFrame used by the camera manipulators. --- examples/osgviewer/osgviewer.cpp | 16 +------ include/osg/CoordinateSystemNode | 2 +- include/osgProducer/OsgCameraGroup | 9 +++- include/osgProducer/Viewer | 15 ++++-- src/osgProducer/OsgCameraGroup.cpp | 9 +++- src/osgProducer/Viewer.cpp | 76 ++++++++++++++++++++++++++++-- 6 files changed, 100 insertions(+), 27 deletions(-) diff --git a/examples/osgviewer/osgviewer.cpp b/examples/osgviewer/osgviewer.cpp index 92310c69e..c4560fd01 100644 --- a/examples/osgviewer/osgviewer.cpp +++ b/examples/osgviewer/osgviewer.cpp @@ -85,23 +85,9 @@ int main( int argc, char **argv ) osgUtil::Optimizer optimizer; optimizer.optimize(loadedModel.get()); -#if 0 - osg::CoordinateSystemNode* csn = new osg::CoordinateSystemNode; - csn->addChild(loadedModel.get()); - csn->setEllipsoidModel(new osg::EllipsoidModel()); - - osg::NodePath nodepath; - nodepath.push_back(csn); - - viewer.setCoordindateSystemNodePath(nodepath); - - // set the scene to render - viewer.setSceneData(csn); -#else - + // pass the loaded scene graph to the viewer. viewer.setSceneData(loadedModel.get()); -#endif // create the windows and run the threads. viewer.realize(); diff --git a/include/osg/CoordinateSystemNode b/include/osg/CoordinateSystemNode index a75e3850a..be1828c6c 100644 --- a/include/osg/CoordinateSystemNode +++ b/include/osg/CoordinateSystemNode @@ -89,7 +89,7 @@ class SG_EXPORT CoordinateSystemNode : public Group /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ CoordinateSystemNode(const CoordinateSystemNode&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); - META_Object(osg,CoordinateSystemNode); + META_Node(osg,CoordinateSystemNode); /** Set the CoordinateSystem reference string, should be stored in OpenGIS Well Know Text form.*/ diff --git a/include/osgProducer/OsgCameraGroup b/include/osgProducer/OsgCameraGroup index e90eb2ced..ca3b74795 100644 --- a/include/osgProducer/OsgCameraGroup +++ b/include/osgProducer/OsgCameraGroup @@ -78,7 +78,11 @@ class OSGPRODUCER_EXPORT OsgCameraGroup : public Producer::CameraGroup const osg::Node* getTopMostSceneData() const; - + + /** update internal structures w.r.t updated scene data.*/ + virtual void updatedSceneData(); + + void setDisplaySettings( osg::DisplaySettings *ds ) { _ds = ds; } osg::DisplaySettings *getDisplaySettings() { return _ds.get(); } @@ -165,7 +169,8 @@ class OSGPRODUCER_EXPORT OsgCameraGroup : public Producer::CameraGroup protected : - void setUpSceneViewsWithData(); + + virtual void setUpSceneViewsWithData(); osg::ApplicationUsage* _applicationUsage; diff --git a/include/osgProducer/Viewer b/include/osgProducer/Viewer index 37e57d415..762be486e 100644 --- a/include/osgProducer/Viewer +++ b/include/osgProducer/Viewer @@ -100,9 +100,13 @@ class OSGPRODUCER_EXPORT Viewer : public OsgCameraGroup, public osgGA::GUIAction const osg::NodeVisitor* getUpdateVisitor() const { return _updateVisitor.get(); } - void setCoordindateSystemNodePath(const osg::NodePath& nodePath) { _coordinateSystemNodePath = nodePath; } + typedef std::vector< osg::ref_ptr > RefNodePath; - const osg::NodePath& getCoordindateSystemNodePath() { return _coordinateSystemNodePath; } + void setCoordindateSystemNodePath(const RefNodePath& nodePath) { _coordinateSystemNodePath = nodePath; } + + void setCoordindateSystemNodePath(const osg::NodePath& nodePath); + + const RefNodePath& getCoordindateSystemNodePath() { return _coordinateSystemNodePath; } /** Dispatch the cull and draw for each of the Camera's for this frame.*/ virtual void frame(); @@ -166,7 +170,9 @@ class OSGPRODUCER_EXPORT Viewer : public OsgCameraGroup, public osgGA::GUIAction /** Get the keyboard and mouse usage of this viewer.*/ virtual void getUsage(osg::ApplicationUsage& usage) const; - + + /** update internal structures w.r.t updated scene data.*/ + virtual void updatedSceneData(); protected : @@ -183,7 +189,8 @@ class OSGPRODUCER_EXPORT Viewer : public OsgCameraGroup, public osgGA::GUIAction osg::ref_ptr _updateVisitor; - osg::NodePath _coordinateSystemNodePath; + + RefNodePath _coordinateSystemNodePath; bool _recordingAnimationPath; double _recordingStartTime; diff --git a/src/osgProducer/OsgCameraGroup.cpp b/src/osgProducer/OsgCameraGroup.cpp index 6625dfae5..03a7f4dc6 100644 --- a/src/osgProducer/OsgCameraGroup.cpp +++ b/src/osgProducer/OsgCameraGroup.cpp @@ -166,7 +166,7 @@ void OsgCameraGroup::setSceneData( osg::Node *scene ) _scene_decorator->addChild(scene); } - setUpSceneViewsWithData(); + updatedSceneData(); } void OsgCameraGroup::setSceneDecorator( osg::Group* decorator) @@ -179,10 +179,15 @@ void OsgCameraGroup::setSceneDecorator( osg::Group* decorator) { decorator->addChild(_scene_data.get()); } - setUpSceneViewsWithData(); + updatedSceneData(); } +void OsgCameraGroup::updatedSceneData() +{ + setUpSceneViewsWithData(); +} + void OsgCameraGroup::setUpSceneViewsWithData() { for(SceneHandlerList::iterator p = _shvec.begin(); p != _shvec.end(); p++ ) diff --git a/src/osgProducer/Viewer.cpp b/src/osgProducer/Viewer.cpp index 6ff70ce23..c878ef4a9 100644 --- a/src/osgProducer/Viewer.cpp +++ b/src/osgProducer/Viewer.cpp @@ -135,6 +135,40 @@ private: osgUtil::IntersectVisitor::HitList _PIVsegHitList; }; + +class CollectedCoordinateSystemNodesVisitor : public osg::NodeVisitor +{ +public: + + CollectedCoordinateSystemNodesVisitor(): + NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {} + + + virtual void apply(osg::Node& node) + { + traverse(node); + } + + virtual void apply(osg::CoordinateSystemNode& node) + { + if (_pathToCoordinateSystemNode.empty()) + { + osg::notify(osg::NOTICE)<<"Found CoordianteSystemNode node"<