-
Notifications
You must be signed in to change notification settings - Fork 46
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
CollisionGroup not updating value #346
Comments
Hey @ScheiklP I tested a very simple xml scenario where I set in the XML the Maybe something related to the binding between the python array and the C++ Data which is a Thanks for reporting it anyway @ScheiklP 👍 |
Sorry my bad, it's indeed not working 👍 |
@hugtalbot So it's more a Sofa than a SofaPython3 issue? Should I open another issue there? |
Yes 👍 |
My first feeling would be that this is due to the 2-step broad-narrow phases : the data Let's investigate |
I did self.assertEqual(node.PointCollisionModel.group.value, [[0]])
node.PointCollisionModel.group = [8]
self.assertEqual(node.PointCollisionModel.group.value, [[8]]) and the result is
It seems that setting a value in a set insert the new value, but does not remove the old one. I think it is due to https://github.com/sofa-framework/sofa/blob/918cd66008f586575c92c1e068f5c267a952b936/Sofa/framework/DefaultType/src/sofa/defaulttype/typeinfo/models/SetTypeInfo.h#L113. I think this discussion should involve @damienmarchal. |
Here is the unit test: # coding: utf8
import Sofa.Core
import Sofa.Components
import unittest
import numpy as np
class Test(unittest.TestCase):
def test_setting_collision_group(self):
root = Sofa.Core.Node("rootNode")
plugins = [
"Sofa.Component.Collision.Detection.Algorithm",
"Sofa.Component.Collision.Detection.Intersection",
]
for plugin in plugins:
root.addObject("RequiredPlugin", pluginName=plugin, name=plugin)
root.addObject("DefaultAnimationLoop")
root.addObject("DefaultPipeline")
root.addObject("BruteForceBroadPhase")
root.addObject("BVHNarrowPhase")
root.addObject("DefaultContactManager")
root.addObject("LocalMinDistance", alarmDistance=5.0, contactDistance=0.5)
node = root.addChild("child")
node.addObject("MechanicalObject", position=[0, 0, 0] * 5)
node.addObject("PointCollisionModel", group=0)
Sofa.Simulation.init(root)
Sofa.Simulation.animate(root, root.getDt())
self.assertEqual(node.PointCollisionModel.group.value, [[0]])
node.PointCollisionModel.group = [8]
self.assertEqual(node.PointCollisionModel.group.value, [[8]]) |
Thanks for having added me in this nicely documented issues with code to code & paste for testing things. |
Ok, so after quick investigation, there are several issues related to how sets are exposed to python related to what @alxbilger pointed. The real problem is that SetTypeinfo is "hijacking" the typeinfo API for indexable container. This is very visible in the SetTypeInfo::setSize() that actually clears the set as well as using setValue(..., index, ) which is ignoring the index and insert the data. The consequence of that is that sets are considered as an indexable container by the python binding but as they are not really fullfilling what could be expected from an indexable container things goes badly wrong. eg:
Quick fix can be done in the python binding by calling setSize() everytime we do setValue, this will force the set to be cleared, this fix only solve the reported issue but not the other problems (the conversion when we get the data). A much clean way of fixing that is to add complete support for "Unique Key containers" the typeinfo system with specific dedicated API. This probably means adding feature in AbstractTypeInfo. |
Thanks for the feedback @damienmarchal |
@damienmarchal Thanks a lot! :) |
In PythonFactory.cpp you need to comment the pointed line... template<class DestType>
void copyFromListOf(BaseData& d, const AbstractTypeInfo& nfo, const py::list& l)
{
/// Check if the data is a single dimmension or not.
py::buffer_info dstinfo = toBufferInfo(d);
if(dstinfo.ndim>2)
throw py::index_error("Invalid number of dimension only 1 or 2 dimensions are supported).");
if(dstinfo.ndim==1)
{
void* ptr = d.beginEditVoidPtr();
if( size_t(dstinfo.shape[0]) != l.size()) // THIS IS THE LINE TO COMMENT TO FORCE CLEARING of a set<-
nfo.setSize(ptr, l.size());
for(size_t i=0;i<l.size();++i)
{
copyFromListOf<DestType>(nfo, ptr, i, l[i]);
}
d.endEditVoidPtr();
return;
}
/// ...
} NB: I tried to fix that the right way... but working in TypeInfo.h is such a source of pain because of its misdesign that I will probably give-up soon. |
Did this quick-dirty fix solve your issue @ScheiklP ? |
I did not try it yet. I was hoping for a miracle in sofa-framework/sofa#3851 :D |
Hi! :)
I am trying to change the collision group of a collision model during runtime.
However, the values are not updated correctly, and the
.array()
method returns weird values.Example to reproduce:
Output:
Any ideas what might be wrong here?
Sofa commit: sofa-framework/sofa@9a0d4b9
SP3 commit: 5a73716
Cheers,
Paul
The text was updated successfully, but these errors were encountered: