test_fcl_collision.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2011, Willow Garage, Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of Willow Garage, Inc. nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  */
00034 
00037 #define BOOST_TEST_MODULE "FCL_COLLISION"
00038 #include <boost/test/unit_test.hpp>
00039 
00040 #include "fcl/traversal/traversal_node_bvhs.h"
00041 #include "fcl/traversal/traversal_node_setup.h"
00042 #include "fcl/collision_node.h"
00043 #include "fcl/collision.h"
00044 #include "fcl/BV/BV.h"
00045 #include "fcl/shape/geometric_shapes.h"
00046 #include "fcl/narrowphase/narrowphase.h"
00047 #include "test_fcl_utility.h"
00048 #include "fcl_resources/config.h"
00049 #include <boost/filesystem.hpp>
00050 
00051 using namespace fcl;
00052 
00053 template<typename BV>
00054 bool collide_Test(const Transform3f& tf,
00055                   const std::vector<Vec3f>& vertices1, const std::vector<Triangle>& triangles1,
00056                   const std::vector<Vec3f>& vertices2, const std::vector<Triangle>& triangles2, SplitMethodType split_method, bool verbose = true);
00057 
00058 template<typename BV>
00059 bool collide_Test2(const Transform3f& tf,
00060                    const std::vector<Vec3f>& vertices1, const std::vector<Triangle>& triangles1,
00061                    const std::vector<Vec3f>& vertices2, const std::vector<Triangle>& triangles2, SplitMethodType split_method, bool verbose = true);
00062 
00063 template<typename BV, typename TraversalNode>
00064 bool collide_Test_Oriented(const Transform3f& tf,
00065                            const std::vector<Vec3f>& vertices1, const std::vector<Triangle>& triangles1,
00066                            const std::vector<Vec3f>& vertices2, const std::vector<Triangle>& triangles2, SplitMethodType split_method, bool verbose = true);
00067 
00068 
00069 template<typename BV>
00070 bool test_collide_func(const Transform3f& tf,
00071                        const std::vector<Vec3f>& vertices1, const std::vector<Triangle>& triangles1,
00072                        const std::vector<Vec3f>& vertices2, const std::vector<Triangle>& triangles2, SplitMethodType split_method);
00073 
00074 int num_max_contacts = std::numeric_limits<int>::max();
00075 bool enable_contact = true;
00076 
00077 std::vector<Contact> global_pairs;
00078 std::vector<Contact> global_pairs_now;
00079 
00080 BOOST_AUTO_TEST_CASE(OBB_Box_test)
00081 {
00082   FCL_REAL r_extents[] = {-1000, -1000, -1000, 1000, 1000, 1000};
00083   std::vector<Transform3f> rotate_transform;
00084   generateRandomTransforms(r_extents, rotate_transform, 1);
00085   
00086   AABB aabb1;
00087   aabb1.min_ = Vec3f(-600, -600, -600);
00088   aabb1.max_ = Vec3f(600, 600, 600);
00089 
00090   OBB obb1;
00091   convertBV(aabb1, rotate_transform[0], obb1);
00092   Box box1;
00093   Transform3f box1_tf;
00094   constructBox(aabb1, rotate_transform[0], box1, box1_tf);
00095 
00096   FCL_REAL extents[] = {-1000, -1000, -1000, 1000, 1000, 1000};
00097   std::size_t n = 1000;
00098 
00099   std::vector<Transform3f> transforms;
00100   generateRandomTransforms(extents, transforms, n);
00101 
00102   for(std::size_t i = 0; i < transforms.size(); ++i)
00103   {
00104     AABB aabb;
00105     aabb.min_ = aabb1.min_ * 0.5;
00106     aabb.max_ = aabb1.max_ * 0.5;    
00107 
00108     OBB obb2;
00109     convertBV(aabb, transforms[i], obb2);
00110     
00111     Box box2;
00112     Transform3f box2_tf;
00113     constructBox(aabb, transforms[i], box2, box2_tf);
00114 
00115     GJKSolver_libccd solver;
00116 
00117     bool overlap_obb = obb1.overlap(obb2);
00118     bool overlap_box = solver.shapeIntersect(box1, box1_tf, box2, box2_tf, NULL, NULL, NULL);
00119     
00120     BOOST_CHECK(overlap_obb == overlap_box);
00121   }
00122 }
00123 
00124 BOOST_AUTO_TEST_CASE(OBB_shape_test)
00125 {
00126   FCL_REAL r_extents[] = {-1000, -1000, -1000, 1000, 1000, 1000};
00127   std::vector<Transform3f> rotate_transform;
00128   generateRandomTransforms(r_extents, rotate_transform, 1);
00129   
00130   AABB aabb1;
00131   aabb1.min_ = Vec3f(-600, -600, -600);
00132   aabb1.max_ = Vec3f(600, 600, 600);
00133 
00134   OBB obb1;
00135   convertBV(aabb1, rotate_transform[0], obb1);
00136   Box box1;
00137   Transform3f box1_tf;
00138   constructBox(aabb1, rotate_transform[0], box1, box1_tf);
00139 
00140   FCL_REAL extents[] = {-1000, -1000, -1000, 1000, 1000, 1000};
00141   std::size_t n = 1000;
00142 
00143   std::vector<Transform3f> transforms;
00144   generateRandomTransforms(extents, transforms, n);
00145 
00146   for(std::size_t i = 0; i < transforms.size(); ++i)
00147   {
00148     FCL_REAL len = (aabb1.max_[0] - aabb1.min_[0]) * 0.5;
00149     OBB obb2;
00150     GJKSolver_libccd solver;
00151  
00152     {  
00153       Sphere sphere(len);
00154       computeBV(sphere, transforms[i], obb2);
00155  
00156       bool overlap_obb = obb1.overlap(obb2);
00157       bool overlap_sphere = solver.shapeIntersect(box1, box1_tf, sphere, transforms[i], NULL, NULL, NULL);
00158       BOOST_CHECK(overlap_obb >= overlap_sphere);
00159     }
00160 
00161     {
00162       Capsule capsule(len, 2 * len);
00163       computeBV(capsule, transforms[i], obb2);
00164       
00165       bool overlap_obb = obb1.overlap(obb2);
00166       bool overlap_capsule = solver.shapeIntersect(box1, box1_tf, capsule, transforms[i], NULL, NULL, NULL);
00167       BOOST_CHECK(overlap_obb >= overlap_capsule);
00168     }
00169 
00170     {
00171       Cone cone(len, 2 * len);
00172       computeBV(cone, transforms[i], obb2);
00173       
00174       bool overlap_obb = obb1.overlap(obb2);
00175       bool overlap_cone = solver.shapeIntersect(box1, box1_tf, cone, transforms[i], NULL, NULL, NULL);
00176       BOOST_CHECK(overlap_obb >= overlap_cone);
00177     }
00178 
00179     {
00180       Cylinder cylinder(len, 2 * len);
00181       computeBV(cylinder, transforms[i], obb2);
00182       
00183       bool overlap_obb = obb1.overlap(obb2);
00184       bool overlap_cylinder = solver.shapeIntersect(box1, box1_tf, cylinder, transforms[i], NULL, NULL, NULL);
00185       BOOST_CHECK(overlap_obb >= overlap_cylinder);
00186     }
00187   }
00188 }
00189 
00190 BOOST_AUTO_TEST_CASE(OBB_AABB_test)
00191 {
00192   FCL_REAL extents[] = {-1000, -1000, -1000, 1000, 1000, 1000};
00193   std::size_t n = 1000;
00194 
00195   std::vector<Transform3f> transforms;
00196   generateRandomTransforms(extents, transforms, n);
00197 
00198   AABB aabb1;
00199   aabb1.min_ = Vec3f(-600, -600, -600);
00200   aabb1.max_ = Vec3f(600, 600, 600);
00201   
00202   OBB obb1;
00203   convertBV(aabb1, Transform3f(), obb1);
00204   
00205   for(std::size_t i = 0; i < transforms.size(); ++i)
00206   {
00207     AABB aabb;
00208     aabb.min_ = aabb1.min_ * 0.5;
00209     aabb.max_ = aabb1.max_ * 0.5;    
00210 
00211     AABB aabb2 = translate(aabb, transforms[i].getTranslation());
00212     
00213     OBB obb2;
00214     convertBV(aabb, Transform3f(transforms[i].getTranslation()), obb2);
00215 
00216     bool overlap_aabb = aabb1.overlap(aabb2);
00217     bool overlap_obb = obb1.overlap(obb2);
00218     if(overlap_aabb != overlap_obb)
00219     {
00220       std::cout << aabb1.min_ << " " << aabb1.max_ << std::endl;
00221       std::cout << aabb2.min_ << " " << aabb2.max_ << std::endl;
00222       std::cout << obb1.To << " " << obb1.extent << " " << obb1.axis[0] << " " << obb1.axis[1] << " " << obb1.axis[2] << std::endl;
00223       std::cout << obb2.To << " " << obb2.extent << " " << obb2.axis[0] << " " << obb2.axis[1] << " " << obb2.axis[2] << std::endl;
00224     }
00225 
00226     BOOST_CHECK(overlap_aabb == overlap_obb);
00227   }
00228   std::cout << std::endl;
00229 }
00230 
00231 BOOST_AUTO_TEST_CASE(mesh_mesh)
00232 {
00233   std::vector<Vec3f> p1, p2;
00234   std::vector<Triangle> t1, t2;
00235   boost::filesystem::path path(TEST_RESOURCES_DIR);
00236   
00237   loadOBJFile((path / "env.obj").string().c_str(), p1, t1);
00238   loadOBJFile((path / "rob.obj").string().c_str(), p2, t2);
00239 
00240   std::vector<Transform3f> transforms;
00241   FCL_REAL extents[] = {-3000, -3000, 0, 3000, 3000, 3000};
00242   std::size_t n = 10;
00243   bool verbose = false;
00244 
00245   generateRandomTransforms(extents, transforms, n);
00246 
00247   // collision
00248   for(std::size_t i = 0; i < transforms.size(); ++i)
00249   {
00250     global_pairs.clear();
00251     global_pairs_now.clear();
00252 
00253     collide_Test<OBB>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEAN, verbose);
00254 
00255     collide_Test<OBB>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_BV_CENTER, verbose);
00256     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00257     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00258     {
00259       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00260       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00261     }
00262 
00263     collide_Test<OBB>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEDIAN, verbose);
00264     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00265     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00266     {
00267       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00268       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00269     }
00270 
00271     collide_Test<RSS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEAN, verbose);
00272     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00273     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00274     {
00275       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00276       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00277     }
00278 
00279     collide_Test<RSS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_BV_CENTER, verbose);
00280     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00281     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00282     {
00283       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00284       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00285     }
00286 
00287     collide_Test<RSS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEDIAN, verbose);
00288     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00289     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00290     {
00291       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00292       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00293     }
00294 
00295     collide_Test<AABB>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEAN, verbose);
00296     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00297     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00298     {
00299       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00300       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00301     }
00302 
00303     collide_Test<AABB>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_BV_CENTER, verbose);
00304     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00305     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00306     {
00307       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00308       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00309     }
00310 
00311     collide_Test<AABB>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEDIAN, verbose);
00312     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00313     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00314     {
00315       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00316       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00317     }
00318 
00319     collide_Test<KDOP<24> >(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEAN, verbose);
00320     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00321     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00322     {
00323       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00324       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00325     }
00326 
00327     collide_Test<KDOP<24> >(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_BV_CENTER, verbose);
00328     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00329     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00330     {
00331       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00332       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00333     }
00334 
00335     collide_Test<KDOP<24> >(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEDIAN, verbose);
00336     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00337     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00338     {
00339       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00340       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00341     }
00342 
00343     collide_Test<KDOP<18> >(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEAN, verbose);
00344     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00345     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00346     {
00347       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00348       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00349     }
00350 
00351     collide_Test<KDOP<18> >(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_BV_CENTER, verbose);
00352     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00353     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00354     {
00355       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00356       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00357     }
00358 
00359     collide_Test<KDOP<18> >(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEDIAN, verbose);
00360     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00361     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00362     {
00363       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00364       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00365     }
00366 
00367     collide_Test<KDOP<16> >(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEAN, verbose);
00368     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00369     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00370     {
00371       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00372       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00373     }
00374 
00375     collide_Test<KDOP<16> >(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_BV_CENTER, verbose);
00376     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00377     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00378     {
00379       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00380       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00381     }
00382 
00383     collide_Test<KDOP<16> >(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEDIAN, verbose);
00384     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00385     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00386     {
00387       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00388       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00389     }
00390 
00391     collide_Test2<OBB>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEAN, verbose);
00392     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00393     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00394     {
00395       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00396       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00397     }
00398 
00399     collide_Test2<OBB>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_BV_CENTER, verbose);
00400     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00401     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00402     {
00403       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00404       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00405     }
00406 
00407     collide_Test2<OBB>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEDIAN, verbose);
00408     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00409     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00410     {
00411       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00412       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00413     }
00414 
00415     collide_Test2<RSS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEAN, verbose);
00416     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00417     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00418     {
00419       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00420       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00421     }
00422 
00423     collide_Test2<RSS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_BV_CENTER, verbose);
00424     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00425     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00426     {
00427       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00428       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00429     }
00430 
00431     collide_Test2<RSS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEDIAN, verbose);
00432     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00433     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00434     {
00435       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00436       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00437     }
00438 
00439     collide_Test2<AABB>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEAN, verbose);
00440     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00441     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00442     {
00443       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00444       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00445     }
00446 
00447     collide_Test2<AABB>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_BV_CENTER, verbose);
00448     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00449     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00450     {
00451       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00452       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00453     }
00454 
00455     collide_Test2<AABB>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEDIAN, verbose);
00456     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00457     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00458     {
00459       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00460       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00461     }
00462 
00463     collide_Test2<KDOP<24> >(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEAN, verbose);
00464     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00465     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00466     {
00467       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00468       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00469     }
00470 
00471     collide_Test2<KDOP<24> >(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_BV_CENTER, verbose);
00472     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00473     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00474     {
00475       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00476       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00477     }
00478 
00479     collide_Test2<KDOP<24> >(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEDIAN, verbose);
00480     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00481     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00482     {
00483       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00484       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00485     }
00486 
00487     collide_Test2<KDOP<18> >(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEAN, verbose);
00488     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00489     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00490     {
00491       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00492       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00493     }
00494 
00495     collide_Test2<KDOP<18> >(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_BV_CENTER, verbose);
00496     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00497     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00498     {
00499       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00500       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00501     }
00502 
00503     collide_Test2<KDOP<18> >(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEDIAN, verbose);
00504     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00505     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00506     {
00507       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00508       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00509     }
00510 
00511     collide_Test2<KDOP<16> >(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEAN, verbose);
00512     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00513     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00514     {
00515       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00516       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00517     }
00518 
00519     collide_Test2<KDOP<16> >(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_BV_CENTER, verbose);
00520     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00521     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00522     {
00523       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00524       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00525     }
00526 
00527     collide_Test2<KDOP<16> >(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEDIAN, verbose);
00528     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00529     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00530     {
00531       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00532       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00533     }
00534 
00535     collide_Test_Oriented<OBB, MeshCollisionTraversalNodeOBB>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEAN, verbose);
00536 
00537     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00538     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00539     {
00540       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00541       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00542     }
00543 
00544     collide_Test_Oriented<OBB, MeshCollisionTraversalNodeOBB>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_BV_CENTER, verbose);
00545 
00546     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00547     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00548     {
00549       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00550       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00551     }
00552 
00553     collide_Test_Oriented<OBB, MeshCollisionTraversalNodeOBB>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEDIAN, verbose);
00554     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00555     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00556     {
00557       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00558       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00559     }
00560 
00561     collide_Test_Oriented<RSS, MeshCollisionTraversalNodeRSS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEAN, verbose);
00562     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00563     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00564     {
00565       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00566       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00567     }
00568 
00569     collide_Test_Oriented<RSS, MeshCollisionTraversalNodeRSS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_BV_CENTER, verbose);
00570     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00571     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00572     {
00573       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00574       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00575     }
00576 
00577     collide_Test_Oriented<RSS, MeshCollisionTraversalNodeRSS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEDIAN, verbose);
00578     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00579     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00580     {
00581       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00582       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00583     }
00584 
00585     test_collide_func<RSS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEDIAN);
00586     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00587     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00588     {
00589       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00590       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00591     }
00592 
00593     test_collide_func<OBB>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEDIAN);
00594     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00595     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00596     {
00597       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00598       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00599     }
00600 
00601     test_collide_func<AABB>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEDIAN);
00602     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00603     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00604     {
00605       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00606       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00607     }
00608 
00609     
00610     collide_Test<kIOS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEAN, verbose);
00611     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00612     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00613     {
00614       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00615       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00616     }
00617 
00618     collide_Test<kIOS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEDIAN, verbose);
00619     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00620     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00621     {
00622       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00623       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00624     }
00625 
00626     collide_Test<kIOS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_BV_CENTER, verbose);
00627     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00628     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00629     {
00630       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00631       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00632     }
00633 
00634     collide_Test2<kIOS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEAN, verbose);
00635     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00636     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00637     {
00638       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00639       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00640     }
00641 
00642     collide_Test2<kIOS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEDIAN, verbose);
00643     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00644     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00645     {
00646       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00647       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00648     }
00649 
00650     collide_Test2<kIOS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_BV_CENTER, verbose);
00651     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00652     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00653     {
00654       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00655       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00656     }
00657     
00658     collide_Test_Oriented<kIOS, MeshCollisionTraversalNodekIOS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEAN, verbose);
00659     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00660     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00661     {
00662       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00663       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00664     }
00665 
00666     collide_Test_Oriented<kIOS, MeshCollisionTraversalNodekIOS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEDIAN, verbose);
00667     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00668     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00669     {
00670       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00671       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00672     }
00673 
00674     collide_Test_Oriented<kIOS, MeshCollisionTraversalNodekIOS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_BV_CENTER, verbose);
00675     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00676     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00677     {
00678       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00679       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00680     }
00681 
00682     test_collide_func<kIOS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEAN);
00683     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00684     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00685     {
00686       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00687       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00688     }
00689 
00690     test_collide_func<kIOS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEDIAN);
00691     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00692     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00693     {
00694       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00695       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00696     }
00697 
00698     test_collide_func<kIOS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_BV_CENTER);
00699     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00700     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00701     {
00702       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00703       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00704     }
00705 
00706     collide_Test<OBBRSS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEAN, verbose);
00707     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00708     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00709     {
00710       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00711       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00712     }
00713 
00714     collide_Test<OBBRSS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEDIAN, verbose);
00715     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00716     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00717     {
00718       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00719       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00720     }
00721 
00722     collide_Test<OBBRSS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_BV_CENTER, verbose);
00723     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00724     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00725     {
00726       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00727       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00728     }
00729 
00730     collide_Test2<OBBRSS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEAN, verbose);
00731     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00732     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00733     {
00734       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00735       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00736     }
00737 
00738     collide_Test2<OBBRSS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEDIAN, verbose);
00739     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00740     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00741     {
00742       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00743       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00744     }
00745 
00746     collide_Test2<OBBRSS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_BV_CENTER, verbose);
00747     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00748     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00749     {
00750       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00751       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00752     }
00753     
00754     collide_Test_Oriented<OBBRSS, MeshCollisionTraversalNodeOBBRSS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEAN, verbose);
00755     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00756     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00757     {
00758       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00759       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00760     }
00761 
00762     collide_Test_Oriented<OBBRSS, MeshCollisionTraversalNodeOBBRSS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEDIAN, verbose);
00763     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00764     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00765     {
00766       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00767       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00768     }
00769 
00770     collide_Test_Oriented<OBBRSS, MeshCollisionTraversalNodeOBBRSS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_BV_CENTER, verbose);
00771     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00772     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00773     {
00774       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00775       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00776     }
00777 
00778     test_collide_func<OBBRSS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEAN);
00779     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00780     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00781     {
00782       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00783       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00784     }
00785 
00786     test_collide_func<OBBRSS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_MEDIAN);
00787     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00788     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00789     {
00790       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00791       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00792     }
00793 
00794     test_collide_func<OBBRSS>(transforms[i], p1, t1, p2, t2, SPLIT_METHOD_BV_CENTER);
00795     BOOST_CHECK(global_pairs.size() == global_pairs_now.size());
00796     for(std::size_t j = 0; j < global_pairs.size(); ++j)
00797     {
00798       BOOST_CHECK(global_pairs[j].b1 == global_pairs_now[j].b1);
00799       BOOST_CHECK(global_pairs[j].b2 == global_pairs_now[j].b2);
00800     }
00801   }
00802 }
00803 
00804 
00805 template<typename BV>
00806 bool collide_Test2(const Transform3f& tf,
00807                    const std::vector<Vec3f>& vertices1, const std::vector<Triangle>& triangles1,
00808                    const std::vector<Vec3f>& vertices2, const std::vector<Triangle>& triangles2, SplitMethodType split_method, bool verbose)
00809 {
00810   BVHModel<BV> m1;
00811   BVHModel<BV> m2;
00812   m1.bv_splitter.reset(new BVSplitter<BV>(split_method));
00813   m2.bv_splitter.reset(new BVSplitter<BV>(split_method));
00814 
00815   std::vector<Vec3f> vertices1_new(vertices1.size());
00816   for(unsigned int i = 0; i < vertices1_new.size(); ++i)
00817   {
00818     vertices1_new[i] = tf.transform(vertices1[i]);
00819   }
00820 
00821 
00822   m1.beginModel();
00823   m1.addSubModel(vertices1_new, triangles1);
00824   m1.endModel();
00825 
00826   m2.beginModel();
00827   m2.addSubModel(vertices2, triangles2);
00828   m2.endModel();
00829 
00830   Transform3f pose1, pose2;
00831 
00832   CollisionResult local_result;
00833   MeshCollisionTraversalNode<BV> node;
00834 
00835   if(!initialize<BV>(node, m1, pose1, m2, pose2,
00836                      CollisionRequest(num_max_contacts, enable_contact), local_result))
00837     std::cout << "initialize error" << std::endl;
00838 
00839   node.enable_statistics = verbose;
00840 
00841   collide(&node);
00842 
00843 
00844   if(local_result.numContacts() > 0)
00845   {
00846     if(global_pairs.size() == 0)
00847     {
00848       local_result.getContacts(global_pairs);
00849       std::sort(global_pairs.begin(), global_pairs.end());
00850     }
00851     else
00852     {
00853       local_result.getContacts(global_pairs_now);
00854       std::sort(global_pairs_now.begin(), global_pairs_now.end());
00855     }
00856 
00857 
00858     if(verbose)
00859       std::cout << "in collision " << local_result.numContacts() << ": " << std::endl;
00860     if(verbose) std::cout << node.num_bv_tests << " " << node.num_leaf_tests << std::endl;
00861     return true;
00862   }
00863   else
00864   {
00865     if(verbose) std::cout << "collision free " << std::endl;
00866     if(verbose) std::cout << node.num_bv_tests << " " << node.num_leaf_tests << std::endl;
00867     return false;
00868   }
00869 }
00870 
00871 template<typename BV>
00872 bool collide_Test(const Transform3f& tf,
00873                   const std::vector<Vec3f>& vertices1, const std::vector<Triangle>& triangles1,
00874                   const std::vector<Vec3f>& vertices2, const std::vector<Triangle>& triangles2, SplitMethodType split_method, bool verbose)
00875 {
00876   BVHModel<BV> m1;
00877   BVHModel<BV> m2;
00878   m1.bv_splitter.reset(new BVSplitter<BV>(split_method));
00879   m2.bv_splitter.reset(new BVSplitter<BV>(split_method));
00880 
00881   m1.beginModel();
00882   m1.addSubModel(vertices1, triangles1);
00883   m1.endModel();
00884 
00885   m2.beginModel();
00886   m2.addSubModel(vertices2, triangles2);
00887   m2.endModel();
00888 
00889   Transform3f pose1(tf), pose2;
00890 
00891   CollisionResult local_result;
00892   MeshCollisionTraversalNode<BV> node;
00893 
00894   if(!initialize<BV>(node, m1, pose1, m2, pose2,
00895                      CollisionRequest(num_max_contacts, enable_contact), local_result))
00896     std::cout << "initialize error" << std::endl;
00897 
00898   node.enable_statistics = verbose;
00899 
00900   collide(&node);
00901 
00902 
00903   if(local_result.numContacts() > 0)
00904   {
00905     if(global_pairs.size() == 0)
00906     {
00907       local_result.getContacts(global_pairs);
00908       std::sort(global_pairs.begin(), global_pairs.end());
00909     }
00910     else
00911     {
00912       local_result.getContacts(global_pairs_now);
00913       std::sort(global_pairs_now.begin(), global_pairs_now.end());
00914     }
00915 
00916     if(verbose)
00917       std::cout << "in collision " << local_result.numContacts() << ": " << std::endl;
00918     if(verbose) std::cout << node.num_bv_tests << " " << node.num_leaf_tests << std::endl;
00919     return true;
00920   }
00921   else
00922   {
00923     if(verbose) std::cout << "collision free " << std::endl;
00924     if(verbose) std::cout << node.num_bv_tests << " " << node.num_leaf_tests << std::endl;
00925     return false;
00926   }
00927 }
00928 
00929 template<typename BV, typename TraversalNode>
00930 bool collide_Test_Oriented(const Transform3f& tf,
00931                            const std::vector<Vec3f>& vertices1, const std::vector<Triangle>& triangles1,
00932                            const std::vector<Vec3f>& vertices2, const std::vector<Triangle>& triangles2, SplitMethodType split_method, bool verbose)
00933 {
00934   BVHModel<BV> m1;
00935   BVHModel<BV> m2;
00936   m1.bv_splitter.reset(new BVSplitter<BV>(split_method));
00937   m2.bv_splitter.reset(new BVSplitter<BV>(split_method));
00938 
00939   m1.beginModel();
00940   m1.addSubModel(vertices1, triangles1);
00941   m1.endModel();
00942 
00943   m2.beginModel();
00944   m2.addSubModel(vertices2, triangles2);
00945   m2.endModel();
00946 
00947   Transform3f pose1(tf), pose2;
00948 
00949   CollisionResult local_result;
00950   TraversalNode node;
00951   if(!initialize(node, (const BVHModel<BV>&)m1, pose1, (const BVHModel<BV>&)m2, pose2, 
00952                  CollisionRequest(num_max_contacts, enable_contact), local_result))
00953     std::cout << "initialize error" << std::endl;
00954 
00955   node.enable_statistics = verbose;
00956 
00957   collide(&node);
00958 
00959   if(local_result.numContacts() > 0)
00960   {
00961     if(global_pairs.size() == 0)
00962     {
00963       local_result.getContacts(global_pairs);
00964       std::sort(global_pairs.begin(), global_pairs.end());
00965     }
00966     else
00967     {
00968       local_result.getContacts(global_pairs_now);
00969       std::sort(global_pairs_now.begin(), global_pairs_now.end());
00970     }
00971 
00972     if(verbose)
00973       std::cout << "in collision " << local_result.numContacts() << ": " << std::endl;
00974     if(verbose) std::cout << node.num_bv_tests << " " << node.num_leaf_tests << std::endl;
00975     return true;
00976   }
00977   else
00978   {
00979     if(verbose) std::cout << "collision free " << std::endl;
00980     if(verbose) std::cout << node.num_bv_tests << " " << node.num_leaf_tests << std::endl;
00981     return false;
00982   }
00983 }
00984 
00985 
00986 template<typename BV>
00987 bool test_collide_func(const Transform3f& tf,
00988                        const std::vector<Vec3f>& vertices1, const std::vector<Triangle>& triangles1,
00989                        const std::vector<Vec3f>& vertices2, const std::vector<Triangle>& triangles2, SplitMethodType split_method)
00990 {
00991   BVHModel<BV> m1;
00992   BVHModel<BV> m2;
00993   m1.bv_splitter.reset(new BVSplitter<BV>(split_method));
00994   m2.bv_splitter.reset(new BVSplitter<BV>(split_method));
00995 
00996   m1.beginModel();
00997   m1.addSubModel(vertices1, triangles1);
00998   m1.endModel();
00999 
01000   m2.beginModel();
01001   m2.addSubModel(vertices2, triangles2);
01002   m2.endModel();
01003 
01004   Transform3f pose1(tf), pose2;
01005 
01006   std::vector<Contact> contacts;
01007 
01008   CollisionRequest request(num_max_contacts, enable_contact);
01009   CollisionResult result;
01010   int num_contacts = collide(&m1, pose1, &m2, pose2, 
01011                              request, result);
01012         
01013   result.getContacts(contacts);
01014 
01015   global_pairs_now.resize(num_contacts);
01016 
01017   for(int i = 0; i < num_contacts; ++i)
01018   {
01019     global_pairs_now[i].b1 = contacts[i].b1;
01020     global_pairs_now[i].b2 = contacts[i].b2;
01021   }
01022 
01023   std::sort(global_pairs_now.begin(), global_pairs_now.end());
01024 
01025   if(num_contacts > 0) return true;
01026   else return false;
01027 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


fcl
Author(s): Jia Pan
autogenerated on Tue Jan 15 2013 16:05:30