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.
François12 March 2020 at 10 h 51 min #15389remibessardParticipant
I would like to suggest you to check the pull request I just did in your github repository.
I was able to compile your code (by adding some lines, eg. some ContactMapper) and pushed a version in which I was able to run your scene and see the 2 cubes interacting one another.
I hope you will be able to compile this update on your side (I changed a bit the architecture in a way it is a Sofa plugin you can add in your SOFA_EXTERNAL_DIRECTORIES CMakeLists.
Let me know if something gets wrong.
Remi.12 March 2020 at 19 h 00 min #15392VincentParticipant
- Polytechnique Montréal
We just figured yesterday that the ContactMapper was the missing element. Thanks for the code, it also works on our side. In combination with using a custom MeshTopology component, this actually results in very little code for the collision components.
Thanks also for the new plugin structure, I was not aware we could do that.
Vincent13 March 2020 at 9 h 29 min #15400remibessardParticipant
Glad to hear from you Vincent !
And happy to read it helped you a bit.
Your developments sound interesting, good luck with it !
Rémi17 March 2020 at 18 h 08 min #15425
- You must be logged in to reply to this topic.