38 #define BOOST_TEST_MODULE COAL_BROADPHASE_COLLISION_1
39 #include <boost/test/included/unit_test.hpp>
53 #include <boost/math/constants/constants.hpp>
56 #include <sparsehash/sparse_hash_map>
57 #include <sparsehash/dense_hash_map>
75 std::size_t query_size,
77 bool exhaustive =
false,
78 bool use_mesh =
false);
81 template <
typename U,
typename V>
82 struct GoogleSparseHashTable
83 :
public google::sparse_hash_map<U, V, std::tr1::hash<size_t>,
84 std::equal_to<size_t>> {};
86 template <
typename U,
typename V>
87 struct GoogleDenseHashTable
88 :
public google::dense_hash_map<U, V, std::tr1::hash<size_t>,
89 std::equal_to<size_t>> {
90 GoogleDenseHashTable()
91 : google::dense_hash_map<
U,
V, std::tr1::hash<size_t>,
92 std::equal_to<size_t>>() {
93 this->set_empty_key(
nullptr);
143 test_core_mesh_bf_broad_phase_update_collision_mesh_binary) {
166 test_core_mesh_bf_broad_phase_update_collision_mesh_exhaustive) {
181 auto search = checkedPairs.find(std::make_pair(o1, o2));
183 if (search != checkedPairs.end())
return false;
185 checkedPairs.emplace(o1, o2);
194 BOOST_CHECK(
data.checkUniquenessAndAddPair(o1, o2));
203 std::size_t env_size,
bool verbose) {
204 std::vector<TStruct>
ts;
205 std::vector<BenchTimer> timers;
207 std::vector<CollisionObject*> env;
210 std::vector<BroadPhaseCollisionManager*> managers;
215 Vec3s lower_limit, upper_limit;
218 std::min(std::min((upper_limit[0] - lower_limit[0]) / 20,
219 (upper_limit[1] - lower_limit[1]) / 20),
220 (upper_limit[2] - lower_limit[2]) / 20);
224 cell_size, lower_limit, upper_limit));
229 cell_size, lower_limit, upper_limit));
233 cell_size, lower_limit, upper_limit));
240 m->tree_init_level = 2;
241 managers.push_back(
m);
247 m->tree_init_level = 2;
248 managers.push_back(
m);
251 ts.resize(managers.size());
252 timers.resize(managers.size());
254 for (
size_t i = 0; i < managers.size(); ++i) {
256 managers[i]->registerObjects(env);
258 ts[i].push_back(timers[i].getElapsedTime());
261 for (
size_t i = 0; i < managers.size(); ++i) {
263 managers[i]->setup();
265 ts[i].push_back(timers[i].getElapsedTime());
270 10 / 360.0 * 2 * boost::math::constants::pi<CoalScalar>();
271 CoalScalar delta_trans_max = 0.01 * env_scale;
272 for (
size_t i = 0; i < env.size(); ++i) {
274 2 * (rand() / (
CoalScalar)RAND_MAX - 0.5) * delta_angle_max;
276 2 * (rand() / (
CoalScalar)RAND_MAX - 0.5) * delta_trans_max;
278 2 * (rand() / (
CoalScalar)RAND_MAX - 0.5) * delta_angle_max;
280 2 * (rand() / (
CoalScalar)RAND_MAX - 0.5) * delta_trans_max;
282 2 * (rand() / (
CoalScalar)RAND_MAX - 0.5) * delta_angle_max;
284 2 * (rand() / (
CoalScalar)RAND_MAX - 0.5) * delta_trans_max;
289 Vec3s dT(rand_trans_x, rand_trans_y, rand_trans_z);
292 Vec3s T = env[i]->getTranslation();
293 env[i]->setTransform(dR *
R, dR * T + dT);
294 env[i]->computeAABB();
297 for (
size_t i = 0; i < managers.size(); ++i) {
299 managers[i]->update();
301 ts[i].push_back(timers[i].getElapsedTime());
304 std::vector<CollisionDataForUniquenessChecking> self_data(managers.size());
306 for (
size_t i = 0; i < managers.size(); ++i) {
311 ts[i].push_back(timers[i].getElapsedTime());
314 for (
auto obj : env)
delete obj;
318 std::cout.setf(std::ios_base::left, std::ios_base::adjustfield);
321 std::cout <<
"collision timing summary" << std::endl;
322 std::cout << env_size <<
" objs" << std::endl;
323 std::cout <<
"register time" << std::endl;
324 for (
size_t i = 0; i <
ts.size(); ++i)
325 std::cout << std::setw(w) <<
ts[i].records[0] <<
" ";
326 std::cout << std::endl;
328 std::cout <<
"setup time" << std::endl;
329 for (
size_t i = 0; i <
ts.size(); ++i)
330 std::cout << std::setw(w) <<
ts[i].records[1] <<
" ";
331 std::cout << std::endl;
333 std::cout <<
"update time" << std::endl;
334 for (
size_t i = 0; i <
ts.size(); ++i)
335 std::cout << std::setw(w) <<
ts[i].records[2] <<
" ";
336 std::cout << std::endl;
338 std::cout <<
"self collision time" << std::endl;
339 for (
size_t i = 0; i <
ts.size(); ++i)
340 std::cout << std::setw(w) <<
ts[i].records[3] <<
" ";
341 std::cout << std::endl;
343 std::cout <<
"collision time" << std::endl;
344 for (
size_t i = 0; i <
ts.size(); ++i) {
346 for (
size_t j = 4; j <
ts[i].records.size(); ++j) tmp +=
ts[i].records[j];
347 std::cout << std::setw(w) << tmp <<
" ";
349 std::cout << std::endl;
351 std::cout <<
"overall time" << std::endl;
352 for (
size_t i = 0; i <
ts.size(); ++i)
353 std::cout << std::setw(w) <<
ts[i].overall_time <<
" ";
354 std::cout << std::endl;
355 std::cout << std::endl;
359 std::size_t env_size,
360 std::size_t query_size,
362 bool exhaustive,
bool use_mesh) {
363 std::vector<TStruct>
ts;
364 std::vector<BenchTimer> timers;
366 std::vector<CollisionObject*> env;
372 std::vector<CollisionObject*> query;
378 std::vector<BroadPhaseCollisionManager*> managers;
386 Vec3s lower_limit, upper_limit;
389 std::min(std::min((upper_limit[0] - lower_limit[0]) / 20,
390 (upper_limit[1] - lower_limit[1]) / 20),
391 (upper_limit[2] - lower_limit[2]) / 20);
397 cell_size, lower_limit, upper_limit));
402 cell_size, lower_limit, upper_limit));
406 cell_size, lower_limit, upper_limit));
413 m->tree_init_level = 2;
414 managers.push_back(
m);
420 m->tree_init_level = 2;
421 managers.push_back(
m);
424 ts.resize(managers.size());
425 timers.resize(managers.size());
427 for (
size_t i = 0; i < managers.size(); ++i) {
429 managers[i]->registerObjects(env);
431 ts[i].push_back(timers[i].getElapsedTime());
434 for (
size_t i = 0; i < managers.size(); ++i) {
436 managers[i]->setup();
438 ts[i].push_back(timers[i].getElapsedTime());
443 10 / 360.0 * 2 * boost::math::constants::pi<CoalScalar>();
444 CoalScalar delta_trans_max = 0.01 * env_scale;
445 for (
size_t i = 0; i < env.size(); ++i) {
447 2 * (rand() / (
CoalScalar)RAND_MAX - 0.5) * delta_angle_max;
449 2 * (rand() / (
CoalScalar)RAND_MAX - 0.5) * delta_trans_max;
451 2 * (rand() / (
CoalScalar)RAND_MAX - 0.5) * delta_angle_max;
453 2 * (rand() / (
CoalScalar)RAND_MAX - 0.5) * delta_trans_max;
455 2 * (rand() / (
CoalScalar)RAND_MAX - 0.5) * delta_angle_max;
457 2 * (rand() / (
CoalScalar)RAND_MAX - 0.5) * delta_trans_max;
462 Vec3s dT(rand_trans_x, rand_trans_y, rand_trans_z);
465 Vec3s T = env[i]->getTranslation();
466 env[i]->setTransform(dR *
R, dR * T + dT);
467 env[i]->computeAABB();
470 for (
size_t i = 0; i < managers.size(); ++i) {
472 managers[i]->update();
474 ts[i].push_back(timers[i].getElapsedTime());
477 std::vector<CollisionData> self_data(managers.size());
478 for (
size_t i = 0; i < managers.size(); ++i) {
480 self_data[i].request.num_max_contacts = 100000;
485 for (
size_t i = 0; i < managers.size(); ++i) {
490 ts[i].push_back(timers[i].getElapsedTime());
493 for (
size_t i = 0; i < managers.size(); ++i)
494 std::cout << self_data[i].result.numContacts() <<
" ";
495 std::cout << std::endl;
498 for (
size_t i = 1; i < managers.size(); ++i)
499 BOOST_CHECK(self_data[i].result.numContacts() ==
500 self_data[0].result.numContacts());
502 std::vector<bool> self_res(managers.size());
503 for (
size_t i = 0; i < self_res.size(); ++i)
504 self_res[i] = (self_data[i].result.numContacts() > 0);
506 for (
size_t i = 1; i < self_res.size(); ++i)
507 BOOST_CHECK(self_res[0] == self_res[i]);
509 for (
size_t i = 1; i < managers.size(); ++i)
510 BOOST_CHECK(self_data[i].result.numContacts() ==
511 self_data[0].result.numContacts());
514 for (
size_t i = 0; i < query.size(); ++i) {
515 std::vector<CollisionCallBackDefault> query_callbacks(managers.size());
517 for (
size_t j = 0; j < query_callbacks.size(); ++j) {
519 query_callbacks[j].data.request.num_max_contacts = 100000;
524 for (
size_t j = 0; j < query_callbacks.size(); ++j) {
526 managers[j]->collide(query[i], &query_callbacks[j]);
528 ts[j].push_back(timers[j].getElapsedTime());
536 for (
size_t j = 1; j < managers.size(); ++j)
537 BOOST_CHECK(query_callbacks[j].
data.result.numContacts() ==
538 query_callbacks[0].data.result.numContacts());
540 std::vector<bool> query_res(managers.size());
541 for (
size_t j = 0; j < query_res.size(); ++j)
542 query_res[j] = (query_callbacks[j].
data.result.numContacts() > 0);
543 for (
size_t j = 1; j < query_res.size(); ++j)
544 BOOST_CHECK(query_res[0] == query_res[j]);
546 for (
size_t j = 1; j < managers.size(); ++j)
547 BOOST_CHECK(query_callbacks[j].
data.result.numContacts() ==
548 query_callbacks[0].data.result.numContacts());
552 for (
size_t i = 0; i < env.size(); ++i)
delete env[i];
553 for (
size_t i = 0; i < query.size(); ++i)
delete query[i];
555 for (
size_t i = 0; i < managers.size(); ++i)
delete managers[i];
557 std::cout.setf(std::ios_base::left, std::ios_base::adjustfield);
560 std::cout <<
"collision timing summary" << std::endl;
561 std::cout << env_size <<
" objs, " << query_size <<
" queries" << std::endl;
562 std::cout <<
"register time" << std::endl;
563 for (
size_t i = 0; i <
ts.size(); ++i)
564 std::cout << std::setw(w) <<
ts[i].records[0] <<
" ";
565 std::cout << std::endl;
567 std::cout <<
"setup time" << std::endl;
568 for (
size_t i = 0; i <
ts.size(); ++i)
569 std::cout << std::setw(w) <<
ts[i].records[1] <<
" ";
570 std::cout << std::endl;
572 std::cout <<
"update time" << std::endl;
573 for (
size_t i = 0; i <
ts.size(); ++i)
574 std::cout << std::setw(w) <<
ts[i].records[2] <<
" ";
575 std::cout << std::endl;
577 std::cout <<
"self collision time" << std::endl;
578 for (
size_t i = 0; i <
ts.size(); ++i)
579 std::cout << std::setw(w) <<
ts[i].records[3] <<
" ";
580 std::cout << std::endl;
582 std::cout <<
"collision time" << std::endl;
583 for (
size_t i = 0; i <
ts.size(); ++i) {
585 for (
size_t j = 4; j <
ts[i].records.size(); ++j) tmp +=
ts[i].records[j];
586 std::cout << std::setw(w) << tmp <<
" ";
588 std::cout << std::endl;
590 std::cout <<
"overall time" << std::endl;
591 for (
size_t i = 0; i <
ts.size(); ++i)
592 std::cout << std::setw(w) <<
ts[i].overall_time <<
" ";
593 std::cout << std::endl;
594 std::cout << std::endl;