mirror of https://github.com/CGAL/cgal
fixed benchmark by switching to Rigid_triangle_mesh_collision_detection
This commit is contained in:
parent
8e7b7da17c
commit
7dd2d0be13
|
|
@ -1,4 +1,4 @@
|
|||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
#include <CGAL/Surface_mesh.h>
|
||||
|
||||
#include <CGAL/Polygon_mesh_processing/intersection.h>
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
#include <CGAL/boost/graph/copy_face_graph.h>
|
||||
#include <CGAL/AABB_tree.h>
|
||||
#include <CGAL/AABB_traits_3.h>
|
||||
#include <CGAL/Polygon_mesh_processing/internal/AABB_traversal_traits_with_transformation.h>
|
||||
#include <CGAL/Rigid_triangle_mesh_collision_detection.h>
|
||||
#include <CGAL/AABB_face_graph_triangle_primitive.h>
|
||||
#include <CGAL/Side_of_triangle_mesh.h>
|
||||
|
||||
|
|
@ -19,12 +19,11 @@ typedef CGAL::Surface_mesh<K::Point_3> Surface_mesh;
|
|||
|
||||
typedef CGAL::AABB_face_graph_triangle_primitive<Surface_mesh> Primitive;
|
||||
typedef CGAL::AABB_traits_3<K, Primitive> Traits;
|
||||
//typedef CGAL::AABB_do_intersect_transform_traits<K, Primitive> Traits;
|
||||
typedef CGAL::AABB_tree<Traits> Tree;
|
||||
|
||||
namespace PMP = CGAL::Polygon_mesh_processing;
|
||||
|
||||
void naive_test(int k, const char* fname,
|
||||
void naive_test(int k, const std::string& fname,
|
||||
int& nb_inter, int& nb_no_inter, int& nb_include)
|
||||
{
|
||||
std::ifstream input(fname);
|
||||
|
|
@ -34,7 +33,7 @@ void naive_test(int k, const char* fname,
|
|||
CGAL::Aff_transformation_3<K> init1(CGAL::SCALING, 6.0);
|
||||
PMP::transform(init1, tm);
|
||||
CGAL::Bbox_3 box = PMP::bbox(tm);
|
||||
typedef CGAL::AABB_tree<Traits> Tree;
|
||||
|
||||
Tree tmTree(tm.faces_begin(), tm.faces_end(), tm);
|
||||
Tree tmTree2(tm2.faces_begin(), tm2.faces_end(), tm2);
|
||||
CGAL::Aff_transformation_3<K> init2(CGAL::TRANSLATION, - K::Vector_3(
|
||||
|
|
@ -87,7 +86,8 @@ void naive_test(int k, const char* fname,
|
|||
T0 = CGAL::Aff_transformation_3<K>(CGAL::TRANSLATION, -i*unit_vec);
|
||||
}
|
||||
}
|
||||
void test_no_collision(int k, const char* fname,
|
||||
|
||||
void test_no_collision(int k, const std::string &fname,
|
||||
int& nb_inter, int& nb_no_inter, int& nb_include)
|
||||
{
|
||||
std::ifstream input(fname);
|
||||
|
|
@ -98,9 +98,11 @@ void test_no_collision(int k, const char* fname,
|
|||
PMP::transform(init1, tm);
|
||||
CGAL::Bbox_3 box = PMP::bbox(tm);
|
||||
Tree tmTree(tm.faces_begin(), tm.faces_end(), tm);
|
||||
|
||||
Tree tmTree2(tm2.faces_begin(), tm2.faces_end(), tm2);
|
||||
CGAL::Aff_transformation_3<K> init2(CGAL::TRANSLATION, - K::Vector_3(
|
||||
(box.xmax()-box.xmin()),0,0));
|
||||
|
||||
PMP::transform(init2, tm2);
|
||||
|
||||
tmTree.build();
|
||||
|
|
@ -114,6 +116,12 @@ void test_no_collision(int k, const char* fname,
|
|||
|
||||
CGAL::Side_of_triangle_mesh<Surface_mesh, K,
|
||||
VPM, Tree> sotm1(tmTree);
|
||||
|
||||
CGAL::Rigid_triangle_mesh_collision_detection<Surface_mesh> collision_detection;
|
||||
|
||||
collision_detection.add_mesh(tm);
|
||||
collision_detection.add_mesh(tm2);
|
||||
|
||||
for(int i=1; i<k+1; ++i)
|
||||
{
|
||||
K::FT rot[9];
|
||||
|
|
@ -131,34 +139,24 @@ void test_no_collision(int k, const char* fname,
|
|||
rot[6], rot[7], rot[8]);
|
||||
CGAL::Aff_transformation_3<K> T1 = CGAL::Aff_transformation_3<K>(CGAL::TRANSLATION, i*unit_vec);
|
||||
CGAL::Aff_transformation_3<K> transfo = R*T1;
|
||||
tmTree2.traits().set_transformation(transfo);
|
||||
CGAL::Interval_nt_advanced::Protector protector;
|
||||
if(tmTree2.do_intersect(tmTree))
|
||||
|
||||
collision_detection.set_transformation(1, transfo);
|
||||
|
||||
std::vector< std::pair<std::size_t, bool> > res = collision_detection.get_all_intersections_and_inclusions(0);
|
||||
|
||||
if (res.empty())
|
||||
nb_no_inter++;
|
||||
else if(!res[0].second)
|
||||
++nb_inter;
|
||||
else
|
||||
{
|
||||
if(sotm1(transfo.transform(vpm2[*tm2.vertices().begin()])) != CGAL::ON_UNBOUNDED_SIDE)
|
||||
{
|
||||
++nb_include;
|
||||
}
|
||||
else
|
||||
{
|
||||
CGAL::Side_of_triangle_mesh<Surface_mesh, K,
|
||||
VPM, Tree> sotm2(tmTree2);
|
||||
if(sotm2(tm.point(*tm.vertices().begin())) != CGAL::ON_UNBOUNDED_SIDE)
|
||||
++nb_include;
|
||||
else
|
||||
++nb_no_inter;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, const char** argv)
|
||||
{
|
||||
int k = (argc>1) ? atoi(argv[1]) : 10;
|
||||
const char* path = (argc>2)?argv[2]:"data/handle"
|
||||
".off";
|
||||
int k = (argc>1) ? atoi(argv[1]) : 20;
|
||||
std::string path = (argc>2)?argv[2]: CGAL::data_file_path("meshes/handle.off");
|
||||
|
||||
std::cout<< k<<" steps in "<<path<<std::endl;
|
||||
int nb_inter(0), nb_no_inter(0), nb_include(0),
|
||||
|
|
@ -167,11 +165,11 @@ int main(int argc, const char** argv)
|
|||
naive_test(k, path, naive_inter, naive_no_inter, naive_include);
|
||||
auto end = std::chrono::steady_clock::now();
|
||||
std::cout<<"Naive test : "<<naive_inter<<" collisions, "<<naive_include<<" inclusions, "<<naive_no_inter<<" no collision, calculated in "
|
||||
<<std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() << "μs." << std::endl;
|
||||
<<std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << " ms." << std::endl;
|
||||
start = std::chrono::steady_clock::now();
|
||||
test_no_collision(k, path,nb_inter, nb_no_inter, nb_include);
|
||||
end = std::chrono::steady_clock::now();
|
||||
std::cout<<"With transform_traits: "<<nb_inter<<" collisions, "<<nb_include<<" inclusions, "<<nb_no_inter<<" no collision, calculated in "
|
||||
<<std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() << "μs." << std::endl;
|
||||
<<std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << " ms." << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue