remove requirements of having get_reference_point and get_datum in the traits

This commit is contained in:
Sébastien Loriot 2012-06-04 14:14:11 +00:00
parent 567e637484
commit 21283eab97
9 changed files with 106 additions and 50 deletions

1
.gitattributes vendored
View File

@ -51,6 +51,7 @@ AABB_tree/include/CGAL/AABB_polyhedron_triangle_primitive.h -text
AABB_tree/include/CGAL/AABB_primitive.h -text
AABB_tree/include/CGAL/AABB_traits.h -text
AABB_tree/include/CGAL/internal/AABB_tree/Has_nested_type_Shared_data.h -text
AABB_tree/include/CGAL/internal/AABB_tree/Primitive_helper.h -text
AABB_tree/test/AABB_tree/AABB_test_util.h -text
AABB_tree/test/AABB_tree/aabb_correctness_triangle_test.cpp -text
AABB_tree/test/AABB_tree/aabb_distance_edge_test.cpp -text

View File

@ -18,7 +18,7 @@ The concept is similar to \ccc{AABBPrimitive} except that some data stored outsi
\ccNestedType{Datum_reference}{The type of a reference to an element of type \ccc{Datum} returned by the \ccc{datum(const Shared_data&)} function.}
\ccNestedType{Shared_data}{An arbitrary type.}
\ccNestedType{Shared_data}{An arbitrary type default constructible.}
% variable name
\ccCreationVariable{primitive}

View File

@ -94,18 +94,15 @@ for which the class \ccc{AABB_tree<AT>} may receive a distance query.
\ccMethod{Closest_point closest_point_object();}{Returns the closest point constructor.}
\ccMethod{typename Primitive::Point_reference get_reference_point(const Primitive& p);}
{Returns the reference point of \ccc{p}. The \ccc{AABB_tree} will access the reference point of a primitive only through this function.}
\ccMethod{typename Primitive::Datum_reference get_datum(const Primitive& p);}
{Returns the datum of \ccc{p}. The \ccc{AABB_tree} will access the datum of a primitive only through this function.}
In addition, if \ccc{Primitive} is a model of the concept \ccc{AABBPrimitiveWithSharedData}, the following function is part of the concept:
\ccMethod{template <class ... T> void set_shared_data(T ... t);}
{the signature of that function must be the same as the static function \ccc{Primitive::construct_shared_data}. The type \ccc{Primitive} expects that the data constructed
by a call to \ccc{Primitive::construct_shared_data(t...)} is the one given back when accessing the reference point and the datum of a primitive.}
\ccMethod{const Primitive::Shared_data& shared_data() const;}{Returns the shared data of the primitive constructed after a call to \ccc{set_shared_data}. If no call to \ccc{set_shared_data}
has been done, Primitive::Shared_data() is returned.}
\ccHasModels
\ccc{AABB_traits<GeomTraits,Primitive>}.

View File

@ -94,11 +94,13 @@ class AABB_primitive<Id, ObjectPropertyMap, PointPropertyMap,Tag_false,Tag_true>
typename boost::property_traits< ObjectPropertyMap >::value_type m_datum;
PointPropertyMap m_pt_pmap;
public:
typedef const typename Base::Datum& Datum_reference;
AABB_primitive(Id id, ObjectPropertyMap obj_pmap=ObjectPropertyMap(), PointPropertyMap pt_pmap=PointPropertyMap())
: Base(id), m_datum( get(obj_pmap,id) ), m_pt_pmap(pt_pmap){}
const typename Base::Datum&
datum() const { return m_datum; }
Datum_reference datum() const { return m_datum; }
typename Base::Point_reference
reference_point() const { return get(m_pt_pmap,this->m_id); }
@ -139,15 +141,15 @@ class AABB_primitive<Id, ObjectPropertyMap, PointPropertyMap,Tag_true,Tag_true>
typename boost::property_traits< ObjectPropertyMap >::value_type m_datum;
public:
typedef PointPropertyMap Shared_data;
typedef const typename Base::Datum& Datum_reference;
AABB_primitive(Id id, ObjectPropertyMap obj_pmap=ObjectPropertyMap(), PointPropertyMap=PointPropertyMap())
: Base(id), m_datum( get(obj_pmap,id) ) {}
const typename Base::Datum&
datum(Shared_data) const { return m_datum; }
Datum_reference datum(Shared_data) const { return m_datum; }
typename Base::Point_reference
reference_point(Shared_data data) const { return get(data,this->m_id); }
reference_point(const Shared_data& data) const { return get(data,this->m_id); }
static Shared_data construct_shared_data(ObjectPropertyMap, PointPropertyMap pt) {return pt;}
};

View File

@ -29,8 +29,8 @@
#include <CGAL/Bbox_3.h>
#include <CGAL/AABB_intersections.h>
#include <CGAL/internal/AABB_tree/Has_nested_type_Shared_data.h>
#include <CGAL/internal/AABB_tree/Primitive_helper.h>
#include <boost/optional.hpp>
#include <boost/mpl/has_xxx.hpp>
#include <boost/bind.hpp>
namespace CGAL {
@ -38,34 +38,17 @@ namespace CGAL {
namespace internal{
//for backward compatibility (if auto is available, use it)
BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(Has_nested_type_Datum_reference,Datum_reference,false)
BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(Has_nested_type_Point_reference,Point_reference,false)
template<class Primitive,bool has_nested_type=Has_nested_type_Datum_reference<Primitive>::value>
struct Datum_result_type{ typedef typename Primitive::Datum_reference type; };
template<class Primitive>
struct Datum_result_type<Primitive,false>{ typedef typename Primitive::Datum type; };
template<class Primitive,bool has_nested_type=Has_nested_type_Point_reference<Primitive>::value>
struct Point_result_type{ typedef typename Primitive::Point_reference type; };
template<class Primitive>
struct Point_result_type<Primitive,false>{ typedef typename Primitive::Point type; };
//helper controlling whether extra data should be stored in the AABB_tree traits class
template <class Primitive, bool has_shared_data=Has_nested_type_Shared_data<Primitive>::value>
struct Primitive_helper;
struct AABB_traits_base;
template <class Primitive>
struct Primitive_helper<Primitive,false>{
typename Datum_result_type<Primitive>::type get_datum(const Primitive& p) const {return p.datum();}
typename Point_result_type<Primitive>::type get_reference_point(const Primitive& p) const {return p.reference_point();}
};
struct AABB_traits_base<Primitive,false>{};
template <class Primitive>
struct Primitive_helper<Primitive,true>{
struct AABB_traits_base<Primitive,true>{
typename Primitive::Shared_data m_primitive_data;
#ifndef CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES
@ -99,9 +82,7 @@ struct Primitive_helper<Primitive,true>{
m_primitive_data=PrimitiveType::construct_shared_data(t1,t2,t3,t4,t5);
}
#endif
typename Datum_result_type<Primitive>::type get_datum(const Primitive& p) const {return p.datum(m_primitive_data);}
typename Point_result_type<Primitive>::type get_reference_point(const Primitive& p) const {return p.reference_point(m_primitive_data);}
const typename Primitive::Shared_data& shared_data() const {return m_primitive_data;}
};
}
@ -113,7 +94,7 @@ struct Primitive_helper<Primitive,true>{
*/
template<typename GeomTraits, typename AABBPrimitive>
class AABB_traits:
public internal::Primitive_helper<AABBPrimitive>
public internal::AABB_traits_base<AABBPrimitive>
{
public:
typedef AABB_traits<GeomTraits, AABBPrimitive> AT;
@ -239,7 +220,7 @@ public:
template<typename Query>
bool operator()(const Query& q, const Primitive& pr) const
{
return GeomTraits().do_intersect_3_object()(q, m_traits.get_datum(pr));
return GeomTraits().do_intersect_3_object()(q, internal::Primitive_helper<AT>::get_datum(pr,m_traits));
}
};
@ -257,7 +238,7 @@ public:
{
typedef boost::optional<Object_and_primitive_id> Intersection;
CGAL::Object object = GeomTraits().intersect_3_object()(m_traits.get_datum(primitive),query);
CGAL::Object object = GeomTraits().intersect_3_object()(internal::Primitive_helper<AT>::get_datum(primitive,m_traits),query);
if ( object.empty() )
return Intersection();
else
@ -280,7 +261,7 @@ public:
Point operator()(const Point& p, const Primitive& pr, const Point& bound) const
{
return CGAL::nearest_point_3(p, m_traits.get_datum(pr), bound);
return CGAL::nearest_point_3(p, internal::Primitive_helper<AT>::get_datum(pr,m_traits), bound);
}
};
@ -326,7 +307,7 @@ private:
static Bounding_box compute_bbox (const Primitive& pr,
const AABB_traits<GeomTraits,AABBPrimitive>& traits)
{
return traits.get_datum(pr).bbox();
return internal::Primitive_helper<AT>::get_datum(pr,traits).bbox();
}
typedef enum { CGAL_AXIS_X = 0,
@ -336,11 +317,11 @@ private:
static Axis longest_axis(const Bounding_box& bbox);
/// Comparison functions
static bool less_x(const Primitive& pr1, const Primitive& pr2,const AABB_traits<GeomTraits,AABBPrimitive>& traits)
{ return traits.get_reference_point(pr1).x() < traits.get_reference_point(pr2).x(); }
{ return internal::Primitive_helper<AT>::get_reference_point(pr1,traits).x() < internal::Primitive_helper<AT>::get_reference_point(pr2,traits).x(); }
static bool less_y(const Primitive& pr1, const Primitive& pr2,const AABB_traits<GeomTraits,AABBPrimitive>& traits)
{ return traits.get_reference_point(pr1).y() < traits.get_reference_point(pr2).y(); }
{ return internal::Primitive_helper<AT>::get_reference_point(pr1,traits).y() < internal::Primitive_helper<AT>::get_reference_point(pr2,traits).y(); }
static bool less_z(const Primitive& pr1, const Primitive& pr2,const AABB_traits<GeomTraits,AABBPrimitive>& traits)
{ return traits.get_reference_point(pr1).z() < traits.get_reference_point(pr2).z(); }
{ return internal::Primitive_helper<AT>::get_reference_point(pr1,traits).z() < internal::Primitive_helper<AT>::get_reference_point(pr2,traits).z(); }
}; // end class AABB_traits

View File

@ -27,6 +27,7 @@
#include <CGAL/internal/AABB_tree/AABB_node.h>
#include <CGAL/internal/AABB_tree/AABB_search_tree.h>
#include <CGAL/internal/AABB_tree/Has_nested_type_Shared_data.h>
#include <CGAL/internal/AABB_tree/Primitive_helper.h>
#include <boost/optional.hpp>
#ifdef CGAL_HAS_THREADS
@ -342,7 +343,9 @@ public:
Point_and_primitive_id any_reference_point_and_id() const
{
CGAL_assertion(!empty());
return Point_and_primitive_id(m_traits.get_reference_point(m_primitives[0]), m_primitives[0].id());
return Point_and_primitive_id(
internal::Primitive_helper<AABB_traits>::get_reference_point(m_primitives[0],m_traits), m_primitives[0].id()
);
}
public:
@ -811,7 +814,11 @@ public:
points.reserve(m_primitives.size());
typename Primitives::const_iterator it;
for(it = m_primitives.begin(); it != m_primitives.end(); ++it)
points.push_back(Point_and_primitive_id(m_traits.get_reference_point(*it), it->id()));
points.push_back(
Point_and_primitive_id(
internal::Primitive_helper<AABB_traits>::get_reference_point(*it,m_traits), it->id()
)
);
// clears current KD tree
clear_search_tree();

View File

@ -70,7 +70,7 @@ public:
// constructors
AABB_triangle_primitive(Iterator it) : Base(it){}
static typename Base::Shared_data construct_primitive_data() {return typename Base::Shared_data();}
static typename Base::Shared_data construct_shared_data() {return typename Base::Shared_data();}
};
} // end namespace CGAL

View File

@ -0,0 +1,68 @@
// Copyright (c) 2012 INRIA Sophia-Antipolis (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
// You can redistribute it and/or modify it under the terms of the GNU
// General Public License as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// 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: svn+ssh://sloriot@scm.gforge.inria.fr/svn/cgal/branches/features/AABB_tree-one_primitive_per_object-sloriot/AABB_tree/include/CGAL/AABB_tree.h $
// $Id: AABB_tree.h 69132 2012-05-15 08:46:42Z sloriot $
//
//
// Author(s) : Sébastien Loriot
#ifndef CGAL_INTERNAL_AABB_TREE_PRIMITIVE_HELPER
#define CGAL_INTERNAL_AABB_TREE_PRIMITIVE_HELPER
#include <CGAL/internal/AABB_tree/Has_nested_type_Shared_data.h>
#include <boost/mpl/has_xxx.hpp>
namespace CGAL{
namespace internal{
//for backward compatibility: if Datum_reference and Point_reference are not defined in the primitive
//(using auto would solve the pb)
BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(Has_nested_type_Datum_reference,Datum_reference,false)
BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(Has_nested_type_Point_reference,Point_reference,false)
template<class Primitive,bool has_nested_type=Has_nested_type_Datum_reference<Primitive>::value>
struct Datum_result_type{ typedef typename Primitive::Datum_reference type; };
template<class Primitive>
struct Datum_result_type<Primitive,false>{ typedef typename Primitive::Datum type; };
template<class Primitive,bool has_nested_type=Has_nested_type_Point_reference<Primitive>::value>
struct Point_result_type{ typedef typename Primitive::Point_reference type; };
template<class Primitive>
struct Point_result_type<Primitive,false>{ typedef typename Primitive::Point type; };
//helper controlling whether extra data should be stored in the AABB_tree traits class
template <class AABBTraits, bool has_shared_data=Has_nested_type_Shared_data<typename AABBTraits::Primitive>::value>
struct Primitive_helper;
template <class AABBTraits>
struct Primitive_helper<AABBTraits,true>{
static typename Datum_result_type<typename AABBTraits::Primitive>::type get_datum(const typename AABBTraits::Primitive& p,const AABBTraits& traits)
{
return p.datum(traits.shared_data());
}
static typename Point_result_type<typename AABBTraits::Primitive>::type get_reference_point(const typename AABBTraits::Primitive& p,const AABBTraits& traits) {
return p.reference_point(traits.shared_data());
}
};
template <class AABBTraits>
struct Primitive_helper<AABBTraits,false>{
static typename Datum_result_type<typename AABBTraits::Primitive>::type get_datum(const typename AABBTraits::Primitive& p,const AABBTraits&) {return p.datum();}
static typename Point_result_type<typename AABBTraits::Primitive>::type get_reference_point(const typename AABBTraits::Primitive& p,const AABBTraits&) {return p.reference_point();}
};
} } //namespace CGAL::internal
#endif //CGAL_INTERNAL_AABB_TREE_PRIMITIVE_HELPER

View File

@ -29,7 +29,7 @@
#include <CGAL/AABB_FaceGraph_triangle_primitive.h>
#include <CGAL/AABB_HalfedgeGraph_segment_primitive.h>
#include <CGAL/internal/AABB_tree/Primitive_helper.h>
double random_in(const double a,
const double b)
@ -388,7 +388,7 @@ public:
assert ( it != Pr_generator().end(p) );
// Get a point on the primitive
Point closest_point = m_traits.get_reference_point(Pr(it));
Point closest_point = CGAL::internal::Primitive_helper<Traits>::get_reference_point(Pr(it),m_traits);
for ( ; it != Pr_generator().end(p) ; ++it )
{
@ -407,7 +407,7 @@ public:
// Get a point on the primitive
Pr closest_primitive = Pr(it);
Point closest_point = m_traits.get_reference_point(closest_primitive);
Point closest_point = CGAL::internal::Primitive_helper<Traits>::get_reference_point(closest_primitive,m_traits);
for ( ; it != Pr_generator().end(p) ; ++it )
{