23 #include <LinearMath/btConvexHullComputer.h>
25 #include <Eigen/Geometry>
40 inline std::pair<std::string, std::string>
getObjectPairKey(
const std::string& obj1,
const std::string& obj2)
50 inline bool isLinkActive(
const std::vector<std::string>& active,
const std::string& name)
52 return active.empty() || (std::find(active.begin(), active.end(), name) != active.end());
59 const std::pair<std::string, std::string>& key,
bool found)
62 if (cdata.req.distance)
64 if (contact.
depth < cdata.res.distance)
66 cdata.res.distance = contact.
depth;
71 "Contact btw " << key.first <<
" and " << key.second <<
" dist: " << contact.
depth);
75 if (contact.
depth <= 0)
77 cdata.res.collision =
true;
80 std::vector<collision_detection::Contact> data;
83 if (!cdata.req.contacts)
85 if (!cdata.req.distance)
93 data.reserve(cdata.req.max_contacts_per_pair);
94 data.emplace_back(contact);
95 cdata.res.contact_count++;
98 if (cdata.res.contact_count >= cdata.req.max_contacts)
100 if (!cdata.req.distance)
106 if (cdata.req.max_contacts_per_pair == 1u)
108 cdata.pair_done =
true;
111 return &(cdata.res.contacts.insert(std::make_pair(key, data)).first->second.back());
115 std::vector<collision_detection::Contact>& dr = cdata.res.contacts[key];
116 dr.emplace_back(contact);
117 cdata.res.contact_count++;
119 if (dr.size() >= cdata.req.max_contacts_per_pair)
121 cdata.pair_done =
true;
124 if (cdata.res.contact_count >= cdata.req.max_contacts)
126 if (!cdata.req.distance)
150 inline int createConvexHull(AlignedVector<Eigen::Vector3d>& vertices, std::vector<int>& faces,
151 const AlignedVector<Eigen::Vector3d>& input,
double shrink = -1,
double shrinkClamp = -1)
156 btConvexHullComputer conv;
157 btAlignedObjectArray<btVector3> points;
158 points.reserve(
static_cast<int>(input.size()));
161 points.push_back(btVector3(
static_cast<btScalar
>(v[0]),
static_cast<btScalar
>(v[1]),
static_cast<btScalar
>(v[2])));
164 btScalar val = conv.compute(&points[0].getX(),
sizeof(btVector3), points.size(),
static_cast<btScalar
>(shrink),
165 static_cast<btScalar
>(shrinkClamp));
168 ROS_ERROR(
"Failed to create convex hull");
172 int num_verts = conv.vertices.size();
173 vertices.reserve(
static_cast<size_t>(num_verts));
174 for (
int i = 0; i < num_verts; i++)
176 btVector3& v = conv.vertices[i];
180 int num_faces = conv.faces.size();
181 faces.reserve(
static_cast<size_t>(3 * num_faces));
182 for (
int i = 0; i < num_faces; i++)
184 std::vector<int> face;
187 const btConvexHullComputer::Edge* source_edge = &(conv.edges[conv.faces[i]]);
188 int a = source_edge->getSourceVertex();
191 int b = source_edge->getTargetVertex();
194 const btConvexHullComputer::Edge* edge = source_edge->getNextEdgeOfFace();
195 int c = edge->getTargetVertex();
198 edge = edge->getNextEdgeOfFace();
199 c = edge->getTargetVertex();
204 edge = edge->getNextEdgeOfFace();
205 c = edge->getTargetVertex();
207 faces.push_back(
static_cast<int>(face.size()));
208 faces.insert(faces.end(), face.begin(), face.end());