38 #define BOOST_TEST_MODULE COAL_BROADPHASE_COLLISION_2
39 #include <boost/test/included/unit_test.hpp>
54 #include <sparsehash/sparse_hash_map>
55 #include <sparsehash/dense_hash_map>
66 std::size_t query_size,
68 bool exhaustive =
false,
bool use_mesh =
false);
71 template <
typename U,
typename V>
72 struct GoogleSparseHashTable
73 :
public google::sparse_hash_map<U, V, std::tr1::hash<size_t>,
74 std::equal_to<size_t> > {};
76 template <
typename U,
typename V>
77 struct GoogleDenseHashTable
78 :
public google::dense_hash_map<U, V, std::tr1::hash<size_t>,
79 std::equal_to<size_t> > {
80 GoogleDenseHashTable()
81 : google::dense_hash_map<
U,
V, std::tr1::hash<size_t>,
82 std::equal_to<size_t> >() {
83 this->set_empty_key(
nullptr);
186 std::size_t query_size,
189 std::vector<TStruct>
ts;
190 std::vector<BenchTimer> timers;
192 std::vector<CollisionObject*> env;
198 std::vector<CollisionObject*> query;
204 std::vector<BroadPhaseCollisionManager*> managers;
211 Vec3s lower_limit, upper_limit;
216 std::min(std::min((upper_limit[0] - lower_limit[0]) / ncell_per_axis,
217 (upper_limit[1] - lower_limit[1]) / ncell_per_axis),
218 (upper_limit[2] - lower_limit[2]) / ncell_per_axis);
223 cell_size, lower_limit, upper_limit));
228 cell_size, lower_limit, upper_limit));
232 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());
268 std::vector<CollisionCallBackDefault> callbacks(managers.size());
269 for (
size_t i = 0; i < managers.size(); ++i) {
271 callbacks[i].data.request.num_max_contacts = 100000;
276 for (
size_t i = 0; i < managers.size(); ++i) {
278 managers[i]->collide(&callbacks[i]);
280 ts[i].push_back(timers[i].getElapsedTime());
283 for (
size_t i = 0; i < managers.size(); ++i)
284 std::cout << callbacks[i].
data.result.numContacts() <<
" ";
285 std::cout << std::endl;
288 for (
size_t i = 1; i < managers.size(); ++i)
289 BOOST_CHECK(callbacks[i].
data.result.numContacts() ==
290 callbacks[0].data.result.numContacts());
292 std::vector<bool> self_res(managers.size());
293 for (
size_t i = 0; i < self_res.size(); ++i)
294 self_res[i] = (callbacks[i].
data.result.numContacts() > 0);
296 for (
size_t i = 1; i < self_res.size(); ++i)
297 BOOST_CHECK(self_res[0] == self_res[i]);
299 for (
size_t i = 1; i < managers.size(); ++i)
300 BOOST_CHECK(callbacks[i].
data.result.numContacts() ==
301 callbacks[0].data.result.numContacts());
304 for (
size_t i = 0; i < query.size(); ++i) {
305 std::vector<CollisionCallBackDefault> callbacks(managers.size());
306 for (
size_t j = 0; j < managers.size(); ++j) {
308 callbacks[j].data.request.num_max_contacts = 100000;
313 for (
size_t j = 0; j < managers.size(); ++j) {
315 managers[j]->collide(query[i], &callbacks[j]);
317 ts[j].push_back(timers[j].getElapsedTime());
325 for (
size_t j = 1; j < managers.size(); ++j)
326 BOOST_CHECK(callbacks[j].
data.result.numContacts() ==
327 callbacks[0].data.result.numContacts());
329 std::vector<bool> query_res(managers.size());
330 for (
size_t j = 0; j < query_res.size(); ++j)
331 query_res[j] = (callbacks[j].
data.result.numContacts() > 0);
332 for (
size_t j = 1; j < query_res.size(); ++j)
333 BOOST_CHECK(query_res[0] == query_res[j]);
335 for (
size_t j = 1; j < managers.size(); ++j)
336 BOOST_CHECK(callbacks[j].
data.result.numContacts() ==
337 callbacks[0].data.result.numContacts());
341 for (
size_t i = 0; i < env.size(); ++i)
delete env[i];
342 for (
size_t i = 0; i < query.size(); ++i)
delete query[i];
344 for (
size_t i = 0; i < managers.size(); ++i)
delete managers[i];
346 std::cout.setf(std::ios_base::left, std::ios_base::adjustfield);
349 std::cout <<
"collision timing summary" << std::endl;
350 std::cout << env_size <<
" objs, " << query_size <<
" queries" << std::endl;
351 std::cout <<
"register time" << std::endl;
352 for (
size_t i = 0; i <
ts.size(); ++i)
353 std::cout << std::setw(w) <<
ts[i].records[0] <<
" ";
354 std::cout << std::endl;
356 std::cout <<
"setup time" << std::endl;
357 for (
size_t i = 0; i <
ts.size(); ++i)
358 std::cout << std::setw(w) <<
ts[i].records[1] <<
" ";
359 std::cout << std::endl;
361 std::cout <<
"self collision time" << std::endl;
362 for (
size_t i = 0; i <
ts.size(); ++i)
363 std::cout << std::setw(w) <<
ts[i].records[2] <<
" ";
364 std::cout << std::endl;
366 std::cout <<
"collision time" << std::endl;
367 for (
size_t i = 0; i <
ts.size(); ++i) {
369 for (
size_t j = 3; j <
ts[i].records.size(); ++j) tmp +=
ts[i].records[j];
370 std::cout << std::setw(w) << tmp <<
" ";
372 std::cout << std::endl;
374 std::cout <<
"overall time" << std::endl;
375 for (
size_t i = 0; i <
ts.size(); ++i)
376 std::cout << std::setw(w) <<
ts[i].overall_time <<
" ";
377 std::cout << std::endl;
378 std::cout << std::endl;