mirror of https://github.com/CGAL/cgal
AABB tree: more on tests
This commit is contained in:
parent
e5b9f33cab
commit
7c56be7711
|
|
@ -30,6 +30,7 @@ AABB_tree/include/CGAL/AABB_triangle_primitive.h -text
|
|||
AABB_tree/include/CGAL/Triangle_3_line_3_intersection.h -text
|
||||
AABB_tree/test/AABB_tree/CMakeLists.txt -text
|
||||
AABB_tree/test/AABB_tree/aabb_intersection_triangle_test.cpp -text
|
||||
AABB_tree/test/AABB_tree/aabb_projection_segment_test.cpp -text
|
||||
AABB_tree/test/AABB_tree/aabb_projection_triangle_test.cpp -text
|
||||
AABB_tree/test/AABB_tree/cleanup.bat -text
|
||||
AABB_tree/test/AABB_tree/data/coverrear.off -text
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ typedef K::FT FT;
|
|||
typedef K::Point_3 Point;
|
||||
typedef K::Plane_3 Plane;
|
||||
typedef K::Vector_3 Vector;
|
||||
typedef K::Triangle_3 Triangle;
|
||||
typedef CGAL::Polyhedron_3<K> Polyhedron;
|
||||
typedef CGAL::AABB_polyhedron_edge_primitive<K,Polyhedron> Primitive;
|
||||
typedef CGAL::AABB_traits<K, Primitive> Traits;
|
||||
|
|
@ -51,11 +52,19 @@ int main(void)
|
|||
Polyhedron polyhedron;
|
||||
polyhedron.make_tetrahedron( p, q, r, s);
|
||||
|
||||
// constructs the AABB tree and the internal search tree for
|
||||
// efficient projection computations.
|
||||
Tree tree(polyhedron.edges_begin(),polyhedron.edges_end());
|
||||
Point base(0.2, 0.2, 0.2);
|
||||
Vector normal(0.1, 0.2, 0.3);
|
||||
Plane plane(base,normal);
|
||||
std::cout << tree.number_of_intersections(plane)
|
||||
<< " intersections(s) with plane" << std::endl;
|
||||
tree.construct_search_tree();
|
||||
|
||||
// counts #intersections with a triangle
|
||||
Triangle triangle(p,q,r);
|
||||
std::cout << tree.number_of_intersections(triangle)
|
||||
<< " intersections(s) with triangle" << std::endl;
|
||||
|
||||
// computes the closest point from a query point
|
||||
Point query(2.0, 2.0, 2.0);
|
||||
Point closest = tree.closest_point(query);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,22 +56,24 @@ int main(void)
|
|||
segments.push_back(Segment(a,c));
|
||||
segments.push_back(Segment(c,d));
|
||||
|
||||
// constructs the AABB tree and the internal search tree for
|
||||
// efficient projection computations.
|
||||
Tree tree(segments.begin(),segments.end());
|
||||
tree.construct_search_tree();
|
||||
|
||||
// counts #intersections with a plane
|
||||
Plane plane(a,b,d);
|
||||
std::cout << tree.number_of_intersections(plane)
|
||||
<< " intersections(s) with plane" << std::endl;
|
||||
|
||||
// counts #intersections with a triangle
|
||||
Triangle triangle(a,b,c);
|
||||
std::cout << tree.number_of_intersections(triangle)
|
||||
<< " intersections(s) with triangle" << std::endl;
|
||||
|
||||
// TOFIX: following does not compile due to intersection(const Sphere& sphere,
|
||||
// const P& pr,Projection&...function in AABB_traits.h
|
||||
|
||||
//Point hint(a);
|
||||
//Point query(2.0, 2.0, 2.0);
|
||||
//Point closest = tree.closest_point(query,hint);
|
||||
// computes the closest point from a query point
|
||||
Point query(2.0, 2.0, 2.0);
|
||||
Point closest = tree.closest_point(query);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ if ( CGAL_FOUND )
|
|||
|
||||
create_single_source_cgal_program("aabb_intersection_triangle_test.cpp")
|
||||
create_single_source_cgal_program("aabb_projection_triangle_test.cpp")
|
||||
create_single_source_cgal_program("aabb_projection_segment_test.cpp")
|
||||
|
||||
else()
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,120 @@
|
|||
// Copyright (c) 2009 INRIA Sophia-Antipolis (France).
|
||||
// All rights reserved.
|
||||
//
|
||||
// This file is part of CGAL (www.cgal.org); you may redistribute it under
|
||||
// the terms of the Q Public License version 1.0.
|
||||
// See the file LICENSE.QPL distributed with CGAL.
|
||||
//
|
||||
// Licensees holding a valid commercial license may use this file in
|
||||
// accordance with the commercial license agreement provided with the software.
|
||||
//
|
||||
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
||||
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// $URL: $
|
||||
// $Id: $
|
||||
//
|
||||
//
|
||||
// Author(s) : Pierre Alliez
|
||||
//
|
||||
//******************************************************************************
|
||||
// File Description :
|
||||
//
|
||||
//******************************************************************************
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <CGAL/Timer.h>
|
||||
|
||||
#include <CGAL/AABB_intersections.h>
|
||||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
#include <CGAL/Cartesian.h>
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
|
||||
#include <CGAL/AABB_tree.h>
|
||||
#include <CGAL/AABB_traits.h>
|
||||
#include <CGAL/Polyhedron_3.h>
|
||||
#include <CGAL/IO/Polyhedron_iostream.h>
|
||||
#include <CGAL/AABB_polyhedron_edge_primitive.h>
|
||||
|
||||
template <class Tree, class K>
|
||||
void test_speed(Tree& tree)
|
||||
{
|
||||
typedef typename K::FT FT;
|
||||
typedef typename K::Ray_3 Ray;
|
||||
typedef typename K::Point_3 Point;
|
||||
typedef typename K::Vector_3 Vector;
|
||||
|
||||
CGAL::Timer timer;
|
||||
unsigned int nb = 0;
|
||||
timer.start();
|
||||
Point query((FT)0.0, (FT)0.0, (FT)0.0);
|
||||
while(timer.time() < 1.0)
|
||||
{
|
||||
Point closest = tree.closest_point(query);
|
||||
nb++;
|
||||
}
|
||||
double speed = (double)nb / timer.time();
|
||||
std::cout << speed << " projections/s" << std::endl;
|
||||
timer.stop();
|
||||
}
|
||||
|
||||
template <class K>
|
||||
void test(const char *filename)
|
||||
{
|
||||
typedef typename K::FT FT;
|
||||
typedef typename K::Ray_3 Ray;
|
||||
typedef typename K::Point_3 Point;
|
||||
typedef typename K::Vector_3 Vector;
|
||||
typedef typename K::Segment_3 Segment;
|
||||
typedef CGAL::Polyhedron_3<K> Polyhedron;
|
||||
typedef CGAL::AABB_polyhedron_edge_primitive<K,Polyhedron> Primitive;
|
||||
typedef CGAL::AABB_traits<K, Primitive> Traits;
|
||||
typedef CGAL::AABB_tree<Traits> Tree;
|
||||
|
||||
Polyhedron polyhedron;
|
||||
std::ifstream ifs(filename);
|
||||
ifs >> polyhedron;
|
||||
|
||||
// constructs AABB tree and internal search KD-tree
|
||||
Tree tree(polyhedron.edges_begin(),polyhedron.edges_end());
|
||||
tree.construct_search_tree();
|
||||
|
||||
// call all tests
|
||||
test_speed<Tree,K>(tree);
|
||||
}
|
||||
|
||||
void test_kernels(const char *filename)
|
||||
{
|
||||
std::cout << std::endl;
|
||||
std::cout << "Polyhedron " << filename << std::endl;
|
||||
|
||||
std::cout << std::endl;
|
||||
std::cout << "Simple cartesian float kernel" << std::endl;
|
||||
test<CGAL::Simple_cartesian<float> >(filename);
|
||||
|
||||
std::cout << std::endl;
|
||||
std::cout << "Cartesian float kernel" << std::endl;
|
||||
test<CGAL::Cartesian<float> >(filename);
|
||||
|
||||
std::cout << std::endl;
|
||||
std::cout << "Simple cartesian double kernel" << std::endl;
|
||||
test<CGAL::Simple_cartesian<double> >(filename);
|
||||
|
||||
std::cout << std::endl;
|
||||
std::cout << "Cartesian double kernel" << std::endl;
|
||||
test<CGAL::Cartesian<double> >(filename);
|
||||
|
||||
std::cout << std::endl;
|
||||
std::cout << "Epic kernel" << std::endl;
|
||||
test<CGAL::Exact_predicates_inexact_constructions_kernel>(filename);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
std::cout << "AABB projection tests" << std::endl;
|
||||
test_kernels("./data/cube.off");
|
||||
test_kernels("./data/coverrear.off");
|
||||
test_kernels("./data/nested_spheres.off");
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -37,9 +37,8 @@
|
|||
#include <CGAL/IO/Polyhedron_iostream.h>
|
||||
#include <CGAL/AABB_polyhedron_triangle_primitive.h>
|
||||
|
||||
template <class Tree, class Polyhedron, class K>
|
||||
void test_speed(Tree& tree,
|
||||
Polyhedron& polyhedron)
|
||||
template <class Tree, class K>
|
||||
void test_speed(Tree& tree)
|
||||
{
|
||||
typedef typename K::FT FT;
|
||||
typedef typename K::Ray_3 Ray;
|
||||
|
|
@ -76,10 +75,13 @@ void test(const char *filename)
|
|||
std::ifstream ifs(filename);
|
||||
ifs >> polyhedron;
|
||||
|
||||
// construct AABB tree without internal search KD-tree
|
||||
// constructs AABB tree and internal search KD-tree with
|
||||
// the points of the polyhedron
|
||||
Tree tree(polyhedron.facets_begin(),polyhedron.facets_end());
|
||||
tree.construct_search_tree(polyhedron.points_begin(),polyhedron.points_end());
|
||||
test_speed<Tree,Polyhedron,K>(tree,polyhedron);
|
||||
|
||||
// call all tests
|
||||
test_speed<Tree,K>(tree);
|
||||
}
|
||||
|
||||
void test_kernels(const char *filename)
|
||||
|
|
@ -114,6 +116,5 @@ int main(void)
|
|||
test_kernels("./data/cube.off");
|
||||
test_kernels("./data/coverrear.off");
|
||||
test_kernels("./data/nested_spheres.off");
|
||||
test_kernels("./data/lucy.off");
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue