Home › Forum › SofaPython3 › Programming with SofaPython3 › [SOLVED] Collision not work through python
Tagged: 64_bits, Collision not working, Linux_ubuntu, SOFA_2012
- This topic has 8 replies, 3 voices, and was last updated 3 years, 6 months ago by chiarasapo.
-
AuthorPosts
-
20 February 2021 at 13:53 #18727MikePBlocked
I am using Sofa and Sofapython3 v20.12. I recently watched the SOFA Training Session 2020 which was extremely helpful. I tried to replicate the example that Hugo does during the session in python. I successfully managed to replicate everything he did using SofaPython3 and everything has worked except the last part, which includes a rigid object colliding with a deformable liver object. The code I used is:
import sys, os sys.path.append(os.path.abspath("./bindings/Sofa/package")) sys.path.append(os.path.abspath("./bindings/SofaRuntime/package")) sys.path.append(os.path.abspath("./bindings/SofaTypes/package")) import Sofa # Choose in your script to activate or not the GUI USE_GUI = True # Function called when the scene graph is being created def createScene(root): # Set time step and gravity of the Scene root.gravity=[0, 0, 0] root.dt=0.01 # Scene must now include a VisualLoop root.addObject('DefaultVisualManagerLoop') # Scene must now include a AnimationLoop root.addObject('DefaultAnimationLoop') # In order to simulate collision, a collision pipeline needs to be created root.addObject('CollisionPipeline', verbose=0, draw=0) root.addObject('BruteForceDetection', name="N2") root.addObject('NewProximityIntersection', name="Proximity", alarmDistance=0.5, contactDistance=0.25) root.addObject('CollisionResponse', name="Response", response="default") # Load mesh file to accessed by other objects in child nodes root.addObject('MeshGmshLoader', name="meshLoaderCoarse", filename="mesh/liver.msh") # Load finer mesh for visual model. root.addObject('MeshObjLoader', name="meshLoaderFine", filename="mesh/liver-smooth.obj") # Add child node liver = root.addChild('Liver') # Add physics solver to determine effect of forces on the object liver.addObject('EulerImplicitSolver') liver.addObject('CGLinearSolver', iterations=200, tolerance=1e-09, threshold=1e-09) # Load tetrhedron mesh from loaded mesh and storing it in a container liver.addObject('TetrahedronSetTopologyContainer', name="topo", src="@../meshLoaderCoarse") liver.addObject('TetrahedronSetGeometryAlgorithms', name="GeomAlgo", template="Vec3d") # Add rigid body with its degrees of freedom and initial position liver.addObject('MechanicalObject', name="MechanicalModel", template="Vec3d", showObject=1) # Add a mechaincal model for example Elasticity liver.addObject('TetrahedronFEMForceField', name="FEM", youngModulus=600, poissonRatio=0.4, method="large") liver.addObject('MeshMatrixMass', massDensity=1) liver.addObject('ConstantForceField', totalForce=[100,0,0]) # Add constraint to the model at the following points liver.addObject('FixedConstraint', indices=[1,3,50]) # Only a surface mesh is required for a visual model, which can be extracted from the TetrahedronSetTopologyContainer using the below child node. surfaceMesh = liver.addChild('ExtractSurface') surfaceMesh.addObject('TriangleSetTopologyContainer', name="Container") surfaceMesh.addObject('TriangleSetTopologyModifier', name="Modifier") surfaceMesh.addObject('Tetra2TriangleTopologicalMapping', input="@../topo", output="@Container") # In order to create a visual model which moves with the physics model,the visual mesh must be mapped to the physics mesh # This is done by creating a child node of the particle for the visual model visual = surfaceMesh.addChild('Visual') # Add a visual model using the same mesh that was loaded visual.addObject('OglModel', name="VisualModel", color="red") # Add mapping of the visual model to the 'Liver' physics model. visual.addObject('IdentityMapping', name="VMapping", input="@../../MechanicalModel", output="@VisualModel") # In order to simulate collisions, a collision model and mesh must be added and mapped to the physics model collision = liver.addChild('Collision') collision.addObject('MeshTopology', src="@../../meshLoaderFine") collision.addObject('MechanicalObject', name="CollisionMO", scale=1.0) collision.addObject('TriangleCollisionModel', name="CollisionModel", contactStiffness=3) collision.addObject('BarycentricMapping', name="CollisionMapping", input="@../MechanicalModel", output="@CollisionMO") # Create a new child node of root to create a new object in the Simulation sphere = root.addChild('Sphere') sphere.addObject('EulerImplicitSolver', rayleighStiffness=0) sphere.addObject('CGLinearSolver', iterations=200, tolerance=1e-06, threshold=1e-06) sphere.addObject('MechanicalObject', name="mySphere", template="Rigid3d", position=[-2,10,0,0,0,0,1], showObject=1, showObjectScale=0.5) sphere.addObject('UniformMass', totalMass=1) sphere.addObject('ConstantForceField', force=[0,-1,0,0,0,0]) sphere.addObject('SphereCollisionModel', name="SphereCollision", listRadius=1, simulated=1, moving=1, contactStiffness=100) return root def main(): import SofaRuntime import Sofa.Gui # Make sure to load all SOFA libraries SofaRuntime.importPlugin("SofaComponentAll") #Create the root node root = Sofa.Core.Node("root") # Call the below 'createScene' function to create the scene graph createScene(root) Sofa.Simulation.init(root) if not USE_GUI: for iteration in range(10): Sofa.Simulation.animate(root, root.dt.value) else: # Find out the supported GUIs print ("Supported GUIs are: " + Sofa.Gui.GUIManager.ListSupportedGUI(",")) # Launch the GUI (qt or qglviewer) Sofa.Gui.GUIManager.Init("myscene", "qglviewer") Sofa.Gui.GUIManager.createGUI(root, __file__) Sofa.Gui.GUIManager.SetDimension(1080, 1080) # Initialization of the scene will be done here Sofa.Gui.GUIManager.MainLoop(root) Sofa.Gui.GUIManager.closeGUI() print("GUI was closed") print("Simulation is done.") # Function used only if this script is called from a python environment if __name__ == '__main__': main()
When I used runSofa the animation works perfectly, however when I used python3 the rigid sphere passes through the liver and no interactions are shown. Additionally, in the terminal the following warning is displayed:
[WARNING] [IntersectorMap] Element Intersector SphereCollisionModel<StdRigidTypes<3u, double> >-TriangleCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > NOT FOUND within : OBBCollisionModel<StdRigidTypes<3u, double> >-OBBCollisionModel<StdRigidTypes<3u, double> > TOBB<StdRigidTypes<3u, double> >-TOBB<StdRigidTypes<3u, double> > CubeCollisionModel-CubeCollisionModel Cube-Cube SphereCollisionModel<StdRigidTypes<3u, double> >-OBBCollisionModel<StdRigidTypes<3u, double> > TSphere<StdRigidTypes<3u, double> >-TOBB<StdRigidTypes<3u, double> > SphereCollisionModel<StdRigidTypes<3u, double> >-SphereCollisionModel<StdRigidTypes<3u, double> > TSphere<StdRigidTypes<3u, double> >-TSphere<StdRigidTypes<3u, double> > SphereCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-OBBCollisionModel<StdRigidTypes<3u, double> > TSphere<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-TOBB<StdRigidTypes<3u, double> > SphereCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-SphereCollisionModel<StdRigidTypes<3u, double> > TSphere<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-TSphere<StdRigidTypes<3u, double> > SphereCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-SphereCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > TSphere<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-TSphere<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > CapsuleCollisionModel<StdRigidTypes<3u, double> >-OBBCollisionModel<StdRigidTypes<3u, double> > TCapsule<StdRigidTypes<3u, double> >-TOBB<StdRigidTypes<3u, double> > CapsuleCollisionModel<StdRigidTypes<3u, double> >-SphereCollisionModel<StdRigidTypes<3u, double> > TCapsule<StdRigidTypes<3u, double> >-TSphere<StdRigidTypes<3u, double> > CapsuleCollisionModel<StdRigidTypes<3u, double> >-SphereCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > TCapsule<StdRigidTypes<3u, double> >-TSphere<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > CapsuleCollisionModel<StdRigidTypes<3u, double> >-CapsuleCollisionModel<StdRigidTypes<3u, double> > TCapsule<StdRigidTypes<3u, double> >-TCapsule<StdRigidTypes<3u, double> > CapsuleCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-OBBCollisionModel<StdRigidTypes<3u, double> > TCapsule<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-TOBB<StdRigidTypes<3u, double> > CapsuleCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-SphereCollisionModel<StdRigidTypes<3u, double> > TCapsule<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-TSphere<StdRigidTypes<3u, double> > CapsuleCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-SphereCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > TCapsule<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-TSphere<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > CapsuleCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-CapsuleCollisionModel<StdRigidTypes<3u, double> > TCapsule<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-TCapsule<StdRigidTypes<3u, double> > CapsuleCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-CapsuleCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > TCapsule<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-TCapsule<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >
I probably won’t need this, but I would appreciate insight into the problem and its cause to help my understanding and ability to figure it out in the future.
Thanks,
Michael Pienaar25 February 2021 at 23:08 #18748HugoKeymasterHey @quantanovo
Thank you very much for your interest in SOFA, for your feedback regarding the YouTube tutorial videos and SofaPython3.
The problem you point out is strange indeed. @jnbrunet could this be due to a missing binding for OBBs?
In the meantime @quantanovo could you try replacing theNewProximityIntersection
byLocalMinDistance
instead? Let us know if it helps.Best wishes,
Hugo
26 February 2021 at 10:45 #18757MikePBlockedHi @Hugo
Thank you so much for the response as well as the providing the training session as it has been extremely helpful!
Unfortunately,LocalMinDistance
does not work either and provides a similar warning:[WARNING] [IntersectorMap] Element Intersector SphereCollisionModel<StdRigidTypes<3u, double> >-TriangleCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > NOT FOUND within : OBBCollisionModel<StdRigidTypes<3u, double> >-OBBCollisionModel<StdRigidTypes<3u, double> > TOBB<StdRigidTypes<3u, double> >-TOBB<StdRigidTypes<3u, double> > RayCollisionModel-LineCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > nullptr RayCollisionModel-PointCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > nullptr RayCollisionModel-SphereCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > Ray-TSphere<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > RayCollisionModel-TriangleCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > Ray-TTriangle<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > CubeCollisionModel-CubeCollisionModel Cube-Cube LineCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-LineCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > TLine<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-TLine<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > LineCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-PointCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > TLine<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-TPoint<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > LineCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-SphereCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > TLine<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-TSphere<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > PointCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-PointCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > TPoint<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-TPoint<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > SphereCollisionModel<StdRigidTypes<3u, double> >-OBBCollisionModel<StdRigidTypes<3u, double> > TSphere<StdRigidTypes<3u, double> >-TOBB<StdRigidTypes<3u, double> > SphereCollisionModel<StdRigidTypes<3u, double> >-SphereCollisionModel<StdRigidTypes<3u, double> > TSphere<StdRigidTypes<3u, double> >-TSphere<StdRigidTypes<3u, double> > SphereCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-OBBCollisionModel<StdRigidTypes<3u, double> > TSphere<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-TOBB<StdRigidTypes<3u, double> > SphereCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-PointCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > TSphere<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-TPoint<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > SphereCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-SphereCollisionModel<StdRigidTypes<3u, double> > TSphere<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-TSphere<StdRigidTypes<3u, double> > SphereCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-SphereCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > TSphere<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-TSphere<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > CapsuleCollisionModel<StdRigidTypes<3u, double> >-OBBCollisionModel<StdRigidTypes<3u, double> > TCapsule<StdRigidTypes<3u, double> >-TOBB<StdRigidTypes<3u, double> > CapsuleCollisionModel<StdRigidTypes<3u, double> >-SphereCollisionModel<StdRigidTypes<3u, double> > TCapsule<StdRigidTypes<3u, double> >-TSphere<StdRigidTypes<3u, double> > CapsuleCollisionModel<StdRigidTypes<3u, double> >-SphereCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > TCapsule<StdRigidTypes<3u, double> >-TSphere<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > CapsuleCollisionModel<StdRigidTypes<3u, double> >-CapsuleCollisionModel<StdRigidTypes<3u, double> > TCapsule<StdRigidTypes<3u, double> >-TCapsule<StdRigidTypes<3u, double> > CapsuleCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-OBBCollisionModel<StdRigidTypes<3u, double> > TCapsule<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-TOBB<StdRigidTypes<3u, double> > CapsuleCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-SphereCollisionModel<StdRigidTypes<3u, double> > TCapsule<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-TSphere<StdRigidTypes<3u, double> > CapsuleCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-SphereCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > TCapsule<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-TSphere<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > CapsuleCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-CapsuleCollisionModel<StdRigidTypes<3u, double> > TCapsule<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-TCapsule<StdRigidTypes<3u, double> > CapsuleCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-CapsuleCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > TCapsule<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-TCapsule<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > TriangleCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-LineCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > nullptr TriangleCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-PointCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > TTriangle<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-TPoint<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > TriangleCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-SphereCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > TTriangle<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-TSphere<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > TriangleCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> >-TriangleCollisionModel<StdVectorTypes<Vec<3u, double>, Vec<3u, double>, double> > nullptr
Kind regards,
Mike2 March 2021 at 21:53 #18796HugoKeymasterHey @quantanovo
I tested it with the recent v20.12.01 release of SOFA it seems to work well.
Could you try it as well?Only a set of RequiredPlugin was missing:
root.addObject('RequiredPlugin', pluginName="SofaGeneralLoader") root.addObject('RequiredPlugin', pluginName="SofaLoader") root.addObject('RequiredPlugin', pluginName="SofaImplicitOdeSolver") root.addObject('RequiredPlugin', pluginName="SofaSimpleFem") root.addObject('RequiredPlugin', pluginName="SofaOpenglVisual")
Hope this helps.
BestHugo
16 March 2021 at 11:20 #18861MikePBlockedHi @Hugo
Apologies for the late reply.
I have rebuilt SOFA with the latest release and unfortunately it still does not work. I have converted a few collision examples into python scripts such as SphereModel.scn and TriangleModel.scn and they both give a similar warning as above. That being said, the SphereModel example still works, but the TriangleModel example does not.
Considering, that you have tested it on your side and it works, then it must be something wrong on my side. I’m clueless what it could be especially since I did rebuild it from sources again.
Regards,
Mike17 March 2021 at 22:43 #18876HugoKeymasterHi @quantanovo
I understand that you have updated your SOFA (and SofaPython3) sources and compiled again. Despite this it does not work properly. Is this correct?
Could you tell me what a “git log” command gives you from the SOFA sources?
Are you fetching SofaPython3 when configuring the project in the CMake phase ?Best,
Hugo
20 April 2021 at 10:42 #19220MikePBlockedHi @Hugo
I apologize for the late reply. I decided to reinstall sofa v20.12.01 from the binaries. And this solved my issue.
Kind regards,
Michael20 April 2021 at 10:44 #19221HugoKeymasterGreat to hear, thanks @quantanovo for letting us know and closing the topic!
Looking forward to seeing your simulation achievements!Hugo
3 May 2021 at 10:59 #19352chiarasapoBlockedI have the exact same problem, should I go back to the previous version too? Or do you think that there is another solution? Thanks in advance!
-
AuthorPosts
- You must be logged in to reply to this topic.