Added support for passing in an options string to control the orientation of the generated graph

This commit is contained in:
Robert Osfield 2010-04-28 18:52:58 +00:00
parent f27678dbb9
commit b459fb4a25
3 changed files with 41 additions and 4 deletions

View File

@ -18,23 +18,51 @@
#include <osg/Node>
#include <osg/Geode>
#include <osg/Group>
#include <osg/Notify>
using namespace osg;
namespace osgDot {
BaseDotVisitor::BaseDotVisitor() {
BaseDotVisitor::BaseDotVisitor()
{
_rankdir = "rankdir = LR;";
}
BaseDotVisitor::~BaseDotVisitor() {
}
bool BaseDotVisitor::run( osg::Node& root, std::ostream* fout ) {
void BaseDotVisitor::setOptions(const osgDB::Options* options)
{
_options = const_cast<osgDB::Options*>(options);
OSG_INFO<<"BaseDotVisitor::setOptions("<<options<<")"<<std::endl;
if (_options.valid() && !(_options->getOptionString().empty()))
{
std::string optionString = _options->getOptionString();
OSG_INFO<<" BaseDotVisitor::optionString ("<<optionString<<")"<<std::endl;
std::string::size_type pos = optionString.find("rankdir");
if (pos!=std::string::npos)
{
std::string::size_type semi_pos = optionString.find(";",pos);
if (semi_pos!=std::string::npos)
{
_rankdir = optionString.substr(pos, semi_pos-pos);
OSG_INFO<<" BaseDotVisitor::Set _rankdir to "<<_rankdir<<std::endl;
}
}
}
}
bool BaseDotVisitor::run( osg::Node& root, std::ostream* fout ) {
setTraversalMode( TRAVERSE_ALL_CHILDREN );
if ( fout && *fout ) {
root.accept( *this );
*fout << "digraph osg_scenegraph { rankdir = LR;" << std::endl;
*fout << "digraph osg_scenegraph { "<<_rankdir<< std::endl;
*fout << _nodes.str() << _edges.str();

View File

@ -26,6 +26,8 @@
#include <osg/Geode>
#include <osg/ref_ptr>
#include <osgDB/Options>
namespace osgDot {
class BaseDotVisitor : public osg::NodeVisitor {
@ -37,6 +39,8 @@ namespace osgDot {
virtual ~BaseDotVisitor();
void setOptions(const osgDB::Options* options);
bool run( osg::Node& root, std::ostream* ostream );
virtual void apply(osg::Node& node);
@ -61,6 +65,9 @@ namespace osgDot {
virtual void handle(osg::Geode& geode, osg::Drawable& drawable, int parentID, int childID);
virtual void handle(osg::Drawable& drawable, osg::StateSet& stateset, int parentID, int childID );
osg::ref_ptr<osgDB::Options> _options;
std::string _rankdir;
std::stringstream _nodes;
std::stringstream _edges;

View File

@ -34,8 +34,10 @@ class ReaderWriterDOT : public osgDB::ReaderWriter {
return WriteResult(WriteResult::ERROR_IN_WRITING_FILE);
}
virtual WriteResult writeNode(const osg::Node& node,std::ostream& fout,const Options* options = NULL) const {
virtual WriteResult writeNode(const osg::Node& node,std::ostream& fout,const Options* options = NULL) const
{
osgDot::SimpleDotVisitor sdv;
sdv.setOptions(options);
sdv.run( *const_cast<osg::Node*>( &node ), &fout );
return WriteResult(WriteResult::FILE_SAVED);
}