diff --git a/Spatial_searching/doc/Spatial_searching/CGAL/Euclidean_distance.h b/Spatial_searching/doc/Spatial_searching/CGAL/Euclidean_distance.h index 5421d59035e..6dc886e36a6 100644 --- a/Spatial_searching/doc/Spatial_searching/CGAL/Euclidean_distance.h +++ b/Spatial_searching/doc/Spatial_searching/CGAL/Euclidean_distance.h @@ -9,7 +9,7 @@ To optimize distance computations squared distances are used. \cgalHeading{Parameters} -Expects for the first template argument a model of the concept +\tparam Traits must be a model of the concept `SearchTraits`, for example `Search_traits_2 >`. \cgalModels `OrthogonalDistance` diff --git a/Spatial_searching/doc/Spatial_searching/CGAL/Euclidean_distance_sphere_point.h b/Spatial_searching/doc/Spatial_searching/CGAL/Euclidean_distance_sphere_point.h index c764e92ee40..76765cf3c01 100644 --- a/Spatial_searching/doc/Spatial_searching/CGAL/Euclidean_distance_sphere_point.h +++ b/Spatial_searching/doc/Spatial_searching/CGAL/Euclidean_distance_sphere_point.h @@ -11,7 +11,7 @@ Euclidean distance between a \f$ d\f$-dimensional sphere and a \cgalHeading{Parameters} -Expects for the template argument a model of the concept `SearchTraits`, +\tparam Traits must be a model of the concept `SearchTraits`, for example `Simple_cartesian_d`. \cgalModels `GeneralDistance` diff --git a/Spatial_searching/doc/Spatial_searching/CGAL/Fuzzy_iso_box.h b/Spatial_searching/doc/Spatial_searching/CGAL/Fuzzy_iso_box.h index 222202966df..737f6aa67f2 100644 --- a/Spatial_searching/doc/Spatial_searching/CGAL/Fuzzy_iso_box.h +++ b/Spatial_searching/doc/Spatial_searching/CGAL/Fuzzy_iso_box.h @@ -10,7 +10,7 @@ by a `d`-dim square with side length \f$ \epsilon\f$. \cgalHeading{Parameters} -Expects for the template argument a model of the concept +\tparam Traits must be a model of the concept `SearchTraits`, for example `CGAL::Search_traits_2 >`. \cgalModels `FuzzyQueryItem` diff --git a/Spatial_searching/doc/Spatial_searching/CGAL/Fuzzy_sphere.h b/Spatial_searching/doc/Spatial_searching/CGAL/Fuzzy_sphere.h index 1bde80c36a7..e5eb0f2a080 100644 --- a/Spatial_searching/doc/Spatial_searching/CGAL/Fuzzy_sphere.h +++ b/Spatial_searching/doc/Spatial_searching/CGAL/Fuzzy_sphere.h @@ -10,7 +10,7 @@ as inner approximation a sphere with radius \f$ r-\epsilon\f$. \cgalHeading{Parameters} -Expects for the template argument a model of the concept +\tparam Traits must be a model of the concept `SearchTraits`, for example `CGAL::Cartesian_d`. \cgalModels `FuzzyQueryItem` diff --git a/Spatial_searching/doc/Spatial_searching/CGAL/Incremental_neighbor_search.h b/Spatial_searching/doc/Spatial_searching/CGAL/Incremental_neighbor_search.h index 629a28417e4..27d789a75f6 100644 --- a/Spatial_searching/doc/Spatial_searching/CGAL/Incremental_neighbor_search.h +++ b/Spatial_searching/doc/Spatial_searching/CGAL/Incremental_neighbor_search.h @@ -8,19 +8,19 @@ on a tree. The tree may have extended or unextended nodes. \cgalHeading{Parameters} -Expects for the first template argument a model of the concept `SearchTraits`, +\tparam Traits must be a model of the concept `SearchTraits`, for example `Search_traits_2 >`. -Expects for the second template argument a model of the +\tparam GeneralDistance must be a model of the concept `GeneralDistance`. If `Traits` is `Search_traits_adapter` the default type is `Distance_adapter >`, and `Euclidean_distance` otherwise. -Expects for third template argument a model of the concept `Splitter`. +\tparam Splitter must be a model of the concept `Splitter`. The default type is `Sliding_midpoint`. -Expects for fourth template argument a model of the concept `SpatialTree`. +\tparam SpatialTree must be a model of the concept `SpatialTree`. The default type is `Kd_tree`. The template argument `Tag_false` makes that the tree is built with unextended nodes. diff --git a/Spatial_searching/doc/Spatial_searching/CGAL/K_neighbor_search.h b/Spatial_searching/doc/Spatial_searching/CGAL/K_neighbor_search.h index 03e89a81c0e..7192b5e29a8 100644 --- a/Spatial_searching/doc/Spatial_searching/CGAL/K_neighbor_search.h +++ b/Spatial_searching/doc/Spatial_searching/CGAL/K_neighbor_search.h @@ -9,16 +9,16 @@ extended or unextended nodes. \cgalHeading{Parameters} -Expects for the first template argument an implementation of the concept `SearchTraits`, +\tparam Traits must be an implementation of the concept `SearchTraits`, for example `Simple_cartesian`. -Expects for the second template argument a model of the +\tparam Splitter must be a model of the concept `GeneralDistance`. If `Traits` is `Search_traits_adapter` the default type is `Distance_adapter >`, and `Euclidean_distance` otherwise. -Expects for fourth template argument an implementation of the concept `SpatialTree`. +\tparam SpatialTree must be an implementation of the concept `SpatialTree`. The default type is `Kd_tree`. The template argument `Tag_false` makes that the tree is built with unextended nodes. diff --git a/Spatial_searching/doc/Spatial_searching/CGAL/Kd_tree_node.h b/Spatial_searching/doc/Spatial_searching/CGAL/Kd_tree_node.h index 4a90161a4b7..2f483f1c53d 100644 --- a/Spatial_searching/doc/Spatial_searching/CGAL/Kd_tree_node.h +++ b/Spatial_searching/doc/Spatial_searching/CGAL/Kd_tree_node.h @@ -15,9 +15,11 @@ along the node's cutting dimension. \cgalHeading{Parameters} -Expects for the template argument a model of the concept `SearchTraits`, +\tparam Traits must be a model of the concept `SearchTraits`, for example `Search_traits_2 >`, or `Cartesian_d`. +\tparam Splitter must be a model of the concept `Splitter`. + */ template< typename Traits, typename Splitter, typename UseExtendedNode > class Kd_tree_node { diff --git a/Spatial_searching/doc/Spatial_searching/CGAL/Manhattan_distance_iso_box_point.h b/Spatial_searching/doc/Spatial_searching/CGAL/Manhattan_distance_iso_box_point.h index 87f4d761ebb..00a22569990 100644 --- a/Spatial_searching/doc/Spatial_searching/CGAL/Manhattan_distance_iso_box_point.h +++ b/Spatial_searching/doc/Spatial_searching/CGAL/Manhattan_distance_iso_box_point.h @@ -12,7 +12,7 @@ and a `d`-dimensional iso-box defined as a `k-d` tree rectangle. \cgalHeading{Parameters} -Expects for the template argument a model for the concept +\tparam Traits must be a model for the concept `SearchTraits`, for example `Search_traits_3 >`. \cgalModels `GeneralDistance` diff --git a/Spatial_searching/doc/Spatial_searching/CGAL/Orthogonal_incremental_neighbor_search.h b/Spatial_searching/doc/Spatial_searching/CGAL/Orthogonal_incremental_neighbor_search.h index 9338d5a0362..c11d29daf3c 100644 --- a/Spatial_searching/doc/Spatial_searching/CGAL/Orthogonal_incremental_neighbor_search.h +++ b/Spatial_searching/doc/Spatial_searching/CGAL/Orthogonal_incremental_neighbor_search.h @@ -7,19 +7,19 @@ The class `Orthogonal_incremental_neighbor_search` implements incremental neares \cgalHeading{Parameters} -Expects for the first template argument a model of the concept `SearchTraits`, +\tparam Traits must be a model of the concept `SearchTraits`, for example `Search_traits_2 >`. -Expects for the second template argument a model of the -concept `GeneralDistance`. If `Traits` is +\tparam OrthogonalDistance must be a model of the +concept `OrthogonalDistance`. If `Traits` is `Search_traits_adapter` the default type is `Distance_adapter >`, and `Euclidean_distance` otherwise. -Expects for third template argument a model of the concept `Splitter`. +\tparam Splitter must be a model of the concept `Splitter`. The default type is `Sliding_midpoint`. -Expects for fourth template argument a model of the concept `SpatialTree`. +\tparam SpatialTree must be a model of the concept `SpatialTree`. The default type is `Kd_tree`. The template argument must be `Tag_true` because orthogonal search needs extended kd tree nodes. diff --git a/Spatial_searching/doc/Spatial_searching/CGAL/Search_traits_2.h b/Spatial_searching/doc/Spatial_searching/CGAL/Search_traits_2.h index dd9a24a1fe7..c074be47f20 100644 --- a/Spatial_searching/doc/Spatial_searching/CGAL/Search_traits_2.h +++ b/Spatial_searching/doc/Spatial_searching/CGAL/Search_traits_2.h @@ -10,7 +10,7 @@ Added Dimension \cgalModifEnd \cgalHeading{Parameters} -Expects for the template argument a model of the concept `Kernel`, +\tparam Kernel must be a model of the concept `Kernel`, for example `Simple_cartesian` or `Simple_cartesian`. \cgalModels `SearchTraits` diff --git a/Spatial_searching/doc/Spatial_searching/CGAL/Search_traits_3.h b/Spatial_searching/doc/Spatial_searching/CGAL/Search_traits_3.h index 21e9c8e7f74..f25a632b78c 100644 --- a/Spatial_searching/doc/Spatial_searching/CGAL/Search_traits_3.h +++ b/Spatial_searching/doc/Spatial_searching/CGAL/Search_traits_3.h @@ -10,7 +10,7 @@ Added Dimension \cgalModifEnd \cgalHeading{Parameters} -Expects for the template argument a model of the concept `Kernel`, +\tparam Kernel must be a model of the concept `Kernel`, for example `Simple_cartesian` or `Simple_cartesian`. \cgalModels `SearchTraits` diff --git a/Spatial_searching/doc/Spatial_searching/CGAL/Search_traits_adapter.h b/Spatial_searching/doc/Spatial_searching/CGAL/Search_traits_adapter.h index 3885ba036e5..4049313cdc1 100644 --- a/Spatial_searching/doc/Spatial_searching/CGAL/Search_traits_adapter.h +++ b/Spatial_searching/doc/Spatial_searching/CGAL/Search_traits_adapter.h @@ -10,12 +10,12 @@ in a nearest neighbor search algorithm, this class must be used as distance. \cgalHeading{Parameters} -`Key` is a type that is associated to a point of type `Base_distance::Point_d`. +\tparam Key is a type that is associated to a point of type `Base_distance::Point_d`. -`PointPropertyMap` is a model of `LvaluePropertyMap` +\tparam PointPropertyMap is a model of `LvaluePropertyMap` with `Key` as `key_type` and `Base_distance::Point_d` as `value_type`. -`Base_distance` is a model of either `GeneralDistance` or `OrthogonalDistance`. +\tparam Base_distance is a model of either `GeneralDistance` or `OrthogonalDistance`. \cgalModels `GeneralDistance` if Base_distance is a model of `GeneralDistance` \cgalModels `OrthogonalDistance` if Base_distance is a model of `OrthogonalDistance` diff --git a/Spatial_searching/doc/Spatial_searching/CGAL/Search_traits_d.h b/Spatial_searching/doc/Spatial_searching/CGAL/Search_traits_d.h index 4c173266eaf..acc57140986 100644 --- a/Spatial_searching/doc/Spatial_searching/CGAL/Search_traits_d.h +++ b/Spatial_searching/doc/Spatial_searching/CGAL/Search_traits_d.h @@ -12,8 +12,10 @@ Added Dimension \cgalHeading{Parameters} -Expects for the first template argument a model of the concept `Kernel_d` -(for example `Cartesian_d`) and for the second argument a `Dimension_tag` +\tparam Kernel must be a model of the concept `Kernel_d` +(for example `Cartesian_d`) + +\tparam Dim must be a `Dimension_tag` (default value is `Dynamic_dimension_tag`). \cgalModels `SearchTraits` diff --git a/Spatial_searching/doc/Spatial_searching/CGAL/Splitters.h b/Spatial_searching/doc/Spatial_searching/CGAL/Splitters.h index 813d4927451..b7eef3caee2 100644 --- a/Spatial_searching/doc/Spatial_searching/CGAL/Splitters.h +++ b/Spatial_searching/doc/Spatial_searching/CGAL/Splitters.h @@ -16,12 +16,12 @@ the ratio of the resulting rectangles. \cgalHeading{Parameters} -Expects for the first template argument a model of +\tparam Traits must be a model of the concept `SearchTraits`, for example `Simple_cartesian`. -Expects for the second template argument a model of the concept `SpatialSeparator`. -It has as default value the type, `Plane_separator`. +\tparam SpatialSeparator must be a model of the concept `SpatialSeparator`. +It has as default value the type `Plane_separator`. \cgalModels `Splitter` diff --git a/Spatial_searching/doc/Spatial_searching/CGAL/Weighted_Minkowski_distance.h b/Spatial_searching/doc/Spatial_searching/CGAL/Weighted_Minkowski_distance.h index fe14a534621..1fc8de5e787 100644 --- a/Spatial_searching/doc/Spatial_searching/CGAL/Weighted_Minkowski_distance.h +++ b/Spatial_searching/doc/Spatial_searching/CGAL/Weighted_Minkowski_distance.h @@ -12,7 +12,7 @@ the transformed distance \f$ {\sigma_{i=1}^{i=d} \, w_i(r_i-q_i)^p}\f$ instead o \cgalHeading{Parameters} -Expects for the template argument a model of the concept +\tparam Traits must be a model of the concept `SearchTraits`, for example `Search_traits_2`. \cgalModels `OrthogonalDistance` diff --git a/Spatial_searching/examples/Spatial_searching/Distance.h b/Spatial_searching/examples/Spatial_searching/Distance.h index 4fb3bc13054..7f28e0036e7 100644 --- a/Spatial_searching/examples/Spatial_searching/Distance.h +++ b/Spatial_searching/examples/Spatial_searching/Distance.h @@ -24,6 +24,39 @@ struct Distance { return distance; } + template + double min_distance_to_rectangle(const Point& p, + const CGAL::Kd_tree_rectangle& b,std::vector& dists){ + double distance(0.0), h = p.x(); + if (h < b.min_coord(0)){ + dists[0] = (b.min_coord(0)-h); + distance += dists[0]*dists[0]; + } + if (h > b.max_coord(0)){ + dists[0] = (h-b.max_coord(0)); + distance += dists[0]*dists[0]; + } + h=p.y(); + if (h < b.min_coord(1)){ + dists[1] = (b.min_coord(1)-h); + distance += dists[1]*dists[1]; + } + if (h > b.max_coord(1)){ + dists[1] = (h-b.max_coord(1)); + distance += dists[1]*dists[1]; + } + h=p.z(); + if (h < b.min_coord(2)){ + dists[2] = (b.min_coord(2)-h); + distance += dists[2]*dists[2]; + } + if (h > b.max_coord(2)){ + dists[2] = (h-b.max_coord(2)); + distance += dists[2]*dists[2]; + } + return distance; + } + template double max_distance_to_rectangle(const Point& p, const CGAL::Kd_tree_rectangle& b) const { @@ -41,6 +74,23 @@ struct Distance { return d0 + d1 + d2; } + template + double max_distance_to_rectangle(const Point& p, + const CGAL::Kd_tree_rectangle& b,std::vector& dists){ + double h = p.x(); + + dists[0] = (h >= (b.min_coord(0)+b.max_coord(0))/2.0) ? + (h-b.min_coord(0)) : (b.max_coord(0)-h); + + h=p.y(); + dists[1] = (h >= (b.min_coord(1)+b.max_coord(1))/2.0) ? + (h-b.min_coord(1)) : (b.max_coord(1)-h); + h=p.z(); + dists[2] = (h >= (b.min_coord(2)+b.max_coord(2))/2.0) ? + (h-b.min_coord(2)) : (b.max_coord(2)-h); + return dists[0] * dists[0] + dists[1] * dists[1] + dists[2] * dists[2]; + } + double new_distance(double& dist, double old_off, double new_off, int /* cutting_dimension */) const { return dist + new_off*new_off - old_off*old_off; diff --git a/Spatial_searching/examples/Spatial_searching/Point.h b/Spatial_searching/examples/Spatial_searching/Point.h index 1e87c6fea37..ad94baad469 100644 --- a/Spatial_searching/examples/Spatial_searching/Point.h +++ b/Spatial_searching/examples/Spatial_searching/Point.h @@ -1,6 +1,8 @@ struct Point { double vec[3]; + Point(){} + Point() { vec[0]= vec[1] = vec[2] = 0; } Point (double x, double y, double z) { vec[0]=x; vec[1]=y; vec[2]=z; } diff --git a/Spatial_searching/include/CGAL/Euclidean_distance.h b/Spatial_searching/include/CGAL/Euclidean_distance.h index 7c20cc32c95..cd5513a3281 100644 --- a/Spatial_searching/include/CGAL/Euclidean_distance.h +++ b/Spatial_searching/include/CGAL/Euclidean_distance.h @@ -71,41 +71,65 @@ namespace CGAL { typedef typename SearchTraits::Point_d Point_d; typedef Point_d Query_item; - typedef typename internal::Euclidean_distance_base::Dimension D; + typedef typename internal::Euclidean_distance_base::Dimension D; - // default constructor - Euclidean_distance(const SearchTraits& traits_=SearchTraits()):traits(traits_) {} - - + // default constructor + Euclidean_distance(const SearchTraits& traits_=SearchTraits()):traits(traits_) {} + + inline FT transformed_distance(const Query_item& q, const Point_d& p) const { + return transformed_distance(q,p, D()); + } + //Dynamic version for runtime dimension inline FT transformed_distance(const Query_item& q, const Point_d& p, Dynamic_dimension_tag dt) const { - FT distance = FT(0); - typename SearchTraits::Construct_cartesian_const_iterator_d construct_it=traits.construct_cartesian_const_iterator_d_object(); - typename SearchTraits::Cartesian_const_iterator_d qit = construct_it(q), - qe = construct_it(q,1), pit = construct_it(p); - for(; qit != qe; qit++, pit++){ - distance += ((*qit)-(*pit))*((*qit)-(*pit)); - } - return distance; + FT distance = FT(0); + typename SearchTraits::Construct_cartesian_const_iterator_d construct_it=traits.construct_cartesian_const_iterator_d_object(); + typename SearchTraits::Cartesian_const_iterator_d qit = construct_it(q), + qe = construct_it(q,1), pit = construct_it(p); + for(; qit != qe; qit++, pit++){ + distance += ((*qit)-(*pit))*((*qit)-(*pit)); } + return distance; + } + //Generic version for DIM > 3 template < int DIM > inline FT transformed_distance(const Query_item& q, const Point_d& p, Dimension_tag dt) const { - std::cerr << "here goes the generic code" < + //DIM = 2 loop unrolled inline FT transformed_distance(const Query_item& q, const Point_d& p, Dimension_tag<2> dt) const { - std::cerr << "here goes the unrolled code for 3D" < dt) const { + typename SearchTraits::Construct_cartesian_const_iterator_d construct_it=traits.construct_cartesian_const_iterator_d_object(); + typename SearchTraits::Cartesian_const_iterator_d qit = construct_it(q),pit = construct_it(p); + FT distance = square(*qit - *pit); + qit++;pit++; + distance += square(*qit - *pit); + qit++;pit++; + distance += square(*qit - *pit); + return distance; + } + + inline FT min_distance_to_rectangle(const Query_item& q, diff --git a/Spatial_searching/include/CGAL/Weighted_Minkowski_distance.h b/Spatial_searching/include/CGAL/Weighted_Minkowski_distance.h index d53ed807ad8..2827d480b1c 100644 --- a/Spatial_searching/include/CGAL/Weighted_Minkowski_distance.h +++ b/Spatial_searching/include/CGAL/Weighted_Minkowski_distance.h @@ -119,9 +119,11 @@ namespace CGAL { } + + //Dynamic version for runtime dimension inline FT - transformed_distance(const Query_item& q, const Point_d& p) const + transformed_distance(const Query_item& q, const Point_d& p, Dynamic_dimension_tag dt) const { FT distance = FT(0); typename SearchTraits::Construct_cartesian_const_iterator_d construct_it= @@ -140,7 +142,87 @@ namespace CGAL { the_weights[i] * std::pow(CGAL::abs((*qit)-(*pit)),power); return distance; } - + + //Generic version for DIM > 3 + template + inline FT + transformed_distance(const Query_item& q, const Point_d& p, Dimension_tag dt) const + { + FT distance = FT(0); + typename SearchTraits::Construct_cartesian_const_iterator_d construct_it= + traits.construct_cartesian_const_iterator_d_object(); + Coord_iterator qit = construct_it(q), + qe = construct_it(q,1), + pit = construct_it(p); + if (power == FT(0)) { + for (unsigned int i = 0; qit != qe; ++qit, ++i) + if (the_weights[i] * CGAL::abs((*qit) - (*pit)) > distance) + distance = the_weights[i] * CGAL::abs((*qit)-(*pit)); + } + else + for (unsigned int i = 0; qit != qe; ++qit, ++i) + distance += + the_weights[i] * std::pow(CGAL::abs((*qit)-(*pit)),power); + return distance; + } + + //DIM = 2 loop unrolled + inline FT + transformed_distance(const Query_item& q, const Point_d& p, Dimension_tag<2> dt) const + { + FT distance = FT(0); + typename SearchTraits::Construct_cartesian_const_iterator_d construct_it= + traits.construct_cartesian_const_iterator_d_object(); + Coord_iterator qit = construct_it(q), + pit = construct_it(p); + if (power == FT(0)) { + if (the_weights[0] * CGAL::abs((*qit) - (*pit)) > distance) + distance = the_weights[0] * CGAL::abs((*qit)-(*pit)); + qit++;pit++; + if (the_weights[1] * CGAL::abs((*qit) - (*pit)) > distance) + distance = the_weights[1] * CGAL::abs((*qit)-(*pit)); + } + else{ + distance += + the_weights[0] * std::pow(CGAL::abs((*qit)-(*pit)),power); + qit++;pit++; + distance += + the_weights[1] * std::pow(CGAL::abs((*qit)-(*pit)),power); + } + return distance; + } + + //DIM = 3 loop unrolled + inline FT + transformed_distance(const Query_item& q, const Point_d& p, Dimension_tag<3> dt) const + { + FT distance = FT(0); + typename SearchTraits::Construct_cartesian_const_iterator_d construct_it= + traits.construct_cartesian_const_iterator_d_object(); + Coord_iterator qit = construct_it(q), + pit = construct_it(p); + if (power == FT(0)) { + if (the_weights[0] * CGAL::abs((*qit) - (*pit)) > distance) + distance = the_weights[0] * CGAL::abs((*qit)-(*pit)); + qit++;pit++; + if (the_weights[1] * CGAL::abs((*qit) - (*pit)) > distance) + distance = the_weights[1] * CGAL::abs((*qit)-(*pit)); + qit++;pit++; + if (the_weights[2] * CGAL::abs((*qit) - (*pit)) > distance) + distance = the_weights[2] * CGAL::abs((*qit)-(*pit)); + } + else{ + distance += + the_weights[0] * std::pow(CGAL::abs((*qit)-(*pit)),power); + qit++;pit++; + distance += + the_weights[1] * std::pow(CGAL::abs((*qit)-(*pit)),power); + qit++;pit++; + distance += + the_weights[2] * std::pow(CGAL::abs((*qit)-(*pit)),power); + } + return distance; + } inline FT