[Solved]Applying SoReorganizeAction on a scenegraph

Need help, or want to share a macro? Post here!
kwahoo
Posts: 235
Joined: Fri Nov 29, 2013 3:09 pm
Contact:

[Solved]Applying SoReorganizeAction on a scenegraph

Postby kwahoo » Thu Oct 03, 2019 9:01 pm

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
Site Admin
Posts: 14886
Joined: Thu Feb 19, 2009 10:32 am

Re: Applying SoReorganizeAction on a scenegraph

Postby wmayer » Fri Oct 04, 2019 8:29 am

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.
looo
Posts: 2905
Joined: Mon Nov 11, 2013 5:29 pm

Re: Applying SoReorganizeAction on a scenegraph

Postby looo » Fri Oct 04, 2019 9:17 am

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
please help with my conda-packaging efforts: https://liberapay.com/looooo/
wmayer
Site Admin
Posts: 14886
Joined: Thu Feb 19, 2009 10:32 am

Re: Applying SoReorganizeAction on a scenegraph

Postby wmayer » 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.
looo
Posts: 2905
Joined: Mon Nov 11, 2013 5:29 pm

Re: Applying SoReorganizeAction on a scenegraph

Postby looo » Fri Oct 04, 2019 10:58 am

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)
please help with my conda-packaging efforts: https://liberapay.com/looooo/
looo
Posts: 2905
Joined: Mon Nov 11, 2013 5:29 pm

Re: Applying SoReorganizeAction on a scenegraph

Postby looo » Fri Oct 04, 2019 11:01 am

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)
please help with my conda-packaging efforts: https://liberapay.com/looooo/
wmayer
Site Admin
Posts: 14886
Joined: Thu Feb 19, 2009 10:32 am

Re: Applying SoReorganizeAction on a scenegraph

Postby wmayer » Fri Oct 04, 2019 11:15 am

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!
kwahoo
Posts: 235
Joined: Fri Nov 29, 2013 3:09 pm
Contact:

Re: [Solved]Applying SoReorganizeAction on a scenegraph

Postby kwahoo » Fri Oct 04, 2019 4:33 pm

Wow, that was fast!

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