Test suite code factorization. Minor fix (return type) in AABB_tree.h.

This commit is contained in:
Stéphane Tayeb 2009-05-18 14:26:29 +00:00
parent d4be110f43
commit 729ba7be05
7 changed files with 207 additions and 288 deletions

View File

@ -40,16 +40,16 @@ namespace CGAL {
typedef typename GeomTraits::Point_3 Point; typedef typename GeomTraits::Point_3 Point;
typedef typename GeomTraits::Segment_3 Datum; typedef typename GeomTraits::Segment_3 Datum;
typedef typename Polyhedron::Halfedge_handle Id; typedef typename Polyhedron::Halfedge_handle Id;
/// Self
typedef AABB_polyhedron_segment_primitive<GeomTraits,Polyhedron> Self;
/// Constructor /// Constructor
AABB_polyhedron_segment_primitive() {} AABB_polyhedron_segment_primitive() {}
AABB_polyhedron_segment_primitive(const Id& handle) AABB_polyhedron_segment_primitive(const Id& handle)
: m_halfedge_handle(handle) { }; : m_halfedge_handle(handle) { };
AABB_polyhedron_segment_primitive(const AABB_polyhedron_segment_primitive& primitive) AABB_polyhedron_segment_primitive(const Self& primitive)
{ : m_halfedge_handle(primitive.m_halfedge_handle) {}
m_halfedge_handle = primitive.id();
}
// Default destructor, copy constructor and assignment operator are ok // Default destructor, copy constructor and assignment operator are ok

View File

@ -505,7 +505,7 @@ namespace CGAL {
template<typename Tr> template<typename Tr>
template<typename Query> template<typename Query>
typename Tr::size_type typename AABB_tree<Tr>::size_type
AABB_tree<Tr>::number_of_intersected_primitives(const Query& query) const AABB_tree<Tr>::number_of_intersected_primitives(const Query& query) const
{ {
Counting_traits<Query> traversal_traits; Counting_traits<Query> traversal_traits;

View File

@ -26,6 +26,9 @@
#include <CGAL/Cartesian.h> #include <CGAL/Cartesian.h>
#include <CGAL/Simple_cartesian.h> #include <CGAL/Simple_cartesian.h>
#include <CGAL/AABB_polyhedron_triangle_primitive.h>
#include <CGAL/AABB_polyhedron_segment_primitive.h>
double random_in(const double a, double random_in(const double a,
const double b) const double b)
@ -54,6 +57,7 @@ typename K::Vector_3 random_vector()
return typename K::Vector_3(x,y,z); return typename K::Vector_3(x,y,z);
} }
template <class Tree, class K> template <class Tree, class K>
void test_all_intersection_query_types(Tree& tree) void test_all_intersection_query_types(Tree& tree)
{ {
@ -115,54 +119,163 @@ void test_all_intersection_query_types(Tree& tree)
template <class Tree, class K> template <class Tree, class K>
void test_all_distance_query_types(Tree& tree) void test_all_distance_query_types(Tree& tree)
{ {
typedef typename K::FT FT; typedef typename K::FT FT;
typedef typename K::Ray_3 Ray; typedef typename K::Ray_3 Ray;
typedef typename K::Point_3 Point; typedef typename K::Point_3 Point;
typedef typename K::Vector_3 Vector; typedef typename K::Vector_3 Vector;
typedef typename Tree::Primitive Primitive; typedef typename Tree::Primitive Primitive;
typedef typename Tree::Point_and_primitive_id Point_and_primitive_id; typedef typename Tree::Point_and_primitive_id Point_and_primitive_id;
Point query = random_point_in<K>(tree.bbox()); Point query = random_point_in<K>(tree.bbox());
Point_and_primitive_id hint = tree.any_reference_point_and_id(); Point_and_primitive_id hint = tree.any_reference_point_and_id();
FT sqd1 = tree.squared_distance(query); FT sqd1 = tree.squared_distance(query);
FT sqd2 = tree.squared_distance(query,hint.first); FT sqd2 = tree.squared_distance(query,hint.first);
if(sqd1 != sqd2) if(sqd1 != sqd2)
std::cout << "warning: different distances with and without hint"; std::cout << "warning: different distances with and without hint";
Point p1 = tree.closest_point(query); Point p1 = tree.closest_point(query);
Point p2 = tree.closest_point(query,hint.first); Point p2 = tree.closest_point(query,hint.first);
if(sqd1 != sqd2) if(sqd1 != sqd2)
std::cout << "warning: different closest points with and without hint (possible, in case there are more than one)"; std::cout << "warning: different closest points with and without hint (possible, in case there are more than one)";
Point_and_primitive_id pp1 = tree.closest_point_and_primitive(query); Point_and_primitive_id pp1 = tree.closest_point_and_primitive(query);
Point_and_primitive_id pp2 = tree.closest_point_and_primitive(query,hint); Point_and_primitive_id pp2 = tree.closest_point_and_primitive(query,hint);
if(pp1.second != pp2.second) if(pp1.second != pp2.second)
std::cout << "warning: different closest primitives with and without hint (possible, in case there are more than one)"; std::cout << "warning: different closest primitives with and without hint (possible, in case there are more than one)";
} }
template <class Tree, class K> template <class Tree, class K>
void test_distance_speed(Tree& tree) void test_distance_speed(Tree& tree)
{ {
typedef typename K::FT FT; typedef typename K::FT FT;
typedef typename K::Ray_3 Ray; typedef typename K::Ray_3 Ray;
typedef typename K::Point_3 Point; typedef typename K::Point_3 Point;
typedef typename K::Vector_3 Vector; typedef typename K::Vector_3 Vector;
CGAL::Timer timer; CGAL::Timer timer;
timer.start(); timer.start();
unsigned int nb = 0; unsigned int nb = 0;
while(timer.time() < 1.0) while(timer.time() < 1.0)
{ {
// picks a random point in the tree bbox // picks a random point in the tree bbox
Point query = random_point_in<K>(tree.bbox()); Point query = random_point_in<K>(tree.bbox());
Point closest = tree.closest_point(query); Point closest = tree.closest_point(query);
nb++; nb++;
} }
double speed = (double)nb / timer.time(); double speed = (double)nb / timer.time();
std::cout << speed << " distance queries/s" << std::endl; std::cout << speed << " distance queries/s" << std::endl;
timer.stop(); timer.stop();
} }
//-------------------------------------------------------
// Helpers
//-------------------------------------------------------
enum Primitive_type {
SEGMENT, TRIANGLE
};
/**
* Primitive_generator : designed to tell void test<K,Primitive>(const char* filename)
* some information about which primitive to use.
*
* Must define:
* type Primitive
* type iterator
* iterator begin(Polyhedron&)
* iterator end(Polyhedron&)
*
* begin & end are used to build the AABB_tree.
*/
template<Primitive_type Primitive, class K, class Polyhedron>
struct Primitive_generator {};
template<class K, class Polyhedron>
struct Primitive_generator<SEGMENT, K, Polyhedron>
{
typedef CGAL::AABB_polyhedron_segment_primitive<K,Polyhedron> Primitive;
typedef typename Polyhedron::Edge_iterator iterator;
iterator begin(Polyhedron& p) { return p.edges_begin(); }
iterator end(Polyhedron& p) { return p.edges_end(); }
};
template<class K, class Polyhedron>
struct Primitive_generator<TRIANGLE, K, Polyhedron>
{
typedef CGAL::AABB_polyhedron_triangle_primitive<K,Polyhedron> Primitive;
typedef typename Polyhedron::Facet_iterator iterator;
iterator begin(Polyhedron& p) { return p.facets_begin(); }
iterator end(Polyhedron& p) { return p.facets_end(); }
};
/**
* Declaration only, implementation should be given in .cpp file
*/
template<class K, class Tree, class Polyhedron>
void test_impl(Tree& tree, Polyhedron& p);
/**
* Generic test method. Build AABB_tree and call test_impl()
*/
template <class K, Primitive_type Primitive>
void test(const char *filename)
{
typedef CGAL::Polyhedron_3<K> Polyhedron;
typedef Primitive_generator<Primitive,K,Polyhedron> Pr_generator;
typedef typename Pr_generator::Primitive Pr;
typedef CGAL::AABB_traits<K, Pr> Traits;
typedef CGAL::AABB_tree<Traits> Tree;
Polyhedron polyhedron;
std::ifstream ifs(filename);
ifs >> polyhedron;
// constructs AABB tree and internal search KD-tree with
// the points of the polyhedron
Tree tree(Pr_generator().begin(polyhedron),Pr_generator().end(polyhedron));
tree.accelerate_distance_queries(polyhedron.points_begin(),polyhedron.points_end());
// call all tests
test_impl<K,Tree,Polyhedron>(tree,polyhedron);
}
/**
* Generic test_kernel method. call test<K> for various kernel K.
*/
template<Primitive_type Primitive>
void test_kernels(const char *filename)
{
std::cout << std::endl;
std::cout << "Polyhedron " << filename << std::endl;
std::cout << "============================" << std::endl;
std::cout << std::endl;
std::cout << "Simple cartesian float kernel" << std::endl;
test<CGAL::Simple_cartesian<float>,Primitive>(filename);
std::cout << std::endl;
std::cout << "Cartesian float kernel" << std::endl;
test<CGAL::Cartesian<float>,Primitive>(filename);
std::cout << std::endl;
std::cout << "Simple cartesian double kernel" << std::endl;
test<CGAL::Simple_cartesian<double>,Primitive>(filename);
std::cout << std::endl;
std::cout << "Cartesian double kernel" << std::endl;
test<CGAL::Cartesian<double>,Primitive>(filename);
std::cout << std::endl;
std::cout << "Epic kernel" << std::endl;
test<CGAL::Exact_predicates_inexact_constructions_kernel,Primitive>(filename);
}

View File

@ -40,68 +40,19 @@
#include "AABB_test_util.h" #include "AABB_test_util.h"
template <class K> template<class K, class Tree, class Polyhedron>
void test(const char *filename) void test_impl(Tree& tree, Polyhedron&)
{ {
typedef typename K::FT FT; test_distance_speed<Tree,K>(tree);
typedef typename K::Ray_3 Ray; test_all_distance_query_types<Tree,K>(tree);
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_segment_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
Tree tree(polyhedron.edges_begin(),polyhedron.edges_end());
// constructs internal search KD-tree with points from the polyhedron vertex points
tree.accelerate_distance_queries(polyhedron.points_begin(),polyhedron.points_end());
// call all tests
test_distance_speed<Tree,K>(tree);
test_all_distance_query_types<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 << 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) int main(void)
{ {
std::cout << "AABB distance tests" << std::endl; std::cout << "AABB distance tests" << std::endl;
test_kernels("./data/cube.off"); test_kernels<SEGMENT>("./data/cube.off");
test_kernels("./data/coverrear.off"); test_kernels<SEGMENT>("./data/coverrear.off");
test_kernels("./data/nested_spheres.off"); test_kernels<SEGMENT>("./data/nested_spheres.off");
test_kernels("./data/finger.off"); test_kernels<SEGMENT>("./data/finger.off");
return 0; return 0;
} }

View File

@ -127,64 +127,18 @@ void test_hint_strategies(Tree& tree, CGAL::Polyhedron_3<K>& polyhedron)
std::cout << std::endl; std::cout << std::endl;
} }
template <class K> template<class K, class Tree, class Polyhedron>
void test(const char *filename) void test_impl(Tree& tree, Polyhedron& p)
{ {
typedef typename K::FT FT; test_hint_strategies<Tree,K>(tree, p);
typedef typename K::Ray_3 Ray;
typedef typename K::Point_3 Point;
typedef typename K::Vector_3 Vector;
typedef CGAL::Polyhedron_3<K> Polyhedron;
typedef CGAL::AABB_polyhedron_triangle_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 with
// the points of the polyhedron
Tree tree(polyhedron.facets_begin(),polyhedron.facets_end());
// tests hint strategies
test_hint_strategies<Tree,K>(tree, polyhedron);
} }
void test_kernels(const char *filename)
{
std::cout << std::endl;
std::cout << "Polyhedron " << filename << std::endl;
std::cout << "============================" << 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) int main(void)
{ {
std::cout << "AABB hint strategies tests" << std::endl; std::cout << "AABB hint strategies tests" << std::endl;
test_kernels("./data/cube.off"); test_kernels<TRIANGLE>("./data/cube.off");
test_kernels("./data/coverrear.off"); test_kernels<TRIANGLE>("./data/coverrear.off");
test_kernels("./data/nested_spheres.off"); test_kernels<TRIANGLE>("./data/nested_spheres.off");
test_kernels("./data/finger.off"); test_kernels<TRIANGLE>("./data/finger.off");
return 0; return 0;
} }

View File

@ -37,65 +37,19 @@
#include "AABB_test_util.h" #include "AABB_test_util.h"
template <class K> template<class K, class Tree, class Polyhedron>
void test(const char *filename) void test_impl(Tree& tree, Polyhedron&)
{ {
typedef typename K::FT FT; test_distance_speed<Tree,K>(tree);
typedef typename K::Ray_3 Ray; test_all_distance_query_types<Tree,K>(tree);
typedef typename K::Point_3 Point;
typedef typename K::Vector_3 Vector;
typedef CGAL::Polyhedron_3<K> Polyhedron;
typedef CGAL::AABB_polyhedron_triangle_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 with
// the points of the polyhedron
Tree tree(polyhedron.facets_begin(),polyhedron.facets_end());
tree.accelerate_distance_queries(polyhedron.points_begin(),polyhedron.points_end());
// call all tests
test_distance_speed<Tree,K>(tree);
test_all_distance_query_types<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 << 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) int main(void)
{ {
std::cout << "AABB distance tests" << std::endl; std::cout << "AABB distance tests" << std::endl;
test_kernels("./data/cube.off"); test_kernels<TRIANGLE>("./data/cube.off");
test_kernels("./data/coverrear.off"); test_kernels<TRIANGLE>("./data/coverrear.off");
test_kernels("./data/nested_spheres.off"); test_kernels<TRIANGLE>("./data/nested_spheres.off");
test_kernels("./data/finger.off"); test_kernels<TRIANGLE>("./data/finger.off");
return 0; return 0;
} }

View File

@ -108,72 +108,19 @@ void test_speed(Tree& tree)
test_speed_for_query<Tree,K>(tree,SEGMENT_QUERY,"segment"); test_speed_for_query<Tree,K>(tree,SEGMENT_QUERY,"segment");
} }
template <class K> template<class K, class Tree, class Polyhedron>
void test(const char *filename) void test_impl(Tree& tree, Polyhedron&)
{ {
typedef typename K::FT FT; test_all_intersection_query_types<Tree,K>(tree);
typedef typename K::Ray_3 Ray; test_speed<Tree,K>(tree);
typedef typename K::Point_3 Point;
typedef typename K::Vector_3 Vector;
typedef CGAL::Polyhedron_3<K> Polyhedron;
typedef CGAL::AABB_polyhedron_triangle_primitive<K,Polyhedron> Primitive;
typedef CGAL::AABB_traits<K, Primitive> Traits;
typedef CGAL::AABB_tree<Traits> Tree;
// loads triangle polyhedral surface
Polyhedron polyhedron;
std::ifstream ifs(filename);
ifs >> polyhedron;
// constructs tree
std::cout << "construct tree...";
CGAL::Timer timer;
timer.start();
Tree tree(polyhedron.facets_begin(),polyhedron.facets_end());
timer.stop();
std::cout << "done (" << timer.time() << " s)" << std::endl;
// tests rebuilding
tree.rebuild(polyhedron.facets_begin(),polyhedron.facets_end());
// calls all tests
test_all_intersection_query_types<Tree,K>(tree);
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 << 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) int main(void)
{ {
std::cout << "AABB intersection tests" << std::endl; std::cout << "AABB intersection tests" << std::endl;
test_kernels("./data/cube.off"); test_kernels<TRIANGLE>("./data/cube.off");
test_kernels("./data/coverrear.off"); test_kernels<TRIANGLE>("./data/coverrear.off");
test_kernels("./data/nested_spheres.off"); test_kernels<TRIANGLE>("./data/nested_spheres.off");
test_kernels("./data/finger.off"); test_kernels<TRIANGLE>("./data/finger.off");
return 0; return 0;
} }