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::Segment_3 Datum;
typedef typename Polyhedron::Halfedge_handle Id;
/// Self
typedef AABB_polyhedron_segment_primitive<GeomTraits,Polyhedron> Self;
/// Constructor
AABB_polyhedron_segment_primitive() {}
AABB_polyhedron_segment_primitive(const Id& handle)
: m_halfedge_handle(handle) { };
AABB_polyhedron_segment_primitive(const AABB_polyhedron_segment_primitive& primitive)
{
m_halfedge_handle = primitive.id();
}
AABB_polyhedron_segment_primitive(const Self& primitive)
: m_halfedge_handle(primitive.m_halfedge_handle) {}
// Default destructor, copy constructor and assignment operator are ok

View File

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

View File

@ -26,6 +26,9 @@
#include <CGAL/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,
const double b)
@ -54,6 +57,7 @@ typename K::Vector_3 random_vector()
return typename K::Vector_3(x,y,z);
}
template <class Tree, class K>
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>
void test_all_distance_query_types(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;
typedef typename Tree::Primitive Primitive;
typedef typename Tree::Point_and_primitive_id Point_and_primitive_id;
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 Tree::Primitive Primitive;
typedef typename Tree::Point_and_primitive_id Point_and_primitive_id;
Point query = random_point_in<K>(tree.bbox());
Point_and_primitive_id hint = tree.any_reference_point_and_id();
Point query = random_point_in<K>(tree.bbox());
Point_and_primitive_id hint = tree.any_reference_point_and_id();
FT sqd1 = tree.squared_distance(query);
FT sqd2 = tree.squared_distance(query,hint.first);
if(sqd1 != sqd2)
std::cout << "warning: different distances with and without hint";
FT sqd1 = tree.squared_distance(query);
FT sqd2 = tree.squared_distance(query,hint.first);
if(sqd1 != sqd2)
std::cout << "warning: different distances with and without hint";
Point p1 = tree.closest_point(query);
Point p2 = tree.closest_point(query,hint.first);
if(sqd1 != sqd2)
std::cout << "warning: different closest points with and without hint (possible, in case there are more than one)";
Point p1 = tree.closest_point(query);
Point p2 = tree.closest_point(query,hint.first);
if(sqd1 != sqd2)
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 pp2 = tree.closest_point_and_primitive(query,hint);
if(pp1.second != pp2.second)
std::cout << "warning: different closest primitives 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 pp2 = tree.closest_point_and_primitive(query,hint);
if(pp1.second != pp2.second)
std::cout << "warning: different closest primitives with and without hint (possible, in case there are more than one)";
}
template <class Tree, class K>
void test_distance_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;
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;
timer.start();
unsigned int nb = 0;
while(timer.time() < 1.0)
{
// picks a random point in the tree bbox
Point query = random_point_in<K>(tree.bbox());
Point closest = tree.closest_point(query);
nb++;
}
double speed = (double)nb / timer.time();
std::cout << speed << " distance queries/s" << std::endl;
timer.stop();
CGAL::Timer timer;
timer.start();
unsigned int nb = 0;
while(timer.time() < 1.0)
{
// picks a random point in the tree bbox
Point query = random_point_in<K>(tree.bbox());
Point closest = tree.closest_point(query);
nb++;
}
double speed = (double)nb / timer.time();
std::cout << speed << " distance queries/s" << std::endl;
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"
template <class K>
void test(const char *filename)
template<class K, class Tree, class Polyhedron>
void test_impl(Tree& tree, Polyhedron&)
{
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_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);
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)
{
std::cout << "AABB distance tests" << std::endl;
test_kernels("./data/cube.off");
test_kernels("./data/coverrear.off");
test_kernels("./data/nested_spheres.off");
test_kernels("./data/finger.off");
return 0;
std::cout << "AABB distance tests" << std::endl;
test_kernels<SEGMENT>("./data/cube.off");
test_kernels<SEGMENT>("./data/coverrear.off");
test_kernels<SEGMENT>("./data/nested_spheres.off");
test_kernels<SEGMENT>("./data/finger.off");
return 0;
}

View File

@ -62,20 +62,20 @@ void test_hint_strategies(Tree& tree, CGAL::Polyhedron_3<K>& polyhedron)
std::vector<Point> queries;
std::vector<Id> outputs1, outputs2, outputs3;
queries.reserve(NBQ);
outputs1.reserve(NBQ);
outputs2.reserve(NBQ);
outputs3.reserve(NBQ);
// size_t common_min = NBQ;
size_t counter;
for(size_t i = 0; i < NBQ; ++i)
queries.push_back(random_point_in<K>(tree.bbox()));
CGAL::spatial_sort(queries.begin(), queries.end());
CGAL::Timer timer;
timer.start();
counter = 0;
@ -84,12 +84,12 @@ void test_hint_strategies(Tree& tree, CGAL::Polyhedron_3<K>& polyhedron)
++counter;
}
timer.stop();
double speed = static_cast<double>(counter)/(counter == NBQ? timer.time(): 1.);
double speed = static_cast<double>(counter)/(counter == NBQ? timer.time(): 1.);
std::cout << "without hint: " << speed << " queries/s" << std::endl;
timer.reset();
Point_and_primitive_id hint = tree.any_reference_point_and_id();
timer.start();
counter = 0;
while(timer.time() < 1. && counter < NBQ) {
@ -97,94 +97,48 @@ void test_hint_strategies(Tree& tree, CGAL::Polyhedron_3<K>& polyhedron)
++counter;
}
timer.stop();
speed = static_cast<double>(counter)/(counter == NBQ? timer.time(): 1.);
speed = static_cast<double>(counter)/(counter == NBQ? timer.time(): 1.);
std::cout << "with spatial sort: " << speed << " queries/s" << std::endl;
timer.reset();
timer.reset();
tree.accelerate_distance_queries(polyhedron.points_begin(),polyhedron.points_end());
timer.start();
timer.start();
counter = 0;
while(timer.time() < 1. && counter < NBQ) {
outputs3.push_back(tree.closest_point_and_primitive(queries[counter]).second);
++counter;
}
timer.stop();
speed = static_cast<double>(counter)/(counter == NBQ? timer.time(): 1.);
speed = static_cast<double>(counter)/(counter == NBQ? timer.time(): 1.);
std::cout << "with KD-tree: " << speed << " queries/s" << std::endl << std::endl;
timer.stop();
timer.stop();
std::cout << "Consistency:" << std::endl;
if((counter = check_outputs(outputs1, outputs2, Id())) == 0)
std::cout << " without hint and spatial sort are consistent" << std::endl;
else
std::cout << "WARNING, without hint and spatial sort have " << counter << " inconsistencies (closest point on vertex/edge?)" << std::endl;
if((counter = check_outputs(outputs1, outputs3, Id())) == 0)
std::cout << " without hint and with KD-tree are consistent (modulo hint case)" << std::endl;
else
std::cout << "WARNING, without hint and with KD-tree have " << counter << " inconsistencies (closest point on vertex/edge? the hint case has been excluded)" << std::endl;
std::cout << std::endl;
}
template <class K>
void test(const char *filename)
template<class K, class Tree, class Polyhedron>
void test_impl(Tree& tree, Polyhedron& p)
{
typedef typename K::FT FT;
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);
test_hint_strategies<Tree,K>(tree, p);
}
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)
{
std::cout << "AABB hint strategies tests" << std::endl;
test_kernels("./data/cube.off");
test_kernels("./data/coverrear.off");
test_kernels("./data/nested_spheres.off");
test_kernels("./data/finger.off");
test_kernels<TRIANGLE>("./data/cube.off");
test_kernels<TRIANGLE>("./data/coverrear.off");
test_kernels<TRIANGLE>("./data/nested_spheres.off");
test_kernels<TRIANGLE>("./data/finger.off");
return 0;
}

View File

@ -37,65 +37,19 @@
#include "AABB_test_util.h"
template <class K>
void test(const char *filename)
template<class K, class Tree, class Polyhedron>
void test_impl(Tree& tree, Polyhedron&)
{
typedef typename K::FT FT;
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());
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);
test_distance_speed<Tree,K>(tree);
test_all_distance_query_types<Tree,K>(tree);
}
int main(void)
{
std::cout << "AABB distance tests" << std::endl;
test_kernels("./data/cube.off");
test_kernels("./data/coverrear.off");
test_kernels("./data/nested_spheres.off");
test_kernels("./data/finger.off");
return 0;
std::cout << "AABB distance tests" << std::endl;
test_kernels<TRIANGLE>("./data/cube.off");
test_kernels<TRIANGLE>("./data/coverrear.off");
test_kernels<TRIANGLE>("./data/nested_spheres.off");
test_kernels<TRIANGLE>("./data/finger.off");
return 0;
}

View File

@ -108,72 +108,19 @@ void test_speed(Tree& tree)
test_speed_for_query<Tree,K>(tree,SEGMENT_QUERY,"segment");
}
template <class K>
void test(const char *filename)
template<class K, class Tree, class Polyhedron>
void test_impl(Tree& tree, Polyhedron&)
{
typedef typename K::FT FT;
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;
// 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);
test_all_intersection_query_types<Tree,K>(tree);
test_speed<Tree,K>(tree);
}
int main(void)
{
std::cout << "AABB intersection tests" << std::endl;
test_kernels("./data/cube.off");
test_kernels("./data/coverrear.off");
test_kernels("./data/nested_spheres.off");
test_kernels("./data/finger.off");
test_kernels<TRIANGLE>("./data/cube.off");
test_kernels<TRIANGLE>("./data/coverrear.off");
test_kernels<TRIANGLE>("./data/nested_spheres.off");
test_kernels<TRIANGLE>("./data/finger.off");
return 0;
}