Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SofaPython3] Changes how addObject process its arguments when they are of type: numpy & data #198

Merged

Conversation

damienmarchal
Copy link
Contributor

@damienmarchal damienmarchal commented Sep 23, 2021

The PR changes how addObject is handling some parameter according to their type.

numpy array

When passing a numpy array to the addObject simply does not work reporting an unparsable string.
Eg:

   node.addObject("MeshObjLoader", name=loader)
   node.addObject("MechanicalObject", position=node.loader.position.value)

This does not work because position.value is of type numpy and that the object creation is trying to do a string conversion (which does not returns string parsable by Sofa). The PR detect numpy arrays and implement the proper conversion.

Data fields

When passing a BaseData object to the addObject the current implementation is copying the data.
Eg:

   node.addObject("MeshObjLoader", name=loader)
   node.addObject("MechanicalObject", position=node.loader.position)

It was discussed in #197 what should be the most appropriate scenario.
This PR implement the following scenario:

def createScene(root):
    root.addObject("MeshObjLoader", filename="mesh/cube.obj", name="loader");
    a = root.addObject("PointSetTopologyContainer", position=root.loader.position.linkpath, name="topo") # explicitly makes a link
    b = root.addObject("PointSetTopologyContainer", position=root.loader.position.value, name="topo")     # explicitly makes copy
    c = root.addObject("PointSetTopologyContainer", position=root.loader.position, name="topo") # implicitly makes a link 

It is yet undecided if we prevent the implicit version, and if we keep it if it should makes a link or a copy.

NB: the tests for linkpath will fails until the following sofa PR: sofa-framework/sofa#2354
is not merged.

…ing (in object creation)

So we can write:
```python
def createScene(root):
	root.addObject("MechanicalObject", name="loader", filename="mesh/cube.obj")
	root.addObject("MechanicalObject", name="dofs", position=root.loader.position)        # to make a link
	root.addObject("MechanicalObject", name="dofs", position=root.loader.position.value)  # to make a copy by value
```
…ring

Because it breaks bckward compatibility and was not really better.
So we can write:
object.position.link instead of object.position.getLinkPath()

Which will make the syntax a bit more compact.

Signed-off-by: Damien Marchal <damien.marchal@univ-lille1.fr>
Signed-off-by: Damien Marchal <damien.marchal@univ-lille1.fr>
@damienmarchal
Copy link
Contributor Author

tests are passing now (not the one with 21.06...but this is expected)

@hugtalbot
Copy link
Contributor

it works for me ! 👍
I will add this in the SP3 doc !

@hugtalbot hugtalbot added pr: breaking pr: new feature pr: highlighted in next release Highlight this contribution in the notes of the upcoming release labels Oct 11, 2021
hugtalbot added a commit to hugtalbot/SofaPython3 that referenced this pull request Oct 11, 2021
@damienmarchal
Copy link
Contributor Author

I remember a long time ago there was a rule saying that a PR without a "no go message" for more than seven days were considered as ready to merge.

This one is on-hold for 19 days now.

@guparan guparan modified the milestones: v21.06, v21.12 Oct 26, 2021
@damienmarchal
Copy link
Contributor Author

@hugtalbot, @fredroy the changes requested are done.

@damienmarchal damienmarchal merged commit 166f7f5 into sofa-framework:master Nov 3, 2021
@damienmarchal damienmarchal deleted the pr-add-createobject-behavior branch November 3, 2021 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: breaking pr: highlighted in next release Highlight this contribution in the notes of the upcoming release pr: new feature pr: status ready
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants