7 #ifndef NUKLEI_KERNEL_COLLECTION_FLEXIBLE_POINT_H
8 #define NUKLEI_KERNEL_COLLECTION_FLEXIBLE_POINT_H
20 FlexiblePoint() : idx_(-1) { vec_[0]= vec_[1] = vec_[2] = 0; }
21 FlexiblePoint (value_type x, value_type y, value_type z) : idx_(-1)
22 { vec_[0]=x; vec_[1]=y; vec_[2]=z; }
23 FlexiblePoint (value_type x, value_type y, value_type z,
int idx) : idx_(idx)
24 { vec_[0]=x; vec_[1]=y; vec_[2]=z; }
27 inline value_type x()
const {
return vec_[ 0 ]; }
28 inline value_type y()
const {
return vec_[ 1 ]; }
29 inline value_type z()
const {
return vec_[ 2 ]; }
32 inline value_type& x() {
return vec_[ 0 ]; }
33 inline value_type& y() {
return vec_[ 1 ]; }
34 inline value_type& z() {
return vec_[ 2 ]; }
37 inline const value_type* vec()
const {
return vec_; }
38 inline value_type* vec() {
return vec_; }
41 inline value_type operator[](
const size_t i)
const {
return vec_[i]; }
46 return (x() == p.x()) && (y() == p.y()) && (z() == p.z()) && (idx() == p.idx());
51 {
return ! (*
this == p); }
54 inline int idx()
const {
return idx_; }
55 inline int& idx() {
return idx_; }
59 {
return static_cast<const value_type*
>(p.vec()); }
61 const value_type* operator()(
const FlexiblePoint& p,
int)
const
62 {
return static_cast<const value_type*
>(p.vec()+3); }
67 typedef value_type result_type;
70 operator()(
const FlexiblePoint& p,
const size_t i)
const throw ()
80 value_type distx= p1.x()-p2.x();
81 value_type disty= p1.y()-p2.y();
82 value_type distz= p1.z()-p2.z();
83 return distx*distx+disty*disty+distz*distz;
86 #ifdef NUKLEI_USE_CGAL
87 template <
class TreeTraits>
89 const CGAL::Kd_tree_rectangle<TreeTraits>& b)
const
91 value_type distance(0.0), h = p.x();
92 if (h < b.min_coord(0)) distance += (b.min_coord(0)-h)*(b.min_coord(0)-h);
93 if (h > b.max_coord(0)) distance += (h-b.max_coord(0))*(h-b.max_coord(0));
95 if (h < b.min_coord(1)) distance += (b.min_coord(1)-h)*(b.min_coord(1)-h);
96 if (h > b.max_coord(1)) distance += (h-b.max_coord(1))*(h-b.min_coord(1));
98 if (h < b.min_coord(2)) distance += (b.min_coord(2)-h)*(b.min_coord(2)-h);
99 if (h > b.max_coord(2)) distance += (h-b.max_coord(2))*(h-b.max_coord(2));
103 template <
class TreeTraits>
105 const CGAL::Kd_tree_rectangle<TreeTraits>& b)
const
107 value_type h = p.x();
109 value_type d0 = (h >= (b.min_coord(0)+b.max_coord(0))/2.0) ?
110 (h-b.min_coord(0))*(h-b.min_coord(0)) : (b.max_coord(0)-h)*(b.max_coord(0)-h);
113 value_type d1 = (h >= (b.min_coord(1)+b.max_coord(1))/2.0) ?
114 (h-b.min_coord(1))*(h-b.min_coord(1)) : (b.max_coord(1)-h)*(b.max_coord(1)-h);
116 value_type d2 = (h >= (b.min_coord(2)+b.max_coord(2))/2.0) ?
117 (h-b.min_coord(2))*(h-b.min_coord(2)) : (b.max_coord(2)-h)*(b.max_coord(2)-h);
122 value_type new_distance(value_type&
dist, value_type old_off, value_type new_off,
125 return dist + new_off*new_off - old_off*old_off;
128 value_type transformed_distance(value_type d)
const {
return d*d; }
130 value_type inverse_of_transformed_distance(value_type d) {
return std::sqrt(d); }
139 inline std::ostream& operator<<(std::ostream& out,
const FlexiblePoint& p)
141 out << p.x() <<
" " << p.y() <<
" " << p.z() <<
" " << p.idx();