Home › Forum › SOFA › Programming with SOFA › Question about CollisionElementIterator
Tagged: Linux_ubuntu, SOFA_2106
- This topic has 2 replies, 2 voices, and was last updated 3 years, 3 months ago by Benjamin.
-
AuthorPosts
-
14 September 2021 at 20:25 #20354BenjaminBlocked
Hi everyone,
I am trying to iterate the collision elements in the finalCollisionPairs in BVHNarrowPhase. The original code for iteration is:
for (auto it1 = begin1; it1 != end1; ++it1) { for (auto it2 = begin2; it2 != end2; ++it2) { // Final collision pair if (!selfCollision || it1.canCollideWith(it2)) intersector->intersect(it1, it2, outputs); } }
When I was running the example Caduceus.scn in demo, only loop once in both inner and outer loop. However, in either it1 or begin1 it shows that the size are 30. In my understanding and according to the comment of ‘size’ in CollisionModel.h, the size means the number of elements.
Can I ask if anyone can help that whether this element means the collision element and why it only loop once in both inner and outer loop? What is the way to iterate the collision element in the finest CollisionModel? Thank you so much.
Regards,
Ben15 September 2021 at 09:47 #20355Alex BilgerBlockedHi Ben,
It is obviously confusing. The names are probably not the best ones…
The Bounding Volume Hierarchy algorithm works with a tree of collision models. In SOFA, we use a tree of bounding boxes. Each bounding box has children bounding boxes until the bounding boxes at the deepest level of the tree contain the true collision elements (probably the triangles of your surface mesh). Depending on the depth of the tree, there are not many triangles in a bounding box. Probably only one in your case. So it makes sense that you iterate over only one element in your deepest collision models (the bounding boxes).
However, I don’t understand where the 30 you mentioned comes from. What data are you referring to?
15 September 2021 at 12:28 #20356BenjaminBlockedHi Alex,
Thanks a lot for your explanation. It is a bit confusing about the code. I was looking for the part that iterates the element inside the final bounding box. This is what I found. I actually tried to stop at this statement in the debug mode.
intersector->intersect(it1, it2, outputs);
Then it will go to this statement
return impl->computeIntersection(e1, e2, impl->getOutputVector(e1.getCollisionModel(), e2.getCollisionModel(), contacts));
and finally reach to this function in MeshMinProximityIntersection.cpp
int MeshMinProximityIntersection::computeIntersection(Triangle& e2, Point& e1, OutputVector* contacts);
It seems the loop in the first post is the only iteration I found related to collision elements. But it turns out it is for the bounding box.For the size 30, I found in the most right column of the Qt Creator.
pasteboard.co/MHXMAuh3Znho.pngCan I ask if you can help me how to iterate triangular collision elements in a bounding box?
Regards,
Ben -
AuthorPosts
- You must be logged in to reply to this topic.