1#ifndef TESSERACT_COLLISION_COLLISION_MULTI_THREADED_UNIT_HPP
2#define TESSERACT_COLLISION_COLLISION_MULTI_THREADED_UNIT_HPP
6#include <console_bridge/console.h>
17inline void runTest(DiscreteContactManager& checker,
bool use_convex_mesh =
false)
23 auto mesh_vertices = std::make_shared<tesseract_common::VectorVector3d>();
24 auto mesh_faces = std::make_shared<Eigen::VectorXi>();
26 std::string(TESSERACT_SUPPORT_DIR) +
"/meshes/sphere_p25m.ply", *mesh_vertices, *mesh_faces,
true),
29 auto mesh = std::make_shared<tesseract_geometry::Mesh>(mesh_vertices, mesh_faces);
34 sphere = std::make_shared<tesseract_geometry::Sphere>(0.25);
42 for (std::size_t x = 0; x < t; ++x)
44 for (std::size_t y = 0; y < t; ++y)
46 for (std::size_t z = 0; z < t; ++z)
50 Eigen::Isometry3d sphere_pose;
51 sphere_pose.setIdentity();
54 obj3_poses.push_back(sphere_pose);
56 link_names.push_back(
"sphere_link_" + std::to_string(x) + std::to_string(y) + std::to_string(z));
59 location[
link_names.back()].translation() = Eigen::Vector3d(
60 static_cast<double>(x) * delta,
static_cast<double>(y) * delta,
static_cast<double>(z) * delta);
61 checker.addCollisionObject(
link_names.back(), 0, obj3_shapes, obj3_poses);
68 std::vector<std::string> check_active_links = checker.getActiveCollisionObjects();
71 EXPECT_TRUE(checker.getIsContactAllowedFn() ==
nullptr);
74 EXPECT_NEAR(checker.getCollisionMarginData().getMaxCollisionMargin(), 0.1, 1e-5);
75 checker.setCollisionObjectsTransform(location);
78 std::vector<ContactResultVector>
result_vector(
static_cast<std::size_t
>(num_threads));
79 std::vector<DiscreteContactManager::Ptr> contact_manager(
static_cast<std::size_t
>(num_threads));
80 contact_manager[0] = checker.clone();
81 contact_manager[1] = checker.clone();
82 contact_manager[2] = checker.clone();
83 contact_manager[3] = checker.clone();
85 auto start_time = std::chrono::high_resolution_clock::now();
87#pragma omp parallel for num_threads(num_threads) shared(location)
88 for (
long i = 0; i < num_threads; ++i)
90 const int tn = omp_get_thread_num();
91 CONSOLE_BRIDGE_logDebug(
"Thread (ID: %i): %i of %i", tn, i, num_threads);
93 for (
const auto& co : location)
97 Eigen::Isometry3d
pose = co.second;
98 pose.translation()[0] += 0.1;
99 manager->setCollisionObjectsTransform(co.first,
pose);
103 Eigen::Isometry3d
pose = co.second;
104 pose.translation()[1] += 0.1;
105 std::vector<std::string> names = { co.first };
107 manager->setCollisionObjectsTransform(names, transforms);
111 Eigen::Isometry3d
pose = co.second;
112 pose.translation()[2] += 0.1;
113 manager->setCollisionObjectsTransform(co.first,
pose);
117 Eigen::Isometry3d
pose = co.second;
118 pose.translation()[0] -= 0.1;
119 std::vector<std::string> names = { co.first };
121 manager->setCollisionObjectsTransform(names, transforms);
125 ContactResultMap result;
127 result.flattenMoveResults(
result_vector[
static_cast<size_t>(tn)]);
129 auto end_time = std::chrono::high_resolution_clock::now();
131 CONSOLE_BRIDGE_logInform(
"DT: %f ms", std::chrono::duration<double, std::milli>(end_time - start_time).count());
133 for (
long i = 0; i < num_threads; ++i)
EXPECT_NEAR(config.contact_manager_config.margin_data.getDefaultCollisionMargin(), 5, 1e-6)
tesseract_collision::ContactResultVector result_vector
Definition: collision_core_unit.cpp:410
results link_names[0]
Definition: collision_core_unit.cpp:146
EXPECT_TRUE(tesseract_common::isIdentical< tesseract_collision::ObjectPairKey >(pairs, check_pairs, false))
This is a collection of common methods.
This is a collection of common methods.
EXPECT_GT(m.m.condition, 1e+20)
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
Definition: macros.h:71
Definition: create_convex_hull.cpp:36
Definition: large_dataset_benchmarks.hpp:17
void runTest(ContinuousContactManager &checker)
Definition: collision_box_box_cast_unit.hpp:111
tesseract_common::CollisionMarginData CollisionMarginData
Definition: types.h:50
tesseract_geometry::Geometry::Ptr CollisionShapePtr
Definition: types.h:49
std::vector< tesseract_geometry::Geometry::ConstPtr > CollisionShapesConst
Definition: types.h:47
int loadSimplePlyFile(const std::string &path, tesseract_common::VectorVector3d &vertices, Eigen::VectorXi &faces, bool triangles_only=false)
Loads a simple ply file given a path.
Definition: common.cpp:285
tesseract_geometry::ConvexMesh::Ptr makeConvexMesh(const tesseract_geometry::Mesh &mesh)
Definition: convex_hull_utils.cpp:114
AlignedMap< std::string, Eigen::Isometry3d > TransformMap
Definition: types.h:66
template bool isIdentical< std::string >(const std::vector< std::string > &, const std::vector< std::string > &, bool, const std::function< bool(const std::string &, const std::string &)> &, const std::function< bool(const std::string &, const std::string &)> &)
AlignedVector< Eigen::Isometry3d > VectorIsometry3d
Definition: types.h:62
auto pose
Definition: tesseract_environment_collision.cpp:118
DiscreteContactManager::Ptr manager
Definition: tesseract_environment_collision.cpp:109
auto sphere
Definition: tesseract_geometry_unit.cpp:23
auto mesh
Definition: tesseract_geometry_unit.cpp:25