Home › Forum › SOFA › Programming with SOFA › Creating custom CollisionModel components
Tagged: 64_bits, Linux_mint, SOFA_1906
- This topic has 6 replies, 4 voices, and was last updated 4 years, 8 months ago by Hugo.
-
AuthorPosts
-
23 January 2020 at 22:34 #15135FrancoisBlocked
Hi,
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 advance
7 February 2020 at 19:10 #15191HugoKeymasterHey @fleonard
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.Best
Hugo
10 February 2020 at 18:45 #15200FrancoisBlockedHi Hugo,
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.
Thanks,
François12 March 2020 at 10:51 #15389remibessardBlockedHi François,
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.
Cheers,
Remi.
12 March 2020 at 19:00 #15392VincentBlockedThanks Rémi!
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.
Cheers,
Vincent13 March 2020 at 09:29 #15400remibessardBlockedGlad to hear from you Vincent !
And happy to read it helped you a bit.Your developments sound interesting, good luck with it !
Cheers,
Rémi17 March 2020 at 18:08 #15425HugoKeymasterGreat thanks @remibessard!
Yes, please @vincent keep us posted! I am eager to see some of your oversea-results!Cheers,
Hugo
-
AuthorPosts
- You must be logged in to reply to this topic.