33 #include <boost/algorithm/string.hpp>
34 #include <console_bridge/console.h>
44 std::vector<ObjectPairKey>
46 const std::vector<std::string>& static_links,
47 const std::shared_ptr<const tesseract_common::ContactAllowedValidator>& validator)
49 std::size_t num_pairs = active_links.size() * (active_links.size() - 1) / 2;
50 num_pairs += (active_links.size() * static_links.size());
52 std::vector<ObjectPairKey> clp;
53 clp.reserve(num_pairs);
56 for (std::size_t i = 0; i < active_links.size() - 1; ++i)
58 const std::string& l1 = active_links[i];
59 for (std::size_t j = i + 1; j < active_links.size(); ++j)
61 const std::string& l2 = active_links[j];
62 if (validator ==
nullptr || (validator !=
nullptr && !(*validator)(l1, l2)))
68 for (
const auto& l1 : active_links)
70 for (
const auto& l2 : static_links)
72 if (validator ==
nullptr || (validator !=
nullptr && !(*validator)(l1, l2)))
80 bool isLinkActive(
const std::vector<std::string>& active,
const std::string& name)
82 return active.empty() || (std::find(active.begin(), active.end(),
name) != active.end());
86 const std::string& name2,
87 const std::shared_ptr<const tesseract_common::ContactAllowedValidator>& validator,
94 if (validator !=
nullptr && (*validator)(name1, name2))
98 CONSOLE_BRIDGE_logError(
99 "Collision between '%s' and '%s' is allowed. No contacts are computed.", name1.c_str(), name2.c_str());
106 CONSOLE_BRIDGE_logError(
"Actually checking collisions between %s and %s", name1.c_str(), name2.c_str());
114 const std::pair<std::string, std::string>& key,
138 const auto& cv = cdata.
res->
at(key);
141 if (contact.
distance < cv.front().distance)
156 const Eigen::Vector3d& center,
157 const Eigen::Vector3d& scale)
159 for (
auto& v : vertices)
160 v = scale.cwiseProduct(v - center) + center;
165 Eigen::Vector3d center(0, 0, 0);
166 for (
const auto& v : vertices)
169 center = (1.0 /
static_cast<double>(vertices.size())) * center;
176 const std::vector<Eigen::Vector3i>& vectices_color,
177 const Eigen::VectorXi& faces,
208 std::ofstream myfile;
212 CONSOLE_BRIDGE_logError(
"Failed to open file: %s", path.c_str());
217 myfile <<
"format ascii 1.0\n";
218 myfile <<
"comment made by tesseract\n";
219 myfile <<
"element vertex " << vertices.size() <<
"\n";
220 myfile <<
"property float x\n";
221 myfile <<
"property float y\n";
222 myfile <<
"property float z\n";
223 if (!vectices_color.empty())
225 myfile <<
"property uchar red\n";
226 myfile <<
"property uchar green\n";
227 myfile <<
"property uchar blue\n";
229 myfile <<
"element face " << num_faces <<
"\n";
230 myfile <<
"property list uchar int vertex_indices\n";
231 myfile <<
"end_header\n";
234 if (vectices_color.empty())
236 for (
const auto& v : vertices)
238 myfile << std::fixed << std::setprecision(std::numeric_limits<float>::digits10 + 1) << v[0] <<
" " << v[1] <<
" "
242 else if (vectices_color.size() == 1)
244 const Eigen::Vector3i& default_color = vectices_color[0];
245 for (
const auto& v : vertices)
247 myfile << std::fixed << std::setprecision(std::numeric_limits<float>::digits10 + 1) << v[0] <<
" " << v[1] <<
" "
248 << v[2] <<
" " << default_color[0] <<
" " << default_color[1] <<
" " << default_color[2] <<
"\n";
253 for (std::size_t i = 0; i < vertices.size(); ++i)
255 const Eigen::Vector3d& v = vertices[i];
256 const Eigen::Vector3i& v_color = vectices_color[i];
257 myfile << std::fixed << std::setprecision(std::numeric_limits<float>::digits10 + 1) << v[0] <<
" " << v[1] <<
" "
258 << v[2] <<
" " << v_color[0] <<
" " << v_color[1] <<
" " << v_color[2] <<
"\n";
264 for (
long i = 0; i < num_faces; ++i)
266 long num_vert = faces[idx];
267 for (
long j = 0; j < num_vert; ++j)
269 myfile << faces[idx] <<
" ";
272 myfile << faces[idx] <<
"\n";
282 const Eigen::VectorXi& faces,
285 std::vector<Eigen::Vector3i> vertices_color;
291 Eigen::VectorXi& faces,
322 std::ifstream myfile;
326 CONSOLE_BRIDGE_logError(
"Failed to open file: %s", path.c_str());
330 std::getline(myfile, str);
331 std::getline(myfile, str);
332 std::getline(myfile, str);
333 std::getline(myfile, str);
334 std::vector<std::string> tokens;
335 boost::split(tokens, str, boost::is_any_of(
" "));
338 CONSOLE_BRIDGE_logError(
"Failed to parse file: %s", path.c_str());
341 auto num_vertices =
static_cast<size_t>(std::stoi(tokens.back()));
343 std::getline(myfile, str);
344 std::getline(myfile, str);
345 std::getline(myfile, str);
346 std::getline(myfile, str);
349 boost::split(tokens, str, boost::is_any_of(
" "));
352 CONSOLE_BRIDGE_logError(
"Failed to parse file: %s", path.c_str());
356 auto num_faces =
static_cast<size_t>(std::stoi(tokens.back()));
357 std::getline(myfile, str);
358 std::getline(myfile, str);
359 if (str !=
"end_header")
361 CONSOLE_BRIDGE_logError(
"Failed to parse file: %s", path.c_str());
365 vertices.reserve(num_vertices);
366 for (
size_t i = 0; i < num_vertices; ++i)
368 std::getline(myfile, str);
370 boost::split(tokens, str, boost::is_any_of(
" "));
371 if (tokens.size() != 3)
373 CONSOLE_BRIDGE_logError(
"Failed to parse file: %s", path.c_str());
377 vertices.emplace_back(std::stod(tokens[0]), std::stod(tokens[1]), std::stod(tokens[2]));
380 std::vector<int> local_faces;
381 local_faces.reserve(num_faces * 3);
382 size_t copy_num_faces = num_faces;
383 for (
size_t i = 0; i < copy_num_faces; ++i)
385 std::getline(myfile, str);
387 boost::split(tokens, str, boost::is_any_of(
" "));
388 if (tokens.size() < 3)
390 CONSOLE_BRIDGE_logError(
"Failed to parse file: %s", path.c_str());
394 auto num_verts =
static_cast<int>(tokens.size());
395 assert(num_verts >= 3);
396 if (triangles_only && num_verts > 3)
398 local_faces.push_back(3);
399 local_faces.push_back(std::stoi(tokens[0]));
400 local_faces.push_back(std::stoi(tokens[1]));
401 local_faces.push_back(std::stoi(tokens[2]));
402 for (
size_t i = 3; i < tokens.size(); ++i)
405 local_faces.push_back(3);
406 local_faces.push_back(std::stoi(tokens[0]));
407 local_faces.push_back(std::stoi(tokens[i - 1]));
408 local_faces.push_back(std::stoi(tokens[i]));
413 local_faces.push_back(
static_cast<int>(tokens.size()));
414 for (
const auto& t : tokens)
415 local_faces.push_back(std::stoi(t));
419 faces.resize(
static_cast<long>(local_faces.size()));
420 for (
size_t i = 0; i < local_faces.size(); ++i)
421 faces[
static_cast<long>(i)] = local_faces[i];
424 return static_cast<int>(num_faces);