fcl_discrete_bvh_benchmarks.cpp
Go to the documentation of this file.
1 #include <benchmark/benchmark.h>
2 #include <Eigen/Eigen>
3 
9 
10 using namespace tesseract_collision;
11 using namespace test_suite;
12 using namespace tesseract_geometry;
13 
14 // Removes some of the long running tests (greater than 30s). Set to false to run everything.
15 static bool RUN_QUICK = true;
16 
17 int main(int argc, char** argv)
18 {
20  std::make_shared<tesseract_collision_fcl::FCLDiscreteBVHManager>();
21 
23  // Clone
25  {
26  std::vector<int> num_links = { 0, 2, 4, 8, 16, 32, 64, 128, 256, 512 };
27  std::function<void(benchmark::State&, DiscreteBenchmarkInfo, int)> BM_CLONE_FUNC = BM_CLONE;
28  for (const auto& num_link : num_links)
29  {
30  std::string name = "BM_CLONE_" + checker->getName() + "_ACTIVE_OBJ_" + std::to_string(num_link);
31  benchmark::RegisterBenchmark(name.c_str(),
32  BM_CLONE_FUNC,
33  DiscreteBenchmarkInfo(checker,
34  CreateUnitPrimative(GeometryType::BOX),
35  Eigen::Isometry3d::Identity(),
36  CreateUnitPrimative(GeometryType::BOX),
37  Eigen::Isometry3d::Identity(),
39  num_link)
40  ->UseRealTime()
41  ->Unit(benchmark::TimeUnit::kMicrosecond);
42  }
43  }
44 
46  // contactTest
48  std::function<void(benchmark::State&, DiscreteBenchmarkInfo)> BM_CONTACT_TEST_FUNC = BM_CONTACT_TEST;
49 
50  // Make vector of all shapes to try
51  // Cone, Sphere, and Capsule are absurdly slow. It doesn't even make sense to run them (4/7/2020).
52  std::vector<tesseract_geometry::GeometryType> geometry_types = {
53  GeometryType::BOX, GeometryType::CYLINDER, GeometryType::CONE, GeometryType::SPHERE, GeometryType::CAPSULE
54  };
55  if (RUN_QUICK)
56  {
57  geometry_types.pop_back();
58  geometry_types.pop_back();
59  geometry_types.pop_back();
60  }
61 
62  std::vector<ContactTestType> test_types = {
64  };
65 
66  // In Collision
67  {
68  for (const auto& test_type : test_types)
69  {
70  // Loop over all primitive combinations
71  for (const auto& type1 : geometry_types)
72  {
73  for (const auto& type2 : geometry_types)
74  {
75  auto tf = Eigen::Isometry3d::Identity();
76  std::string name = "BM_CONTACT_TEST_0_" + checker->getName() + "_" +
77  ContactTestTypeStrings[static_cast<std::size_t>(test_type)] + "_" +
78  GeometryTypeStrings[static_cast<std::size_t>(type1)] + "_" +
79  GeometryTypeStrings[static_cast<std::size_t>(type2)];
80  benchmark::RegisterBenchmark(name.c_str(),
81  BM_CONTACT_TEST_FUNC,
82  DiscreteBenchmarkInfo(checker,
83  CreateUnitPrimative(type1),
84  Eigen::Isometry3d::Identity(),
85  CreateUnitPrimative(type2),
86  tf.translate(Eigen::Vector3d(0.0001, 0, 0)),
87  test_type))
88  ->UseRealTime()
89  ->Unit(benchmark::TimeUnit::kMicrosecond);
90  }
91  }
92  }
93  }
94  // Not in collision. Within contact threshold
95  {
96  for (const auto& test_type : test_types)
97  {
98  // Loop over all primitive combinations
99  for (const auto& type1 : geometry_types)
100  {
101  for (const auto& type2 : geometry_types)
102  {
103  auto tf = Eigen::Isometry3d::Identity();
104  std::string name = "BM_CONTACT_TEST_1_" + checker->getName() + "_" +
105  ContactTestTypeStrings[static_cast<std::size_t>(test_type)] + "_" +
106  GeometryTypeStrings[static_cast<std::size_t>(type1)] + "_" +
107  GeometryTypeStrings[static_cast<std::size_t>(type2)];
108  benchmark::RegisterBenchmark(name.c_str(),
109  BM_CONTACT_TEST_FUNC,
110  DiscreteBenchmarkInfo(checker,
111  CreateUnitPrimative(type1),
112  Eigen::Isometry3d::Identity(),
113  CreateUnitPrimative(type2),
114  tf.translate(Eigen::Vector3d(0.6, 0, 0)),
115  test_type))
116  ->UseRealTime()
117  ->Unit(benchmark::TimeUnit::kMicrosecond);
118  }
119  }
120  }
121  }
122 
123  // Not in collision. Outside contact threshold
124  {
125  for (const auto& test_type : test_types)
126  {
127  // Loop over all primitive combinations
128  for (const auto& type1 : geometry_types)
129  {
130  for (const auto& type2 : geometry_types)
131  {
132  auto tf = Eigen::Isometry3d::Identity();
133  std::string name = "BM_CONTACT_TEST_2_" + checker->getName() + "_" +
134  ContactTestTypeStrings[static_cast<std::size_t>(test_type)] + "_" +
135  GeometryTypeStrings[static_cast<std::size_t>(type1)] + "_" +
136  GeometryTypeStrings[static_cast<std::size_t>(type2)];
137  benchmark::RegisterBenchmark(name.c_str(),
138  BM_CONTACT_TEST_FUNC,
139  DiscreteBenchmarkInfo(checker,
140  CreateUnitPrimative(type1),
141  Eigen::Isometry3d::Identity(),
142  CreateUnitPrimative(type2),
143  tf.translate(Eigen::Vector3d(2, 0, 0)),
144  test_type))
145  ->UseRealTime()
146  ->Unit(benchmark::TimeUnit::kMicrosecond);
147  }
148  }
149  }
150  }
151 
153  // setCollisionObjectTransform
155  {
156  std::function<void(benchmark::State&, int)> BM_SELECT_RANDOM_OBJECT_FUNC = BM_SELECT_RANDOM_OBJECT;
157  benchmark::RegisterBenchmark("BM_SELECT_RANDOM_OBJECT", BM_SELECT_RANDOM_OBJECT_FUNC, 256)
158  ->UseRealTime()
159  ->Unit(benchmark::TimeUnit::kNanosecond);
160  }
161  {
162  std::function<void(benchmark::State&, DiscreteBenchmarkInfo, int)> BM_SET_COLLISION_OBJECTS_TRANSFORM_SINGLE_FUNC =
164  std::vector<int> num_links = { 2, 4, 8, 16, 32, 64, 128, 256, 512 };
165 
166  for (const auto& num_link : num_links)
167  {
168  auto tf = Eigen::Isometry3d::Identity();
169  std::string name =
170  "BM_SET_COLLISION_OBJECTS_TRANSFORM_SINGLE_" + checker->getName() + "_ACTIVE_OBJ_" + std::to_string(num_link);
171  benchmark::RegisterBenchmark(name.c_str(),
172  BM_SET_COLLISION_OBJECTS_TRANSFORM_SINGLE_FUNC,
173  DiscreteBenchmarkInfo(checker,
174  CreateUnitPrimative(GeometryType::BOX),
175  Eigen::Isometry3d::Identity(),
176  CreateUnitPrimative(GeometryType::BOX),
177  tf.translate(Eigen::Vector3d(2, 0, 0)),
179  num_link)
180  ->UseRealTime()
181  ->Unit(benchmark::TimeUnit::kNanosecond);
182  }
183  }
184  {
185  std::function<void(benchmark::State&, DiscreteBenchmarkInfo, int)> BM_SET_COLLISION_OBJECTS_TRANSFORM_VECTOR_FUNC =
187  std::vector<std::size_t> num_links = { 2, 4, 8, 16, 32, 64, 128, 256, 512 };
188 
189  for (const auto& num_link : num_links)
190  {
191  auto tf = Eigen::Isometry3d::Identity();
192  std::string name =
193  "BM_SET_COLLISION_OBJECTS_TRANSFORM_VECTOR_" + checker->getName() + "_ACTIVE_OBJ_" + std::to_string(num_link);
194  benchmark::RegisterBenchmark(name.c_str(),
195  BM_SET_COLLISION_OBJECTS_TRANSFORM_VECTOR_FUNC,
196  DiscreteBenchmarkInfo(checker,
197  CreateUnitPrimative(GeometryType::BOX),
198  Eigen::Isometry3d::Identity(),
199  CreateUnitPrimative(GeometryType::BOX),
200  tf.translate(Eigen::Vector3d(2, 0, 0)),
202  num_link)
203  ->UseRealTime()
204  ->Unit(benchmark::TimeUnit::kNanosecond);
205  }
206  }
207  {
208  std::function<void(benchmark::State&, DiscreteBenchmarkInfo, int)> BM_SET_COLLISION_OBJECTS_TRANSFORM_MAP_FUNC =
210  std::vector<std::size_t> num_links = { 2, 4, 8, 16, 32, 64, 128, 256, 512 };
211 
212  for (const auto& num_link : num_links)
213  {
214  auto tf = Eigen::Isometry3d::Identity();
215  std::string name =
216  "BM_SET_COLLISION_OBJECTS_TRANSFORM_MAP_" + checker->getName() + "_ACTIVE_OBJ_" + std::to_string(num_link);
217  benchmark::RegisterBenchmark(name.c_str(),
218  BM_SET_COLLISION_OBJECTS_TRANSFORM_MAP_FUNC,
219  DiscreteBenchmarkInfo(checker,
220  CreateUnitPrimative(GeometryType::BOX),
221  Eigen::Isometry3d::Identity(),
222  CreateUnitPrimative(GeometryType::BOX),
223  tf.translate(Eigen::Vector3d(2, 0, 0)),
225  num_link)
226  ->UseRealTime()
227  ->Unit(benchmark::TimeUnit::kNanosecond);
228  }
229  }
231  // Large Dataset contactTest
233  if (std::string(BENCHMARK_ARGS) != "CI_ONLY")
234  {
235  std::function<void(benchmark::State&, DiscreteContactManager::Ptr, int, tesseract_geometry::GeometryType)>
236  BM_LARGE_DATASET_MULTILINK_FUNC = BM_LARGE_DATASET_MULTILINK;
237  std::vector<int> edge_sizes = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
238 
239  for (const auto& edge_size : edge_sizes)
240  {
241  DiscreteContactManager::Ptr clone = checker->clone();
242  std::string name =
243  "BM_LARGE_DATASET_MULTILINK_" + checker->getName() + "_CONVEX_MESH_EDGE_SIZE_" + std::to_string(edge_size);
244  benchmark::RegisterBenchmark(name.c_str(),
245  BM_LARGE_DATASET_MULTILINK_FUNC,
246  clone,
247  edge_size,
249  ->UseRealTime()
250  ->Unit(benchmark::TimeUnit::kNanosecond);
251  }
252  for (const auto& edge_size : edge_sizes)
253  {
254  DiscreteContactManager::Ptr clone = checker->clone();
255  std::string name =
256  "BM_LARGE_DATASET_MULTILINK_" + checker->getName() + "_PRIMATIVE_EDGE_SIZE_" + std::to_string(edge_size);
257  benchmark::RegisterBenchmark(
258  name.c_str(), BM_LARGE_DATASET_MULTILINK_FUNC, clone, edge_size, tesseract_geometry::GeometryType::SPHERE)
259  ->UseRealTime()
260  ->Unit(benchmark::TimeUnit::kNanosecond);
261  }
262  // These last two took 45s and 120s. Too long to run in CI, and impractical for our purposes anyway.
263  if (RUN_QUICK)
264  {
265  edge_sizes.pop_back();
266  edge_sizes.pop_back();
267  }
268  for (const auto& edge_size : edge_sizes)
269  {
270  DiscreteContactManager::Ptr clone = checker->clone();
271  std::string name =
272  "BM_LARGE_DATASET_MULTILINK_" + checker->getName() + "_DETAILED_MESH_EDGE_SIZE_" + std::to_string(edge_size);
273  benchmark::RegisterBenchmark(
274  name.c_str(), BM_LARGE_DATASET_MULTILINK_FUNC, clone, edge_size, tesseract_geometry::GeometryType::MESH)
275  ->UseRealTime()
276  ->Unit(benchmark::TimeUnit::kMillisecond);
277  }
278  std::function<void(benchmark::State&, DiscreteContactManager::Ptr, int, tesseract_geometry::GeometryType)>
279  BM_LARGE_DATASET_SINGLELINK_FUNC = BM_LARGE_DATASET_SINGLELINK;
280 
281  for (const auto& edge_size : edge_sizes)
282  {
283  DiscreteContactManager::Ptr clone = checker->clone();
284  std::string name =
285  "BM_LARGE_DATASET_SINGLELINK_" + checker->getName() + "_CONVEX_MESH_EDGE_SIZE_" + std::to_string(edge_size);
286  benchmark::RegisterBenchmark(name.c_str(),
287  BM_LARGE_DATASET_SINGLELINK_FUNC,
288  clone,
289  edge_size,
291  ->UseRealTime()
292  ->Unit(benchmark::TimeUnit::kNanosecond);
293  }
294  for (const auto& edge_size : edge_sizes)
295  {
296  DiscreteContactManager::Ptr clone = checker->clone();
297  std::string name =
298  "BM_LARGE_DATASET_SINGLELINK_" + checker->getName() + "_PRIMATIVE_EDGE_SIZE_" + std::to_string(edge_size);
299  benchmark::RegisterBenchmark(
300  name.c_str(), BM_LARGE_DATASET_SINGLELINK_FUNC, clone, edge_size, tesseract_geometry::GeometryType::SPHERE)
301  ->UseRealTime()
302  ->Unit(benchmark::TimeUnit::kNanosecond);
303  }
304  for (const auto& edge_size : edge_sizes)
305  {
306  DiscreteContactManager::Ptr clone = checker->clone();
307  std::string name =
308  "BM_LARGE_DATASET_SINGLELINK_" + checker->getName() + "_DETAILED_MESH_EDGE_SIZE_" + std::to_string(edge_size);
309  benchmark::RegisterBenchmark(
310  name.c_str(), BM_LARGE_DATASET_SINGLELINK_FUNC, clone, edge_size, tesseract_geometry::GeometryType::MESH)
311  ->UseRealTime()
312  ->Unit(benchmark::TimeUnit::kMillisecond);
313  }
314  }
315 
316  benchmark::Initialize(&argc, argv);
317  benchmark::RunSpecifiedBenchmarks();
318 }
tesseract_collision::test_suite::BM_CLONE
static void BM_CLONE(benchmark::State &state, DiscreteBenchmarkInfo info, std::size_t num_obj)
Benchmark that checks the clone method in discrete contact managers.
Definition: primatives_benchmarks.hpp:42
fcl_discrete_managers.h
Tesseract ROS FCL contact checker implementation.
tesseract_geometry::GeometryType
GeometryType
tesseract_collision::ContactTestType::LIMITED
@ LIMITED
tesseract_geometry::GeometryType::MESH
@ MESH
tesseract_collision::tesseract_collision_fcl::FCLDiscreteBVHManager::ConstPtr
std::shared_ptr< const FCLDiscreteBVHManager > ConstPtr
Definition: fcl_discrete_managers.h:55
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
RUN_QUICK
static bool RUN_QUICK
Definition: fcl_discrete_bvh_benchmarks.cpp:15
large_dataset_benchmarks.hpp
name
std::string name
tesseract_geometry::GeometryType::SPHERE
@ SPHERE
tesseract_collision::test_suite::DiscreteBenchmarkInfo
Contains the information necessary to run the benchmarks for discrete collision checking.
Definition: primatives_benchmarks.hpp:16
main
int main(int argc, char **argv)
Definition: fcl_discrete_bvh_benchmarks.cpp:17
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
primatives_benchmarks.hpp
CreateUnitPrimative
tesseract_geometry::Geometry::Ptr CreateUnitPrimative(const tesseract_geometry::GeometryType type, const double scale=1.0)
Definition: benchmark_utils.hpp:12
geometry.h
tesseract_collision::ContactTestType::FIRST
@ FIRST
tesseract_collision::test_suite::BM_CONTACT_TEST
static void BM_CONTACT_TEST(benchmark::State &state, DiscreteBenchmarkInfo info)
Benchmark that checks the contactTest function in discrete contact managers.
Definition: primatives_benchmarks.hpp:62
tesseract_collision::test_suite::BM_SET_COLLISION_OBJECTS_TRANSFORM_VECTOR
static void BM_SET_COLLISION_OBJECTS_TRANSFORM_VECTOR(benchmark::State &state, DiscreteBenchmarkInfo info, std::size_t num_obj)
Benchmark that checks the setCollisionObjectsTransform(const std::vector<std::string>& names,...
Definition: primatives_benchmarks.hpp:118
tesseract_collision::test_suite::BM_SET_COLLISION_OBJECTS_TRANSFORM_MAP
static void BM_SET_COLLISION_OBJECTS_TRANSFORM_MAP(benchmark::State &state, DiscreteBenchmarkInfo info, std::size_t num_obj)
Benchmark that checks the setCollisionObjectsTransform(const tesseract_common::TransformMap& transfor...
Definition: primatives_benchmarks.hpp:146
tesseract_geometry
tesseract_collision::test_suite::BM_SELECT_RANDOM_OBJECT
static void BM_SELECT_RANDOM_OBJECT(benchmark::State &state, int num_obj)
Benchmark that checks how long it takes to select a random object so that number can be subtracted fr...
Definition: primatives_benchmarks.hpp:80
tesseract_collision
Definition: bullet_cast_bvh_manager.h:48
tesseract_geometry::GeometryType::CONVEX_MESH
@ CONVEX_MESH
tesseract_collision::ContactTestType::ALL
@ ALL
tesseract_collision::ContactTestTypeStrings
static const std::vector< std::string > ContactTestTypeStrings
Definition: types.h:74
tesseract_collision::test_suite::BM_SET_COLLISION_OBJECTS_TRANSFORM_SINGLE
static void BM_SET_COLLISION_OBJECTS_TRANSFORM_SINGLE(benchmark::State &state, DiscreteBenchmarkInfo info, std::size_t num_obj)
Benchmark that checks the setCollisionObjectsTransform(const std::string& name, const Eigen::Isometry...
Definition: primatives_benchmarks.hpp:91
tesseract_collision::DiscreteContactManager::Ptr
std::shared_ptr< DiscreteContactManager > Ptr
Definition: discrete_contact_manager.h:48
tesseract_collision::ContactTestType::CLOSEST
@ CLOSEST
benchmark_utils.hpp


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