All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
SBL.h
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2008, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
35 /* Author: Ioan Sucan */
36 
37 #ifndef OMPL_GEOMETRIC_PLANNERS_SBL_SBL_
38 #define OMPL_GEOMETRIC_PLANNERS_SBL_SBL_
39 
40 #include "ompl/geometric/planners/PlannerIncludes.h"
41 #include "ompl/base/ProjectionEvaluator.h"
42 #include "ompl/datastructures/Grid.h"
43 #include "ompl/datastructures/PDF.h"
44 #include <vector>
45 
46 namespace ompl
47 {
48 
49  namespace geometric
50  {
51 
85  class SBL : public base::Planner
86  {
87  public:
88 
90  SBL(const base::SpaceInformationPtr &si);
91 
92  virtual ~SBL(void);
93 
96  void setProjectionEvaluator(const base::ProjectionEvaluatorPtr &projectionEvaluator)
97  {
98  projectionEvaluator_ = projectionEvaluator;
99  }
100 
103  void setProjectionEvaluator(const std::string &name)
104  {
105  projectionEvaluator_ = si_->getStateSpace()->getProjection(name);
106  }
107 
110  {
111  return projectionEvaluator_;
112  }
113 
119  void setRange(double distance)
120  {
121  maxDistance_ = distance;
122  }
123 
125  double getRange(void) const
126  {
127  return maxDistance_;
128  }
129 
130  virtual void setup(void);
131 
133 
134  virtual void clear(void);
135 
136  virtual void getPlannerData(base::PlannerData &data) const;
137 
138  protected:
139 
140  struct MotionInfo;
141 
144 
147 
149  class Motion
150  {
151  public:
152 
154  Motion(void) : root(NULL), state(NULL), parent(NULL), valid(false)
155  {
156  }
157 
159  Motion(const base::SpaceInformationPtr &si) : root(NULL), state(si->allocState()), parent(NULL), valid(false)
160  {
161  }
162 
165 
168 
171 
173  bool valid;
174 
176  std::vector<Motion*> children;
177  };
178 
180  struct MotionInfo
181  {
182  Motion* operator[](unsigned int i)
183  {
184  return motions_[i];
185  }
186  std::vector<Motion*>::iterator begin (void)
187  {
188  return motions_.begin ();
189  }
190  void erase (std::vector<Motion*>::iterator iter)
191  {
192  motions_.erase (iter);
193  }
194  void push_back(Motion* m)
195  {
196  motions_.push_back(m);
197  }
198  unsigned int size(void) const
199  {
200  return motions_.size();
201  }
202  bool empty(void) const
203  {
204  return motions_.empty();
205  }
206 
207  std::vector<Motion*> motions_;
208  CellPDF::Element* elem_;
209  };
210 
212  struct TreeData
213  {
214  TreeData(void) : grid(0), size(0)
215  {
216  }
217 
220 
222  unsigned int size;
223 
226  };
227 
229  void freeMemory(void)
230  {
233  }
234 
236  void freeGridMotions(Grid<MotionInfo> &grid);
237 
239  void addMotion(TreeData &tree, Motion *motion);
240 
242  Motion* selectMotion(TreeData &tree);
243 
245  void removeMotion(TreeData &tree, Motion *motion);
246 
252  bool isPathValid(TreeData &tree, Motion *motion);
253 
255  bool checkSolution(bool start, TreeData &tree, TreeData &otherTree, Motion *motion, std::vector<Motion*> &solution);
256 
259 
262 
265 
268 
270  double maxDistance_;
271 
274 
276  std::pair<base::State*, base::State*> connectionPoint_;
277  };
278 
279  }
280 }
281 
282 #endif