29 September 2015 at 8 h 59 min #3689
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.
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)
Weng Bin29 September 2015 at 9 h 49 min #3696RomainParticipant
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 7 h 29 min #3707
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
[WARNING] [DefaultContactManager “response”] FrictionContact<TPointModel<StdV
My collision model seems not supported by the contact FrictionContact. How to make it supported?
Weng Bin30 September 2015 at 8 h 43 min #3708RomainParticipant
You 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);
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 2 h 00 min #3724
Thank you, Romain.
Finally, I add my collision model successfully, although I have not implemented the different proximity yet.
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:
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.
Weng Bin21 October 2015 at 8 h 18 min #3782HugoKeymaster
- SOFA Consortium
Thank you for your summary.
Enjoy SOFA and do not hesitate to ask any other question.
- You must be logged in to reply to this topic.