Interesting... Multiple references _does_ seem to be the cause!

I modified my simple test app to make a second ref_ptr to the loaded scene
graph. So the pseudocode is:

  Load scene graph into first ref_ptr.
  Create a second ref_ptr and make it reference the first ref_ptr's child 0.
  Run the Optimizer
  Write the scene graph

(Code attached. Run it with my previous "opt1.osg" file to reproduce the
problem.)

With the second ref_ptr pointing to the child of the top level Transform,
the top level Transform does not flatten.

Is this a bug? Why does the Optimizer (apparently) not flatten a transform
if it has a child with reference count greater than 1?
   -Paul


> Thanks for the quick reply, Robert.
> 
> It's really the flattening that I require, and not 
> necessarily the type change.
> 
> For example, I see that osgconv doesn't change the type of 
> the top level Transform node, but it does flatten it so that 
> its transform is the identity. In my app, however, this top 
> level transform is simply not flattened; the matrix is still 
> non-identity.
> 
> To be pedantic, I added a top level Group above my (previous) 
> top level Transform. In my app, this Transform remains unflattened.
> 
> My app maintains other ref_ptrs into this scene graph, could 
> this be the problem? To check, I set a breakpoint in 
> Referenced::referenceCount() just before calling optimize(). 
> Aside from the explicit calls in
> FSTV::apply(Geode&) for the vertex and normal arrays, FSTV 
> does not appear to query the referenceCount of any Node. So I 
> suspect this is not the issue.
> 
> So I'm really quite stumped. I know it's difficult to debug 
> remotely, but this app is rather large and impractical to 
> share. Guidance on debugging would be appreciated.
>    -Paul
> 
> 
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] On Behalf Of 
> > Robert Osfield
> > Sent: Friday, October 24, 2008 1:35 PM
> > To: OpenSceneGraph Users
> > Subject: Re: [osg-users] Problems flattening static transforms
> > 
> > Hi Paul,
> > 
> > I'm just online briefly so I'll give you my first thought 
> as what is 
> > amiss.  Optimizer::optimize() method takes a reference to the scene 
> > graph to optimize, this means that it can't change it's type, so it 
> > can't flatten it.  If you place a Group above it and then optimize 
> > it'll be able to optimize the node away.
> > 
> > One could possibly write an additional method that takes a 
> pointer to 
> > a scene graph node and then return the new scene graph with 
> > potentially a new root node.  For compatibility we'd need 
> to keep the 
> > present one.
> > 
> > Robert.
> > 
> > On Fri, Oct 24, 2008 at 8:24 PM, Paul Martz 
> <[EMAIL PROTECTED]> 
> > wrote:
> > > Hi all -- I have a scene graph containing multiple static
> > transforms. 
> > > My application runs the osgUtil::Optimizer on this scene
> > graph. This
> > > should flatten all the static transforms. Unfortunately,
> > the result is
> > > that all the transforms flatten _except_ for the top level
> > transform. 
> > > If I do an osgconv on this same scene graph, all the static
> > transforms
> > > flatten -- they are converted to Group nodes, and their 
> > > transformations are folded into the geometry. Clearly, the
> > issue isn't
> > > with the scene graph itself, but it's something my app is
> > doing wrong when it invokes the Optimizer. My dilemma:
> > > why doesn't this work properly for osgconv, but not for my app?
> > >
> > > I have dug into thisu  for quite some time now, trying to
> > uncover the
> > > difference between osgconv (which works) and my code (which
> > doesn't work).
> > > Here's what I know so far:
> > >
> > > * I've written a small test app to try to reproduce the 
> problem. It 
> > > loads the scene graph, runs the Optimizer, and writes the
> > scene graph back out.
> > > Unfortunately, it works properly, just like osgconv. It
> > flattens all
> > > the transforms. I'm unable to reproduce the problem in
> > anything other
> > > than my
> > > (larger) application. This must be a bug in my code, I must
> > be doing
> > > something wrong.
> > >
> > > * I have verified that the problem is not non-STATIC transforms, 
> > > multiple parents, or ProxyNodes. The same scene graph 
> works fine in 
> > > osgconv and my little test app, so it isn't a scene graph 
> issue. I 
> > > believe my app handles the scene graph the same as in these
> > other two apps, which work.
> > >
> > > * Yes I'm invoking the Optimizer the same way, with no
> > flags. I'm sure
> > > that the OSG_OPTIMIZER variable is not set in the
> > environment. I get
> > > the same behavior if I just pass the 
> FLATTEN_STATIC_TRANSFORMS flag 
> > > (top level node fails to flatten). If I set 
> > > OSG_OPTIMIZER=FLATTEN_STATIC_TRANSFORMS and run osgconv, it
> > still works properly and flattens all transforms.
> > >
> > > * ObjectStruct has a Boolean called
> > _moreThanOneMatrixRequired. In my
> > > app, this gets set to true at Optimizer.cpp line 826. 
> This doesn't 
> > > happen when running osgconv or my small test code. This 
> seems to be 
> > > part of the problem, but the root cause that triggers this
> > event is still unknown to me.
> > >
> > > I'll attach the scene graph in question, though I doubt 
> it will do 
> > > anyone much good, because it works fine in osgconv and my
> > simple test
> > > app. It only fails in my larger app. Note the top level 
> Node named 
> > > "CenterOfMassOffset"; this is the transform that refuses 
> to flatten.
> > >
> > > I'm wondering if anyone has encountered the same issue
> > before, has any
> > > info on how to resolve the issue, or might know how to
> > proceed with debugging it.
> > > Notify level DEBUG_INFO does not produce any enlightening
> > information.
> > >
> > > I admit I'm stumped on this one. It's extremely out of 
> the ordinary 
> > > when OSG doesn't just do what I expect it to. I 
> appreciate any info.
> > >
> > > Thanks,
> > >
> > > Paul Martz
> > > Skew Matrix Software LLC
> > > http://www.skew-matrix.com
> > > +1 303 859 9466
> > >
> > > _______________________________________________
> > > osg-users mailing list
> > > osg-users@lists.openscenegraph.org
> > > 
> > 
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.
> > > org
> > >
> > >
> > _______________________________________________
> > osg-users mailing list
> > osg-users@lists.openscenegraph.org
> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-opensce
> negraph.org
> > 
> 
> _______________________________________________
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-opensce
negraph.org
> 
//
// Copyright (c) 2008 Blue Newt Software LLC and Skew Matrix  Software LLC.
// All rights reserved.
//

#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osgUtil/Optimizer>


int
main( int argc,
      char ** argv )
{
    osg::ref_ptr< osg::Node > root = osgDB::readNodeFile( "out1.osg" );
    osg::ref_ptr< osg::Node > p =
        (dynamic_cast<osg::Group*>(root.get()))->getChild( 0 );

    osg::setNotifyLevel( osg::INFO );
    osgUtil::Optimizer opt;
    opt.optimize( root.get(), osgUtil::Optimizer::FLATTEN_STATIC_TRANSFORMS );

    osgDB::writeNodeFile( *root, "out2.osg" );

    return( 0 );
}

_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to