Skip to content

Commit

Permalink
Fixes for the testuniqifier regression test. Add comments
Browse files Browse the repository at this point in the history
to Uniqifier documentation noting how Geodes, Drawables,
and Geometry are handled with contemporary OSG.
  • Loading branch information
pmartz committed Dec 12, 2015
1 parent a90a986 commit 334b045
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
19 changes: 14 additions & 5 deletions include/osgwTools/Uniqifier.h
Expand Up @@ -22,14 +22,15 @@
#define __OSGWTOOLS_UNIQIFIER_H__ 1

#include <osgwTools/Export.h>
#include <osgwTools/Version.h>
#include <osg/NodeVisitor>


namespace osgwTools
{


/** \defgroup uniqifiers Node Uniqification Tools
/** \defgroup uniqifiers Node Uniquification Tools
\brief Tools to eliminate shared nodes and multiparenting.
These tools make shallow copies of shared nodes, all shared nodes in a NodePath, and
Expand All @@ -42,27 +43,35 @@ and the decorator design pattern can't be used (for whatever reason). */
/*@{*/


/** \brief Uniqify a shared Node.
/** \brief Uniquify a shared Node.
Remove \c child from \c parent's child list and replace it
with a shallow copy of \c child.
\return The address of the new shallow copy of \c child. */
OSGWTOOLS_EXPORT osg::Node* uniqify( osg::Node* child, osg::Group* parent );

/** \brief Uniqify a NodePath to eliminate all shared Nodes.
/** \brief Uniquify a NodePath to eliminate all shared Nodes.
Starting with the second Node in \c np, iterate over \c np
and call uniqify(osg::Node*,osg::Group*) so that the entire
and call uniquify(osg::Node*,osg::Group*) so that the entire
NodePath contains no multiparenting.
Because uniqify(osg::Node*,osg::Group*) creates shallow copies
Because uniquify(osg::Node*,osg::Group*) creates shallow copies
with new addresses, \c np is invalid after this operation. Use
the return value instead.
\return A new NodePath that references the created nodes. */
OSGWTOOLS_EXPORT osg::NodePath uniqify( const osg::NodePath& np );

/** \class Uniqifier Uniqifier.h <osgwTools/Uniqifier.h>
\brief Eliminates multiparenting by turning shared nodes into unique nodes.
Note regarding Geometry and Drawable Handling
Around OSG v3.5.1, Geode was made to derive from Group, and Drawable made to
derive from Node, such that Geodes have Drawable children. Prior to this change,
the Uniqifier visitor did not make Drawables unique, as they were data, not
Nodes. For backwards compatibility, Uniqifier still treats Drawables as data
and makes no attempt to make them unique.
*/
class OSGWTOOLS_EXPORT Uniqifier : public osg::NodeVisitor
{
Expand Down
4 changes: 4 additions & 0 deletions src/osgwTools/Uniqifier.cpp
Expand Up @@ -77,8 +77,12 @@ Uniqifier::Uniqifier( osg::NodeVisitor::TraversalMode mode )

void Uniqifier::apply( osg::Node& node )
{
#if( OSGWORKS_OSG_VERSION < 30501 )
// Unusual. A node that is neither a Group nor a Geode.
osg::notify( osg::WARN ) << "Uniqifier: apply(osg::Node&)" << std::endl;
// But, for OSG v3.5.1 and later, not so unusual. Drawables
// and Geometries fall into this category.
#endif

traverse( node );
}
Expand Down
21 changes: 17 additions & 4 deletions tests/testuniqifier/testuniqifier.cpp
Expand Up @@ -18,6 +18,7 @@
*
*************** <auto-copyright.pl END do not edit this line> ***************/

#include <osgwTools/Version.h>
#include <osgwTools/Uniqifier.h>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
Expand Down Expand Up @@ -86,6 +87,16 @@ class NodeCounter : public osg::NodeVisitor

virtual void apply( osg::Node& node )
{
#if( OSGWORKS_OSG_VERSION >= 30501 )
if( node.asDrawable() != NULL )
{
// In OSG v3.05.01 (and perhaps earlier?), Drawables
// are now Nodes. For backwards compatibility, don't
// count them. Uniqifier currently doesn't operate on
// them, so counting them would cause the test to fail.
return;
}
#endif
_totalNodes++;
_uniqueNodes.insert( &node );
traverse( node );
Expand Down Expand Up @@ -151,12 +162,14 @@ int main( int argc, char** argv )
nc.reset();
root->accept( nc );

// Pass/fail condition. The total number of nodes should not
// have changed. But the Uniqifier should have changed the
// Pass/fail condition. (a) The total number of nodes should not
// have changed. But (b) the Uniqifier should have changed the
// number of unique nodes so that it is not the same as the
// total number of nodes.
// total number of nodes, and (c) the new number of unique nodes
// should be greater than the previous number of unique nodes.
bool passed( ( nc._totalNodes == preUniqifyNumNodes ) &&
( nc._uniqueNodes.size() == preUniqifyNumNodes ) );
( nc._uniqueNodes.size() == nc._totalNodes ) &&
( nc._uniqueNodes.size() > preUniqifyUniqueNodes ) );


if( !passed )
Expand Down

0 comments on commit 334b045

Please sign in to comment.