OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

wireframe


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
gambr
Appreciator


Joined: 22 Jun 2010
Posts: 355

PostPosted: Mon Aug 25, 2014 10:54 am    Post subject:
wireframe
Reply with quote

Hi All,
I found a way to display graphics in wireframe,
Code:
stateset->setAttributeAndModes(polymode,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);

but is it possible to "add" a wireframe visualization over the shaded graphic? Please see attached picture.

Regards,
Gianni
Back to top
View user's profile Send private message
Bacttrack
User


Joined: 13 Mar 2014
Posts: 58

PostPosted: Mon Aug 25, 2014 11:09 am    Post subject:
wireframe
Reply with quote

Hi Gianni,

As an entrypoint, take a look at the osgscribe.cpp demo it helps you to perform shaded model + wireframing,
along with that you can use osgFX::Scribe as a parent to your modelling object which allows you to
set SetWireFRameColor, SetWireframeLineWidth ...etc.. attributes.


Regards,

From: g.ambrosio+
Date: Mon, 25 Aug 2014 12:54:23 +0200
To:
Subject: wireframe

Quote:
Hi All,I found a way to display graphics in wireframe, Code:stateset->setAttributeAndModes(polymode,osg::StateAttribute::OVERRIDE|osg::StateAttribute:ShockedN); but is it possible to "add" a wireframe visualization over the shaded graphic? Please see attached picture. Regards,Gianni ------------------Read this topic online here:http://forum.openscenegraph.org/viewtopic.php?p=60758#60758



------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
gambr
Appreciator


Joined: 22 Jun 2010
Posts: 355

PostPosted: Mon Aug 25, 2014 1:03 pm    Post subject:
Reply with quote

Thank you Bacttrack,
I didn't realized from the code that osgscribe example implemented what I need. osgFX::Scribe is also useful.

Regards,
Gianni
Back to top
View user's profile Send private message
gambr
Appreciator


Joined: 22 Jun 2010
Posts: 355

PostPosted: Tue Aug 26, 2014 12:51 pm    Post subject:
Reply with quote

Hi,
I used osgFX easily but it seems the solution of osgscribe looks nicer (i.e. the wireframe color is the same of the surface but a little darker)

Code:

    osg::StateSet* stateset = new osg::StateSet;
    osg::PolygonMode* polymode = new osg::PolygonMode;
    polymode->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE);
    stateset->setAttributeAndModes(polymode,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);

    osg::Material* material = new osg::Material;
    stateset->setAttributeAndModes(material,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
    stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);
   
   decorator->setStateSet(stateset);

Now I need to switch the wireframe on and off.
To remove the wireframe, the following code does not work:

Code:

   osg::StateSet* stateset = decorator->getOrCreateStateSet();
   osg::StateAttribute* attribute = stateset->getAttribute(osg::StateAttribute::POLYGONMODE);
   stateset->setAttribute(attribute, osg::StateAttribute::OFF);

But it works with:

Code:

   osg::StateSet* stateset = decorator->getOrCreateStateSet();
   stateset->removeAttribute(osg::StateAttribute::POLYGONMODE);

Is it correct for switching from wireframe on and off to create new osg::PolygonMode every time and then respectively remove that attribute? Or is there a better implementation?

Regards,
Gianni
Back to top
View user's profile Send private message
gambr
Appreciator


Joined: 22 Jun 2010
Posts: 355

PostPosted: Tue Aug 26, 2014 1:28 pm    Post subject:
Reply with quote

Hi,
unfortunately now I found an unexpected behavior with the non-osgFX solution. Pushing wireframe button on and off quite fast from my application I get sometimes a crash, sometimes the surface disappears and I can see just the wireframe (there's no way to get the surface visible again). OSG 3.1.4 are used in this case.

The crash happens at the end of this piece of code (osg/State):

Code:

        inline bool applyAttribute(const StateAttribute* attribute,AttributeStack& as)
        {
            if (as.last_applied_attribute != attribute)
            {
                if (!as.global_default_attribute.valid()) as.global_default_attribute = dynamic_cast<StateAttribute*>(attribute->cloneType());

                as.last_applied_attribute = attribute;
                attribute->apply(*this);

And here is the call stack:

Code:
   osg95-osgd.dll!osg::State::applyAttribute(const osg::StateAttribute * attribute, osg::State::AttributeStack & as)  Line 1596 + 0xe bytes   C++
    osg95-osgd.dll!osg::State::applyAttributeList(std::map<std::pair<enum osg::StateAttribute::Type,unsigned int>,osg::State::AttributeStack,std::less<std::pair<enum osg::StateAttribute::Type,unsigned int> >,std::allocator<std::pair<std::pair<enum osg::StateAttribute::Type,unsigned int> const ,osg::State::AttributeStack> > > & attributeMap, const std::map<std::pair<enum osg::StateAttribute::Type,unsigned int>,std::pair<osg::ref_ptr<osg::StateAttribute>,unsigned int>,std::less<std::pair<enum osg::StateAttribute::Type,unsigned int> >,std::allocator<std::pair<std::pair<enum osg::StateAttribute::Type,unsigned int> const ,std::pair<osg::ref_ptr<osg::StateAttribute>,unsigned int> > > > & attributeList)  Line 2324   C++
    osg95-osgd.dll!osg::State::apply(const osg::StateSet * dstate)  Line 508   C++
    osg95-osgUtild.dll!osgUtil::RenderLeaf::render(osg::RenderInfo & renderInfo, osgUtil::RenderLeaf * previous)  Line 47 + 0x14 bytes   C++
    osg95-osgUtild.dll!osgUtil::RenderBin::drawImplementation(osg::RenderInfo & renderInfo, osgUtil::RenderLeaf * & previous)  Line 483 + 0x19 bytes   C++
    osg95-osgUtild.dll!osgUtil::RenderStage::drawImplementation(osg::RenderInfo & renderInfo, osgUtil::RenderLeaf * & previous)  Line 1398   C++
    osg95-osgUtild.dll!osgUtil::RenderBin::draw(osg::RenderInfo & renderInfo, osgUtil::RenderLeaf * & previous)  Line 428 + 0x17 bytes   C++
    osg95-osgUtild.dll!osgUtil::RenderStage::drawInner(osg::RenderInfo & renderInfo, osgUtil::RenderLeaf * & previous, bool & doCopyTexture)  Line 933   C++
    osg95-osgUtild.dll!osgUtil::RenderStage::draw(osg::RenderInfo & renderInfo, osgUtil::RenderLeaf * & previous)  Line 1237 + 0x1b bytes   C++
    osg95-osgUtild.dll!osgUtil::SceneView::draw()  Line 1443 + 0x37 bytes   C++
    osg95-osgViewerd.dll!osgViewer::Renderer::draw()  Line 732 + 0xf bytes   C++
    osg95-osgViewerd.dll!osgViewer::Renderer::operator()(osg::GraphicsContext * context)  Line 899 + 0xf bytes   C++
    osg95-osgd.dll!osg::GraphicsContext::runOperations()  Line 777 + 0x33 bytes   C++
    osg95-osgQtd.dll!osgQt::GraphicsWindowQt::runOperations()  Line 685 + 0xb bytes   C++
    osg95-osgd.dll!osg::RunOperations::operator()(osg::GraphicsContext * context)  Line 137 + 0xf bytes   C++
    osg95-osgd.dll!osg::GraphicsOperation::operator()(osg::Object * object)  Line 53 + 0x19 bytes   C++
    osg95-osgd.dll!osg::OperationThread::run()  Line 426 + 0x26 bytes   C++
    osg95-osgd.dll!osg::GraphicsThread::run()  Line 41   C++
    ot12-OpenThreadsd.dll!OpenThreads::ThreadPrivateActions::StartThread(void * data)  Line 113 + 0xf bytes   C++
    msvcr100d.dll!_callthreadstartex()  Line 314 + 0xf bytes   C
    msvcr100d.dll!_threadstartex(void * ptd)  Line 297   C
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12269

PostPosted: Tue Aug 26, 2014 1:40 pm    Post subject:
wireframe
Reply with quote

HI Gianni,


My guess would be that you've introduced a threading bug by creating/destroying state objects in the scene graph whilst it's being rendered.


If you want to toggle on/off behavior like this considering using a NodeMask on the wireframe portion of the subgraph and just toggle the wireframe version on/off as required by sett the Node::setNodeMask() to 0x and 0xffffffff to switch it off/on respectively.


If you do want to create/destroy state then just make sure you are using a ref_ptr<> to any objects you want to keep around and reuse a C pointer will just end up a dangling pointer when your remove the object it's pointing to from the scene graph.

Robert.




On 26 August 2014 14:28, Gianni Ambrosio <g.ambrosio+ ([email]g.ambrosio+[/email])> wrote:
Quote:
Hi,
unfortunately now I found an unexpected behavior with the non-osgFX solution. Pushing wireframe button on and off quite fast from my application I get sometimes a crash, sometimes the surface disappears and I can see just the wireframe (there's no way to get the surface visible again). OSG 3.1.4 are used in this case.

The crash happens at the end of this piece of code (osg/State):


Code:

        inline bool applyAttribute(const StateAttribute* attribute,AttributeStack& as)
        {
            if (as.last_applied_attribute != attribute)
            {
                if (!as.global_default_attribute.valid()) as.global_default_attribute = dynamic_cast<StateAttribute*>(attribute->cloneType());

                as.last_applied_attribute = attribute;
                attribute->apply(*this);



And here is the call stack:


Code:
        osg95-osgd.dll!osg::State::applyAttribute(const osg::StateAttribute * attribute, osg::State::AttributeStack & as)  Line 1596 + 0xe bytes        C++
        osg95-osgd.dll!osg::State::applyAttributeList(std::map<std::pair<enum osg::StateAttribute::Type,unsigned int>,osg::State::AttributeStack,std::less<std::pair<enum osg::StateAttribute::Type,unsigned int> >,std::allocator<std::pair<std::pair<enum osg::StateAttribute::Type,unsigned int> const ,osg::State::AttributeStack> > > & attributeMap, const std::map<std::pair<enum osg::StateAttribute::Type,unsigned int>,std::pair<osg::ref_ptr<osg::StateAttribute>,unsigned int>,std::less<std::pair<enum osg::StateAttribute::Type,unsigned int> >,std::allocator<std::pair<std::pair<enum osg::StateAttribute::Type,unsigned int> const ,std::pair<osg::ref_ptr<osg::StateAttribute>,unsigned int> > > > & attributeList)  Line 2324        C++
        osg95-osgd.dll!osg::State::apply(const osg::StateSet * dstate)  Line 508        C++
        osg95-osgUtild.dll!osgUtil::RenderLeaf::render(osg::RenderInfo & renderInfo, osgUtil::RenderLeaf * previous)  Line 47 + 0x14 bytes      C++
        osg95-osgUtild.dll!osgUtil::RenderBin::drawImplementation(osg::RenderInfo & renderInfo, osgUtil::RenderLeaf * & previous)  Line 483 + 0x19 bytes        C++
        osg95-osgUtild.dll!osgUtil::RenderStage::drawImplementation(osg::RenderInfo & renderInfo, osgUtil::RenderLeaf * & previous)  Line 1398  C++
        osg95-osgUtild.dll!osgUtil::RenderBin::draw(osg::RenderInfo & renderInfo, osgUtil::RenderLeaf * & previous)  Line 428 + 0x17 bytes      C++
        osg95-osgUtild.dll!osgUtil::RenderStage::drawInner(osg::RenderInfo & renderInfo, osgUtil::RenderLeaf * & previous, bool & doCopyTexture)  Line 933      C++
        osg95-osgUtild.dll!osgUtil::RenderStage::draw(osg::RenderInfo & renderInfo, osgUtil::RenderLeaf * & previous)  Line 1237 + 0x1b bytes   C++
        osg95-osgUtild.dll!osgUtil::SceneView::draw()  Line 1443 + 0x37 bytes   C++
        osg95-osgViewerd.dll!osgViewer::Renderer::draw()  Line 732 + 0xf bytes  C++
        osg95-osgViewerd.dll!osgViewer::Renderer::operator()(osg::GraphicsContext * context)  Line 899 + 0xf bytes      C++
        osg95-osgd.dll!osg::GraphicsContext::runOperations()  Line 777 + 0x33 bytes     C++
        osg95-osgQtd.dll!osgQt::GraphicsWindowQt::runOperations()  Line 685 + 0xb bytes C++
        osg95-osgd.dll!osg::RunOperations::operator()(osg::GraphicsContext * context)  Line 137 + 0xf bytes     C++
        osg95-osgd.dll!osg::GraphicsOperation::operator()(osg::Object * object)  Line 53 + 0x19 bytes   C++
        osg95-osgd.dll!osg::OperationThread::run()  Line 426 + 0x26 bytes       C++
        osg95-osgd.dll!osg::GraphicsThread::run()  Line 41      C++
        ot12-OpenThreadsd.dll!OpenThreads::ThreadPrivateActions::StartThread(void * data)  Line 113 + 0xf bytes C++
        msvcr100d.dll!_callthreadstartex()  Line 314 + 0xf bytes        C
        msvcr100d.dll!_threadstartex(void * ptd)  Line 297      C




------------------
Read this topic online here:

http://forum.openscenegraph.org/viewtopic.php?p=60793#60793





_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org




------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
gambr
Appreciator


Joined: 22 Jun 2010
Posts: 355

PostPosted: Tue Aug 26, 2014 2:28 pm    Post subject:
Reply with quote

Thanks Robert for the reply.
I suspected a thread issus but since osgFX::Scribe code does not do anything special regarding thread safety I expected my code should work fine as well.

Can you see the point in my code? Or maybe a threading issue in OSG code? The difference wrt the osgFX::Scribe usage is that the Scribe node is removed from the OSG graph in that case instead of removing attributes from stateset.

Code:


osg::ref_ptr< osg::Group > decorator; // class member

Constructor(osg::ref_ptr<osg::Node> iNode)
{
   decorator = new osg::Group;
   decorator->addChild(iNode);
   iNode->getParent(0)->addChild(decorator);

   osg::StateSet* stateset = decorator->getOrCreateStateSet();
   osg::Material* material = new osg::Material;
   stateset->setMode(GL_LIGHTING, osg::StateAttribute::OVERRIDE | osg::StateAttribute::OFF);
   stateset->setAttributeAndModes(material, osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);
}

void removeWireframe()
{
   osg::StateSet* stateset = decorator->getStateSet();
   stateset->removeAttribute(osg::StateAttribute::POLYGONMODE);
   stateset->removeAttribute(osg::StateAttribute::POLYGONOFFSET);
}

void setWireframe()
{
   osg::StateSet* stateset = decorator->getStateSet();

   osg::PolygonOffset* polyoffset = new osg::PolygonOffset;
   polyoffset->setFactor(-1.0f);
   polyoffset->setUnits(-1.0f);
   stateset->setAttributeAndModes(polyoffset, osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);

   osg::PolygonMode* polymode = new osg::PolygonMode;
   polymode->setMode(osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE);
   stateset->setAttributeAndModes(polymode, osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);
}
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12269

PostPosted: Tue Aug 26, 2014 3:07 pm    Post subject:
wireframe
Reply with quote

Hi Gianni,


If you want to remove and add back StateAttribute to a StateSet you have to mark the StateSet's DataVariance as DYNAMIC, otherwise the draw thread will overlap the update traversal and contend on the data structure and crash.  Setting DataVariance to DYNAMIC isn't ideal though as it breaks the multi-threading benefit as it enforces serialization until the last dynamic StateSet/Drawable is dispatched to OpenGL.  If you use DYNAMIC DataVariance on Stateset or Drawable you performance is unlikely to benefit too much from multi-threading but at least it won't crash.


A MUCH better solution, as I suggested, is not to modify the scene graph by adding/remove stuff, but instead toggle on/off effects by toggle NodeMask on the multi-pass subgraph, this solution is threadsafe and allows for full multi-threading.


Robert.



On 26 August 2014 15:28, Gianni Ambrosio <g.ambrosio+ ([email]g.ambrosio+[/email])> wrote:
Quote:
Thanks Robert for the reply.
I suspected a thread issus but since osgFX::Scribe code does not do anything special regarding thread safety I expected my code should work fine as well.

Can you see the point in my code? Or maybe a threading issue in OSG code? The difference wrt the osgFX::Scribe usage is that the Scribe node is removed from the OSG graph in that case instead of removing attributes from stateset.


Code:


osg::ref_ptr< osg::Group > decorator; // class member

Constructor(osg::ref_ptr<osg::Node> iNode)
{
   decorator = new osg::Group;
   decorator->addChild(iNode);
   iNode->getParent(0)->addChild(decorator);

   osg::StateSet* stateset = decorator->getOrCreateStateSet();

   osg::Material* material = new osg::Material;

   stateset->setMode(GL_LIGHTING, osg::StateAttribute::OVERRIDE | osg::StateAttribute::OFF);
   stateset->setAttributeAndModes(material, osg::StateAttribute::OVERRIDE | osg::StateAttribute:ShockedN);
}

void removeWireframe()
{
   osg::StateSet* stateset = decorator->getStateSet();
   stateset->removeAttribute(osg::StateAttribute::POLYGONMODE);
   stateset->removeAttribute(osg::StateAttribute::POLYGONOFFSET);
}

void setWireframe()
{
   osg::StateSet* stateset = decorator->getStateSet();

   osg::PolygonOffset* polyoffset = new osg::PolygonOffset;
   polyoffset->setFactor(-1.0f);
   polyoffset->setUnits(-1.0f);
   stateset->setAttributeAndModes(polyoffset, osg::StateAttribute::OVERRIDE | osg::StateAttribute:ShockedN);

   osg::PolygonMode* polymode = new osg::PolygonMode;
   polymode->setMode(osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE);

   stateset->setAttributeAndModes(polymode, osg::StateAttribute::OVERRIDE | osg::StateAttribute:ShockedN);
}




------------------
Read this topic online here:

http://forum.openscenegraph.org/viewtopic.php?p=60795#60795





_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org




------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
gambr
Appreciator


Joined: 22 Jun 2010
Posts: 355

PostPosted: Tue Aug 26, 2014 3:50 pm    Post subject:
Reply with quote

OK Robert, thank you for the explanation.

Gianni
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Toggling between wireframe modes Igor Naigovzin General 2 Wed Nov 07, 2018 9:41 am View latest post
No new posts wireframe darker wrt the surface color gambr General 10 Tue Mar 21, 2017 4:00 pm View latest post
No new posts wireframe mode and degenerate triangles cbuchner1 General 1 Fri Dec 30, 2016 1:39 pm View latest post
No new posts WireFrame display for 3d model using ... umadevi2193 General 1 Sat Sep 24, 2016 7:12 am View latest post
No new posts Wireframe rendering on Android SMesserschmidt General 3 Wed Mar 05, 2014 9:33 am View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP