Robotics Library  0.6.2
Orthogonal_k_neighbor_search.h
Go to the documentation of this file.
1 // Copyright (c) 2002,2011 Utrecht University (The Netherlands).
2 // All rights reserved.
3 //
4 // This file is part of CGAL (www.cgal.org).
5 // You can redistribute it and/or modify it under the terms of the GNU
6 // General Public License as published by the Free Software Foundation,
7 // either version 3 of the License, or (at your option) any later version.
8 //
9 // Licensees holding a valid commercial license may use this file in
10 // accordance with the commercial license agreement provided with the software.
11 //
12 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14 //
15 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/next/Spatial_searching/include/CGAL/Orthogonal_k_neighbor_search.h $
16 // $Id: Orthogonal_k_neighbor_search.h 67117 2012-01-13 18:14:48Z lrineau $
17 //
18 //
19 // Author(s) : Gael Guennebaud (gael.guennebaud@inria.fr), Hans Tangelder (<hanst@cs.uu.nl>)
20 // Markus Rickert
21 
22 #ifndef _RL_PLAN_ORTHOGONAL_K_NEIGHBOR_SEARCH_H_
23 #define _RL_PLAN_ORTHOGONAL_K_NEIGHBOR_SEARCH_H_
24 
25 #include <CGAL/internal/K_neighbor_search.h>
26 
27 namespace rl { namespace plan {
28 
29 template <class SearchTraits,
30 #if (CGAL_VERSION_NR > 1030801000)
31  class Distance= typename ::CGAL::internal::Spatial_searching_default_distance<SearchTraits>::type,
32 #else
33  class Distance= ::CGAL::Euclidean_distance<SearchTraits>,
34 #endif
35  class Splitter= ::CGAL::Sliding_midpoint<SearchTraits> ,
36  class Tree= ::CGAL::Kd_tree<SearchTraits, Splitter, ::CGAL::Tag_true> >
37 class Orthogonal_k_neighbor_search: public ::CGAL::internal::K_neighbor_search<SearchTraits,Distance,Splitter,Tree> {
38  typedef ::CGAL::internal::K_neighbor_search<SearchTraits,Distance,Splitter,Tree> Base;
39 
40  typename SearchTraits::Cartesian_const_iterator_d query_object_it;
41 
42 public:
43  typedef typename Base::FT FT;
44 
45 #if (CGAL_VERSION_NR > 1030901000)
46  Orthogonal_k_neighbor_search(const Tree& tree, const typename Base::Query_item& q,
47 #else
48  Orthogonal_k_neighbor_search(Tree& tree, const typename Base::Query_item& q,
49 #endif
50  unsigned int k=1, FT Eps=FT(0.0), bool Search_nearest=true, const Distance& d=Distance(),bool sorted=true)
51  : Base(q,k,Eps,Search_nearest,d)
52  {
53  if (tree.empty()) return;
54 
55  FT distance_to_root;
56  if (this->search_nearest)
57  distance_to_root = this->distance_instance.min_distance_to_rectangle(q, tree.bounding_box());
58  else
59  distance_to_root = this->distance_instance.max_distance_to_rectangle(q, tree.bounding_box());
60 
61 
62 #if (CGAL_VERSION_NR > 1030801000)
63  typename SearchTraits::Construct_cartesian_const_iterator_d construct_it=tree.traits().construct_cartesian_const_iterator_d_object();
64 #else
65  typename SearchTraits::Construct_cartesian_const_iterator_d construct_it;
66 #endif
67  query_object_it = construct_it(this->query_object);
68 
69  compute_neighbors_orthogonally(tree.root(), distance_to_root);
70 
71  if (sorted) this->queue.sort();
72  }
73 private:
74 
75 #if (CGAL_VERSION_NR > 1030901000)
76  void compute_neighbors_orthogonally(typename Base::Node_const_handle N, FT rd)
77 #else
78  void compute_neighbors_orthogonally(typename Base::Node_handle N, FT rd)
79 #endif
80  {
81  if (!(N->is_leaf()))
82  {
83  this->number_of_internal_nodes_visited++;
84  int new_cut_dim=N->cutting_dimension();
85  FT new_rd;
86  FT low_off = this->distance_instance.min_distance_to_rectangle(
87  *(query_object_it + new_cut_dim),
88  N->low_value(),
89  N->cutting_value(),
90  new_cut_dim
91  );
92  FT high_off = this->distance_instance.min_distance_to_rectangle(
93  *(query_object_it + new_cut_dim),
94  N->cutting_value(),
95  N->high_value(),
96  new_cut_dim
97  );
98  if ( ((low_off < high_off) && (this->search_nearest)) ||
99  ((low_off >= high_off) && (!this->search_nearest)) )
100  {
101  compute_neighbors_orthogonally(N->lower(),rd);
102  if (this->search_nearest) {
103  new_rd = this->distance_instance.new_distance(rd,low_off,high_off,new_cut_dim);
104  }
105  else {
106  new_rd = this->distance_instance.new_distance(rd,high_off,low_off,new_cut_dim);
107  }
108  if (this->branch(new_rd))
109  compute_neighbors_orthogonally(N->upper(), new_rd);
110  }
111  else // compute new distance
112  {
113  compute_neighbors_orthogonally(N->upper(),rd);
114  if (this->search_nearest) {
115  new_rd = this->distance_instance. new_distance(rd,high_off,low_off,new_cut_dim);
116  }
117  else {
118  new_rd = this->distance_instance. new_distance(rd,low_off,high_off,new_cut_dim);
119  }
120  if (this->branch(new_rd))
121  compute_neighbors_orthogonally(N->lower(), new_rd);
122  }
123  }
124  else
125  {
126  // n is a leaf
127  this->number_of_leaf_nodes_visited++;
128  if (N->size() > 0)
129  {
130  for (typename Base::Point_d_iterator it=N->begin(); it != N->end(); it++)
131  {
132  this->number_of_items_visited++;
133  FT distance_to_query_object=
134  this->distance_instance.transformed_distance(this->query_object,**it);
135  this->queue.insert(::std::make_pair(*it,distance_to_query_object));
136  }
137  }
138  }
139  }
140 
141 }; // class
142 
143 } } // namespace
144 
145 #endif // _RL_PLAN_ORTHOGONAL_K_NEIGHBOR_SEARCH_H_
rl::plan::Orthogonal_k_neighbor_search
Definition: Orthogonal_k_neighbor_search.h:37
if
if(BULLET_FOUND) set(BULLET_HDRS bullet/Body.h bullet/Model.h bullet/Scene.h bullet/Shape.h) set(HDRS $
Definition: CMakeLists.txt:39
rl::plan::Orthogonal_k_neighbor_search::compute_neighbors_orthogonally
void compute_neighbors_orthogonally(typename Base::Node_handle N, FT rd)
Definition: Orthogonal_k_neighbor_search.h:78
rl::plan::Orthogonal_k_neighbor_search::Orthogonal_k_neighbor_search
Orthogonal_k_neighbor_search(Tree &tree, const typename Base::Query_item &q, unsigned int k=1, FT Eps=FT(0.0), bool Search_nearest=true, const Distance &d=Distance(), bool sorted=true)
Definition: Orthogonal_k_neighbor_search.h:48
rl::plan::Orthogonal_k_neighbor_search::query_object_it
SearchTraits::Cartesian_const_iterator_d query_object_it
Definition: Orthogonal_k_neighbor_search.h:40
rl::plan::Orthogonal_k_neighbor_search::FT
Base::FT FT
Definition: Orthogonal_k_neighbor_search.h:43
rl::plan::Orthogonal_k_neighbor_search::Base
::CGAL::internal::K_neighbor_search< SearchTraits, Distance, Splitter, Tree > Base
Definition: Orthogonal_k_neighbor_search.h:38
rl
Definition: Ati.cpp:35