Home › Forum › SOFA › Using SOFA › [SOLVED] Attach points from objects with different DOFs
Tagged: SOFA_2012, Windows_10
- This topic has 3 replies, 2 voices, and was last updated 3 years, 4 months ago by SergioPM23.
-
AuthorPosts
-
26 June 2021 at 15:08 #19878SergioPM23Blocked
Hi everyone!
I am trying to attach some points from a deformable object (Vec3d template) to points from a rigid object (Rigid3d template). I have tried with various types of constraints, but it didn’t work due to the fact that the objects used different templates (DOFs). The groups of points I want to attach are selected with BoxROI in both objects.
How could I attach them? I have readen about additional subnodes, mappings, etc, but I don’t see how to proceed.
I would appreciate any help.Cheers,
Sergio.28 June 2021 at 10:49 #19879etagliabueBlockedHi @sergiopm23,
I would suggest implementing your rigid object in this way:
1) you create a node (let’s call it “RigidObj”), which contains a MechanicalObject with template Rigid3d. This MechanicalObject is composed of a single DOF, placed in correspondence of the barycenter of your object.
2) you create a child node of RigidObj (let’s call it “RigidObjVec”). Within this node, you define a new MechanicalObject which is templated with Vec3d and contains all the points of your object (loaded from a surface mesh for example), and you add a RigidMapping component. The RigidMapping allows you to make all the points in your RigidObjVec move following the barycenter.In this way, you can define the BoxROI within the RigidObjVec node, and you should have no more issues with the templates.
Hope it solves the problem!
Eleonora29 June 2021 at 23:09 #19901SergioPM23BlockedHi @etagliabue,
Thank you so much for your response.
I have tried to implement the rigid object just as you wrote and no errors appeared, but the attach constraint seems to be not working (the points from the different pairs do not move united between them). The code of the scene is the following one (note that the deformable object is the node called “Cube1” and the rigid object is the node called “RigidObj”. The mesh file is “cube.obj”, which is include in the mesh Sofa’s folder and it is used in both objects):import SofaRuntime SofaRuntime.importPlugin("SofaComponentAll") # to create elements like Node or objects import Sofa.Core def createScene(rootNode): rootNode.findData('dt').value = 0.01 rootNode.findData('gravity').value = [0., 0., 0.] rootNode.addObject('RequiredPlugin', name="SofaPython3") rootNode.addObject('RequiredPlugin', name="SofaBoundaryCondition") rootNode.addObject('RequiredPlugin', name="SofaImplicitOdeSolver") rootNode.addObject('RequiredPlugin', name="SofaMiscForceField") rootNode.addObject('RequiredPlugin', name="SofaOpenglVisual") rootNode.addObject('RequiredPlugin', name="SofaMeshCollision") rootNode.addObject('RequiredPlugin', name="SofaDeformable") rootNode.addObject('RequiredPlugin', name="SofaGeneralObjectInteraction") rootNode.addObject('RequiredPlugin', name="SofaSimpleFem") rootNode.addObject('RequiredPlugin', name="SofaBoundaryCondition") rootNode.addObject('RequiredPlugin', name="SofaGeneralLoader") rootNode.addObject('RequiredPlugin', name="SofaImplicitOdeSolver") rootNode.addObject('RequiredPlugin', name="SofaLoader") rootNode.addObject('RequiredPlugin', name="SofaSimpleFem") rootNode.addObject('CollisionPipeline', name="PipeLine", verbose=0, draw=0) rootNode.addObject('BruteForceDetection', name="N2") rootNode.addObject('NewProximityIntersection', name="Proximity", alarmDistance=0.5, contactDistance=0.25) rootNode.addObject('CollisionResponse', name="Response", response="default") rootNode.addObject('MeshObjLoader', name="meshLoadercube", filename="mesh/cube.obj") #CUBE1 Cube1 = rootNode.addChild("Cube1") Cube1.addObject('EulerImplicitSolver') Cube1.addObject('CGLinearSolver', iterations=200, tolerance="1e-09", threshold="1e-09") Cube1.addObject('PointSetTopologyContainer', name="topoCube1", src="@../meshLoadercube") Cube1.addObject('PointSetGeometryAlgorithms', template="Vec3d", name="GeomAlgo") Cube1.addObject('MechanicalObject', template="Vec3d", name="MechanicalModel", showObject=1, showObjectScale=3, src="@../meshLoadercube") #Cube1.addObject('MeshSpringForceField', name="Springs", stiffness=20000, damping=1) Cube1.addObject('UniformMass', totalMass=100) Cube1.addObject('ConstantForceField', totalForce=[0., 0., 2.]) Cube1.addObject('BoxROI', name="box_roi1", box=[-1.5, -1.5, 1, 1.5, 1.5, 1]) Cube1.addObject('PartialFixedConstraint', fixAll=True, fixedDirections=[1, 0, 0]) Cube1.addObject('PartialFixedConstraint', fixAll=True, fixedDirections=[0, 1, 0]) VisualCube1 = Cube1.addChild("VisualCube1") VisualCube1.addObject('OglModel', name="VisualModelCube1", src="@../../meshLoadercube", color=[0, 0, 1]) VisualCube1.addObject('IdentityMapping', name="MappingCube1", input="@../MechanicalModel", output="@VisualModelCube1") ColisionCube1 = Cube1.addChild("CollisionCube1") ColisionCube1.addObject('MeshTopology', src="@../../meshLoadercube") ColisionCube1.addObject('MechanicalObject', name="CollisionCube1MO", scale=1.0) ColisionCube1.addObject('PointCollisionModel', name="CollisionModelCube11", contactStiffness=10) ColisionCube1.addObject('LineCollisionModel', name="CollisionModelCube12", contactStiffness=10) ColisionCube1.addObject('CubeCollisionModel', name="CollisionModelCube13", contactStiffness=10) ColisionCube1.addObject('IdentityMapping', name="CollisionMappingCube1", input="@../MechanicalModel", output="@CollisionCube1MO") #RigidObj RigidObj = rootNode.addChild("RigidObj") RigidObj.addObject('EulerImplicitSolver') RigidObj.addObject('CGLinearSolver', iterations=200, tolerance="1e-09", threshold="1e-09") RigidObj.addObject('PointSetTopologyContainer', name="topoRigidObj", src="@../meshLoadercube") RigidObj.addObject('MechanicalObject', template="Rigid3d", name="MechanicalModel2", showObject=0, translation=[-1., 1., 3.], showObjectScale=3, src="@../meshLoadercube") RigidObj.addObject('UniformMass', totalMass=100) RigidObjVec = RigidObj.addChild("RigidObjVec") RigidObjVec.addObject('MechanicalObject', template="Vec3d", name="MechanicalModel3", showObject=1, showObjectScale=3, src="@../../meshLoadercube") RigidObjVec.addObject('RigidMapping', template="Rigid3d,Vec3d", input="@../MechanicalModel2", output="@MechanicalModel3") RigidObjVec.addObject('AttachConstraint', object1="@../../Cube1/MechanicalModel", object2="@MechanicalModel3", indices1="1 2 5 6", indices2="0 3 4 7", twoWay=True, constraintFactor="1 1 1 1") VisualRigidObj = RigidObj.addChild("VisualRigidObj") VisualRigidObj.addObject('OglModel', name="VisualModelRigidObj", src="@../../meshLoadercube", color=[1, 0, 0]) VisualRigidObj.addObject('RigidMapping', name="MappingRigidObj", input="@../MechanicalModel2", output="@VisualModelRigidObj") ColisionRigidObj = RigidObj.addChild("CollisionCube1") ColisionRigidObj.addObject('MeshTopology', src="@../../meshLoadercube") ColisionRigidObj.addObject('MechanicalObject', name="CollisionRigidObjMO", scale=1.0) ColisionRigidObj.addObject('PointCollisionModel', name="CollisionModelRigidObj1", contactStiffness=10) ColisionRigidObj.addObject('LineCollisionModel', name="CollisionModelRigidObj2", contactStiffness=10) ColisionRigidObj.addObject('CubeCollisionModel', name="CollisionModelRigidObj3", contactStiffness=10) ColisionRigidObj.addObject('RigidMapping', name="CollisionMappingRigidObj", input="@.../MechanicalModel2", output="@CollisionRigidObjMO")
I would like to know what should I change in order to make the scene work propperly. I would appreciate any help. Thanks in advance.
Cheers,
Sergio.29 June 2021 at 23:16 #19902SergioPM23BlockedHi @etagliabue,
Thank you so much for your response.
I have tried to implement the rigid object just as you wrote and no errors appeared, but the attach constraint seems to be not working (the points from the different pairs do not move united between them). The code of the scene is the following one (note that the deformable object is the node called “Cube1” and the rigid object is the node called “RigidObj”. The mesh file is “cube.obj”, which is include in the mesh Sofa’s folder and it is used in both objects):import SofaRuntime SofaRuntime.importPlugin("SofaComponentAll") # to create elements like Node or objects import Sofa.Core def createScene(rootNode): rootNode.findData('dt').value = 0.01 rootNode.findData('gravity').value = [0., 0., 0.] rootNode.addObject('RequiredPlugin', name="SofaPython3") rootNode.addObject('RequiredPlugin', name="SofaBoundaryCondition") rootNode.addObject('RequiredPlugin', name="SofaImplicitOdeSolver") rootNode.addObject('RequiredPlugin', name="SofaMiscForceField") rootNode.addObject('RequiredPlugin', name="SofaOpenglVisual") rootNode.addObject('RequiredPlugin', name="SofaMeshCollision") rootNode.addObject('RequiredPlugin', name="SofaDeformable") rootNode.addObject('RequiredPlugin', name="SofaGeneralObjectInteraction") rootNode.addObject('RequiredPlugin', name="SofaSimpleFem") rootNode.addObject('RequiredPlugin', name="SofaBoundaryCondition") rootNode.addObject('RequiredPlugin', name="SofaGeneralLoader") rootNode.addObject('RequiredPlugin', name="SofaImplicitOdeSolver") rootNode.addObject('RequiredPlugin', name="SofaLoader") rootNode.addObject('RequiredPlugin', name="SofaSimpleFem") rootNode.addObject('CollisionPipeline', name="PipeLine", verbose=0, draw=0) rootNode.addObject('BruteForceDetection', name="N2") rootNode.addObject('NewProximityIntersection', name="Proximity", alarmDistance=0.5, contactDistance=0.25) rootNode.addObject('CollisionResponse', name="Response", response="default") rootNode.addObject('MeshObjLoader', name="meshLoadercube", filename="mesh/cube.obj") #CUBE1 Cube1 = rootNode.addChild("Cube1") Cube1.addObject('EulerImplicitSolver') Cube1.addObject('CGLinearSolver', iterations=200, tolerance="1e-09", threshold="1e-09") Cube1.addObject('PointSetTopologyContainer', name="topoCube1", src="@../meshLoadercube") Cube1.addObject('PointSetGeometryAlgorithms', template="Vec3d", name="GeomAlgo") Cube1.addObject('MechanicalObject', template="Vec3d", name="MechanicalModel", showObject=1, showObjectScale=3, src="@../meshLoadercube") #Cube1.addObject('MeshSpringForceField', name="Springs", stiffness=20000, damping=1) Cube1.addObject('UniformMass', totalMass=100) Cube1.addObject('ConstantForceField', totalForce=[0., 0., 2.]) Cube1.addObject('BoxROI', name="box_roi1", box=[-1.5, -1.5, 1, 1.5, 1.5, 1]) Cube1.addObject('PartialFixedConstraint', fixAll=True, fixedDirections=[1, 0, 0]) Cube1.addObject('PartialFixedConstraint', fixAll=True, fixedDirections=[0, 1, 0]) VisualCube1 = Cube1.addChild("VisualCube1") VisualCube1.addObject('OglModel', name="VisualModelCube1", src="@../../meshLoadercube", color=[0, 0, 1]) VisualCube1.addObject('IdentityMapping', name="MappingCube1", input="@../MechanicalModel", output="@VisualModelCube1") ColisionCube1 = Cube1.addChild("CollisionCube1") ColisionCube1.addObject('MeshTopology', src="@../../meshLoadercube") ColisionCube1.addObject('MechanicalObject', name="CollisionCube1MO", scale=1.0) ColisionCube1.addObject('PointCollisionModel', name="CollisionModelCube11", contactStiffness=10) ColisionCube1.addObject('LineCollisionModel', name="CollisionModelCube12", contactStiffness=10) ColisionCube1.addObject('CubeCollisionModel', name="CollisionModelCube13", contactStiffness=10) ColisionCube1.addObject('IdentityMapping', name="CollisionMappingCube1", input="@../MechanicalModel", output="@CollisionCube1MO") #RigidObj RigidObj = rootNode.addChild("RigidObj") RigidObj.addObject('EulerImplicitSolver') RigidObj.addObject('CGLinearSolver', iterations=200, tolerance="1e-09", threshold="1e-09") RigidObj.addObject('PointSetTopologyContainer', name="topoRigidObj", src="@../meshLoadercube") RigidObj.addObject('MechanicalObject', template="Rigid3d", name="MechanicalModel2", showObject=0, translation=[-1., 1., 3.], showObjectScale=3, src="@../meshLoadercube") RigidObj.addObject('UniformMass', totalMass=100) RigidObjVec = RigidObj.addChild("RigidObjVec") RigidObjVec.addObject('MechanicalObject', template="Vec3d", name="MechanicalModel3", showObject=1, showObjectScale=3, src="@../../meshLoadercube") RigidObjVec.addObject('RigidMapping', template="Rigid3d,Vec3d", input="@../MechanicalModel2", output="@MechanicalModel3") RigidObjVec.addObject('AttachConstraint', object1="@../../Cube1/MechanicalModel", object2="@MechanicalModel3", indices1="1 2 5 6", indices2="0 3 4 7", twoWay=True, constraintFactor="1 1 1 1") VisualRigidObj = RigidObj.addChild("VisualRigidObj") VisualRigidObj.addObject('OglModel', name="VisualModelRigidObj", src="@../../meshLoadercube", color=[1, 0, 0]) VisualRigidObj.addObject('RigidMapping', name="MappingRigidObj", input="@../MechanicalModel2", output="@VisualModelRigidObj") ColisionRigidObj = RigidObj.addChild("CollisionCube1") ColisionRigidObj.addObject('MeshTopology', src="@../../meshLoadercube") ColisionRigidObj.addObject('MechanicalObject', name="CollisionRigidObjMO", scale=1.0) ColisionRigidObj.addObject('PointCollisionModel', name="CollisionModelRigidObj1", contactStiffness=10) ColisionRigidObj.addObject('LineCollisionModel', name="CollisionModelRigidObj2", contactStiffness=10) ColisionRigidObj.addObject('CubeCollisionModel', name="CollisionModelRigidObj3", contactStiffness=10) ColisionRigidObj.addObject('RigidMapping', name="CollisionMappingRigidObj", input="@../MechanicalModel2", output="@CollisionRigidObjMO")
I would like to know what should I change in order to make the scene work propperly. I would appreciate any help. Thanks in advance.
Cheers,
Sergio. -
AuthorPosts
- You must be logged in to reply to this topic.