23 January 2020 at 22 h 34 min #15135FrancoisParticipant
I’m trying to create a new collision detection method in a plugin. I want to create new CollisionModel components, but I can’t get them to work with the collision response in Sofa. Is it possible to create custom collisionModels? If it is, what do I need to do for Sofa to use them?
At the moment, they are almost exact copies of PointCollisionModel and TriangleCollisionModel. I also created a detection and an intersection components. In the intersection class, I’m adding the models in the init function (e.g.: intersectors.add<MyPointModel, MyPointModel, MyIntersection>(this);) and created the corresponding computeIntersection() and testIntersection() functions.
After getting a runtime error that mentioned the BarycentricPenalityContact class, I tried adding the following lines in one of my plugin’s .cpp file:
Creator<Contact::Factory, BarycentricPenalityContact<MyPointModel, MyPointModel>> MyPointMyPointPenalityContactClass("default", true); Creator<Contact::Factory, BarycentricPenalityContact<MyTriangleModel, MyPointModel>> MyTriangleMyPointPenalityContactClass("default", true); template class SOFA_MESH_COLLISION_API sofa::component::collision::BarycentricPenalityContact<MyPointModel, MyPointModel>; template class SOFA_MESH_COLLISION_API sofa::component::collision::BarycentricPenalityContact<MyTriangleModel, MyPointModel>;
and these lines to the .h file:
extern template class SOFA_MESH_COLLISION_API BarycentricPenalityContact<myPointModel, myPointModel>; extern template class SOFA_MESH_COLLISION_API BarycentricPenalityContact<myTriangleModel, myPointModel>;
Now, I’m getting this compilation error:
/home/franc/sofa/v19.06/build/install/include/SofaCommon/SofaMeshCollision/BarycentricPenalityContact.h:71:47: error: ‘sofa::component::collision::BarycentricPenalityContact<TCollisionModel1, TCollisionModel2, ResponseDataTypes>::mapper1’ has incomplete type ContactMapper<CollisionModel1,DataTypes1> mapper1; ^~~~~~~ ... /home/franc/sofa/v19.06/build/install/include/SofaCommon/SofaMeshCollision/BarycentricPenalityContact.h:72:47: error: ‘sofa::component::collision::BarycentricPenalityContact<TCollisionModel1, TCollisionModel2, ResponseDataTypes>::mapper2’ has incomplete type ContactMapper<CollisionModel2,DataTypes2> mapper2; ^~~~~~~
Am I missing or getting wrong any major thing? Do I need to declare anything else for Sofa to find my collision models? If it can help, I can put the relevant classes in on GitHub.
Thanks in advance7 February 2020 at 19 h 10 min #15191HugoKeymaster
- SOFA Consortium
I am sorry for this late reply.
That’s an interesting and challenging objective. I am no expert of the collision detection pipeline however.
Could you share your code on any GitHub repo ?
I will discuss with experts next week and get back to you.
Hugo10 February 2020 at 18 h 45 min #15200FrancoisParticipant
Thanks for the reply. I added the relevant classes in https://github.com/FrancoisLeonard/SOFA_Custom_CollisionModels. There’s also a scene and its output in output.txt.
I’m mostly interested in solving the error:
[ERROR] [DefaultContactManager(collision response)] Contact default between ScytherPointCollisionModel and ScytherPointCollisionModel creation failed
To add some context, my colleague is working on a cutting algorithm in a library and the plugin is essentially an interface with SOFA. I need to modify the collisionModel’s topology to adapt it to our own surface mesh after it gets cut. I would also like to modify the method that build the bounding volume tree. This is why I’m trying to create my own collision models.
After the initial post, I thought that another way might be to create classes that inherit from SOFA’s PointCollisionModel and TriangleCollisionModel, override the relevant methods, and send the parent classes to the contact manager so that it can recognize them. I didn’t test it yet.
Let me know what you think.
- You must be logged in to reply to this topic.