diff --git a/.gitattributes b/.gitattributes index e76c2a8659e..00a9e79a385 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/AABB_tree/doc_tex/AABB_tree_ref/AABBPrimitiveWithSharedData.tex b/AABB_tree/doc_tex/AABB_tree_ref/AABBPrimitiveWithSharedData.tex index 3e0a9e32001..e6c7bc2f87a 100644 --- a/AABB_tree/doc_tex/AABB_tree_ref/AABBPrimitiveWithSharedData.tex +++ b/AABB_tree/doc_tex/AABB_tree_ref/AABBPrimitiveWithSharedData.tex @@ -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} diff --git a/AABB_tree/doc_tex/AABB_tree_ref/AABBTraits.tex b/AABB_tree/doc_tex/AABB_tree_ref/AABBTraits.tex index 19c2191bef7..9b98d8d243b 100644 --- a/AABB_tree/doc_tex/AABB_tree_ref/AABBTraits.tex +++ b/AABB_tree/doc_tex/AABB_tree_ref/AABBTraits.tex @@ -94,18 +94,15 @@ for which the class \ccc{AABB_tree} 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 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}. diff --git a/AABB_tree/include/CGAL/AABB_primitive.h b/AABB_tree/include/CGAL/AABB_primitive.h index 6741136350d..d67d49e241d 100644 --- a/AABB_tree/include/CGAL/AABB_primitive.h +++ b/AABB_tree/include/CGAL/AABB_primitive.h @@ -94,11 +94,13 @@ class AABB_primitive 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 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;} }; diff --git a/AABB_tree/include/CGAL/AABB_traits.h b/AABB_tree/include/CGAL/AABB_traits.h index b5a111bfce9..6e8afd112a9 100644 --- a/AABB_tree/include/CGAL/AABB_traits.h +++ b/AABB_tree/include/CGAL/AABB_traits.h @@ -29,8 +29,8 @@ #include #include #include +#include #include -#include #include 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::value> -struct Datum_result_type{ typedef typename Primitive::Datum_reference type; }; - -template -struct Datum_result_type{ typedef typename Primitive::Datum type; }; - -template::value> -struct Point_result_type{ typedef typename Primitive::Point_reference type; }; - -template -struct Point_result_type{ typedef typename Primitive::Point type; }; //helper controlling whether extra data should be stored in the AABB_tree traits class template ::value> -struct Primitive_helper; +struct AABB_traits_base; template -struct Primitive_helper{ - typename Datum_result_type::type get_datum(const Primitive& p) const {return p.datum();} - typename Point_result_type::type get_reference_point(const Primitive& p) const {return p.reference_point();} -}; +struct AABB_traits_base{}; template -struct Primitive_helper{ +struct AABB_traits_base{ typename Primitive::Shared_data m_primitive_data; #ifndef CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES @@ -99,9 +82,7 @@ struct Primitive_helper{ m_primitive_data=PrimitiveType::construct_shared_data(t1,t2,t3,t4,t5); } #endif - - typename Datum_result_type::type get_datum(const Primitive& p) const {return p.datum(m_primitive_data);} - typename Point_result_type::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{ */ template class AABB_traits: - public internal::Primitive_helper + public internal::AABB_traits_base { public: typedef AABB_traits AT; @@ -239,7 +220,7 @@ public: template 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::get_datum(pr,m_traits)); } }; @@ -257,7 +238,7 @@ public: { typedef boost::optional Intersection; - CGAL::Object object = GeomTraits().intersect_3_object()(m_traits.get_datum(primitive),query); + CGAL::Object object = GeomTraits().intersect_3_object()(internal::Primitive_helper::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::get_datum(pr,m_traits), bound); } }; @@ -326,7 +307,7 @@ private: static Bounding_box compute_bbox (const Primitive& pr, const AABB_traits& traits) { - return traits.get_datum(pr).bbox(); + return internal::Primitive_helper::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& traits) - { return traits.get_reference_point(pr1).x() < traits.get_reference_point(pr2).x(); } + { return internal::Primitive_helper::get_reference_point(pr1,traits).x() < internal::Primitive_helper::get_reference_point(pr2,traits).x(); } static bool less_y(const Primitive& pr1, const Primitive& pr2,const AABB_traits& traits) - { return traits.get_reference_point(pr1).y() < traits.get_reference_point(pr2).y(); } + { return internal::Primitive_helper::get_reference_point(pr1,traits).y() < internal::Primitive_helper::get_reference_point(pr2,traits).y(); } static bool less_z(const Primitive& pr1, const Primitive& pr2,const AABB_traits& traits) - { return traits.get_reference_point(pr1).z() < traits.get_reference_point(pr2).z(); } + { return internal::Primitive_helper::get_reference_point(pr1,traits).z() < internal::Primitive_helper::get_reference_point(pr2,traits).z(); } }; // end class AABB_traits diff --git a/AABB_tree/include/CGAL/AABB_tree.h b/AABB_tree/include/CGAL/AABB_tree.h index 776a08ee49a..38e06ae9bc5 100644 --- a/AABB_tree/include/CGAL/AABB_tree.h +++ b/AABB_tree/include/CGAL/AABB_tree.h @@ -27,6 +27,7 @@ #include #include #include +#include #include #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::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::get_reference_point(*it,m_traits), it->id() + ) + ); // clears current KD tree clear_search_tree(); diff --git a/AABB_tree/include/CGAL/AABB_triangle_primitive.h b/AABB_tree/include/CGAL/AABB_triangle_primitive.h index 3026449f98a..db9865b4880 100644 --- a/AABB_tree/include/CGAL/AABB_triangle_primitive.h +++ b/AABB_tree/include/CGAL/AABB_triangle_primitive.h @@ -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 diff --git a/AABB_tree/include/CGAL/internal/AABB_tree/Primitive_helper.h b/AABB_tree/include/CGAL/internal/AABB_tree/Primitive_helper.h new file mode 100644 index 00000000000..3b8b29df391 --- /dev/null +++ b/AABB_tree/include/CGAL/internal/AABB_tree/Primitive_helper.h @@ -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 +#include + +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::value> +struct Datum_result_type{ typedef typename Primitive::Datum_reference type; }; +template +struct Datum_result_type{ typedef typename Primitive::Datum type; }; +template::value> +struct Point_result_type{ typedef typename Primitive::Point_reference type; }; +template +struct Point_result_type{ typedef typename Primitive::Point type; }; + + +//helper controlling whether extra data should be stored in the AABB_tree traits class +template ::value> +struct Primitive_helper; + +template +struct Primitive_helper{ + static typename Datum_result_type::type get_datum(const typename AABBTraits::Primitive& p,const AABBTraits& traits) + { + return p.datum(traits.shared_data()); + } + static typename Point_result_type::type get_reference_point(const typename AABBTraits::Primitive& p,const AABBTraits& traits) { + return p.reference_point(traits.shared_data()); + } +}; + +template +struct Primitive_helper{ + static typename Datum_result_type::type get_datum(const typename AABBTraits::Primitive& p,const AABBTraits&) {return p.datum();} + static typename Point_result_type::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 diff --git a/AABB_tree/test/AABB_tree/AABB_test_util.h b/AABB_tree/test/AABB_tree/AABB_test_util.h index 3f3e0fd95c4..403e3d5f842 100644 --- a/AABB_tree/test/AABB_tree/AABB_test_util.h +++ b/AABB_tree/test/AABB_tree/AABB_test_util.h @@ -29,7 +29,7 @@ #include #include - +#include 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::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::get_reference_point(closest_primitive,m_traits); for ( ; it != Pr_generator().end(p) ; ++it ) {