Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can i calculate all the contact triangles pairs in hpp::fcl::BVHModel<hpp::fcl::OBBRSS>? #615

Open
damengziuu opened this issue Aug 8, 2024 · 10 comments

Comments

@damengziuu
Copy link

damengziuu commented Aug 8, 2024

I want to use this library to calculate all the triangle pairs that come into contact when two convex bodies come into contact. But now I can only get the boundary of the intersecting convex bodies.
How should I solve this problem? I'll make sure I set more pieces to detect than triangles

Here is my code:
// Initial position
Transform3f tf1; // identity
Transform3f tf2; // identity
Eigen::MatrixXd tR1(3, 3),tR2(3, 3);
Eigen::MatrixXd tT1(3, 1),tT2(3, 1);
tR1 << 1.0000000000000000, 0, 0,
0, 1, 0,
0, 0, 1;
tT1 << 0.25900000099999998,
0.091704199000000000,
0.14302674900000001;
tf1.setRotation(tR1);
tf1.setTranslation(tT1);

tR2 << 1.0000000000000000, 0, 0,
	0, 1, 0,
	0, 0, 1;
tT2 << 0.26099999699999998,
	0.16467816463778484,
	0.18763962100000001;
tf2.setRotation(tR2);
tf2.setTranslation(tT2);

//  Read file : Isurf-ID and Jsurf-ID 
std::shared_ptr<std::vector<Triangle>> IsurfTri(new std::vector<Triangle>);
std::shared_ptr<std::vector<Triangle>> JsurfTri(new std::vector<Triangle>);
parseTriIdFile("IsurfTriID.txt",
	IsurfTri);

parseTriIdFile("JsurfTriID.txt",
	JsurfTri);

// read file points position 
std::shared_ptr < std::vector<Vec3f>> Ipos(new std::vector<Vec3f>);
std::shared_ptr < std::vector<Vec3f>> Jpos(new std::vector<Vec3f>);
parseTriPosFile("IsurfTriPointRapid.txt",
	Ipos);
parseTriPosFile("JsurfTriPointRapid.txt",
	Jpos);


CollisionResult col_res;
const ContactPatchRequest patch_req;
ContactPatchResult patch_res(patch_req);
CollisionRequest col_req(CollisionRequestFlag::DISTANCE_LOWER_BOUND, (*Jpos).size());
col_req.distance_upper_bound = 0.1;


hpp::fcl::BVHModel<hpp::fcl::OBBRSS> iSurfMesh;
iSurfMesh.beginModel();
iSurfMesh.addSubModel(*Ipos, *IsurfTri);
iSurfMesh.endModel();

hpp::fcl::BVHModel<hpp::fcl::OBBRSS> jSurfMesh;
jSurfMesh.beginModel();
jSurfMesh.addSubModel(*Jpos, *JsurfTri);
jSurfMesh.endModel();

col_res.clear(); 
patch_res.clear();
hpp::fcl::collide(&iSurfMesh, tf1, &jSurfMesh, tf2, col_req, col_res); 
std::cout << col_res.isCollision() << "\n";
std::cout << col_res.numContacts() << "\n";

// Take surf id
std::vector<int> salveContactId;
std::vector<int> masterContactId;
std::vector<std::pair<size_t, size_t>> contactPairs;
// show the penetration_depth
for (auto singelCol:col_res.getContacts())
{
	salveContactId.emplace_back(singelCol.b2);
	masterContactId.emplace_back(singelCol.b1);
	contactPairs.emplace_back(std::make_pair(singelCol.b1, singelCol.b2));
}

my result:
B~C2J@R0R}U (40PPYFI_`N

@damengziuu damengziuu changed the title How can i calculate all the contact triangles in hpp::fcl::BVHModel<hpp::fcl::OBBRSS>? How can i calculate all the contact triangles pairs in hpp::fcl::BVHModel<hpp::fcl::OBBRSS>? Aug 10, 2024
@damengziuu
Copy link
Author

Who can help me, and who can suggest some pentration depth calculate method?

@florent-lamiraux
Copy link
Contributor

Hello @damengziuu

In this constructor,

CollisionRequest col_req(CollisionRequestFlag::DISTANCE_LOWER_BOUND, (*Jpos).size());

the second argument is the maximal number of contacts (pairs of triangles in collision in your case). I do not know what the value you pass is, but if you pass std::numeric_limits<size_t>::infinity(), it should compute all pairs.

@damengziuu
Copy link
Author

Hello @damengziuu

In this constructor,

CollisionRequest col_req(CollisionRequestFlag::DISTANCE_LOWER_BOUND, (*Jpos).size());

the second argument is the maximal number of contacts (pairs of triangles in collision in your case). I do not know what the value you pass is, but if you pass std::numeric_limits<size_t>::infinity(), it should compute all pairs.

Yes, but the contact pairs are all intersecting triangles. If a contact triangle is in another Geom, it will not form a contact pair.

@jmirabel
Copy link
Contributor

On your plot, are the missing face colliding or are they strictly in the interior of the other geometry ?

@damengziuu
Copy link
Author

On your plot, are the missing face colliding or are they strictly in the interior of the other geometry ?

they strictly in the interior of the other geometry.

@jmirabel
Copy link
Contributor

Then you have to do the work on your own. If you know the meshes are convex, then it isn't hard. The contact triangles form a border and you must find the triangles which are at the interior.

  1. Build a list of neighbors (you can look at how class Convex does it).
  2. Put all the contact triangles in a queue
  3. For each triangle T in the queue,
  4. For each neighbor N of T
    5. Determine if T is in the interior, if yes, then add it to the queue.

A simple geometric analysis to determine if a triangle is in the interior should be sufficient.

@damengziuu
Copy link
Author

Then you have to do the work on your own. If you know the meshes are convex, then it isn't hard. The contact triangles form a border and you must find the triangles which are at the interior.

  1. Build a list of neighbors (you can look at how class Convex does it).
  2. Put all the contact triangles in a queue
  3. For each triangle T in the queue,
  4. For each neighbor N of T
    5. Determine if T is in the interior, if yes, then add it to the queue.

A simple geometric analysis to determine if a triangle is in the interior should be sufficient.

Thank you for your reply.

  1. First I need to establish new topological relationships between triangles
  2. After I obtain the intersecting triangles, I obtain the adjacent triangles, and obtain the inner triangles by projection or halfedge datastruct.
    Do you think that's okay?

@jmirabel
Copy link
Contributor

Yes, it looks like this.

You have to find one triangle in the interior. Then, you can bootstrap the traversal of neighbors for this one then. The only tricky point is to get one triangle in the interior.

@damengziuu
Copy link
Author

Yes, it looks like this.

You have to find one triangle in the interior. Then, you can bootstrap the traversal of neighbors for this one then. The only tricky point is to get one triangle in the interior.

Now I am going to try this method. But I think of a new case, if the geometry is non-convex or if there is an open ring at the intersection, is there a error issue with the internal neighborhood search method?

@jmirabel
Copy link
Contributor

There is no guarantee that this will work for non convex meshes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants