From e6019889cc01f0dcca869a9b440df40a4735d277 Mon Sep 17 00:00:00 2001 From: "m.overtheil" Date: Fri, 28 Nov 2014 15:08:46 +0100 Subject: [PATCH] Added dimension tags to Kd_tree_rectangle Introduced dimension tags for a speedup when we know the dimension at compiletime. --- .../CGAL/Euclidean_distance_sphere_point.h | 30 +++++++++++++++++-- .../include/CGAL/Fuzzy_iso_box.h | 5 ++-- Spatial_searching/include/CGAL/Fuzzy_sphere.h | 5 ++-- .../CGAL/Incremental_neighbor_search.h | 3 +- Spatial_searching/include/CGAL/Kd_tree_node.h | 4 +-- .../include/CGAL/Kd_tree_rectangle.h | 10 +++---- .../CGAL/Manhattan_distance_iso_box_point.h | 26 ++++++++++++++-- .../include/CGAL/Search_traits.h | 2 +- .../include/CGAL/Search_traits_adapter.h | 10 ++++--- .../CGAL/Weighted_Minkowski_distance.h | 26 ++++++++++++++-- 10 files changed, 97 insertions(+), 24 deletions(-) diff --git a/Spatial_searching/include/CGAL/Euclidean_distance_sphere_point.h b/Spatial_searching/include/CGAL/Euclidean_distance_sphere_point.h index c30803d4cf0..6945b5fb8ec 100644 --- a/Spatial_searching/include/CGAL/Euclidean_distance_sphere_point.h +++ b/Spatial_searching/include/CGAL/Euclidean_distance_sphere_point.h @@ -24,11 +24,34 @@ #include #include +#include namespace CGAL { + namespace internal{ + #ifndef HAS_DIMENSION_TAG + #define HAS_DIMENSION_TAG + BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_dimension,Dimension,false); + #endif + + template ::value> + struct Euclidean_distance_sphere_point_base; + + template + struct Euclidean_distance_sphere_point_base{ + typedef typename SearchTraits::Dimension Dimension; + }; + + template + struct Euclidean_distance_sphere_point_base{ + typedef Dynamic_dimension_tag Dimension; + }; + } + template class Euclidean_distance_sphere_point { + + SearchTraits traits; public: @@ -40,7 +63,8 @@ namespace CGAL { typedef typename SearchTraits::Compute_squared_radius_d Compute_squared_radius_d; typedef typename SearchTraits::Construct_cartesian_const_iterator_d Construct_cartesian_const_iterator_d; typedef typename SearchTraits::Cartesian_const_iterator_d Cartesian_const_iterator_d; - typedef Sphere_d Query_item; + typedef Sphere_d Query_item; + typedef typename internal::Euclidean_distance_sphere_point_base::Dimension Dimension; public: // default constructor @@ -63,7 +87,7 @@ namespace CGAL { inline FT min_distance_to_rectangle(const Sphere_d& q, - const Kd_tree_rectangle& r) const { + const Kd_tree_rectangle& r) const { Point_d c= Construct_center_d()(q); FT distance = FT(0); Construct_cartesian_const_iterator_d construct_it=traits.construct_cartesian_const_iterator_d_object(); @@ -84,7 +108,7 @@ namespace CGAL { } inline FT max_distance_to_rectangle(const Sphere_d& q, - const Kd_tree_rectangle& r) const { + const Kd_tree_rectangle& r) const { Construct_center_d construct_center_d; Point_d c = construct_center_d(q); FT distance=FT(0); diff --git a/Spatial_searching/include/CGAL/Fuzzy_iso_box.h b/Spatial_searching/include/CGAL/Fuzzy_iso_box.h index cf15daa8622..3dee187e70c 100644 --- a/Spatial_searching/include/CGAL/Fuzzy_iso_box.h +++ b/Spatial_searching/include/CGAL/Fuzzy_iso_box.h @@ -58,6 +58,7 @@ namespace CGAL { typedef typename SearchTraits::Point_d Point_d; typedef typename SearchTraits::Iso_box_d Iso_box_d; typedef typename SearchTraits::FT FT; + typedef typename SearchTraits::Dimension Dimension; typedef typename SearchTraits::Construct_min_vertex_d Construct_min_vertex_d; typedef typename SearchTraits::Construct_max_vertex_d Construct_max_vertex_d; typedef typename SearchTraits::Cartesian_const_iterator_d Cartesian_const_iterator_d; @@ -121,7 +122,7 @@ namespace CGAL { return true; } - bool inner_range_intersects(const Kd_tree_rectangle& rectangle) const { + bool inner_range_intersects(const Kd_tree_rectangle& rectangle) const { Cartesian_const_iterator_d minit= min_begin, maxit = max_begin; for (unsigned int i = 0; i < dim; ++i, ++minit, ++maxit) { if ( ((*maxit)-eps < rectangle.min_coord(i)) @@ -131,7 +132,7 @@ namespace CGAL { } - bool outer_range_contains(const Kd_tree_rectangle& rectangle) const { + bool outer_range_contains(const Kd_tree_rectangle& rectangle) const { Cartesian_const_iterator_d minit= min_begin, maxit = max_begin; for (unsigned int i = 0; i < dim; ++i, ++minit, ++maxit) { if ( ((*maxit)+eps < rectangle.max_coord(i) ) diff --git a/Spatial_searching/include/CGAL/Fuzzy_sphere.h b/Spatial_searching/include/CGAL/Fuzzy_sphere.h index 7639b2d26f5..a767d7f69be 100644 --- a/Spatial_searching/include/CGAL/Fuzzy_sphere.h +++ b/Spatial_searching/include/CGAL/Fuzzy_sphere.h @@ -34,6 +34,7 @@ namespace CGAL { public: typedef typename SearchTraits::FT FT; + typedef typename SearchTraits::Dimension Dimension; private: Point_d c; @@ -75,7 +76,7 @@ namespace CGAL { } - bool inner_range_intersects(const Kd_tree_rectangle& rectangle) const { + bool inner_range_intersects(const Kd_tree_rectangle& rectangle) const { // test whether the interior of a sphere // with radius (r-eps) intersects r, i.e. // if the minimal distance of r to c is less than r-eps @@ -98,7 +99,7 @@ namespace CGAL { } - bool outer_range_contains(const Kd_tree_rectangle& rectangle) const { + bool outer_range_contains(const Kd_tree_rectangle& rectangle) const { // test whether the interior of a sphere // with radius (r+eps) is contained by r, i.e. // if the minimal distance of the boundary of r diff --git a/Spatial_searching/include/CGAL/Incremental_neighbor_search.h b/Spatial_searching/include/CGAL/Incremental_neighbor_search.h index b9b313ed6c5..8da9914659f 100644 --- a/Spatial_searching/include/CGAL/Incremental_neighbor_search.h +++ b/Spatial_searching/include/CGAL/Incremental_neighbor_search.h @@ -43,10 +43,11 @@ namespace CGAL { typedef Tree_ Tree; typedef typename SearchTraits::Point_d Point_d; typedef typename SearchTraits::FT FT; + typedef typename SearchTraits::Dimension Dimension; typedef typename Tree::Point_d_iterator Point_d_iterator; typedef typename Tree::Node_const_handle Node_const_handle; typedef typename Tree::Splitter Splitter; - typedef Kd_tree_rectangle Node_box; + typedef Kd_tree_rectangle Node_box; typedef typename Distance::Query_item Query_item; class Cell { diff --git a/Spatial_searching/include/CGAL/Kd_tree_node.h b/Spatial_searching/include/CGAL/Kd_tree_node.h index c2f64be060d..1ed0d85f08f 100644 --- a/Spatial_searching/include/CGAL/Kd_tree_node.h +++ b/Spatial_searching/include/CGAL/Kd_tree_node.h @@ -162,7 +162,7 @@ namespace CGAL { template OutputIterator search(OutputIterator it, const FuzzyQueryItem& q, - Kd_tree_rectangle& b) const + Kd_tree_rectangle& b) const { if (is_leaf()) { Leaf_node_const_handle node = @@ -176,7 +176,7 @@ namespace CGAL { Internal_node_const_handle node = static_cast(this); // after splitting b denotes the lower part of b - Kd_tree_rectangle b_upper(b); + Kd_tree_rectangle b_upper(b); b.split(b_upper, node->cutting_dimension(), node->cutting_value()); diff --git a/Spatial_searching/include/CGAL/Kd_tree_rectangle.h b/Spatial_searching/include/CGAL/Kd_tree_rectangle.h index 632e29fed45..8d8a6f5e4d1 100644 --- a/Spatial_searching/include/CGAL/Kd_tree_rectangle.h +++ b/Spatial_searching/include/CGAL/Kd_tree_rectangle.h @@ -55,7 +55,7 @@ namespace CGAL { }; - template + template class Kd_tree_rectangle { public: typedef FT_ FT; @@ -73,7 +73,7 @@ namespace CGAL { inline void set_upper_bound(int i, const FT& x) { - CGAL_assertion(i >= 0 && i < D); + CGAL_assertion(i >= 0 && i < D::value); CGAL_assertion(x >= lower_[i]); upper_[i] = x; set_max_span(); @@ -82,7 +82,7 @@ namespace CGAL { inline void set_lower_bound(int i, const FT& x) { - CGAL_assertion(i >= 0 && i < D); + CGAL_assertion(i >= 0 && i < D::value); CGAL_assertion(x <= upper_[i]); lower_[i] = x; set_max_span(); @@ -162,7 +162,7 @@ namespace CGAL { inline FT min_coord(int i) const { - CGAL_assertion(lower_ != NULL); + CGAL_assertion(lower_.size() != 0); return lower_[i]; } @@ -197,7 +197,7 @@ namespace CGAL { void split(Kd_tree_rectangle& r, int d, FT value) { - CGAL_assertion(d >= 0 && d < D); + CGAL_assertion(d >= 0 && d < D::value); CGAL_assertion(lower_[d] <= value && value <= upper_[d]); //Kd_tree_rectangle* r = new Kd_tree_rectangle(*this); diff --git a/Spatial_searching/include/CGAL/Manhattan_distance_iso_box_point.h b/Spatial_searching/include/CGAL/Manhattan_distance_iso_box_point.h index 95bd96d2e2f..07f6ed292db 100644 --- a/Spatial_searching/include/CGAL/Manhattan_distance_iso_box_point.h +++ b/Spatial_searching/include/CGAL/Manhattan_distance_iso_box_point.h @@ -23,9 +23,30 @@ #define CGAL_MANHATTAN_DISTANCE_ISO_BOX_POINT_H #include +#include namespace CGAL { + namespace internal{ + #ifndef HAS_DIMENSION_TAG + #define HAS_DIMENSION_TAG + BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_dimension,Dimension,false); + #endif + + template ::value> + struct Manhattan_distance_iso_box_point_base; + + template + struct Manhattan_distance_iso_box_point_base{ + typedef typename SearchTraits::Dimension Dimension; + }; + + template + struct Manhattan_distance_iso_box_point_base{ + typedef Dynamic_dimension_tag Dimension; + }; + } + template class Manhattan_distance_iso_box_point { SearchTraits traits; @@ -35,6 +56,7 @@ namespace CGAL { typedef typename SearchTraits::Iso_box_d Iso_box_d; typedef typename SearchTraits::FT FT; typedef Iso_box_d Query_item; + typedef typename internal::Manhattan_distance_iso_box_point_base::Dimension Dimension; Manhattan_distance_iso_box_point(const SearchTraits& traits_=SearchTraits()):traits(traits_) {} @@ -62,7 +84,7 @@ namespace CGAL { inline FT min_distance_to_rectangle(const Query_item& q, - const Kd_tree_rectangle& r) const { + const Kd_tree_rectangle& r) const { FT distance = FT(0); typename SearchTraits::Construct_cartesian_const_iterator_d construct_it= traits.construct_cartesian_const_iterator_d_object(); @@ -82,7 +104,7 @@ namespace CGAL { inline FT max_distance_to_rectangle(const Query_item& q, - const Kd_tree_rectangle& r) const { + const Kd_tree_rectangle& r) const { FT distance=FT(0); typename SearchTraits::Construct_cartesian_const_iterator_d construct_it= traits.construct_cartesian_const_iterator_d_object(); diff --git a/Spatial_searching/include/CGAL/Search_traits.h b/Spatial_searching/include/CGAL/Search_traits.h index 33b4474324e..4f856c0db49 100644 --- a/Spatial_searching/include/CGAL/Search_traits.h +++ b/Spatial_searching/include/CGAL/Search_traits.h @@ -25,7 +25,7 @@ namespace CGAL { - template + template class Search_traits { public: diff --git a/Spatial_searching/include/CGAL/Search_traits_adapter.h b/Spatial_searching/include/CGAL/Search_traits_adapter.h index 1526c084885..315a093d7d2 100644 --- a/Spatial_searching/include/CGAL/Search_traits_adapter.h +++ b/Spatial_searching/include/CGAL/Search_traits_adapter.h @@ -86,6 +86,8 @@ public: typedef typename Base_traits::Cartesian_const_iterator_d Cartesian_const_iterator_d; typedef Point_with_info Point_d; typedef typename Base_traits::FT FT; + typedef typename Base_traits::Dimension Dimension; + struct Construct_cartesian_const_iterator_d: public Base_traits::Construct_cartesian_const_iterator_d{ PointPropertyMap ppmap; @@ -149,14 +151,14 @@ public: return this->transformed_distance(p1,get(ppmap,p2)); } - template - FT min_distance_to_rectangle(const Query_item& p, const CGAL::Kd_tree_rectangle& b) const + template + FT min_distance_to_rectangle(const Query_item& p, const CGAL::Kd_tree_rectangle& b) const { return static_cast(this)->min_distance_to_rectangle(p,b); } - template - FT max_distance_to_rectangle(const Query_item& p,const CGAL::Kd_tree_rectangle& b) const + template + FT max_distance_to_rectangle(const Query_item& p,const CGAL::Kd_tree_rectangle& b) const { return static_cast(this)->max_distance_to_rectangle(p,b); } diff --git a/Spatial_searching/include/CGAL/Weighted_Minkowski_distance.h b/Spatial_searching/include/CGAL/Weighted_Minkowski_distance.h index a99730c0e74..567c8fc8e6d 100644 --- a/Spatial_searching/include/CGAL/Weighted_Minkowski_distance.h +++ b/Spatial_searching/include/CGAL/Weighted_Minkowski_distance.h @@ -29,9 +29,30 @@ #include #include +#include namespace CGAL { + namespace internal{ + #ifndef HAS_DIMENSION_TAG + #define HAS_DIMENSION_TAG + BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_dimension,Dimension,false); + #endif + + template ::value> + struct Weighted_Minkowski_distance_base; + + template + struct Weighted_Minkowski_distance_base{ + typedef typename SearchTraits::Dimension Dimension; + }; + + template + struct Weighted_Minkowski_distance_base{ + typedef Dynamic_dimension_tag Dimension; + }; + } + template class Weighted_Minkowski_distance { SearchTraits traits; @@ -41,6 +62,7 @@ namespace CGAL { typedef Point_d Query_item; typedef typename SearchTraits::FT FT; typedef std::vector Weight_vector; + typedef typename internal::Euclidean_distance_base::Dimension Dimension; private: @@ -123,7 +145,7 @@ namespace CGAL { inline FT min_distance_to_rectangle(const Query_item& q, - const Kd_tree_rectangle& r) const + const Kd_tree_rectangle& r) const { FT distance = FT(0); typename SearchTraits::Construct_cartesian_const_iterator_d construct_it= @@ -159,7 +181,7 @@ namespace CGAL { inline FT max_distance_to_rectangle(const Query_item& q, - const Kd_tree_rectangle& r) const { + const Kd_tree_rectangle& r) const { FT distance=FT(0); typename SearchTraits::Construct_cartesian_const_iterator_d construct_it= traits.construct_cartesian_const_iterator_d_object();