diff --git a/AABB_tree/examples/AABB_tree/AABB_segment_3_example.cpp b/AABB_tree/examples/AABB_tree/AABB_segment_3_example.cpp index 93288489863..46a0c51118e 100644 --- a/AABB_tree/examples/AABB_tree/AABB_segment_3_example.cpp +++ b/AABB_tree/examples/AABB_tree/AABB_segment_3_example.cpp @@ -17,7 +17,7 @@ typedef K::Segment_3 Segment; typedef K::Triangle_3 Triangle; typedef std::list::iterator Iterator; -typedef CGAL::AABB_segment_primitive Primitive; +typedef CGAL::AABB_segment_primitive Primitive; typedef CGAL::AABB_traits Traits; typedef CGAL::AABB_tree Tree; diff --git a/AABB_tree/examples/AABB_tree/AABB_triangle_3_example.cpp b/AABB_tree/examples/AABB_tree/AABB_triangle_3_example.cpp index 3d21f70b0cb..1898ccc4edf 100644 --- a/AABB_tree/examples/AABB_tree/AABB_triangle_3_example.cpp +++ b/AABB_tree/examples/AABB_tree/AABB_triangle_3_example.cpp @@ -17,7 +17,7 @@ typedef K::Point_3 Point; typedef K::Triangle_3 Triangle; typedef std::list::iterator Iterator; -typedef CGAL::AABB_triangle_primitive Primitive; +typedef CGAL::AABB_triangle_primitive Primitive; typedef CGAL::AABB_traits AABB_triangle_traits; typedef CGAL::AABB_tree Tree; diff --git a/AABB_tree/include/CGAL/AABB_segment_primitive.h b/AABB_tree/include/CGAL/AABB_segment_primitive.h index ccd44f5db36..6dafc274081 100644 --- a/AABB_tree/include/CGAL/AABB_segment_primitive.h +++ b/AABB_tree/include/CGAL/AABB_segment_primitive.h @@ -24,43 +24,45 @@ #define CGAL_AABB_SEGMENT_PRIMITIVE_H_ #include -#include +#include #include namespace CGAL { namespace internal { - template + template struct Source_of_segment_3_iterator_property_map{ //classical typedefs - typedef typename CGAL::Kernel_traits< typename std::iterator_traits::value_type >::Kernel GeomTraits; typedef Iterator key_type; typedef typename GeomTraits::Point_3 value_type; - typedef const typename GeomTraits::Point_3& reference; + typedef typename cpp11::result_of< + typename GeomTraits::Construct_source_3(typename GeomTraits::Segment_3) + >::type reference; typedef boost::readable_property_map_tag category; - }; - //get function for property map - template - inline - typename Source_of_segment_3_iterator_property_map::reference - get(Source_of_segment_3_iterator_property_map, Iterator it) - { - return it->source(); - } + inline friend + typename Source_of_segment_3_iterator_property_map::reference + get(Source_of_segment_3_iterator_property_map, Iterator it) + { + return typename GeomTraits::Construct_source_3()( *it ); + } + }; }//namespace internal /*! * \ingroup PkgAABB_tree * Primitive type that uses as identifier an iterator with a 3D segment as `value_type`. - * The iterator from which the primitive is built should not be invalided + * The iterator from which the primitive is built should not be invalided * while the AABB tree holding the primitive is in use. * * \cgalModels `AABBPrimitive` * - * \tparam Iterator is a model of `ForwardIterator`, with `Segment_3` - * as value type + * \tparam GeomTraits is a traits class providing the nested type `Point_3` and `Segment_3`. + * It also provides the functor `Construct_source_3` that has an operator taking a `Segment_3` + * and returning its source as a type convertible to `Point_3`. + * In addition `Construct_source_3` must support the result_of protocol. + * \tparam Iterator is a model of `ForwardIterator` with its value type convertible to `GeomTraits::Segment_3` * \tparam cache_datum is either `CGAL::Tag_true` or `CGAL::Tag_false`. In the former case, * the datum is stored in the primitive, while in the latter it is * constructed on the fly to reduce the memory footprint. @@ -72,20 +74,21 @@ namespace internal { * \sa `AABB_HalfedgeGraph_segment_primitive` * \sa `AABB_FaceGraph_triangle_primitive` */ -template < class Iterator, +template < class GeomTraits, + class Iterator, class cache_datum=Tag_false> class AABB_segment_primitive #ifndef DOXYGEN_RUNNING : public AABB_primitive< Iterator, Input_iterator_property_map, - internal::Source_of_segment_3_iterator_property_map, + internal::Source_of_segment_3_iterator_property_map, Tag_false, cache_datum > #endif { typedef AABB_primitive< Iterator, Input_iterator_property_map, - internal::Source_of_segment_3_iterator_property_map, + internal::Source_of_segment_3_iterator_property_map, Tag_false, cache_datum > Base; public: diff --git a/AABB_tree/include/CGAL/AABB_triangle_primitive.h b/AABB_tree/include/CGAL/AABB_triangle_primitive.h index 514463e9df0..1d05fc4aed2 100644 --- a/AABB_tree/include/CGAL/AABB_triangle_primitive.h +++ b/AABB_tree/include/CGAL/AABB_triangle_primitive.h @@ -24,42 +24,45 @@ #define CGAL_AABB_TRIANGLE_PRIMITIVE_H_ #include -#include +#include +#include namespace CGAL { namespace internal { - template + template struct Point_from_triangle_3_iterator_property_map{ //classical typedefs - typedef typename CGAL::Kernel_traits< typename std::iterator_traits::value_type >::Kernel GeomTraits; typedef Iterator key_type; typedef typename GeomTraits::Point_3 value_type; - typedef const typename GeomTraits::Point_3& reference; + typedef typename cpp11::result_of< + typename GeomTraits::Construct_vertex_3(typename GeomTraits::Triangle_3,int) + >::type reference; typedef boost::readable_property_map_tag category; - }; - //get function for property map - template - inline - typename Point_from_triangle_3_iterator_property_map::reference - get(Point_from_triangle_3_iterator_property_map,Iterator it) - { - return it->vertex(0); - } + inline friend + typename Point_from_triangle_3_iterator_property_map::reference + get(Point_from_triangle_3_iterator_property_map, Iterator it) + { + return typename GeomTraits::Construct_vertex_3()( *it, 0 ); + } + }; }//namespace internal /*! * \ingroup PkgAABB_tree * Primitive type that uses as identifier an iterator with a 3D triangle as `value_type`. - * The iterator from which the primitive is built should not be invalided + * The iterator from which the primitive is built should not be invalided * while the AABB tree holding the primitive is in use. * * \cgalModels `AABBPrimitive` * - * \tparam Iterator is a model of `ForwardIterator`, with `Triangle_3` - * as value type + * \tparam GeomTraits is a traits class providing the nested type `Point_3` and `Triangle_3`. + * It also provides the functor `Construct_vertex_3` that has an operator taking a `Triangle_3` + * and an integer as parameters and returning a triangle point as a type convertible to `Point_3`. + * In addition `Construct_vertex_3` must support the result_of protocol. + * \tparam Iterator is a model of `ForwardIterator` with its value type convertible to `GeomTraits::Triangle_3` * \tparam cache_datum is either `CGAL::Tag_true` or `CGAL::Tag_false`. In the former case, * the datum is stored in the primitive, while in the latter it is * constructed on the fly to reduce the memory footprint. @@ -71,24 +74,25 @@ namespace internal { * \sa `AABB_HalfedgeGraph_segment_primitive` * \sa `AABB_FaceGraph_triangle_primitive` */ -template < class Iterator, +template < class GeomTraits, + class Iterator, class cache_datum=Tag_false> -class AABB_triangle_primitive +class AABB_triangle_primitive #ifndef DOXYGEN_RUNNING - : public AABB_primitive< Iterator, - Input_iterator_property_map, - internal::Point_from_triangle_3_iterator_property_map, - Tag_false, - cache_datum > + : public AABB_primitive< Iterator, + Input_iterator_property_map, + internal::Point_from_triangle_3_iterator_property_map, + Tag_false, + cache_datum > #endif { typedef AABB_primitive< Iterator, Input_iterator_property_map, - internal::Point_from_triangle_3_iterator_property_map, + internal::Point_from_triangle_3_iterator_property_map, Tag_false, cache_datum > Base; public: - // constructors + ///Constructor from an iterator AABB_triangle_primitive(Iterator it) : Base(it){} };