38 #include <gtest/gtest.h>
40 #include "fcl/config.h"
55 #include <sparsehash/sparse_hash_map>
56 #include <sparsehash/dense_hash_map>
70 template<
typename U,
typename V>
71 struct GoogleSparseHashTable :
public google::sparse_hash_map<U, V, std::tr1::hash<size_t>, std::equal_to<size_t> > {};
73 template<
typename U,
typename V>
74 struct GoogleDenseHashTable :
public google::dense_hash_map<U, V, std::tr1::hash<size_t>, std::equal_to<size_t> >
76 GoogleDenseHashTable() : google::dense_hash_map<U, V, std::tr1::hash<size_t>, std::equal_to<size_t> >()
78 this->set_empty_key(
nullptr);
84 GTEST_TEST(FCL_BROADPHASE, test_core_bf_broad_phase_collision_empty)
87 broad_phase_collision_test<double>(2000, 0, 0, 10,
false,
false);
88 broad_phase_collision_test<double>(2000, 0, 1000, 10,
false,
false);
89 broad_phase_collision_test<double>(2000, 100, 0, 10,
false,
false);
91 broad_phase_collision_test<double>(2000, 0, 0, 10,
false,
true);
92 broad_phase_collision_test<double>(2000, 0, 1000, 10,
false,
true);
93 broad_phase_collision_test<double>(2000, 100, 0, 10,
false,
true);
95 broad_phase_collision_test<double>(2000, 0, 0, 10,
true,
false);
96 broad_phase_collision_test<double>(2000, 0, 1000, 10,
true,
false);
97 broad_phase_collision_test<double>(2000, 100, 0, 10,
true,
false);
99 broad_phase_collision_test<double>(2000, 0, 0, 10,
true,
true);
100 broad_phase_collision_test<double>(2000, 0, 1000, 10,
true,
true);
101 broad_phase_collision_test<double>(2000, 100, 0, 10,
true,
true);
103 broad_phase_collision_test<double>(2000, 0, 0, 10,
false,
false);
104 broad_phase_collision_test<double>(2000, 0, 5, 10,
false,
false);
105 broad_phase_collision_test<double>(2000, 2, 0, 10,
false,
false);
107 broad_phase_collision_test<double>(2000, 0, 0, 10,
false,
true);
108 broad_phase_collision_test<double>(2000, 0, 5, 10,
false,
true);
109 broad_phase_collision_test<double>(2000, 2, 0, 10,
false,
true);
111 broad_phase_collision_test<double>(2000, 0, 0, 10,
true,
false);
112 broad_phase_collision_test<double>(2000, 0, 5, 10,
true,
false);
113 broad_phase_collision_test<double>(2000, 2, 0, 10,
true,
false);
115 broad_phase_collision_test<double>(2000, 0, 0, 10,
true,
true);
116 broad_phase_collision_test<double>(2000, 0, 5, 10,
true,
true);
117 broad_phase_collision_test<double>(2000, 2, 0, 10,
true,
true);
122 GTEST_TEST(FCL_BROADPHASE, test_core_bf_broad_phase_collision_binary)
125 broad_phase_collision_test<double>(2000, 100, 1000, 1,
false);
126 broad_phase_collision_test<double>(2000, 1000, 1000, 1,
false);
127 broad_phase_collision_test<double>(2000, 100, 1000, 1,
true);
128 broad_phase_collision_test<double>(2000, 1000, 1000, 1,
true);
130 broad_phase_collision_test<double>(2000, 10, 100, 1,
false);
131 broad_phase_collision_test<double>(2000, 100, 100, 1,
false);
132 broad_phase_collision_test<double>(2000, 10, 100, 1,
true);
133 broad_phase_collision_test<double>(2000, 100, 100, 1,
true);
138 GTEST_TEST(FCL_BROADPHASE, test_core_bf_broad_phase_collision)
141 broad_phase_collision_test<double>(2000, 100, 1000, 10,
false);
142 broad_phase_collision_test<double>(2000, 1000, 1000, 10,
false);
144 broad_phase_collision_test<double>(2000, 10, 100, 10,
false);
145 broad_phase_collision_test<double>(2000, 100, 100, 10,
false);
150 GTEST_TEST(FCL_BROADPHASE, test_core_mesh_bf_broad_phase_collision_mesh_binary)
153 broad_phase_collision_test<double>(2000, 100, 1000, 1,
false,
true);
154 broad_phase_collision_test<double>(2000, 1000, 1000, 1,
false,
true);
156 broad_phase_collision_test<double>(2000, 2, 5, 1,
false,
true);
157 broad_phase_collision_test<double>(2000, 5, 5, 1,
false,
true);
162 GTEST_TEST(FCL_BROADPHASE, test_core_mesh_bf_broad_phase_collision_mesh)
165 broad_phase_collision_test<double>(2000, 100, 1000, 10,
false,
true);
166 broad_phase_collision_test<double>(2000, 1000, 1000, 10,
false,
true);
168 broad_phase_collision_test<double>(2000, 2, 5, 10,
false,
true);
169 broad_phase_collision_test<double>(2000, 5, 5, 10,
false,
true);
174 GTEST_TEST(FCL_BROADPHASE, test_core_mesh_bf_broad_phase_collision_mesh_exhaustive)
177 broad_phase_collision_test<double>(2000, 100, 1000, 1,
true,
true);
178 broad_phase_collision_test<double>(2000, 1000, 1000, 1,
true,
true);
180 broad_phase_collision_test<double>(2000, 2, 5, 1,
true,
true);
181 broad_phase_collision_test<double>(2000, 5, 5, 1,
true,
true);
185 template <
typename S>
188 std::vector<test::TStruct> ts;
189 std::vector<test::Timer> timers;
191 std::vector<CollisionObject<S>*> env;
197 std::vector<CollisionObject<S>*> query;
203 std::vector<BroadPhaseCollisionManager<S>*> managers;
213 S ncell_per_axis = 20;
214 S cell_size =
std::min(
std::min((upper_limit[0] - lower_limit[0]) / ncell_per_axis, (upper_limit[1] - lower_limit[1]) / ncell_per_axis), (upper_limit[2] - lower_limit[2]) / ncell_per_axis);
228 managers.push_back(m);
234 managers.push_back(m);
237 ts.resize(managers.size());
238 timers.resize(managers.size());
240 for(
size_t i = 0; i < managers.size(); ++i)
243 managers[i]->registerObjects(env);
245 ts[i].push_back(timers[i].getElapsedTime());
248 for(
size_t i = 0; i < managers.size(); ++i)
251 managers[i]->setup();
253 ts[i].push_back(timers[i].getElapsedTime());
256 std::vector<DefaultCollisionData<S>> self_data(managers.size());
257 for(
size_t i = 0; i < managers.size(); ++i)
259 if(exhaustive) self_data[i].request.num_max_contacts = 100000;
263 for(
size_t i = 0; i < managers.size(); ++i)
268 ts[i].push_back(timers[i].getElapsedTime());
271 for(
size_t i = 0; i < managers.size(); ++i)
272 std::cout << self_data[i].result.numContacts() <<
" ";
273 std::cout << std::endl;
277 for(
size_t i = 1; i < managers.size(); ++i)
278 EXPECT_TRUE(self_data[i].result.numContacts() == self_data[0].result.numContacts());
282 std::vector<bool> self_res(managers.size());
283 for(
size_t i = 0; i < self_res.size(); ++i)
284 self_res[i] = (self_data[i].result.numContacts() > 0);
286 for(
size_t i = 1; i < self_res.size(); ++i)
289 for(
size_t i = 1; i < managers.size(); ++i)
290 EXPECT_TRUE(self_data[i].result.numContacts() == self_data[0].result.numContacts());
294 for(
size_t i = 0; i < query.size(); ++i)
296 std::vector<DefaultCollisionData<S>> query_data(managers.size());
297 for(
size_t j = 0; j < query_data.size(); ++j)
299 if(exhaustive) query_data[j].request.num_max_contacts = 100000;
303 for(
size_t j = 0; j < query_data.size(); ++j)
308 ts[j].push_back(timers[j].getElapsedTime());
318 for(
size_t j = 1; j < managers.size(); ++j)
319 EXPECT_TRUE(query_data[j].result.numContacts() == query_data[0].result.numContacts());
323 std::vector<bool> query_res(managers.size());
324 for(
size_t j = 0; j < query_res.size(); ++j)
325 query_res[j] = (query_data[j].result.numContacts() > 0);
326 for(
size_t j = 1; j < query_res.size(); ++j)
329 for(
size_t j = 1; j < managers.size(); ++j)
330 EXPECT_TRUE(query_data[j].result.numContacts() == query_data[0].result.numContacts());
334 for(
size_t i = 0; i < env.size(); ++i)
336 for(
size_t i = 0; i < query.size(); ++i)
339 for(
size_t i = 0; i < managers.size(); ++i)
342 std::cout.setf(std::ios_base::left, std::ios_base::adjustfield);
345 std::cout <<
"collision timing summary" << std::endl;
346 std::cout << env_size <<
" objs, " << query_size <<
" queries" << std::endl;
347 std::cout <<
"register time" << std::endl;
348 for(
size_t i = 0; i < ts.size(); ++i)
349 std::cout << std::setw(w) << ts[i].records[0] <<
" ";
350 std::cout << std::endl;
352 std::cout <<
"setup time" << std::endl;
353 for(
size_t i = 0; i < ts.size(); ++i)
354 std::cout << std::setw(w) << ts[i].records[1] <<
" ";
355 std::cout << std::endl;
357 std::cout <<
"self collision time" << std::endl;
358 for(
size_t i = 0; i < ts.size(); ++i)
359 std::cout << std::setw(w) << ts[i].records[2] <<
" ";
360 std::cout << std::endl;
362 std::cout <<
"collision time" << std::endl;
363 for(
size_t i = 0; i < ts.size(); ++i)
366 for(
size_t j = 3; j < ts[i].records.size(); ++j)
367 tmp += ts[i].records[j];
368 std::cout << std::setw(w) << tmp <<
" ";
370 std::cout << std::endl;
373 std::cout <<
"overall time" << std::endl;
374 for(
size_t i = 0; i < ts.size(); ++i)
375 std::cout << std::setw(w) << ts[i].overall_time <<
" ";
376 std::cout << std::endl;
377 std::cout << std::endl;
382 int main(
int argc,
char* argv[])
384 ::testing::InitGoogleTest(&argc, argv);
385 return RUN_ALL_TESTS();