Home › Forum › SOFA › Programming with SOFA › How can I use Tet mesh as collision model?
Tagged: 64_bits, Plugin_Geomagic, SOFA_1912, Windows_10
- This topic has 15 replies, 4 voices, and was last updated 3 years, 6 months ago by Hugo.
-
AuthorPosts
-
16 August 2020 at 07:41 #17032yupengBlocked
Hey, guys.
I’m trying to use plugin SofaMiscCollision when handling the collision between a point model and tetrahedron mesh.
The scene file is as here:
With TetrahedronDiscreteIntersection as my intersection method, I got this message:
[ERROR] [InfoComponent(Not created (TetrahedronDiscreteIntersection))] Object type TetrahedronDiscreteIntersection<> was not created The object is not in the factory. [WARNING] [TetrahedronSetGeometryAlgorithms(GeomAlgo)] Unused Attribute: "d_drawTetrahedra" with value: "true" [WARNING] [Monitor(haptic force)] Unused Attribute: "ForceColor" with value: "0 0 1 0" [ERROR] [SceneLoaderXML] Node initialization failed.
So, I tried to register the TetrahedronDiscreteIntersection in src\applications\plugins\SofaMiscCollision\TetrahedronDiscreteIntersection.cpp
int TetrahedronDiscreteIntersectionClass = core::RegisterObject("Tetrahedron Discrete intersection.") .add< TetrahedronDiscreteIntersection >();
And then I add the following line in src\applications\plugins\SofaMiscCollision\TetrahedronDiscreteIntersection.h
SOFA_CLASS(TetrahedronDiscreteIntersection, BaseIntersector);
It still not works.
Severity Code Description Project File Line Suppression State Error C2039 'sendl': is not a member of 'sofa::core::collision::BaseIntersector' SofaMiscCollision D:\sofa\src\applications\plugins\SofaMiscCollision\TetrahedronDiscreteIntersection.h 46 Error C2873 'sout': symbol cannot be used in a using-declaration SofaMiscCollision D:\sofa\src\applications\plugins\SofaMiscCollision\TetrahedronDiscreteIntersection.h 46 Error C2039 'sout': is not a member of 'sofa::core::collision::BaseIntersector' SofaMiscCollision D:\sofa\src\applications\plugins\SofaMiscCollision\TetrahedronDiscreteIntersection.h 46 Error C3668 'sofa::component::collision::TetrahedronDiscreteIntersection::getClass': method with override specifier 'override' did not override any base class methods SofaMiscCollision D:\sofa\src\applications\plugins\SofaMiscCollision\TetrahedronDiscreteIntersection.h 46 Error C2873 'serr': symbol cannot be used in a using-declaration SofaMiscCollision D:\sofa\src\applications\plugins\SofaMiscCollision\TetrahedronDiscreteIntersection.h 46 Error C2039 'serr': is not a member of 'sofa::core::collision::BaseIntersector' SofaMiscCollision D:\sofa\src\applications\plugins\SofaMiscCollision\TetrahedronDiscreteIntersection.h 46 Error C2873 'sendl': symbol cannot be used in a using-declaration SofaMiscCollision D:\sofa\src\applications\plugins\SofaMiscCollision\TetrahedronDiscreteIntersection.h 46 Error (active) E1455 member function declared with 'override' does not override a base class member SofaMiscCollision D:\sofa\src\applications\plugins\SofaMiscCollision\TetrahedronDiscreteIntersection.h 46
How should I deal with this problem?
14 September 2020 at 23:26 #17141HugoKeymasterHi
The TetrahedronDiscreteIntersection is not actually used in SOFA (written back in 2011 and never actually used). Could you replace it by one of those given here, and let us know if it works.
I created an issue to remove it.
Best wishes,
Hugo
17 September 2020 at 09:13 #17164yupengBlockedHi @Hugo, thanks for your reply.
The function of TetrahedronDiscreteIntersection is just what I want to use.
When my needle inserts into the tet mesh, I have to determine which tetrahedron collides with the needle (represented as a point collision model currently).
However, there are no intersection methods that can handle this.5 October 2020 at 21:48 #17276HugoKeymasterHi @yupeng
Since your point is quite precise for collision detection I needed to get back to other devs for info.
A team that I know working on needle insertion developed some homemade code. But the principle should be close to what is in the open version of SOFA:
– they use a regular DiscreteIntersection
– they use TetrahedronCollisionModel to compute the collision points
– they recover the proximity pairs in the constraint pipeline (function processGeometricalData) to build the sliding constraintYou can also get additional info in the following paper (developers based their work on it): Interactive Simulation of Flexible Needle Insertions Based on Constraint Models
I hope this will help.
Best wishes,Hugo
17 October 2020 at 15:08 #17408yupengBlocked@Hugo, Thanks for your reply. It helps a lot.
I’ve read the paper you suggested. And I’m trying to implement the method in it.About the code, I wonder how can I register TetrahedronDiscreteIntersection into the factory. The error log is shown as the first post.
30 October 2020 at 14:24 #17488HugoKeymasterHi @yupeng
As I said earlier, setting a DiscreteIntersection in your scene will allow you to use collision on Tets. But you need to add in your collision node, a TetrahedronCollisionModel.
Example of a TetrahedronCollisionModel:
<?xml version="1.0" ?> <Node name="lroot" gravity="0 -9.81 0" dt="0.02"> <RequiredPlugin name="SofaOpenglVisual"/> <DefaultPipeline name="CollisionPipeline" verbose="0" /> <BruteForceDetection name="N2" /> <DefaultContactManager name="collision response" response="default" /> <DiscreteIntersection/> <MeshObjLoader name="LiverSurface" filename="mesh/liver-smooth.obj" /> <Node name="Liver" gravity="0 -9.81 0"> <EulerImplicitSolver name="cg_odesolver" rayleighStiffness="0.1" rayleighMass="0.1" /> <CGLinearSolver name="linear solver" iterations="25" tolerance="1e-09" threshold="1e-09" /> <MeshGmshLoader name="meshLoader" filename="mesh/liver.msh" /> <TetrahedronSetTopologyContainer name="topo" src="@meshLoader" /> <MechanicalObject name="dofs" src="@meshLoader" /> <TetrahedronSetGeometryAlgorithms template="Vec3d" name="GeomAlgo" /> <DiagonalMass name="computed using mass density" massDensity="1" /> <TetrahedralCorotationalFEMForceField template="Vec3d" name="FEM" method="large" poissonRatio="0.3" youngModulus="3000" computeGlobalMatrix="0" /> <FixedConstraint name="FixedConstraint" indices="3 39 64" /> <Node name="Visu" tags="Visual" gravity="0 -9.81 0"> <OglModel name="VisualModel" src="@../../LiverSurface" /> <BarycentricMapping name="visual mapping" input="@../dofs" output="@VisualModel" /> </Node> <Node name="Surf" gravity="0 -9.81 0"> <TetrahedronSetTopologyContainer name="topo" src="@../meshLoader" /> <MechanicalObject name="spheres" /> <TetrahedronCollisionModel name="CollisionModel" /> <IdentityMapping name="sphere mapping" input="@../dofs" output="@spheres" /> </Node> </Node> </Node>
I hope this helps.
Best wishes,Hugo
19 January 2021 at 15:11 #18245yupengBlockedHi @Hugo,
Using the scene file you proposed, I could use the
TetrahedronCollisionmodel
now. But, when the haptic device (PointCollisionModel
) contacts with liver, the program corrupt. I found it has a relation with the mapping method.When detecting a collision, the Mapper for
TetrahedronCollisionModel
(derived fromBarycentricContactMapper
) would create aBarycentricMapperMeshTopology
from TetrahedronCollisionModel’s topology which isnullptr
.// model->getCollisionTopology() is nullptr mapper = sofa::core::objectmodel::New<mapping::BarycentricMapperMeshTopology<InDataTypes, typename BarycentricContactMapper::DataTypes> >(model->getCollisionTopology(), (topology::PointSetTopologyContainer*)nullptr); //call stack is as bellow SofaMiscCollision.dll!sofa::component::collision::BarycentricContactMapper<sofa::component::collision::TetrahedronCollisionModel,sofa::defaulttype::StdVectorTypes<sofa::defaulttype::Vec<3,double>,sofa::defaulttype::Vec<3,double>,double>>::createMapping(const char * name) Line 74 C++
This topology would be used when function
apply()
called.
The debugging call stack is as follow:SofaCore.dll!sofa::core::topology::BaseMeshTopology::getLines() Line 237 C++ SofaBaseMechanics.dll!sofa::component::mapping::BarycentricMapperMeshTopology<sofa::defaulttype::StdVectorTypes<sofa::defaulttype::Vec<3,double>,sofa::defaulttype::Vec<3,double>,double>,sofa::defaulttype::StdVectorTypes<sofa::defaulttype::Vec<3,double>,sofa::defaulttype::Vec<3,double>,double>>::apply(sofa::helper::vector<sofa::defaulttype::Vec<3,double>,sofa::helper::CPUMemoryManager<sofa::defaulttype::Vec<3,double>>> & out, const sofa::helper::vector<sofa::defaulttype::Vec<3,double>,sofa::helper::CPUMemoryManager<sofa::defaulttype::Vec<3,double>>> & in) Line 1027 C++ SofaBaseMechanics.dll!sofa::component::mapping::BarycentricMapping<sofa::defaulttype::StdVectorTypes<sofa::defaulttype::Vec<3,double>,sofa::defaulttype::Vec<3,double>,double>,sofa::defaulttype::StdVectorTypes<sofa::defaulttype::Vec<3,double>,sofa::defaulttype::Vec<3,double>,double>>::apply(const sofa::core::MechanicalParams * mparams, sofa::core::objectmodel::Data<sofa::helper::vector<sofa::defaulttype::Vec<3,double>,sofa::helper::CPUMemoryManager<sofa::defaulttype::Vec<3,double>>>> & out, const sofa::core::objectmodel::Data<sofa::helper::vector<sofa::defaulttype::Vec<3,double>,sofa::helper::CPUMemoryManager<sofa::defaulttype::Vec<3,double>>>> & in) Line 308 C++ SofaCore.dll!sofa::core::Mapping<sofa::defaulttype::StdVectorTypes<sofa::defaulttype::Vec<3,double>,sofa::defaulttype::Vec<3,double>,double>,sofa::defaulttype::StdVectorTypes<sofa::defaulttype::Vec<3,double>,sofa::defaulttype::Vec<3,double>,double>>::apply(const sofa::core::MechanicalParams * mparams, sofa::core::TMultiVecId<1,1> outPos, sofa::core::TMultiVecId<1,0> inPos) Line 157 C++ SofaMiscCollision.dll!sofa::component::collision::BarycentricContactMapper<sofa::component::collision::TetrahedronCollisionModel,sofa::defaulttype::StdVectorTypes<sofa::defaulttype::Vec<3,double>,sofa::defaulttype::Vec<3,double>,double>>::update() Line 101 C++ SofaMiscCollision.dll!sofa::component::collision::FrictionContact<sofa::component::collision::TetrahedronCollisionModel,sofa::component::collision::PointCollisionModel<sofa::defaulttype::StdVectorTypes<sofa::defaulttype::Vec<3,double>,sofa::defaulttype::Vec<3,double>,double>>,sofa::defaulttype::StdVectorTypes<sofa::defaulttype::Vec<3,double>,sofa::defaulttype::Vec<3,double>,double>>::activateMappers() Line 205 C++ SofaMiscCollision.dll!sofa::component::collision::FrictionContact<sofa::component::collision::TetrahedronCollisionModel,sofa::component::collision::PointCollisionModel<sofa::defaulttype::StdVectorTypes<sofa::defaulttype::Vec<3,double>,sofa::defaulttype::Vec<3,double>,double>>,sofa::defaulttype::StdVectorTypes<sofa::defaulttype::Vec<3,double>,sofa::defaulttype::Vec<3,double>,double>>::createResponse(sofa::core::objectmodel::BaseContext * group) Line 215 C++ SofaBaseCollision.dll!sofa::component::collision::DefaultPipeline::doCollisionResponse() Line 260 C++ SofaSimulationCore.dll!sofa::simulation::PipelineImpl::computeCollisionResponse() Line 126 C++ [Inline Frame] SofaSimulationCore.dll!sofa::simulation::Visitor::for_each(sofa::simulation::CollisionVisitor *) Line 118 C++ SofaSimulationCore.dll!sofa::simulation::CollisionVisitor::processNodeTopDown(sofa::simulation::Node * node) Line 36 C++ SofaSimulationGraph.dll!sofa::simulation::graph::DAGNode::executeVisitorTopDown(sofa::simulation::Visitor * action, std::list<sofa::simulation::graph::DAGNode *,std::allocator<sofa::simulation::graph::DAGNode *>> & executedNodes, std::map<sofa::simulation::graph::DAGNode *,sofa::simulation::graph::DAGNode::StatusStruct,std::less<sofa::simulation::graph::DAGNode *>,std::allocator<std::pair<sofa::simulation::graph::DAGNode * const,sofa::simulation::graph::DAGNode::StatusStruct>>> & statusMap, sofa::simulation::graph::DAGNode * visitorRoot) Line 693 C++ SofaSimulationGraph.dll!sofa::simulation::graph::DAGNode::doExecuteVisitor(sofa::simulation::Visitor * action, bool precomputedOrder) Line 612 C++ SofaSimulationCore.dll!sofa::simulation::CollisionAnimationLoop::computeCollision(const sofa::core::ExecParams * params) Line 76 C++ SofaConstraint.dll!sofa::component::animationloop::FreeMotionAnimationLoop::step(const sofa::core::ExecParams * params, double dt) Line 234 C++ SofaSimulationCore.dll!sofa::simulation::Simulation::animate(sofa::simulation::Node * root, double dt) Line 245 C++ SofaGuiQt.dll!sofa::gui::qt::RealGUI::step() Line 2147 C++
The scene file is updated here
11 February 2021 at 17:42 #18574HugoKeymasterHi @yupeng
After investigation, my advice was wrong. In SOFA, only the TetrahedronDiscreteIntersection implements the discrete collision between a TetrahedonCollisionModel and any other model. I did not know this. Your there need to use TetrahedronDiscreteIntersection.
As you noticed, when using it in a scene, you receive:
[ERROR] [InfoComponent(Not created (TetrahedronDiscreteIntersection))] Object type TetrahedronDiscreteIntersection<> was not created The object is not in the factory.
I got it as well. This class is not a SOFA object, and it is not added to the Factory. It therefore can not be used in a scene. Moreover, it is only an Intersector: therefore it can not compute the whole discrete intersection. This seems to be an old class.
A solution could be to create in SofaMiscCollision (applications/plugins) a class inheriting from both DiscreteIntersection and TetrahedronDiscreteIntersection. By doing this, you would have the intersection method you want.
However, for needle insertion, people does not seem to use collision models based on Tetras.
Hugo
15 February 2021 at 11:33 #18672agnesenardiBlockedHi @hugo,
I’m new to Sofa and I’m simulating the insertion of a needle inside a brain (with a mesh made of tetras) and I’m wondering if you can share some examples of needle insertion, because I didn’t find anything in the forum.
Thank you a lot
Agnese26 February 2021 at 18:56 #18765HugoKeymasterHi @agnesenardi
I do not unfortunately have an example of needle insertion, working out of the box. I never implemented needle insertion myself.
Such codes are usually implemented by people in plugins. You could maybe collaborate with some research team or consulting company.Needle insertion is far from being trivial: not only collision must be detected, contact creates a Unilateral constraint, when the force applied exceed a threshold aa SlidingConstraint replaces the Unilateral to mimic penetration etc. A complicated pipeline.
Let me know the way you want to follow.
Best wishes,Hugo
11 March 2021 at 13:33 #18840yupengBlockedDear @Hugo,
Thanks for your kind advice.You said people didn’t use Tetra as a collision model, then how did they know which Tetra contains needle points? Is there a more convenient approach to do that?
@agnesenardi, I am also working on this simulation, maybe we could collaborate and see what we could do.31 March 2021 at 23:29 #19040HugoKeymasterHey @yupeng
After asking again to some researchers involved in needle insertion, they are indeed using a TetrahedronCollisionModel but they implemented their own collision detection and tetrahedron-based models. It is therefore not in SOFA.
But, at a glance, the principle is the following:
– on the first contact detected, you can set up a collision response which will determine when there is contact and when there is penetration. If penetration, a Perforation constraint must be implemented as a SlidingConstraint or similar
– then the needle goes through, and you need to compute a collision between your needle tip and the TetrahedronCollisionModel to eventually set new constraints along the needle pathIt is a short and rough explanation because I never implemented it myself but this is the idea. I hope this helps already a bit.
Best wishes,Hugo
20 April 2021 at 10:19 #19217TimesBlockedHey @yupeng,
Could I collaborate with you as well? It seems we more or less have the same goals.Thanks
23 April 2021 at 16:13 #19284HugoKeymasterHey @agnesenardi @yupeng @akthetimes
Yes definitely your topics seem really close!
If you are all interested, we could set up a meeting in the coming weeks to discuss this further.Anyway, the idea of the pipele is described above in my previous post.
Best wishes,
Hugo
24 April 2021 at 11:03 #19306TimesBlockedHey @Hugo,
Yes definitely! I am interested in setting up a meeting within the coming weeks with you, @yupeng and @agnesenardiBest wishes
31 May 2021 at 22:49 #19609HugoKeymasterDo not forget to keep us posted in this forum thread as well about your progresses!
Looking forward to hearing from you again.
Best,Hugo
-
AuthorPosts
- You must be logged in to reply to this topic.