Robotics Library  0.6.2
Rrt.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2009, Markus Rickert
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 //
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 // POSSIBILITY OF SUCH DAMAGE.
25 //
26 
27 #ifndef _RL_PLAN_RRT_H_
28 #define _RL_PLAN_RRT_H_
29 
30 #include <boost/graph/adjacency_list.hpp>
31 #include <CGAL/Search_traits.h>
32 
33 #include "MatrixPtr.h"
35 #include "Planner.h"
36 #include "TransformPtr.h"
37 #include "VectorPtr.h"
38 
39 namespace rl
40 {
41  namespace plan
42  {
43  class Model;
44  class Sampler;
45  class Verifier;
46 
50  class Rrt : public Planner
51  {
52  public:
53  Rrt(const ::std::size_t& trees = 1);
54 
55  virtual ~Rrt();
56 
57  virtual ::std::string getName() const;
58 
59  virtual ::std::size_t getNumEdges() const;
60 
61  virtual ::std::size_t getNumVertices() const;
62 
63  virtual void getPath(VectorList& path);
64 
65  virtual void reset();
66 
67  virtual bool solve();
68 
71 
74 
76  bool kd;
77 
79 
80  protected:
81  struct VertexBundle
82  {
83  ::std::size_t index;
84 
86 
88 
90  };
91 
92  struct TreeBundle;
93 
94  typedef ::boost::adjacency_list<
95  ::boost::listS,
96  ::boost::listS,
97  ::boost::bidirectionalS,
99  ::boost::no_property,
100  TreeBundle
101  > Tree;
102 
103  typedef ::boost::adjacency_list_traits<
104  ::boost::listS,
105  ::boost::listS,
106  ::boost::bidirectionalS,
107  ::boost::listS
108  >::vertex_descriptor Vertex;
109 
110  typedef ::std::pair< const ::rl::math::Vector*, Vertex > QueryItem;
111 
113  {
115 
117 
118  const ::rl::math::Real* operator()(const QueryItem& p, const int&) const;
119  };
120 
121  struct Distance
122  {
124 
125  Distance();
126 
127  Distance(Model* model);
128 
129  template< typename SearchTraits > ::rl::math::Real max_distance_to_rectangle(const Query_item& q, const ::CGAL::Kd_tree_rectangle< SearchTraits >& r) const;
130 
131  template< typename SearchTraits > ::rl::math::Real min_distance_to_rectangle(const Query_item& q, const ::CGAL::Kd_tree_rectangle< SearchTraits >& r) const;
132 
133  ::rl::math::Real min_distance_to_rectangle(const ::rl::math::Real& q, const ::rl::math::Real& min, const ::rl::math::Real& max, const ::std::size_t& cutting_dimension) const;
134 
135  ::rl::math::Real new_distance(const ::rl::math::Real& dist, const ::rl::math::Real& old_off, const ::rl::math::Real& new_off, const int& cutting_dimension) const;
136 
138 
139  ::rl::math::Real transformed_distance(const Query_item& q1, const Query_item& q2) const;
140 
142  };
143 
144  typedef ::CGAL::Search_traits< ::rl::math::Real, QueryItem, const ::rl::math::Real*, CartesianIterator > SearchTraits;
145 
147 
148  typedef NeighborSearch::Tree NeighborSearchTree;
149 
150  typedef ::boost::shared_ptr< NeighborSearchTree > NeighborSearchTreePtr;
151 
152  typedef ::std::vector< NeighborSearchTreePtr > NearestNeighbors;
153 
154  struct TreeBundle
155  {
157  };
158 
159  typedef ::boost::graph_traits< Tree >::edge_descriptor Edge;
160 
161  typedef ::boost::graph_traits< Tree >::edge_iterator EdgeIterator;
162 
163  typedef ::std::pair< EdgeIterator, EdgeIterator > EdgeIteratorPair;
164 
165  typedef ::boost::graph_traits< Tree >::vertex_iterator VertexIterator;
166 
167  typedef ::std::pair< VertexIterator, VertexIterator > VertexIteratorPair;
168 
169  typedef ::std::pair< Vertex, ::rl::math::Real > Neighbor;
170 
171  virtual Edge addEdge(const Vertex& u, const Vertex& v, Tree& tree);
172 
173  void addPoint(NearestNeighbors& nn, const QueryItem& p);
174 
175  Vertex addVertex(Tree& tree, const VectorPtr& q);
176 
178 
179  virtual void choose(::rl::math::Vector& chosen);
180 
181  virtual Vertex connect(Tree& tree, const Neighbor& nearest, const ::rl::math::Vector& chosen);
182 
183  virtual Vertex extend(Tree& tree, const Neighbor& nearest, const ::rl::math::Vector& chosen);
184 
185  virtual Neighbor nearest(const Tree& tree, const ::rl::math::Vector& chosen);
186 
187  ::std::vector< Vertex > begin;
188 
189  ::std::vector< Vertex > end;
190 
191  ::std::vector< Tree > tree;
192 
193  private:
194 
195  };
196  }
197 }
198 
199 #endif // _RL_PLAN_RRT_H_
rl::plan::Rrt::Distance::model
Model * model
Definition: Rrt.h:141
rl::plan::Rrt::kd
bool kd
Use kd-tree for nearest neighbor search instead of brute-force.
Definition: Rrt.h:76
rl::plan::Rrt::TreeBundle
Definition: Rrt.h:155
rl::plan::Rrt::Distance::Distance
Distance()
Definition: Rrt.cpp:396
rl::plan::VectorPtr
::boost::shared_ptr< ::rl::math::Vector > VectorPtr
Definition: VectorPtr.h:37
rl::plan::Rrt::addVertex
Vertex addVertex(Tree &tree, const VectorPtr &q)
Definition: Rrt.cpp:109
rl::plan::Rrt::CartesianIterator::operator()
const ::rl::math::Real * operator()(const QueryItem &p) const
Definition: Rrt.cpp:385
rl::plan::Rrt::SearchTraits
::CGAL::Search_traits< ::rl::math::Real, QueryItem, const ::rl::math::Real *, CartesianIterator > SearchTraits
Definition: Rrt.h:144
rl::plan::Rrt::Distance::max_distance_to_rectangle
::rl::math::Real max_distance_to_rectangle(const Query_item &q, const ::CGAL::Kd_tree_rectangle< SearchTraits > &r) const
rl::plan::Orthogonal_k_neighbor_search
Definition: Orthogonal_k_neighbor_search.h:37
rl::plan::Rrt::VertexBundle::index
::std::size_t index
Definition: Rrt.h:83
rl::plan::Rrt::NeighborSearchTreePtr
::boost::shared_ptr< NeighborSearchTree > NeighborSearchTreePtr
Definition: Rrt.h:150
rl::plan::Rrt::getName
virtual ::std::string getName() const
Definition: Rrt.cpp:245
rl::plan::Rrt::Distance
Definition: Rrt.h:122
rl::plan::Rrt::VertexBundle::radius
::rl::math::Real radius
Definition: Rrt.h:87
rl::plan::Rrt::connect
virtual Vertex connect(Tree &tree, const Neighbor &nearest, const ::rl::math::Vector &chosen)
Definition: Rrt.cpp:149
rl::plan::Rrt::NeighborSearchTree
NeighborSearch::Tree NeighborSearchTree
Definition: Rrt.h:148
rl::plan::Rrt
Rapidly-Exploring Random Trees.
Definition: Rrt.h:51
rl::plan::Rrt::reset
virtual void reset()
Reset planner.
Definition: Rrt.cpp:340
rl::plan::Rrt::CartesianIterator
Definition: Rrt.h:113
rl::plan::Rrt::choose
virtual void choose(::rl::math::Vector &chosen)
Definition: Rrt.cpp:143
rl::plan::Rrt::EdgeIteratorPair
::std::pair< EdgeIterator, EdgeIterator > EdgeIteratorPair
Definition: Rrt.h:163
rl::plan::Rrt::Distance::new_distance
::rl::math::Real new_distance(const ::rl::math::Real &dist, const ::rl::math::Real &old_off, const ::rl::math::Real &new_off, const int &cutting_dimension) const
Definition: Rrt.cpp:453
rl::plan::Rrt::tree
::std::vector< Tree > tree
Definition: Rrt.h:191
rl::plan::Rrt::addPoint
void addPoint(NearestNeighbors &nn, const QueryItem &p)
Definition: Rrt.cpp:73
rl::plan::Rrt::getPath
virtual void getPath(VectorList &path)
Get solution path.
Definition: Rrt.cpp:277
Orthogonal_k_neighbor_search.h
rl::plan::Rrt::EdgeIterator
::boost::graph_traits< Tree >::edge_iterator EdgeIterator
Definition: Rrt.h:161
rl::plan::Rrt::delta
::rl::math::Real delta
Configuration step size.
Definition: Rrt.h:70
rl::plan::Planner
Definition: Planner.h:44
rl::plan::TransformPtr
::boost::shared_ptr< ::rl::math::Transform > TransformPtr
Definition: TransformPtr.h:37
rl::plan::Rrt::QueryItem
::std::pair< const ::rl::math::Vector *, Vertex > QueryItem
Definition: Rrt.h:110
rl::plan::Rrt::Neighbor
::std::pair< Vertex, ::rl::math::Real > Neighbor
Definition: Rrt.h:169
rl::plan::Rrt::VertexBundle
Definition: Rrt.h:82
rl::plan::Rrt::Distance::min_distance_to_rectangle
::rl::math::Real min_distance_to_rectangle(const Query_item &q, const ::CGAL::Kd_tree_rectangle< SearchTraits > &r) const
rl::plan::Rrt::Vertex
::boost::adjacency_list_traits< ::boost::listS, ::boost::listS, ::boost::bidirectionalS, ::boost::listS >::vertex_descriptor Vertex
Definition: Rrt.h:108
rl::plan::Model
Definition: Model.h:42
rl::plan::Rrt::Distance::Query_item
QueryItem Query_item
Definition: Rrt.h:123
rl::plan::Rrt::Edge
::boost::graph_traits< Tree >::edge_descriptor Edge
Definition: Rrt.h:159
rl::plan::Rrt::nearest
virtual Neighbor nearest(const Tree &tree, const ::rl::math::Vector &chosen)
Definition: Rrt.cpp:291
VectorPtr.h
rl::plan::Rrt::areEqual
bool areEqual(const ::rl::math::Vector &lhs, const ::rl::math::Vector &rhs) const
Definition: Rrt.cpp:130
TransformPtr.h
rl::plan::Rrt::epsilon
::rl::math::Real epsilon
Epsilon for configuration comparison.
Definition: Rrt.h:73
rl::plan::Rrt::sampler
Sampler * sampler
Definition: Rrt.h:78
rl::plan::Rrt::VertexIteratorPair
::std::pair< VertexIterator, VertexIterator > VertexIteratorPair
Definition: Rrt.h:167
rl::plan::Rrt::getNumVertices
virtual ::std::size_t getNumVertices() const
Definition: Rrt.cpp:264
rl::plan::VectorList
::std::list< ::rl::math::Vector > VectorList
Definition: VectorList.h:37
rl::plan::Rrt::end
::std::vector< Vertex > end
Definition: Rrt.h:189
rl::plan::Rrt::getNumEdges
virtual ::std::size_t getNumEdges() const
Definition: Rrt.cpp:251
rl::plan::Rrt::TreeBundle::nn
NearestNeighbors nn
Definition: Rrt.h:156
Planner.h
rl::plan::Rrt::extend
virtual Vertex extend(Tree &tree, const Neighbor &nearest, const ::rl::math::Vector &chosen)
Definition: Rrt.cpp:222
rl::plan::Rrt::Tree
::boost::adjacency_list< ::boost::listS, ::boost::listS, ::boost::bidirectionalS, VertexBundle, ::boost::no_property, TreeBundle > Tree
Definition: Rrt.h:92
rl::plan::Rrt::Distance::transformed_distance
::rl::math::Real transformed_distance(const ::rl::math::Real &d) const
Definition: Rrt.cpp:459
rl::plan::Rrt::VertexBundle::q
VectorPtr q
Definition: Rrt.h:85
rl::plan::Sampler
Definition: Sampler.h:39
rl::plan::Rrt::NeighborSearch
Orthogonal_k_neighbor_search< SearchTraits, Distance > NeighborSearch
Definition: Rrt.h:146
rl::math::Vector
::Eigen::Matrix< Real, ::Eigen::Dynamic, 1 > Vector
Definition: Vector.h:41
rl::plan::Rrt::CartesianIterator::result_type
typedefconst ::rl::math::Real * result_type
Definition: Rrt.h:114
rl::plan::Rrt::begin
::std::vector< Vertex > begin
Definition: Rrt.h:187
MatrixPtr.h
rl::plan::Rrt::Rrt
Rrt(const ::std::size_t &trees=1)
Definition: Rrt.cpp:43
rl::math::Real
double Real
Definition: Real.h:34
rl::plan::Rrt::VertexIterator
::boost::graph_traits< Tree >::vertex_iterator VertexIterator
Definition: Rrt.h:165
rl::plan::Rrt::NearestNeighbors
::std::vector< NeighborSearchTreePtr > NearestNeighbors
Definition: Rrt.h:152
rl::plan::Rrt::VertexBundle::t
TransformPtr t
Definition: Rrt.h:89
rl::plan::Rrt::addEdge
virtual Edge addEdge(const Vertex &u, const Vertex &v, Tree &tree)
Definition: Rrt.cpp:60
rl::plan::Rrt::~Rrt
virtual ~Rrt()
Definition: Rrt.cpp:55
rl::plan::Rrt::solve
virtual bool solve()
Find collision free path.
Definition: Rrt.cpp:352
rl
Definition: Ati.cpp:35