diff --git a/src/osgPlugins/dot/BaseDotVisitor.cpp b/src/osgPlugins/dot/BaseDotVisitor.cpp index 3aec31ac2..0a4804495 100644 --- a/src/osgPlugins/dot/BaseDotVisitor.cpp +++ b/src/osgPlugins/dot/BaseDotVisitor.cpp @@ -24,8 +24,11 @@ using namespace osg; namespace osgDot { - BaseDotVisitor::BaseDotVisitor() - { +BaseDotVisitor::BaseDotVisitor(): + osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) +{ + // setNodeMaskOverride(0xffffff); + _rankdir = "rankdir = LR;"; // Set the locale used by the _nodes and _edges streams to the // classic or "C" locale. This is needed because most of the @@ -33,156 +36,145 @@ namespace osgDot { // by id numbers containing commas or periods. _nodes.imbue(std::locale("C")); _edges.imbue(std::locale("C")); - } +} - BaseDotVisitor::~BaseDotVisitor() { - } +BaseDotVisitor::~BaseDotVisitor() +{ +} - void BaseDotVisitor::setOptions(const osgDB::Options* options) +void BaseDotVisitor::setOptions(const osgDB::Options* options) +{ + _options = const_cast(options); + OSG_INFO<<"BaseDotVisitor::setOptions("<getOptionString().empty())) { - _options = const_cast(options); - OSG_INFO<<"BaseDotVisitor::setOptions("<getOptionString().empty())) + + std::string optionString = _options->getOptionString(); + + OSG_INFO<<" BaseDotVisitor::optionString ("<getOptionString(); - - OSG_INFO<<" BaseDotVisitor::optionString ("<getStateSet(); - if ( s ) { - int id3; - if ( getOrCreateId( s, id3 ) ) { - handle( *s, id3 ); - } - handle( *drawable, *s, id2, id3 ); - } - } - handle( node, *drawable, id, id2 ); - } - + if ( getOrCreateId( &drawable, id ) ) + { + handle( drawable, id ); + handleNodeAndTraverse( drawable, id ); } +} - } - - void BaseDotVisitor::apply(Group& node) { +void BaseDotVisitor::apply(Group& node) +{ int id; - if ( getOrCreateId( &node, id ) ) { - handle( node, id ); - handleNodeAndTraverse( node, id ); + if ( getOrCreateId( &node, id ) ) + { + handle( node, id ); + handleNodeAndTraverse( node, id ); - unsigned int i; - for ( i = 0; i < node.getNumChildren(); i++ ) { - osg::Node* child = node.getChild( i ); - //handleNodeAndTraverse( *child ); - int id2; - if (getOrCreateId( child, id2 )) + unsigned int i; + for ( i = 0; i < node.getNumChildren(); i++ ) { + osg::Node* child = node.getChild( i ); + //handleNodeAndTraverse( *child ); + int id2; + getOrCreateId( child, id2 ); handle( node, *child, id, id2 ); } - } } +} - } +void BaseDotVisitor::handle(osg::Node&, int) {} - void BaseDotVisitor::handle(osg::Node&, int) {} +void BaseDotVisitor::handle(osg::Group&, int) {} - void BaseDotVisitor::handle(osg::Geode&, int) {} +void BaseDotVisitor::handle(osg::Group&, osg::Node&, int, int) {} - void BaseDotVisitor::handle(osg::Group&, int) {} - - void BaseDotVisitor::handle(osg::Group&, osg::Node&, int, int) {} - - void BaseDotVisitor::handleNodeAndTraverse(osg::Node& node, int id) { +void BaseDotVisitor::handleNodeAndTraverse(osg::Node& node, int id) +{ osg::StateSet* ss = node.getStateSet(); - if ( ss ) { - int id2; - if ( getOrCreateId( ss, id2 ) ) { - handle( *ss, id2 ); - } - handle( node, *ss, id, id2 ); + if ( ss ) + { + int id2; + if ( getOrCreateId( ss, id2 ) ) + { + handle( *ss, id2 ); + } + handle( node, *ss, id, id2 ); } traverse(node); - } +} - void BaseDotVisitor::handle(osg::StateSet&, int) {} +void BaseDotVisitor::handle(osg::StateSet&, int) {} - void BaseDotVisitor::handle(osg::Node&, osg::StateSet&, int, int) {} +void BaseDotVisitor::handle(osg::Node&, osg::StateSet&, int, int) {} - void BaseDotVisitor::handle(osg::Drawable&, int) {} +void BaseDotVisitor::handle(osg::Drawable&, int) {} - void BaseDotVisitor::handle(osg::Drawable&, osg::StateSet&, int, int) {} +void BaseDotVisitor::handle(osg::Drawable&, osg::StateSet&, int, int) {} - void BaseDotVisitor::handle(osg::Geode&, osg::Drawable&, int, int) {} - - bool BaseDotVisitor::getOrCreateId( osg::Object* object, int &id ) { - assert( object ); +bool BaseDotVisitor::getOrCreateId( osg::Object* object, int &id ) +{ ObjectMap::iterator it = _objectMap.find( object ); - if ( it != _objectMap.end() ) { - id = it->second; - return false; + if ( it != _objectMap.end() ) + { + id = it->second; + return false; } id = _objectMap.size(); _objectMap[ object ] = id; return true; - } +} } // namespace osgDot diff --git a/src/osgPlugins/dot/BaseDotVisitor.h b/src/osgPlugins/dot/BaseDotVisitor.h index 87b06662a..d0e2b2737 100644 --- a/src/osgPlugins/dot/BaseDotVisitor.h +++ b/src/osgPlugins/dot/BaseDotVisitor.h @@ -30,54 +30,52 @@ namespace osgDot { - class BaseDotVisitor : public osg::NodeVisitor { - public: - typedef std::map< osg::Object*, int > ObjectMap; +class BaseDotVisitor : public osg::NodeVisitor +{ + public: + typedef std::map< osg::Object*, int > ObjectMap; - public: - BaseDotVisitor(); + public: + BaseDotVisitor(); - virtual ~BaseDotVisitor(); + virtual ~BaseDotVisitor(); - void setOptions(const osgDB::Options* options); + void setOptions(const osgDB::Options* options); - bool run( osg::Node& root, std::ostream* ostream ); + bool run( osg::Node& root, std::ostream* ostream ); - virtual void apply(osg::Node& node); + virtual void apply(osg::Node& node); - virtual void apply(osg::Geode& node); + virtual void apply(osg::Drawable& node); - virtual void apply(osg::Group& node); + virtual void apply(osg::Group& node); + protected: - protected: + void handleNodeAndTraverse(osg::Node& node, int id); - void handleNodeAndTraverse(osg::Node& node, int id); + virtual void handle(osg::StateSet& stateset, int id); + virtual void handle(osg::Drawable& drawable, int id); + virtual void handle(osg::Node& node, int id); + virtual void handle(osg::Group& node, int id); - virtual void handle(osg::Node& node, int id); - virtual void handle(osg::Geode& node, int id); - virtual void handle(osg::Group& node, int id); - virtual void handle(osg::StateSet& stateset, int id); - virtual void handle(osg::Drawable& drawable, int id); + virtual void handle(osg::Node& node, osg::StateSet& stateset, int parentID, int childID); + virtual void handle(osg::Drawable& drawable, osg::StateSet& stateset, int parentID, int childID ); + virtual void handle(osg::Group& parent, osg::Node& child, int parentID, int childID); - virtual void handle(osg::Node& node, osg::StateSet& stateset, int parentID, int childID); - virtual void handle(osg::Group& parent, osg::Node& child, int parentID, int childID); - 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 _options; - osg::ref_ptr _options; + std::string _rankdir; - std::string _rankdir; + std::stringstream _nodes; + std::stringstream _edges; - std::stringstream _nodes; - std::stringstream _edges; + private: + bool getOrCreateId( osg::Object* object, int& id ); - private: - bool getOrCreateId( osg::Object* object, int& id ); + ObjectMap _objectMap; - ObjectMap _objectMap; - - }; +}; } // namespace osgDot diff --git a/src/osgPlugins/dot/SimpleDotVisitor.cpp b/src/osgPlugins/dot/SimpleDotVisitor.cpp index 60fad98d0..075a6445a 100644 --- a/src/osgPlugins/dot/SimpleDotVisitor.cpp +++ b/src/osgPlugins/dot/SimpleDotVisitor.cpp @@ -15,79 +15,80 @@ namespace osgDot { - SimpleDotVisitor::SimpleDotVisitor() { - } +SimpleDotVisitor::SimpleDotVisitor() +{ +} - SimpleDotVisitor::~SimpleDotVisitor() { - } +SimpleDotVisitor::~SimpleDotVisitor() +{ +} - void SimpleDotVisitor::handle(osg::Node& node, int id) { - std::stringstream label; - label << " Node"; - if ( !node.getName().empty() ) { label << "| " << node.getName(); } - drawNode( id, "record", "solid", label.str(), "black", "white" ); - } - void SimpleDotVisitor::handle(osg::Geode& node, int id) { - std::stringstream label; - label << " " << node.className(); - if ( !node.getName().empty() ) { label << "| " << node.getName(); } - drawNode( id, "record", "solid", label.str(), "brown", "white" ); - } - - void SimpleDotVisitor::handle(osg::Group& node, int id) { - std::stringstream label; - label << " " << node.className(); - if ( !node.getName().empty() ) { label << "| " << node.getName(); } - drawNode( id, "record", "solid", label.str(), "black", "white" ); - } - - void SimpleDotVisitor::handle(osg::Group&, osg::Node&, int parentID, int childID ) { - drawEdge( parentID, childID, "setlinewidth(2)" ); - } - - void SimpleDotVisitor::handle(osg::StateSet& stateset, int id) { +void SimpleDotVisitor::handle(osg::StateSet& stateset, int id) +{ std::stringstream label; label << " " << stateset.className(); - if ( !stateset.getName().empty() ) { label << "| " << stateset.getName(); } - drawNode( id, "Mrecord", "solid", label.str(), "green", "white" ); - } + if ( !stateset.getName().empty() ) { label << " | " << stateset.getName(); } + drawNode( id, "Mrecord", "solid, filled", label.str(), "green", "black" ); +} - void SimpleDotVisitor::handle(osg::Node&, osg::StateSet&, int parentID, int childID ) { - drawEdge( parentID, childID, "dashed" ); - } - - void SimpleDotVisitor::handle(osg::Drawable& drawable, int id) { +void SimpleDotVisitor::handle(osg::Drawable& drawable, int id) +{ std::stringstream label; label << " " << drawable.className(); - if ( !drawable.getName().empty() ) { label << "| " << drawable.getName(); } - drawNode( id, "record", "solid", label.str(), "blue", "white" ); - } + if ( !drawable.getName().empty() ) { label << " | " << drawable.getName(); } + drawNode( id, "record", "solid, filled", label.str(), "lightblue", "black" ); +} - void SimpleDotVisitor::handle(osg::Geode&, osg::Drawable&, int parentID, int childID ) { - drawEdge( parentID, childID, "dashed" ); - } +void SimpleDotVisitor::handle(osg::Node& node, int id) +{ + std::stringstream label; + label << " "< " << node.className(); + if ( !node.getName().empty() ) { label << " | " << node.getName(); } + drawNode( id, "record", "solid, filled", label.str(), "yellow", "black" ); +} - void SimpleDotVisitor::drawNode( int id, const std::string& shape, const std::string& style, const std::string& label, const std::string& color, const std::string& fillColor ) { +void SimpleDotVisitor::handle(osg::Node&, osg::StateSet&, int parentID, int childID ) +{ + drawEdge( parentID, childID, "" ); +} + +void SimpleDotVisitor::handle(osg::Drawable&, osg::StateSet&, int parentID, int childID ) +{ + drawEdge( parentID, childID, "" ); +} + +void SimpleDotVisitor::handle(osg::Group&, osg::Node&, int parentID, int childID ) +{ + drawEdge( parentID, childID, "" ); +} + +void SimpleDotVisitor::drawNode( int id, const std::string& shape, const std::string& style, const std::string& label, const std::string& color, const std::string& fillColor ) +{ _nodes << id << - "[shape=\"" << shape << - "\" ,label=\"" << label << - "\" ,style=\"" << style << - "\" ,color=\"" << color << - "\" ,fillColor=\"" << fillColor << - "\"]" << std::endl; - } + "[shape=\"" << shape << + "\" ,label=\"" << label << + "\" ,style=\"" << style << + "\" ,color=\"" << color << + "\" ,fillColor=\"" << fillColor << + "\"]" << std::endl; +} - void SimpleDotVisitor::drawEdge( int sourceId, int sinkId, const std::string& style ) { +void SimpleDotVisitor::drawEdge( int sourceId, int sinkId, const std::string& style ) +{ _edges - << sourceId << ":top -> " - << sinkId << ":top [style=\"" - << style << "\"];" - << std::endl; - } + << sourceId << ":top -> " + << sinkId << ":top [style=\"" + << style << "\"];" + << std::endl; +} } // namespace osgDot diff --git a/src/osgPlugins/dot/SimpleDotVisitor.h b/src/osgPlugins/dot/SimpleDotVisitor.h index e5e986ebc..94ad8ec69 100644 --- a/src/osgPlugins/dot/SimpleDotVisitor.h +++ b/src/osgPlugins/dot/SimpleDotVisitor.h @@ -23,30 +23,29 @@ namespace osgDot { - class SimpleDotVisitor : public BaseDotVisitor { - public: - SimpleDotVisitor(); +class SimpleDotVisitor : public BaseDotVisitor +{ + public: + SimpleDotVisitor(); - virtual ~SimpleDotVisitor(); + virtual ~SimpleDotVisitor(); - protected: - virtual void handle(osg::Node& node, int id); - virtual void handle(osg::Geode& geode, int id); - virtual void handle(osg::Group& node, int id); + protected: - virtual void handle(osg::StateSet& stateset, int id); - virtual void handle(osg::Drawable& drawable, int id); + virtual void handle(osg::StateSet& stateset, int id); + virtual void handle(osg::Drawable& drawable, int id); + virtual void handle(osg::Node& node, int id); + virtual void handle(osg::Group& node, int id); - virtual void handle(osg::Node& node, osg::StateSet& stateset, int parentID, int childID ); - virtual void handle(osg::Geode& geometry, osg::Drawable& drawable, int parentID, int childID ); - virtual void handle(osg::Group& parent, osg::Node& child, int parentID, int childID ); - virtual void handle(osg::Drawable& drawable, osg::StateSet& stateset, int parentID, int childID ); + virtual void handle(osg::Node& node, osg::StateSet& stateset, int parentID, int childID ); + virtual void handle(osg::Drawable& drawable, osg::StateSet& stateset, int parentID, int childID ); + virtual void handle(osg::Group& parent, osg::Node& child, int parentID, int childID ); - virtual void drawNode( int id, const std::string& shape, const std::string& style, const std::string& label, const std::string& color, const std::string& fillColor ); + virtual void drawNode( int id, const std::string& shape, const std::string& style, const std::string& label, const std::string& color, const std::string& fillColor ); - virtual void drawEdge( int sourceId, int sinkId, const std::string& style ); + virtual void drawEdge( int sourceId, int sinkId, const std::string& style ); - }; +}; } // namespace osgDot