[Solved]Applying SoReorganizeAction on a scenegraph

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
kwahoo
Posts: 680
Joined: Fri Nov 29, 2013 3:09 pm
Contact:

[Solved]Applying SoReorganizeAction on a scenegraph

Post by kwahoo »

Hi!
Based on https://grey.colorado.edu/coin3d/classS ... ction.html I would like to simplify a scenegraph to get a VBO-friendly one. I tried:

Code: Select all

from pivy.coin import SoSeparator
from pivy.coin import SoReorganizeAction
rootScene = SoSeparator()
rootScene.ref()
sg = FreeCADGui.ActiveDocument.ActiveView.getSceneGraph()#get active scenegraph
rootScene.addChild(sg)
sor = SoReorganizeAction
sor.apply(rootScene)
Solved:

Code: Select all

sor = SoReorganizeAction()
but got an error:

Code: Select all

>>> sor.apply(rootScene)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/pivy/coin.py", line 13292, in apply
    return _coin.SoReorganizeAction_apply(self, *args)
NotImplementedError: Wrong number or type of arguments for overloaded function 'SoReorganizeAction_apply'.
  Possible C/C++ prototypes are:
    SoReorganizeAction::apply(SoNode *)
    SoReorganizeAction::apply(SoPath *)
    SoReorganizeAction::apply(SoPathList const &,SbBool)
    SoReorganizeAction::apply(SoPathList const &)
How can I pass scenegraph to SoReorganizeAction?

SoSeparator inherits SoNode, but then the prototype shouldn't be SoReorganizeAction::apply(SoNode * root) as shown here?
Last edited by kwahoo on Fri Oct 04, 2019 4:48 pm, edited 3 times in total.
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Applying SoReorganizeAction on a scenegraph

Post by wmayer »

NotImplementedError: Wrong number or type of arguments for overloaded function 'SoReorganizeAction_apply'.
Possible C/C++ prototypes are:
SoReorganizeAction::apply(SoNode *)
SoReorganizeAction::apply(SoPath *)
SoReorganizeAction::apply(SoPathList const &,SbBool)
SoReorganizeAction::apply(SoPathList const &)
I guess this is a pivy bug. There are a few classes of Coin3d which are not properly wrapped with swig. Maybe you can ask looo since he maintains the pivy sources and has fixed several bugs already.
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: Applying SoReorganizeAction on a scenegraph

Post by looo »

wmayer wrote: Fri Oct 04, 2019 8:29 am I guess this is a pivy bug. There are a few classes of Coin3d which are not properly wrapped with swig. Maybe you can ask looo since he maintains the pivy sources and has fixed several bugs already.
Not sure if it is really a bug or if this is the normal way how swig works. I guess we need to extend the SoReorganizeAction::apply function to also support other classes which inherits from SoNode.

@kwahoo please create an issue: https://github.com/FreeCAD/pivy/issues
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Applying SoReorganizeAction on a scenegraph

Post by wmayer »

Not sure if it is really a bug or if this is the normal way how swig works. I guess we need to extend the SoReorganizeAction::apply function to also support other classes which inherits from SoNode.
If you create e.g. an SoSearchAction then it also works with pivy to traverse the passed node using the apply() function. Only with SoReorganizeAction it doesn't seem to work.
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: Applying SoReorganizeAction on a scenegraph

Post by looo »

wmayer wrote: Fri Oct 04, 2019 9:39 am
Not sure if it is really a bug or if this is the normal way how swig works. I guess we need to extend the SoReorganizeAction::apply function to also support other classes which inherits from SoNode.
If you create e.g. an SoSearchAction then it also works with pivy to traverse the passed node using the apply() function. Only with SoReorganizeAction it doesn't seem to work.
I will have a look. The python code for both of the functions looks the same:

Code: Select all

class SoAction(object):  # base class of SoSearchAction
...
    def apply(self, *args) -> "void":
        r"""
        apply(SoAction self, SoNode root)
        apply(SoAction self, SoPath path)
        apply(SoAction self, SoPathList pathlist, SbBool obeysrules=0)
        apply(SoAction self, SoAction beingApplied)
        """
        return _coin.SoAction_apply(self, *args)

Code: Select all

class SoReorganizeAction(SoSimplifyAction):
...
    def apply(self, *args) -> "void":
        r"""
        apply(SoReorganizeAction self, SoNode root)
        apply(SoReorganizeAction self, SoPath path)
        apply(SoReorganizeAction self, SoPathList pathlist, SbBool obeysrules=0)
        """
        return _coin.SoReorganizeAction_apply(self, *args)
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: Applying SoReorganizeAction on a scenegraph

Post by looo »

Btw.: There seems to be a problem with the code snippet. I guess one must call the apply function on the object and not on the class of SoReorganizeAction. So this works for me:

Code: Select all

from pivy.coin import SoSeparator
from pivy.coin import SoReorganizeAction
rootScene = SoSeparator()
rootScene.ref()
sg = FreeCADGui.ActiveDocument.ActiveView.getSceneGraph()#get active scenegraph
rootScene.addChild(sg)
sor = SoReorganizeAction()  # !!!!!
sor.apply(rootScene)
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Applying SoReorganizeAction on a scenegraph

Post by wmayer »

Btw.: There seems to be a problem with the code snippet.
Yes, you're right!

When correcting the code snippet accordingly no error message occurs any more. Sorry for the noise!
User avatar
kwahoo
Posts: 680
Joined: Fri Nov 29, 2013 3:09 pm
Contact:

Re: [Solved]Applying SoReorganizeAction on a scenegraph

Post by kwahoo »

Wow, that was fast!

How could I miss that :/ Thank you everyone for your help. Have a nice weekend!
Post Reply