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 

Potential Error In Functionality of method findUnit() ?


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> osgPPU [osgPPU]
View previous topic :: View next topic  
Author Message
allensaucier
Appreciator


Joined: 10 Apr 2009
Posts: 126

PostPosted: Thu Apr 15, 2010 7:32 pm    Post subject:
Potential Error In Functionality of method findUnit() ?
Reply with quote

Hi,

I am working with the method, findUnit(), within the class Processor and I have come across something very strange:
In the program, osgppu.cpp using the header hdrppu.h, I do the following in osgppu.cpp/Viewer::initialize():
Code:

            mHDRSetup.createHDRPipeline(mProcessor.get(), firstUnit, lastUnit);
            mProcessor->addChild(firstUnit);
            osgPPU::UnitBypass* ppuUnit = dynamic_cast<osgPPU::UnitBypass*>(mProcessor->findUnit("HDRBypass"));
            osgPPU::UnitBypass* ppuUnit2 = dynamic_cast<osgPPU::UnitBypass*>(getProcessor()->findUnit("HDRBypass"));


findUnit() in both cases returns NULL or 0 but I know for a fact that the firstUnit is the "HDRBypass" Unit or UnitBypass with the name "HDRBypass".
However, when I issue this same findUnit command for this same unit within the KeyboardEventHandler::handle() method, it works. Here is my code snippet:
Code:

                osgPPU::UnitTexture* ppu = dynamic_cast<osgPPU::UnitTexture*>(viewer->getProcessor()->findUnit("TextureUnit"));
                osgPPU::UnitText* textppu = dynamic_cast<osgPPU::UnitText*>(viewer->getProcessor()->findUnit("TextPPU"));
                osgPPU::UnitInOut* pip = dynamic_cast<osgPPU::UnitInOut*>(viewer->getProcessor()->findUnit("PictureInPicturePPU"));
            osgPPU::UnitBypass* ppuUnit = dynamic_cast<osgPPU::UnitBypass*>(viewer->getProcessor()->findUnit("HDRBypass"));


Does anyone know why this is the case? There is no documentation on this anomaly and I need findUnit to work in my 1st case as well as the second case.

Thank you!

Cheers,
Allen
Back to top
View user's profile Send private message
art (Art Tevs)
Site Admin


Joined: 20 Dec 2008
Posts: 414
Location: Saarbrücken, Germany

PostPosted: Thu Apr 15, 2010 8:12 pm    Post subject:
Reply with quote

Hi Allen,

the problem in the first case, is that the unit graph is still not correctly initialised before you call findUnit. When keyboard event handle runs, there is already an update/init call on the unit graph which initialize the whole pipeline.

I could take a look in that, you are right. So that next time nobody get confused about the method. One just have to write a visitor which is able to find a unit also in an unitialized graph.

As simple workaround would be to use osg's internal find node methods (I am pretty sure there must be such) and to look for a node with the given name. Units are derived from nodes, hence it should work in that way too.

Cheers,
Art
Back to top
View user's profile Send private message Visit poster's website
allensaucier
Appreciator


Joined: 10 Apr 2009
Posts: 126

PostPosted: Thu Apr 15, 2010 8:48 pm    Post subject:
Reply with quote

Aaaaaah, I understand. I was hoping I was missing something obvious and something simple.

In OSG there is a "node" visitor find type thing one can do. Below is some example code I found. I have not implemented this code and I hope to find an even easier method.

I agree, though, I should be able to search osg's node tree. But you brought up a very good point I was totally unaware of: the pipeline is not completely instantiated until runtime.

What I was attempting to do was to change a shader value that is sent into my blur shader (the blur shader I got from your examples Smile ) and now I have learned that I must change that blur shader variable at runtime because the pipeline is not fully allocated until then. That is very good to know.

Thanks for your help, Art.

Code:

 osg::Node* findNamedNode(const std::string& searchName,
                                          osg::Node* currNode)
    {
       osg::Group* currGroup;
       osg::Node* foundNode;

       // check to see if we have a valid (non-NULL) node.
       // if we do have a null node, return NULL.
       if ( !currNode)
       {
          return NULL;
       }

       // We have a valid node, check to see if this is the node we
       // are looking for. If so, return the current node.
       if (currNode->getName() == searchName)
       {
          return currNode;
       }

       // We have a valid node, but not the one we are looking for.
       // Check to see if it has children (non-leaf node). If the node
       // has children, check each of the child nodes by recursive call.
       // If one of the recursive calls returns a non-null value we have
       // found the correct node, so return this node.
       // If we check all of the children and have not found the node,
       // return NULL
       currGroup = currNode->asGroup(); // returns NULL if not a group.
       if ( currGroup )
       {
          for (unsigned int i = 0 ; i < currGroup->getNumChildren(); i ++)
          {
             foundNode = findNamedNode(searchName, currGroup->getChild(i));
             if (foundNode)
                return foundNode; // found a match!
          }
          return NULL; // We have checked each child node - no match found.
       }
       else
       {
          return NULL; // leaf node, no match
       }
    }



Cheers,
Allen
Back to top
View user's profile Send private message
art (Art Tevs)
Site Admin


Joined: 20 Dec 2008
Posts: 414
Location: Saarbrücken, Germany

PostPosted: Thu Apr 15, 2010 9:04 pm    Post subject:
Reply with quote

Hi,

I just corrected the findUnit method to also find units on unitialized pipelines, however I haven't submited it yet, since I want to correct another bug first. You should always use the processor's findUnit method, because in the osgPPU pipeline graph there might be potentially loops (see motion blur or hdr example). So using osg's find node method it might not terminate. After the unit pipeline is initialized the loops are resolved and hence afterwards a simple node visitor should be also able to find any unit.

Art
Back to top
View user's profile Send private message Visit poster's website
allensaucier
Appreciator


Joined: 10 Apr 2009
Posts: 126

PostPosted: Thu Apr 15, 2010 10:04 pm    Post subject:
Reply with quote

Hi Art,

I have downloaded the latest version of osgPPU from svn. I fixed one bug - it was easy, just a typo - but I have 2 other bugs only you can fix. Here is the listing:
Code:

  2%] Building CXX object src/osgPPU/CMakeFiles/osgPPU.dir/Unit.o
/home/allen/projects/osgppu/src/osgPPU/Unit.cpp: In member function ‘virtual void osgPPU::Unit::DrawCallback::drawImplementation(osg::RenderInfo&, const osg::Drawable*) const’:
/home/allen/projects/osgppu/src/osgPPU/Unit.cpp:703: error: ‘class osg::PixelDataBufferObject’ has no member named ‘getOrCreateGLBufferObject’
/home/allen/projects/osgppu/src/osgPPU/Unit.cpp:705: error: ‘class osg::PixelDataBufferObject’ has no member named ‘getOrCreateGLBufferObject’
make[2]: *** [src/osgPPU/CMakeFiles/osgPPU.dir/Unit.o] Error 1
make[1]: *** [src/osgPPU/CMakeFiles/osgPPU.dir/all] Error 2
make: *** [all] Error 2

I can not find any function close to the name of this function.
I have included in this post the updated unit.h file for your convenience. I hope it helps.
When you say:
Quote:

After the unit pipeline is initialized the loops are resolved and hence afterwards a simple node visitor should be also able to find any unit.

I understand the term, initialize, means when the application is running and not after the line of code: osgPPU::Processor *processor = new osgPPU::Processor();
Am I correct?

And I will be "happy" to use the findUnit() command once you have corrected any and all bugs you need to.

Sincerely,
Allen
Back to top
View user's profile Send private message
art (Art Tevs)
Site Admin


Joined: 20 Dec 2008
Posts: 414
Location: Saarbrücken, Germany

PostPosted: Thu Apr 15, 2010 10:14 pm    Post subject:
Reply with quote

Hi Allen,

The bug you encounter is not a bug. There was an API change in osg main core from 2.8.1 to 2.8.2 I think. Current svn version of osgPPU is working only with osg version greater than 2.8.2, I think. At least it works with the current osg svn version.

I have already update the svn repository and solved the findUnit issue.


allensaucier wrote:

I understand the term, initialize, means when the application is running and not after the line of code: osgPPU::Processor *processor = new osgPPU::Processor();
Am I correct?


Yes, when there was a first call of Processor::traverse method with an UpdateVisitor. This usually happens when first frame is drawn, so after main application rendering loop is started (osgViewer::run() )

cheers,
art
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> osgPPU [osgPPU] 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 Having an issue with OSG plugins error. Brigham Keys, Esq. General 2 Wed Apr 12, 2017 5:24 am View latest post
No new posts Error building terrain with shapefile... robertosfield VirtualPlanetBuilder [vpb] 0 Mon Feb 06, 2017 9:11 am View latest post
No new posts Error building terrain with shapefile... vinothrajendran4 VirtualPlanetBuilder [vpb] 0 Mon Feb 06, 2017 6:24 am View latest post
No new posts WG: Fix for DICOM plugin (DCMTK) : co... robertosfield Submission 0 Wed Dec 21, 2016 4:03 pm View latest post
No new posts Using StatsHandler rendering method Riccardo Corsi General 1 Tue Nov 29, 2016 3:59 pm 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