Home › Forum › SOFA › Programming with SOFA › [SOLVED] How to develop collision model that support different proximity?
Tagged: CollisionModel
- This topic has 5 replies, 3 voices, and was last updated 9 years, 1 month ago by Hugo.
-
AuthorPosts
-
29 September 2015 at 08:59 #3689WengBlocked
Dear all,
I want to develop a new triangle mesh collision model that each triangle has its own proximity value. I notice that the all the CollisionModel in SOFA have only one proximity value.
questions:
1) How to develop our own collision model? I tried to define new class that derives from CollisionModel by simply copy and rename the existing TriangleModel (TriangleModel change to MyTriangleModel). But there are many errors when I run the new MyTriangleModel. Which part of SOFA do I also need to modify?
2) Any idea of making the collision model support different proximity values? (e.g. each point has its own proximity value in the TPoint model)Thanks!
Best regards,
Weng Bin29 September 2015 at 09:49 #3696RomainBlockedHello Weng,
1) your approach is good, be sure to also create a new class that derives of core::TCollisionElementIterator<MyTriangleModel>, It’s this one which must be added to the scene. You can add a vector to the derived class of collision model to store custom proximities for each triangle.
2) You need to modify/create an intersection method to take into account these new models. I advise you to take a look to the NewProximityIntersection component which only requires Triangle models for mesh intersection (no need of point or line models), the code which handles the mesh collision is in MeshNewProximityIntersection. You will need to write the following function:
int computeIntersection(MyTriangle&, MyTriangle&, OutputVector*)
(that should be very similar to the one with Triangles but it will use the custom proximity).
Don’t forget to register this new intersection method (check the .cpp).Hope that can help,
Romain30 September 2015 at 07:29 #3707WengBlockedHello Romain,
Thank you for answering my question so quickly!
I tried your advice.
But there are still some errors:[WARNING] [DefaultContactManager “response”] Contact FrictionContact between Wen
gTTriangleModel and TPointModel creation failed
[WARNING] [DefaultContactManager “response”] Supported models for contact Fricti
onContact:
[WARNING] [DefaultContactManager “response”] FrictionContact<TPointModel<StdV
ectorTypes<Vec<3,double>,Vec<3,double>,double> >,TPointModel<StdVectorTypes<Vec<
3,double>,Vec<3,double>,double> >,StdVectorTypes<Vec<3,double>,Vec<3,double>,dou
ble> >My collision model seems not supported by the contact FrictionContact. How to make it supported?
Best regards,
Weng Bin30 September 2015 at 08:43 #3708RomainBlockedYou need to add manually the pairs of collision models that involve your new models in the intersector map. Take a look to the constructor in MeshNewProximityIntersection.cpp
you will need to add lines in the follosing form
intersection->intersectors.add<YourTriangleModel, AnotherModel, YourProximityIntersection>(this);by example
intersection->intersectors.add<WengTriangleModel, PointModel, MeshNewProximityIntersection>(this);
to enable collision between Point and your new triangle model, in the case where you add directly the function int computeIntersection(WengTriangleModel&, PointModel&, OutputVector*) directly in the class MeshNewProximityIntersection.For each pair of collision models that involve your new models you will need to write a computeIntersection function and add this new pair in the intersector map.
2 October 2015 at 02:00 #3724WengBlockedThank you, Romain.
Finally, I add my collision model successfully, although I have not implemented the different proximity yet.To summarize,
For the collision detection:
(1) Define MyTriangleModel derived from CollisionModel
(2) Add intersection method for MyTriangleModel to intersection class to allow it to intersect with the other collision models. For example, I add into LocalMinDistance with the following:
int computeIntersection(MyTriangle&, Point&, OutputVector*);
int computeIntersection(MyTriangle&, Sphere&, OutputVector*);
int computeIntersection(Ray&, MyTriangle&, OutputVector*);For the collision response:
(1) Add ContactMapper for MyTriangleModel. What I did is to add to BarycentricContactMapper with the following:template<class DataTypes>
class ContactMapper<MyTriangleModel, DataTypes> : public BarycentricContactMapper<MyTriangleModel, DataTypes>Since, in my scene I use BarycentricMapping. I think if other mapping was used, ContactMapper should be added respectively. The ContactMapper will be used in FrictionContact.
(2) Add Contact for MyTriangleModel. What I did is to add to FrictionContact.cpp with the following:
Creator<sofa::core::collision::Contact::Factory, FrictionContact<MyTriangleModel, PointModel> > MyTrianglePointFrictionContactClass(“FrictionContact”,true);
this should register the new type FrictionContact in the Contact::Factory
For different collision models and different ContactMapper and Contact, I think the steps should be similar.
regards,
Weng Bin21 October 2015 at 08:18 #3782HugoKeymasterThank you for your summary.
Enjoy SOFA and do not hesitate to ask any other question.Best,
Hugo
-
AuthorPosts
- You must be logged in to reply to this topic.