mirror of https://github.com/CGAL/cgal
Added dimension tags to Kd_tree_rectangle
Introduced dimension tags for a speedup when we know the dimension at compiletime.
This commit is contained in:
parent
9da9cff768
commit
e6019889cc
|
|
@ -24,11 +24,34 @@
|
|||
|
||||
#include <CGAL/Kd_tree_rectangle.h>
|
||||
#include <CGAL/number_utils.h>
|
||||
#include <CGAL/Dimension.h>
|
||||
|
||||
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 <class SearchTraits, bool has_dim = has_dimension<SearchTraits>::value>
|
||||
struct Euclidean_distance_sphere_point_base;
|
||||
|
||||
template <class SearchTraits>
|
||||
struct Euclidean_distance_sphere_point_base<SearchTraits,true>{
|
||||
typedef typename SearchTraits::Dimension Dimension;
|
||||
};
|
||||
|
||||
template <class SearchTraits>
|
||||
struct Euclidean_distance_sphere_point_base<SearchTraits,false>{
|
||||
typedef Dynamic_dimension_tag Dimension;
|
||||
};
|
||||
}
|
||||
|
||||
template <class SearchTraits>
|
||||
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<SearchTraits>::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<FT>& r) const {
|
||||
const Kd_tree_rectangle<FT,Dimension>& 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<FT>& r) const {
|
||||
const Kd_tree_rectangle<FT,Dimension>& r) const {
|
||||
Construct_center_d construct_center_d;
|
||||
Point_d c = construct_center_d(q);
|
||||
FT distance=FT(0);
|
||||
|
|
|
|||
|
|
@ -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<FT>& rectangle) const {
|
||||
bool inner_range_intersects(const Kd_tree_rectangle<FT,Dimension>& 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<FT>& rectangle) const {
|
||||
bool outer_range_contains(const Kd_tree_rectangle<FT,Dimension>& 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) )
|
||||
|
|
|
|||
|
|
@ -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<FT>& rectangle) const {
|
||||
bool inner_range_intersects(const Kd_tree_rectangle<FT,Dimension>& 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<FT>& rectangle) const {
|
||||
bool outer_range_contains(const Kd_tree_rectangle<FT,Dimension>& 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
|
||||
|
|
|
|||
|
|
@ -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<FT> Node_box;
|
||||
typedef Kd_tree_rectangle<FT,Dimension> Node_box;
|
||||
typedef typename Distance::Query_item Query_item;
|
||||
|
||||
class Cell {
|
||||
|
|
|
|||
|
|
@ -162,7 +162,7 @@ namespace CGAL {
|
|||
template <class OutputIterator, class FuzzyQueryItem>
|
||||
OutputIterator
|
||||
search(OutputIterator it, const FuzzyQueryItem& q,
|
||||
Kd_tree_rectangle<FT>& b) const
|
||||
Kd_tree_rectangle<FT,D>& b) const
|
||||
{
|
||||
if (is_leaf()) {
|
||||
Leaf_node_const_handle node =
|
||||
|
|
@ -176,7 +176,7 @@ namespace CGAL {
|
|||
Internal_node_const_handle node =
|
||||
static_cast<Internal_node_const_handle>(this);
|
||||
// after splitting b denotes the lower part of b
|
||||
Kd_tree_rectangle<FT> b_upper(b);
|
||||
Kd_tree_rectangle<FT,D> b_upper(b);
|
||||
b.split(b_upper, node->cutting_dimension(),
|
||||
node->cutting_value());
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ namespace CGAL {
|
|||
};
|
||||
|
||||
|
||||
template <class FT_, typename D>
|
||||
template <class FT_, typename D = Dynamic_dimension_tag>
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -23,9 +23,30 @@
|
|||
#define CGAL_MANHATTAN_DISTANCE_ISO_BOX_POINT_H
|
||||
|
||||
#include <CGAL/Kd_tree_rectangle.h>
|
||||
#include <CGAL/Dimension.h>
|
||||
|
||||
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 <class SearchTraits, bool has_dim = has_dimension<SearchTraits>::value>
|
||||
struct Manhattan_distance_iso_box_point_base;
|
||||
|
||||
template <class SearchTraits>
|
||||
struct Manhattan_distance_iso_box_point_base<SearchTraits,true>{
|
||||
typedef typename SearchTraits::Dimension Dimension;
|
||||
};
|
||||
|
||||
template <class SearchTraits>
|
||||
struct Manhattan_distance_iso_box_point_base<SearchTraits,false>{
|
||||
typedef Dynamic_dimension_tag Dimension;
|
||||
};
|
||||
}
|
||||
|
||||
template <class SearchTraits>
|
||||
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<SearchTraits>::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<FT>& r) const {
|
||||
const Kd_tree_rectangle<FT,Dimension>& 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<FT>& r) const {
|
||||
const Kd_tree_rectangle<FT,Dimension>& r) const {
|
||||
FT distance=FT(0);
|
||||
typename SearchTraits::Construct_cartesian_const_iterator_d construct_it=
|
||||
traits.construct_cartesian_const_iterator_d_object();
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
|
||||
namespace CGAL {
|
||||
template <class FT_, class Point, class CartesianCoordinateIterator, class ConstructCartesianCoordinateIterator, typename D>
|
||||
template <class FT_, class Point, class CartesianCoordinateIterator, class ConstructCartesianCoordinateIterator, typename D = Dynamic_dimension_tag>
|
||||
class Search_traits {
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -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 <class FT>
|
||||
FT min_distance_to_rectangle(const Query_item& p, const CGAL::Kd_tree_rectangle<FT>& b) const
|
||||
template <class FT,class Dimension>
|
||||
FT min_distance_to_rectangle(const Query_item& p, const CGAL::Kd_tree_rectangle<FT,Dimension>& b) const
|
||||
{
|
||||
return static_cast<const Base_distance*>(this)->min_distance_to_rectangle(p,b);
|
||||
}
|
||||
|
||||
template <class FT>
|
||||
FT max_distance_to_rectangle(const Query_item& p,const CGAL::Kd_tree_rectangle<FT>& b) const
|
||||
template <class FT,class Dimension>
|
||||
FT max_distance_to_rectangle(const Query_item& p,const CGAL::Kd_tree_rectangle<FT,Dimension>& b) const
|
||||
{
|
||||
return static_cast<const Base_distance*>(this)->max_distance_to_rectangle(p,b);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,9 +29,30 @@
|
|||
|
||||
#include <CGAL/number_utils.h>
|
||||
#include <CGAL/Kd_tree_rectangle.h>
|
||||
#include <CGAL/Dimension.h>
|
||||
|
||||
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 <class SearchTraits, bool has_dim = has_dimension<SearchTraits>::value>
|
||||
struct Weighted_Minkowski_distance_base;
|
||||
|
||||
template <class SearchTraits>
|
||||
struct Weighted_Minkowski_distance_base<SearchTraits,true>{
|
||||
typedef typename SearchTraits::Dimension Dimension;
|
||||
};
|
||||
|
||||
template <class SearchTraits>
|
||||
struct Weighted_Minkowski_distance_base<SearchTraits,false>{
|
||||
typedef Dynamic_dimension_tag Dimension;
|
||||
};
|
||||
}
|
||||
|
||||
template <class SearchTraits>
|
||||
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<FT> Weight_vector;
|
||||
typedef typename internal::Euclidean_distance_base<SearchTraits>::Dimension Dimension;
|
||||
|
||||
private:
|
||||
|
||||
|
|
@ -123,7 +145,7 @@ namespace CGAL {
|
|||
inline
|
||||
FT
|
||||
min_distance_to_rectangle(const Query_item& q,
|
||||
const Kd_tree_rectangle<FT>& r) const
|
||||
const Kd_tree_rectangle<FT,Dimension>& 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<FT>& r) const {
|
||||
const Kd_tree_rectangle<FT,Dimension>& r) const {
|
||||
FT distance=FT(0);
|
||||
typename SearchTraits::Construct_cartesian_const_iterator_d construct_it=
|
||||
traits.construct_cartesian_const_iterator_d_object();
|
||||
|
|
|
|||
Loading…
Reference in New Issue