Adapted AABB_tree for new intersections

This commit is contained in:
Philipp Möller 2011-11-10 16:00:22 +00:00
parent 450f438518
commit bddbfcc8e4
6 changed files with 197 additions and 88 deletions

View File

@ -52,6 +52,12 @@ public:
typedef typename GeomTraits::Point_3 Point;
typedef typename std::pair<Object,typename Primitive::Id> Object_and_primitive_id;
template<typename Query>
struct Intersection_and_primitive_id {
typedef std::pair< typename IT< Query, typename Primitive::Datum >::result_type, typename Primitive::Id > type;
};
typedef typename std::pair<Point,typename Primitive::Id> Point_and_primitive_id;
// types for search tree
@ -160,6 +166,7 @@ Do_intersect do_intersect_object() {return Do_intersect();}
class Intersection {
public:
#if CGAL_INTERSECTION_VERSION < 2
template<typename Query>
boost::optional<typename AT::Object_and_primitive_id>
operator()(const Query& query, const typename AT::Primitive& primitive) const
@ -172,11 +179,18 @@ operator()(const Query& query, const typename AT::Primitive& primitive) const
else
return Intersection(Object_and_primitive_id(object,primitive.id()));
}
#else
template<typename Query>
typename Intersection_and_primitive_id<Query>::type
operator()(const Query& query, const typename AT::Primitive& primitive) const {
return std::make_pair(GeomTraits().intersect_3_object()(primitive.datum(),query),
primitive.id());
}
#endif
};
Intersection intersection_object() {return Intersection();}
// This should go down to the GeomTraits, i.e. the kernel
class Closest_point {
typedef typename AT::Point Point;

View File

@ -145,8 +145,14 @@ namespace CGAL {
// any intersection
template <typename Query>
boost::optional<Primitive_id> any_intersected_primitive(const Query& query) const;
template <typename Query>
boost::optional<Object_and_primitive_id> any_intersection(const Query& query) const;
#if CGAL_INTERSECTION_VERSION < 2
boost::optional<Object_and_primitive_id>
#else
typename AABB_traits::template Intersection_and_primitive_id<Query>::type
#endif
any_intersection(const Query& query) const;
// distance queries
FT squared_distance(const Point& query) const;
@ -422,9 +428,14 @@ namespace CGAL {
return out;
}
template <typename Tr>
template <typename Query>
#if CGAL_INTERSECTION_VERSION < 2
boost::optional<typename AABB_tree<Tr>::Object_and_primitive_id>
#else
typename Tr::template Intersection_and_primitive_id<Query>::type
#endif
AABB_tree<Tr>::any_intersection(const Query& query) const
{
using namespace CGAL::internal::AABB_tree;

View File

@ -76,13 +76,25 @@ class First_intersection_traits
typedef typename ::CGAL::AABB_tree<AABBTraits>::size_type size_type;
public:
typedef typename boost::optional<Object_and_primitive_id> Result;
typedef typename
#if CGAL_INTERSECTION_VERSION < 2
boost::optional<Object_and_primitive_id>
#else
AABBTraits::template Intersection_and_primitive_id<Query>::type
#endif
Result;
public:
First_intersection_traits()
: m_result()
{}
bool go_further() const { return !m_result; }
bool go_further() const {
#if CGAL_INTERSECTION_VERSION < 2
return !m_result;
#else
return !m_result.first;
#endif
}
void intersection(const Query& query, const Primitive& primitive)
{
@ -95,7 +107,13 @@ public:
}
Result result() const { return m_result; }
bool is_intersection_found() const { return m_result; }
bool is_intersection_found() const {
#if CGAL_INTERSECTION_VERSION < 2
return m_result;
#else
return m_result.first;
#endif
}
private:
Result m_result;
@ -126,12 +144,24 @@ public:
void intersection(const Query& query, const Primitive& primitive)
{
boost::optional<Object_and_primitive_id> intersection;
#if CGAL_INTERSECTION_VERSION < 2
boost::optional<Object_and_primitive_id>
#else
typename AABBTraits::template Intersection_and_primitive_id<Query>::type
#endif
intersection = AABBTraits().intersection_object()(query, primitive);
#if CGAL_INTERSECTION_VERSION < 2
if(intersection)
{
*m_out_it++ = *intersection;
}
#else
if(intersection.first)
{
*m_out_it++ = intersection;
}
#endif
}
bool do_intersect(const Query& query, const Node& node) const

View File

@ -29,6 +29,7 @@
#include <CGAL/AABB_polyhedron_triangle_primitive.h>
#include <CGAL/AABB_polyhedron_segment_primitive.h>
#include <boost/mem_fn.hpp>
double random_in(const double a,
const double b)
@ -98,10 +99,16 @@ void test_all_intersection_query_types(Tree& tree)
tree.all_intersected_primitives(segment,std::back_inserter(primitives));
// any_intersection
#if CGAL_INTERSECTION_VERSION < 2
boost::optional<Object_and_primitive_id> optional_object_and_primitive;
optional_object_and_primitive = tree.any_intersection(ray);
optional_object_and_primitive = tree.any_intersection(line);
optional_object_and_primitive = tree.any_intersection(segment);
#else
typename Tree::AABB_traits::template Intersection_and_primitive_id<Ray>::type r = tree.any_intersection(ray);
typename Tree::AABB_traits::template Intersection_and_primitive_id<Line>::type l = tree.any_intersection(line);
typename Tree::AABB_traits::template Intersection_and_primitive_id<Segment>::type s = tree.any_intersection(segment);
#endif
// any_intersected_primitive
boost::optional<typename Primitive::Id> optional_primitive;
@ -110,10 +117,19 @@ void test_all_intersection_query_types(Tree& tree)
optional_primitive = tree.any_intersected_primitive(segment);
// all_intersections
#if CGAL_INTERSECTION_VERSION < 2
std::list<Object_and_primitive_id> 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));
#else
std::list<typename Tree::AABB_traits::template Intersection_and_primitive_id<Ray>::type> intersections_r;
std::list<typename Tree::AABB_traits::template Intersection_and_primitive_id<Line>::type> intersections_l;
std::list<typename Tree::AABB_traits::template Intersection_and_primitive_id<Segment>::type> intersections_s;
tree.all_intersections(ray,std::back_inserter(intersections_r));
tree.all_intersections(line,std::back_inserter(intersections_l));
tree.all_intersections(segment,std::back_inserter(intersections_s));
#endif
}
@ -315,6 +331,7 @@ class Naive_implementations
typedef boost::optional<Object_and_primitive_id> Intersection_result;
public:
template<typename Query>
bool do_intersect(const Query& query, Polyhedron& p) const
@ -368,9 +385,17 @@ public:
Polyhedron_primitive_iterator it = Pr_generator().begin(p);
for ( ; it != Pr_generator().end(p) ; ++it )
{
Intersection_result intersection = Traits().intersection_object()(query, Pr(it));
#if CGAL_INTERSECTION_VERSION < 2
Intersection_result
intersection = Traits().intersection_object()(query, Pr(it));
if ( intersection )
*out++ = *intersection;
#else
typename Traits::template Intersection_and_primitive_id<Query>::type
intersection = Traits().intersection_object()(query, Pr(it));
if ( intersection.first )
*out++ = intersection;
#endif
}
return out;
@ -674,7 +699,17 @@ private:
Tree& tree,
const Naive_implementation& naive) const
{
typedef std::vector<Object_and_primitive_id> Obj_Id_vector;
typedef
#if CGAL_INTERSECTION_VERSION < 2
Object_and_primitive_id
#else
typename Tree::AABB_traits::template Intersection_and_primitive_id<Query>::type
#endif
Obj_type;
typedef
std::vector<Obj_type>
Obj_Id_vector;
Obj_Id_vector intersections_naive;
naive_timer.start();
@ -693,7 +728,8 @@ private:
std::transform(intersections_naive.begin(),
intersections_naive.end(),
std::back_inserter(intersections_naive_id),
primitive_id);
boost::mem_fn(&Obj_type::second)
);
for ( typename Obj_Id_vector::iterator it = intersections_tree.begin() ;
it != intersections_tree.end() ;
@ -706,10 +742,15 @@ private:
}
// Any intersection test (do not count time here)
typedef boost::optional<Object_and_primitive_id> Any_intersection;
Any_intersection intersection = tree.any_intersection(query);
#if CGAL_INTERSECTION_VERSION < 2
boost::optional<Object_and_primitive_id>
#else
typename Tree::AABB_traits::template Intersection_and_primitive_id<Query>::type
#endif
intersection = tree.any_intersection(query);
// Check: verify we do get the result by naive method
#if CGAL_INTERSECTION_VERSION < 2
if ( intersection )
{
assert( std::find(intersections_naive_id.begin(),
@ -717,12 +758,21 @@ private:
intersection->second)
!= intersections_naive_id.end());
}
#else
if ( intersection.first )
{
assert( std::find(intersections_naive_id.begin(),
intersections_naive_id.end(),
intersection.second)
!= intersections_naive_id.end());
}
#endif
else if ( intersections_naive.size() != 0 )
assert(false);
}
static typename Primitive::Id primitive_id(const Object_and_primitive_id& o)
static typename Primitive::Id primitive_id_o(const Object_and_primitive_id& o)
{
return o.second;
}

View File

@ -22,6 +22,8 @@
//
//******************************************************************************
#define CGAL_INTERSECTION_VERSION 1
#include <fstream>
#include <iostream>

View File

@ -22,6 +22,8 @@
//
//******************************************************************************
#define CGAL_INTERSECTION_VERSION 2
#include <fstream>
#include <iostream>