large_dataset_benchmarks.hpp
Go to the documentation of this file.
1 #ifndef TESSERACT_COLLISION_LARGE_DATASET_BENCHMARKS_HPP
2 #define TESSERACT_COLLISION_LARGE_DATASET_BENCHMARKS_HPP
3 
6 #include <chrono>
8 
14 
15 namespace tesseract_collision
16 {
17 namespace test_suite
18 {
21 static void BM_LARGE_DATASET_MULTILINK(benchmark::State& state,
22  DiscreteContactManager::Ptr checker, // NOLINT
23  int edge_size,
25 {
26  // Add Meshed Sphere to checker
27  CollisionShapePtr sphere;
28 
29  auto mesh_vertices = std::make_shared<tesseract_common::VectorVector3d>();
30  auto mesh_faces = std::make_shared<Eigen::VectorXi>();
31 
33  loadSimplePlyFile(locator.locateResource("package://tesseract_support/meshes/sphere_p25m.ply")->getFilePath(),
34  *mesh_vertices,
35  *mesh_faces,
36  true);
37 
38  switch (type)
39  {
41  {
42  auto mesh = std::make_shared<tesseract_geometry::Mesh>(mesh_vertices, mesh_faces);
43  sphere = makeConvexMesh(*mesh);
44  break;
45  }
47  {
48  sphere = std::make_shared<tesseract_geometry::Mesh>(mesh_vertices, mesh_faces);
49  break;
50  }
52  {
53  sphere = std::make_shared<tesseract_geometry::Sphere>(0.25);
54  break;
55  }
56  default:
57  {
58  throw(std::runtime_error("Invalid geometry type"));
59  break;
60  }
61  }
62 
63  double delta = 0.55;
64 
65  std::vector<std::string> link_names;
67  for (int x = 0; x < edge_size; ++x)
68  {
69  for (int y = 0; y < edge_size; ++y)
70  {
71  for (int z = 0; z < edge_size; ++z)
72  {
73  CollisionShapesConst obj3_shapes;
75  Eigen::Isometry3d sphere_pose;
76  sphere_pose.setIdentity();
77 
78  obj3_shapes.push_back(CollisionShapePtr(sphere->clone()));
79  obj3_poses.push_back(sphere_pose);
80 
81  link_names.push_back("sphere_link_" + std::to_string(x) + std::to_string(y) + std::to_string(z));
82 
83  location[link_names.back()] = sphere_pose;
84  location[link_names.back()].translation() = Eigen::Vector3d(
85  static_cast<double>(x) * delta, static_cast<double>(y) * delta, static_cast<double>(z) * delta);
86  checker->addCollisionObject(link_names.back(), 0, obj3_shapes, obj3_poses);
87  }
88  }
89  }
90 
91  // Check if they are in collision
92  checker->setActiveCollisionObjects(link_names);
93  checker->setCollisionMarginData(CollisionMarginData(0.1));
94  checker->setCollisionObjectsTransform(location);
95 
96  ContactResultMap result;
97  ContactResultVector result_vector;
98 
99  for (auto _ : state) // NOLINT
100  {
101  result.clear();
102  result_vector.clear();
103  checker->contactTest(result, ContactTestType::ALL);
104  result.flattenMoveResults(result_vector);
105  }
106 }
107 
110 static void BM_LARGE_DATASET_SINGLELINK(benchmark::State& state,
111  DiscreteContactManager::Ptr checker, // NOLINT
112  int edge_size,
114 {
115  // Add Meshed Sphere to checker
116  CollisionShapePtr sphere;
117 
118  auto mesh_vertices = std::make_shared<tesseract_common::VectorVector3d>();
119  auto mesh_faces = std::make_shared<Eigen::VectorXi>();
120 
122  loadSimplePlyFile(locator.locateResource("package://tesseract_support/meshes/sphere_p25m.ply")->getFilePath(),
123  *mesh_vertices,
124  *mesh_faces,
125  true);
126 
127  switch (type)
128  {
130  {
131  auto mesh = std::make_shared<tesseract_geometry::Mesh>(mesh_vertices, mesh_faces);
132  sphere = makeConvexMesh(*mesh);
133  break;
134  }
136  {
137  sphere = std::make_shared<tesseract_geometry::Mesh>(mesh_vertices, mesh_faces);
138  break;
139  }
141  {
142  sphere = std::make_shared<tesseract_geometry::Sphere>(0.25);
143  break;
144  }
145  default:
146  {
147  throw(std::runtime_error("Invalid geometry type"));
148  break;
149  }
150  }
151 
152  // Add Grid of spheres
153  double delta = 0.55;
154 
155  std::vector<std::string> link_names;
156  // tesseract_common::TransformMap location;
157  CollisionShapesConst obj3_shapes;
159  for (int x = 0; x < edge_size; ++x)
160  {
161  for (int y = 0; y < edge_size; ++y)
162  {
163  for (int z = 0; z < edge_size; ++z)
164  {
165  Eigen::Isometry3d sphere_pose;
166  sphere_pose.setIdentity();
167  sphere_pose.translation() = Eigen::Vector3d(
168  static_cast<double>(x) * delta, static_cast<double>(y) * delta, static_cast<double>(z) * delta);
169 
170  obj3_shapes.push_back(CollisionShapePtr(sphere->clone()));
171  obj3_poses.push_back(sphere_pose);
172  }
173  }
174  }
175  link_names.emplace_back("grid_link");
176  checker->addCollisionObject(link_names.back(), 0, obj3_shapes, obj3_poses);
177 
178  // Add Single Sphere Link
179  Eigen::Isometry3d sphere_pose;
180  sphere_pose.setIdentity();
181  sphere_pose.translation() = Eigen::Vector3d(static_cast<double>(edge_size) / 2.0 * delta,
182  static_cast<double>(edge_size) / 2.0 * delta,
183  static_cast<double>(edge_size) / 2.0 * delta);
184  CollisionShapesConst single_shapes;
186  single_shapes.push_back(CollisionShapePtr(sphere->clone()));
187  single_poses.push_back(sphere_pose);
188  link_names.emplace_back("single_link");
189  checker->addCollisionObject(link_names.back(), 0, single_shapes, single_poses);
190 
191  // Check if they are in collision
192  checker->setActiveCollisionObjects(link_names);
193  checker->setCollisionMarginData(CollisionMarginData(0.1));
194  // checker->setCollisionObjectsTransform(location);
195 
196  ContactResultMap result;
197  ContactResultVector result_vector;
198 
199  for (auto _ : state) // NOLINT
200  {
201  result.clear();
202  result_vector.clear();
203  checker->contactTest(result, ContactTestType::ALL);
204  result.flattenMoveResults(result_vector);
205  }
206 }
207 
208 } // namespace test_suite
209 } // namespace tesseract_collision
210 
211 #endif
tesseract_common::VectorIsometry3d
AlignedVector< Eigen::Isometry3d > VectorIsometry3d
tesseract_geometry::GeometryType
GeometryType
resource_locator.h
tesseract_common::TransformMap
AlignedMap< std::string, Eigen::Isometry3d > TransformMap
discrete_contact_manager.h
This is the discrete contact manager base class.
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
tesseract_collision::ContactResultVector
tesseract_common::AlignedVector< ContactResult > ContactResultVector
Definition: types.h:136
tesseract_collision::ContactResultMap::clear
void clear()
This is a consurvative clear.
Definition: types.cpp:231
tesseract_geometry::GeometryType::MESH
@ MESH
tesseract_collision::loadSimplePlyFile
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:289
convex_hull_utils.h
This is a collection of common methods.
tesseract_collision::test_suite::BM_LARGE_DATASET_SINGLELINK
static void BM_LARGE_DATASET_SINGLELINK(benchmark::State &state, DiscreteContactManager::Ptr checker, int edge_size, tesseract_geometry::GeometryType type)
Benchmark that checks collisions between a lot of objects. In this case it is a grid of spheres in on...
Definition: large_dataset_benchmarks.hpp:110
tesseract_collision::ContactResultMap::flattenMoveResults
void flattenMoveResults(ContactResultVector &v)
Definition: types.cpp:270
geometries.h
tesseract_collision::makeConvexMesh
tesseract_geometry::ConvexMesh::Ptr makeConvexMesh(const tesseract_geometry::Mesh &mesh)
Definition: convex_hull_utils.cpp:113
tesseract_collision::ContactResultMap
This structure hold contact results for link pairs.
Definition: types.h:155
tesseract_geometry::GeometryType::SPHERE
@ SPHERE
tesseract_collision::CollisionShapePtr
std::shared_ptr< tesseract_geometry::Geometry > CollisionShapePtr
Definition: types.h:50
tesseract_collision::test_suite::BM_LARGE_DATASET_MULTILINK
static void BM_LARGE_DATASET_MULTILINK(benchmark::State &state, DiscreteContactManager::Ptr checker, int edge_size, tesseract_geometry::GeometryType type)
Benchmark that checks collisions between a lot of objects. In this case it is a grid of spheres - eac...
Definition: large_dataset_benchmarks.hpp:21
tesseract_collision::CollisionShapesConst
std::vector< CollisionShapeConstPtr > CollisionShapesConst
Definition: types.h:51
TESSERACT_COMMON_IGNORE_WARNINGS_POP
Definition: create_convex_hull.cpp:37
tesseract_common::GeneralResourceLocator::locateResource
std::shared_ptr< Resource > locateResource(const std::string &url) const override
common.h
This is a collection of common methods.
type
type
tesseract_common::GeneralResourceLocator
tesseract_collision
Definition: bullet_cast_bvh_manager.h:48
tesseract_geometry::GeometryType::CONVEX_MESH
@ CONVEX_MESH
macros.h
tesseract_collision::ContactTestType::ALL
@ ALL
tesseract_collision::DiscreteContactManager::Ptr
std::shared_ptr< DiscreteContactManager > Ptr
Definition: discrete_contact_manager.h:48
tesseract_collision::CollisionMarginData
tesseract_common::CollisionMarginData CollisionMarginData
Definition: types.h:52


tesseract_collision
Author(s): Levi Armstrong
autogenerated on Sun May 18 2025 03:01:52