mirror of https://github.com/CGAL/cgal
AABB tree: test all intersection types for triangles
This commit is contained in:
parent
2421c82abe
commit
a8188eb668
|
|
@ -25,7 +25,6 @@
|
|||
|
||||
namespace CGAL
|
||||
{
|
||||
|
||||
template <class Traits>
|
||||
class AABB_search_tree
|
||||
{
|
||||
|
|
@ -35,10 +34,8 @@ namespace CGAL
|
|||
typedef typename CGAL::Search_traits_3<Traits> TreeTraits;
|
||||
typedef typename CGAL::Orthogonal_k_neighbor_search<TreeTraits> Neighbor_search;
|
||||
typedef typename Neighbor_search::Tree Tree;
|
||||
|
||||
private:
|
||||
Tree m_tree;
|
||||
|
||||
public:
|
||||
AABB_search_tree() {}
|
||||
~AABB_search_tree() {}
|
||||
|
|
@ -51,7 +48,6 @@ namespace CGAL
|
|||
|
||||
Point nearest_point(const Point& query)
|
||||
{
|
||||
// queries first nearest neighbor
|
||||
Neighbor_search search(m_tree, query, 1);
|
||||
return search.begin()->first;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,10 +42,10 @@ namespace CGAL {
|
|||
public:
|
||||
/// Traits types
|
||||
typedef typename AABBTraits::Primitive Primitive;
|
||||
typedef typename AABBTraits::Bounding_box Bounding_box;
|
||||
typedef typename AABBTraits::Projection_query Projection_query;
|
||||
typedef typename AABBTraits::Projection Projection;
|
||||
typedef typename AABBTraits::Bounding_box Bounding_box;
|
||||
typedef typename AABBTraits::Intersection Intersection;
|
||||
typedef typename AABBTraits::Projection_query Projection_query;
|
||||
private:
|
||||
typedef typename AABB_search_tree<AABBTraits> Search_tree;
|
||||
|
||||
|
|
@ -69,9 +69,8 @@ namespace CGAL {
|
|||
template<typename ConstPointIterator>
|
||||
void construct_search_tree(ConstPointIterator first, ConstPointIterator beyond);
|
||||
|
||||
/// Construct internal search tree from a point set taken on
|
||||
// the internal primitives
|
||||
void construct_search_tree();
|
||||
/// Construct internal search tree from a point set taken on the internal primitives
|
||||
void construct_search_tree(void);
|
||||
|
||||
template<typename Query>
|
||||
bool do_intersect(const Query& q) const;
|
||||
|
|
@ -295,17 +294,13 @@ namespace CGAL {
|
|||
|
||||
|
||||
private:
|
||||
// member data
|
||||
|
||||
// set of input primitives (halfedge or face handles)
|
||||
// set of input primitives
|
||||
std::vector<Primitive> m_data;
|
||||
// single root node
|
||||
Node* m_p_root;
|
||||
// single root node
|
||||
bool m_search_tree_constructed;
|
||||
|
||||
public:
|
||||
// search KD-tree
|
||||
Search_tree m_search_tree;
|
||||
bool m_search_tree_constructed;
|
||||
|
||||
private:
|
||||
// Disabled copy constructor & assignment operator
|
||||
|
|
@ -332,9 +327,11 @@ namespace CGAL {
|
|||
}
|
||||
|
||||
m_p_root = new Node[m_data.size()-1]();
|
||||
CGAL_assertion(m_p_root != NULL);
|
||||
m_p_root->expand(m_data.begin(), m_data.end(), m_data.size());
|
||||
}
|
||||
|
||||
// constructs the search KD tree from given points
|
||||
template<typename Tr>
|
||||
template<typename ConstPointIterator>
|
||||
void
|
||||
|
|
@ -345,13 +342,14 @@ namespace CGAL {
|
|||
m_search_tree_constructed = true;
|
||||
}
|
||||
|
||||
// constructs the search KD tree from interal primitives
|
||||
template<typename Tr>
|
||||
void AABB_tree<Tr>::construct_search_tree()
|
||||
void AABB_tree<Tr>::construct_search_tree(void)
|
||||
{
|
||||
// iterate over primitives to get points on them
|
||||
std::list<Projection_query> points;
|
||||
std::vector<Primitive>::const_iterator it;
|
||||
for(it = m_data.begin();it != m_data.end();it++)
|
||||
for(it = m_data.begin(); it != m_data.end(); it++)
|
||||
{
|
||||
const Primitive& pr = *it;
|
||||
points.push_back(pr.point_on());
|
||||
|
|
@ -378,8 +376,6 @@ namespace CGAL {
|
|||
return traversal_traits.is_intersection_found();
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename Tr>
|
||||
template<typename Query>
|
||||
int
|
||||
|
|
@ -435,7 +431,6 @@ namespace CGAL {
|
|||
return traversal_traits.is_intersection_found();
|
||||
}
|
||||
|
||||
|
||||
// closest point with user-specified hint
|
||||
template<typename Tr>
|
||||
typename AABB_tree<Tr>::Projection
|
||||
|
|
@ -448,12 +443,13 @@ namespace CGAL {
|
|||
return traversal_traits.projection();
|
||||
}
|
||||
|
||||
// closest point without hint
|
||||
// closest point without hint, the search KD-tree is queried for the
|
||||
// first nearest neighbor point to get a hint
|
||||
template<typename Tr>
|
||||
typename AABB_tree<Tr>::Projection
|
||||
AABB_tree<Tr>::closest_point(const Projection_query& query)
|
||||
{
|
||||
// construct search tree if needed
|
||||
// construct search KD-tree if needed
|
||||
if(!m_search_tree_constructed)
|
||||
construct_search_tree();
|
||||
|
||||
|
|
|
|||
|
|
@ -22,20 +22,77 @@
|
|||
//
|
||||
//******************************************************************************
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
#include <CGAL/Timer.h>
|
||||
#include <CGAL/AABB_tree.h>
|
||||
#include <CGAL/AABB_traits.h>
|
||||
|
||||
#include <CGAL/Cartesian.h>
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
|
||||
#include <CGAL/Polyhedron_3.h>
|
||||
#include <CGAL/IO/Polyhedron_iostream.h>
|
||||
|
||||
#include <CGAL/AABB_tree.h>
|
||||
#include <CGAL/AABB_traits.h>
|
||||
#include <CGAL/AABB_polyhedron_triangle_primitive.h>
|
||||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
|
||||
template <class Tree, class K>
|
||||
void test_all_query_types(Tree& tree)
|
||||
{
|
||||
std::cout << "Test all query types" << std::endl;
|
||||
|
||||
typedef K::FT FT;
|
||||
typedef K::Ray_3 Ray;
|
||||
typedef K::Line_3 Line;
|
||||
typedef K::Point_3 Point;
|
||||
typedef K::Vector_3 Vector;
|
||||
typedef K::Segment_3 Segment;
|
||||
typedef Tree::Primitive Primitive;
|
||||
typedef Tree::Intersection Intersection;
|
||||
|
||||
Point p((FT)-0.5, (FT)-0.5, (FT)-0.5);
|
||||
Point q((FT) 0.5, (FT) 0.5, (FT) 0.5);
|
||||
Ray ray(p,q);
|
||||
Ray line(p,q);
|
||||
Ray segment(p,q);
|
||||
bool success = false;
|
||||
|
||||
// do_intersect
|
||||
success = tree.do_intersect(ray);
|
||||
success = tree.do_intersect(line);
|
||||
success = tree.do_intersect(segment);
|
||||
|
||||
// number_of_intersections
|
||||
tree.number_of_intersections(ray);
|
||||
tree.number_of_intersections(line);
|
||||
tree.number_of_intersections(segment);
|
||||
|
||||
// all_intersected_primitives
|
||||
std::list<Primitive> primitives;
|
||||
tree.all_intersected_primitives(ray,std::back_inserter(primitives));
|
||||
tree.all_intersected_primitives(line,std::back_inserter(primitives));
|
||||
tree.all_intersected_primitives(segment,std::back_inserter(primitives));
|
||||
|
||||
// any_intersection
|
||||
Intersection intersection;
|
||||
success = tree.any_intersection(ray,intersection);
|
||||
success = tree.any_intersection(line,intersection);
|
||||
success = tree.any_intersection(segment,intersection);
|
||||
|
||||
// all_intersections
|
||||
std::list<Intersection> intersections;
|
||||
tree.all_intersections(ray,std::back_inserter(intersections));
|
||||
tree.all_intersections(line,std::back_inserter(intersections));
|
||||
tree.all_intersections(segment,std::back_inserter(intersections));
|
||||
}
|
||||
|
||||
template <class Tree, class Polyhedron, class K>
|
||||
void test_speed(Tree& tree,
|
||||
Polyhedron& polyhedron)
|
||||
{
|
||||
std::cout << "Test for speed" << std::endl;
|
||||
typedef K::FT FT;
|
||||
typedef K::Ray_3 Ray;
|
||||
typedef K::Point_3 Point;
|
||||
|
|
@ -69,27 +126,20 @@ void test(const char *filename)
|
|||
typedef CGAL::AABB_traits<K, Primitive> Traits;
|
||||
typedef CGAL::AABB_tree<Traits> Tree;
|
||||
|
||||
// load (triangle) polyhedral surface
|
||||
Polyhedron polyhedron;
|
||||
std::ifstream ifs(filename);
|
||||
ifs >> polyhedron;
|
||||
|
||||
// construct tree without internal KD-tree as we do not query
|
||||
// any projection.
|
||||
// construct tree (without internal KD-tree as we do not query any projection).
|
||||
Tree tree(polyhedron.facets_begin(),polyhedron.facets_end());
|
||||
|
||||
// TODO
|
||||
// - compare tree tests with exhaustive ones
|
||||
// - query with ray/line/segment
|
||||
|
||||
Point source((FT)0.5, (FT)0.5, (FT)0.5);
|
||||
Ray ray(source, Vector((FT)0.1, (FT)0.2, (FT)0.3));
|
||||
std::cout << tree.number_of_intersections(ray)
|
||||
<< " intersections(s) with ray" << std::endl;
|
||||
|
||||
// call tests
|
||||
test_all_query_types<Tree,K>(tree);
|
||||
test_speed<Tree,Polyhedron,K>(tree,polyhedron);
|
||||
}
|
||||
|
||||
void test_kernels(const char *filename)
|
||||
void test_several_kernels(const char *filename)
|
||||
{
|
||||
std::cout << std::endl;
|
||||
std::cout << "Polyhedron " << filename << std::endl;
|
||||
|
|
@ -97,9 +147,15 @@ void test_kernels(const char *filename)
|
|||
std::cout << "Simple cartesian float kernel" << std::endl;
|
||||
test<CGAL::Simple_cartesian<float> >(filename);
|
||||
|
||||
std::cout << "Cartesian float kernel" << std::endl;
|
||||
test<CGAL::Cartesian<float> >(filename);
|
||||
|
||||
std::cout << "Simple cartesian double kernel" << std::endl;
|
||||
test<CGAL::Simple_cartesian<double> >(filename);
|
||||
|
||||
std::cout << "Cartesian double kernel" << std::endl;
|
||||
test<CGAL::Cartesian<double> >(filename);
|
||||
|
||||
std::cout << "Epic kernel" << std::endl;
|
||||
test<CGAL::Exact_predicates_inexact_constructions_kernel>(filename);
|
||||
}
|
||||
|
|
@ -107,8 +163,8 @@ void test_kernels(const char *filename)
|
|||
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_several_kernels("../data/cube.off");
|
||||
test_several_kernels("../data/coverrear.off");
|
||||
test_several_kernels("../data/nested_spheres.off");
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue