[osg-users] Outline Effect traversal crash

2009-05-20 Thread Brian Stewart
Hi,

I am trying to implement a mechanism by which selected objects in my scene are 
highlighted. Searching the forum I found a reference to the Outline effect (an 
implementation of osgFX::Effect)  on Ulrich Hertlein's web site 
(http://www.sandbox.de/osg/), and I have attempted to integrate it into our app 
- however, most of the time, whenever the object which is outlined first comes 
into view, the app crashes in osg::NodeCallback::traverse, because the 
_nestedCallback member is corrupted. This is on Windows Vista-64, running OSG 
2.6.1 built with Visual Studio 2008, in Debug mode. We are running OSG 
multithreaded, and all my code setting up the effect is called from 
osg::NodeCallback::operator() on the render thread. The general flow is as 
follows:


Code:

osg::NodeCallback::operator()
{
   osg::PositionAttitudeTransform* modelTransform; // local transform to 
position the model in the world
   osg::Node* someChild; // some model
   osg::ref_ptr fxNode = new osgFX::Outline();
   fxNode->addChild( someChild );
   modelTransform->addChild( fxNode.get() );
}




Am I missing something obvious? If not, ideas or debugging strategies would 
also be greatly appreciated!

Thank you!
Brian

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=12628#12628





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


Re: [osg-users] Outline Effect traversal crash

2009-05-21 Thread Robert Osfield
HI Brian,

You have to be very careful about adding or removing nodes during a
traversal as you can invalidate iterators by causing a reorgnization
of the structures the iterators are traversing.  From you code segment
it's unclear what is going on as you must have removed quite a bit of
code.

As a general note it's generally best add/removing elements from the
scene graph in the application's frame loop.

Robert.

On Wed, May 20, 2009 at 10:27 PM, Brian Stewart  wrote:
> Hi,
>
> I am trying to implement a mechanism by which selected objects in my scene 
> are highlighted. Searching the forum I found a reference to the Outline 
> effect (an implementation of osgFX::Effect)  on Ulrich Hertlein's web site 
> (http://www.sandbox.de/osg/), and I have attempted to integrate it into our 
> app - however, most of the time, whenever the object which is outlined first 
> comes into view, the app crashes in osg::NodeCallback::traverse, because the 
> _nestedCallback member is corrupted. This is on Windows Vista-64, running OSG 
> 2.6.1 built with Visual Studio 2008, in Debug mode. We are running OSG 
> multithreaded, and all my code setting up the effect is called from 
> osg::NodeCallback::operator() on the render thread. The general flow is as 
> follows:
>
>
> Code:
>
> osg::NodeCallback::operator()
> {
>   osg::PositionAttitudeTransform* modelTransform; // local transform to 
> position the model in the world
>   osg::Node* someChild; // some model
>   osg::ref_ptr fxNode = new osgFX::Outline();
>   fxNode->addChild( someChild );
>   modelTransform->addChild( fxNode.get() );
> }
>
>
>
>
> Am I missing something obvious? If not, ideas or debugging strategies would 
> also be greatly appreciated!
>
> Thank you!
> Brian
>
> --
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=12628#12628
>
>
>
>
>
> ___
> 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-openscenegraph.org


Re: [osg-users] Outline Effect traversal crash

2009-05-21 Thread Brian Stewart
Hi Robert,

Thanks for that clarification, as my understanding of where nodes should be 
added and removed was exactly backwards.  I did paraphrase my code extensively, 
because there was a lot of unrelated code - but I guess I didn't include 
enough. I went to create a simpler example using osgcompositeviewer as a 
starting point, when I noticed that it is doing exactly the same thing that I 
am trying to, only in the handle() function of osgaGA::GUIEventHandler, which 
is called during the event traversal of frame(). When you said it's best to 
avoid modifying the scenegraph during a traversal, did that specifically mean 
the Update Traversal, when NodeCallbacks are called, and that modifications in 
event callbacks are OK?

Thank you!

Cheers,
Brian

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=12675#12675





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


Re: [osg-users] Outline Effect traversal crash

2009-05-21 Thread Brian Stewart
Hi,

I switched my code around to where the model was being added from the main loop 
rather than the update traversal, and it was still crashing. On closer 
examination I noticed that the crashes were occurring during the render 
traversal, so I began to suspect the effect itself. When I replaced the effect 
with an instance of osgFX::Scribe, then everything worked correctly. So 
something was amiss in the Outline effect itself. I was using it only because I 
did not know about the Scribe effect, which is better for my purposes anyway.

Thank you!

Brian

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=12692#12692





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


Re: [osg-users] Outline Effect traversal crash

2009-05-21 Thread Robert Osfield
Hi Brian,

It sounds like you may have hit upon a threading bug in the Outline
effect.  Try changing the viewer threading mode to either
SingleThreaded or  CullDrawThreadPerCamera, if this works then there
is an threading issue with changing display lists or StateSet's at the
same time that these objects are being rendered.  Changing the
DataVariance to STATIC is the usually the best way to solve this, but
you can also double buffer the problem structures.

Robert.

On Thu, May 21, 2009 at 5:29 PM, Brian Stewart  wrote:
> Hi,
>
> I switched my code around to where the model was being added from the main 
> loop rather than the update traversal, and it was still crashing. On closer 
> examination I noticed that the crashes were occurring during the render 
> traversal, so I began to suspect the effect itself. When I replaced the 
> effect with an instance of osgFX::Scribe, then everything worked correctly. 
> So something was amiss in the Outline effect itself. I was using it only 
> because I did not know about the Scribe effect, which is better for my 
> purposes anyway.
>
> Thank you!
>
> Brian
>
> --
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=12692#12692
>
>
>
>
>
> ___
> 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-openscenegraph.org


Re: [osg-users] Outline Effect traversal crash

2009-05-21 Thread Maciej Krol
Hi Brian, Robert, all,

For object outlining I use cull callback that traverses node two times (its
a simple workaround for two pass techniques). I use well known technique
rendering back faces in wireframe (
http://en.wikipedia.org/wiki/Cel-shaded_animation) prior regular rendering.
It was mentioned several times on osg-users. To outline selected node You
just need to call node->setCullCallback(new OutlineCallback), there is no
need to tweak the scene graph structure. To change outline color You could
use emissive color tweaking on object material, J-S was mentioning it some
time ago
http://www.mail-archive.com/osg-users@lists.openscenegraph.org/msg21935.html

class OutlineCallback : public osg::NodeCallback
{
public:
OutlineCallback();

/** Line width for outline effect */
void setLineWidth(float lineWidth);
float getLineWidth() const;

/** Sets required states */
void resetStateSet();

virtual void operator()(osg::Node *node, osg::NodeVisitor *nv);

protected:

osg::ref_ptr _stateSet;
};

OutlineCallback::OutlineCallback()
{
resetStateSet();
setLineWidth(3.0);
}

void OutlineCallback::resetStateSet()
{
if (!_stateSet)
_stateSet = new osg::StateSet;
osg::StateSet *ss = _stateSet.get();

ss->setRenderBinDetails(200, "RenderBin");

ss->setMode(GL_LIGHTING, osg::StateAttribute::OFF |
osg::StateAttribute::OVERRIDE);
for (unsigned int unit=0;unit<4;++unit)
ss->setTextureMode(unit, GL_TEXTURE_2D, osg::StateAttribute::OFF |
osg::StateAttribute::OVERRIDE);

osg::PolygonMode *polygonMode = dynamic_cast(ss->getAttribute(osg::StateAttribute::POLYGONMODE));
if (!polygonMode)
{
polygonMode = new osg::PolygonMode;
ss->setAttribute(polygonMode, osg::StateAttribute::ON);
}
polygonMode->setMode(osg::PolygonMode::BACK, osg::PolygonMode::LINE);

osg::CullFace *cullFace = dynamic_cast(ss->getAttribute(osg::StateAttribute::CULLFACE));
if (!cullFace)
{
cullFace = new osg::CullFace;
ss->setAttribute(cullFace, osg::StateAttribute::ON);
}
cullFace->setMode(osg::CullFace::FRONT);

osg::Depth *depth = dynamic_cast(ss->getAttribute(osg::StateAttribute::DEPTH));
if (!depth)
{
depth = new osg::Depth;
ss->setAttribute(depth, osg::StateAttribute::ON);
}
depth->setFunction(osg::Depth::LEQUAL);
}

void OutlineCallback::setLineWidth(float width)
{
osg::LineWidth *lineWidth = dynamic_cast(_stateSet->getAttribute(osg::StateAttribute::LINEWIDTH));
if (!lineWidth)
{
lineWidth = new osg::LineWidth;
_stateSet->setAttribute(lineWidth, osg::StateAttribute::ON);
}
lineWidth->setWidth(width);
}

float OutlineCallback::getLineWidth() const
{
osg::LineWidth *lineWidth = dynamic_cast(_stateSet->getAttribute(osg::StateAttribute::LINEWIDTH));
return lineWidth ? lineWidth->getWidth() : 1.0;
}

void OutlineCallback::operator()(osg::Node *node, osg::NodeVisitor *nv)
{
if (nv->getVisitorType() == osg::NodeVisitor::CULL_VISITOR)
{
osgUtil::CullVisitor *cv = dynamic_cast(nv);
if (cv)
{
cv->pushStateSet(_stateSet.get());
traverse(node, cv);
cv->popStateSet();
}
}

traverse(node, nv);
}

Regards,
Maciej

2009/5/21 Robert Osfield 

> Hi Brian,
>
> It sounds like you may have hit upon a threading bug in the Outline
> effect.  Try changing the viewer threading mode to either
> SingleThreaded or  CullDrawThreadPerCamera, if this works then there
> is an threading issue with changing display lists or StateSet's at the
> same time that these objects are being rendered.  Changing the
> DataVariance to STATIC is the usually the best way to solve this, but
> you can also double buffer the problem structures.
>
> Robert.
>
> On Thu, May 21, 2009 at 5:29 PM, Brian Stewart 
> wrote:
> > Hi,
> >
> > I switched my code around to where the model was being added from the
> main loop rather than the update traversal, and it was still crashing. On
> closer examination I noticed that the crashes were occurring during the
> render traversal, so I began to suspect the effect itself. When I replaced
> the effect with an instance of osgFX::Scribe, then everything worked
> correctly. So something was amiss in the Outline effect itself. I was using
> it only because I did not know about the Scribe effect, which is better for
> my purposes anyway.
> >
> > Thank you!
> >
> > Brian
> >
> > --
> > Read this topic online here:
> > http://forum.openscenegraph.org/viewtopic.php?p=12692#12692
> >
> >
> >
> >
> >
> > ___
> > 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-u

Re: [osg-users] Outline Effect traversal crash

2009-05-22 Thread Brian Stewart
Hi Maciej,

Thank you for the example. It seems to be a lot faster than what I was doing 
earlier.  Before when a node was selected, I removed it from its parent, 
created an osgFX::Scribe effect and placed it under the parent, and then 
reattached my node under that. But there was a slight delay between when the 
node disappeared, and when it reappeared selected. Because the nodes are 
buildings placed on geo-specific high-resolution imagery, this had the curious 
effect of make the building appear to be "push into the terrain" temporarily, 
and then spring back into position with the Scribe effect applied. 

Thanks for the links to the post and to the cel-shading article - those helped 
a lot! I did have one question about the  new selection method you 
demonstrated. It makes the building appear to be all white, since the texture 
is turned off. Is this correct? I tried disabling that part of the code, but 
now the backfaced outlines are not enough to make the object stand out. What I 
would really like to do is outline the object in a striking color (say bright 
yellow, or something) and then render the textured object with a slight cast if 
the same color.  Is this possible in OSG? I have searched though the archives, 
but without a lot of success yet. Just a pointer to some techniques that might 
work, or to a forum thread I missed would be a great help!


Thank you!

Cheers,
Brian

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=12792#12792





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


Re: [osg-users] Outline Effect traversal crash

2009-05-22 Thread Jean-Sébastien Guay

Hello Brian,


It makes the building appear to be all white, since the texture is turned off. 
Is this correct? I tried disabling that part of the code, but now the backfaced 
outlines are not enough to make the object stand out. What I would really like 
to do is outline the object in a striking color (say bright yellow, or 
something) and then render the textured object with a slight cast if the same 
color.  Is this possible in OSG? I have searched though the archives, but 
without a lot of success yet. Just a pointer to some techniques that might 
work, or to a forum thread I missed would be a great help!


What you would need to get that effect would be to have the outline's 
stateset contain a material with a bright yellow emissive color (and 
enable GL_LIGHTING) and then change the main pass's stateset to give the 
material a slight yellow tint. Just a bit though, because it will be 
added to the main material color (diffuse * texture) so you don't want 
to drown that out completely with the emissive color.


Play around with these things, you should be able to get what you want.

Hope this helps,

J-S
--
__
Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Outline Effect traversal crash

2009-05-23 Thread Ulrich Hertlein

Hi Brian & all,

On 20/5/09 11:27 PM, Brian Stewart wrote:

I am trying to implement a mechanism by which selected objects in my scene are
highlighted. Searching the forum I found a reference to the Outline effect (an
implementation of osgFX::Effect)  on Ulrich Hertlein's web site
(http://www.sandbox.de/osg/), and I have attempted to integrate it into our app 
-
however, most of the time, whenever the object which is outlined first comes 
into view,
the app crashes in osg::NodeCallback::traverse, because the _nestedCallback 
member is
corrupted. This is on Windows Vista-64, running OSG 2.6.1 built with Visual 
Studio
2008, in Debug mode. We are running OSG multithreaded, and all my code setting 
up the
effect is called from osg::NodeCallback::operator() on the render thread. The 
general
flow is as follows:


Sorry for being quiet for a while, I was out in the big room for a few days ;-)

I seem to remember there was an issue with the code and multiple viewers and I thought I 
had put a big XXX comment somewhere (but I didn't find it).  If I remember correctly it 
had something to do with the EnableStencil callback that I used to enable stencil clear.


It calls node->setCullCallback(0) unconditionally, so maybe if there's something nested 
that breaks?


(Just a quick thought, the code is bloody five years old :-)

Cheers,
/ulrich
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org