Tesseract
Motion Planning Environment
Loading...
Searching...
No Matches
primatives_benchmarks.hpp
Go to the documentation of this file.
1#ifndef TESSERACT_COLLISION_PRIMATIVES_BENCHMARKS_HPP
2#define TESSERACT_COLLISION_PRIMATIVES_BENCHMARKS_HPP
3
6
7#include <Eigen/Eigen>
8
10{
11namespace test_suite
12{
17{
20 const Eigen::Isometry3d& pose1,
22 const Eigen::Isometry3d& pose2,
23 ContactTestType contact_test_type)
24
25 {
26 contact_manager_ = contact_manager->clone();
27 geom1_.push_back(geom1->clone());
28 geom2_.push_back(geom2->clone());
29 obj1_poses.push_back(pose1);
30 obj2_poses.push_back(pose2);
31 contact_test_type_ = contact_test_type;
32 }
39};
40
42static void BM_CLONE(benchmark::State& state, DiscreteBenchmarkInfo info, std::size_t num_obj) // NOLINT
43{
44 std::vector<std::string> active_obj(num_obj);
45 for (std::size_t ind = 0; ind < num_obj; ind++)
46 {
47 std::string name = "geom_" + std::to_string(ind);
48 active_obj.push_back(name);
49 info.contact_manager_->addCollisionObject(name, 0, info.geom1_, info.obj1_poses);
50 }
51 info.contact_manager_->setActiveCollisionObjects(active_obj);
52 info.contact_manager_->setCollisionMarginData(CollisionMarginData(0.5));
53
55 for (auto _ : state) // NOLINT
56 {
57 benchmark::DoNotOptimize(clone = info.contact_manager_->clone());
58 }
59}
60
62static void BM_CONTACT_TEST(benchmark::State& state, DiscreteBenchmarkInfo info) // NOLINT
63{
64 info.contact_manager_->addCollisionObject(std::string("geom1"), 0, info.geom1_, info.obj1_poses);
65 info.contact_manager_->addCollisionObject(std::string("geom2"), 0, info.geom2_, info.obj2_poses);
66
67 info.contact_manager_->setActiveCollisionObjects({ "geom1", "geom2" });
68 info.contact_manager_->setCollisionMarginData(CollisionMarginData(0.5));
69
70 ContactResultMap result;
71 for (auto _ : state) // NOLINT
72 {
73 result.clear();
74 info.contact_manager_->contactTest(result, ContactRequest(info.contact_test_type_));
75 }
76}
77
80static void BM_SELECT_RANDOM_OBJECT(benchmark::State& state, int num_obj)
81{
82 int selected_link{ 0 };
83 for (auto _ : state) // NOLINT
84 {
85 benchmark::DoNotOptimize(selected_link = rand() % num_obj); // NOLINT
86 }
87}
88
91static void BM_SET_COLLISION_OBJECTS_TRANSFORM_SINGLE(benchmark::State& state,
93 std::size_t num_obj)
94{
95 // Setting up collision objects
96 std::vector<std::string> active_obj(num_obj);
97 for (std::size_t ind = 0; ind < num_obj; ind++)
98 {
99 std::string name = "geom_" + std::to_string(ind);
100 active_obj[ind] = name;
101 info.contact_manager_->addCollisionObject(name, 0, info.geom1_, info.obj1_poses);
102 }
103 info.contact_manager_->setActiveCollisionObjects(active_obj);
104 info.contact_manager_->setCollisionMarginData(CollisionMarginData(0.5));
105
106 for (auto _ : state) // NOLINT
107 {
108 // Including this seems necessary to insure that a distribution of links is used rather than always searching for
109 // the same one. Subtract off approximately BM_SELECT_RANDOM_OBJECT if you need absolute numbers rather than
110 // relative.
111 std::size_t selected_link = static_cast<std::size_t>(rand()) % num_obj;
112 info.contact_manager_->setCollisionObjectsTransform(active_obj[selected_link], info.obj2_poses[0]);
113 }
114}
115
118static void BM_SET_COLLISION_OBJECTS_TRANSFORM_VECTOR(benchmark::State& state,
119 DiscreteBenchmarkInfo info, // NOLINT
120 std::size_t num_obj)
121{
122 // Setting up collision objects
123 std::vector<std::string> active_obj(num_obj);
124 for (std::size_t ind = 0; ind < num_obj; ind++)
125 {
126 std::string name = "geom_" + std::to_string(ind);
127 active_obj[ind] = name;
128 info.contact_manager_->addCollisionObject(name, 0, info.geom1_, info.obj1_poses);
129 }
130 info.contact_manager_->setActiveCollisionObjects(active_obj);
131 info.contact_manager_->setCollisionMarginData(CollisionMarginData(0.5));
132
133 std::vector<std::string> selected_links(1);
134 for (auto _ : state) // NOLINT
135 {
136 // Including this seems necessary to insure that a distribution of links is used rather than always searching for
137 // the same one. Subtract off approximately BM_SELECT_RANDOM_OBJECT if you need absolute numbers rather than
138 // relative.
139 selected_links[0] = active_obj[static_cast<std::size_t>(rand()) % num_obj];
140 info.contact_manager_->setCollisionObjectsTransform(selected_links, info.obj2_poses);
141 }
142}
143
146static void BM_SET_COLLISION_OBJECTS_TRANSFORM_MAP(benchmark::State& state,
148 std::size_t num_obj)
149{
150 // Setting up collision objects
151 std::vector<std::string> active_obj(num_obj);
152 for (std::size_t ind = 0; ind < num_obj; ind++)
153 {
154 std::string name = "geom_" + std::to_string(ind);
155 active_obj[ind] = name;
156 info.contact_manager_->addCollisionObject(name, 0, info.geom1_, info.obj1_poses);
157 }
158 info.contact_manager_->setActiveCollisionObjects(active_obj);
159 info.contact_manager_->setCollisionMarginData(CollisionMarginData(0.5));
160
161 tesseract_common::TransformMap selected_link;
162 for (auto _ : state) // NOLINT
163 {
164 // Including this seems necessary to insure that a distribution of links is used rather than always searching for
165 // the same one. It might be worth it to manually time these as well if it's really important
166 selected_link.clear(); // Need to clear or this grows and is not releastic to compare to vector version
167 selected_link[active_obj[static_cast<std::size_t>(rand()) % num_obj]] = info.obj2_poses[0];
168 info.contact_manager_->setCollisionObjectsTransform(selected_link);
169 }
170}
171
172} // namespace test_suite
173} // namespace tesseract_collision
174
175#endif
This structure hold contact results for link pairs.
Definition: types.h:154
void clear()
This is a consurvative clear.
Definition: types.cpp:183
std::shared_ptr< DiscreteContactManager > Ptr
Definition: discrete_contact_manager.h:47
std::shared_ptr< const DiscreteContactManager > ConstPtr
Definition: discrete_contact_manager.h:48
std::shared_ptr< const Geometry > ConstPtr
Definition: geometry.h:63
auto clone
Definition: clone_cache_unit.cpp:126
This is the discrete contact manager base class.
Tesseract Geometries.
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
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
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
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
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
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
Definition: bullet_cast_bvh_manager.h:49
tesseract_common::CollisionMarginData CollisionMarginData
Definition: types.h:50
std::vector< tesseract_geometry::Geometry::ConstPtr > CollisionShapesConst
Definition: types.h:47
ContactTestType
Definition: types.h:70
AlignedMap< std::string, Eigen::Isometry3d > TransformMap
Definition: types.h:66
AlignedVector< Eigen::Isometry3d > VectorIsometry3d
Definition: types.h:62
The ContactRequest struct.
Definition: types.h:294
Contains the information necessary to run the benchmarks for discrete collision checking.
Definition: primatives_benchmarks.hpp:17
tesseract_common::VectorIsometry3d obj2_poses
Definition: primatives_benchmarks.hpp:37
CollisionShapesConst geom1_
Definition: primatives_benchmarks.hpp:34
ContactTestType contact_test_type_
Definition: primatives_benchmarks.hpp:38
DiscreteContactManager::Ptr contact_manager_
Definition: primatives_benchmarks.hpp:33
DiscreteBenchmarkInfo(const DiscreteContactManager::ConstPtr &contact_manager, const tesseract_geometry::Geometry::ConstPtr &geom1, const Eigen::Isometry3d &pose1, const tesseract_geometry::Geometry::ConstPtr &geom2, const Eigen::Isometry3d &pose2, ContactTestType contact_test_type)
Definition: primatives_benchmarks.hpp:18
CollisionShapesConst geom2_
Definition: primatives_benchmarks.hpp:36
tesseract_common::VectorIsometry3d obj1_poses
Definition: primatives_benchmarks.hpp:35
auto pose2
Definition: tesseract_environment_collision.cpp:155
auto pose1
Definition: tesseract_environment_collision.cpp:153
KinematicsInformation info
Definition: tesseract_srdf_unit.cpp:1765