PathGeometric.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_PATH_GEOMETRIC_
38 #define OMPL_GEOMETRIC_PATH_GEOMETRIC_
39 
40 #include "ompl/base/SpaceInformation.h"
41 #include "ompl/base/Path.h"
42 #include <vector>
43 #include <utility>
44 
45 namespace ompl
46 {
47  namespace base
48  {
50  OMPL_CLASS_FORWARD(OptimizationObjective);
52  }
53 
55  namespace geometric
56  {
60  class PathGeometric : public base::Path
61  {
62  public:
63 
65  PathGeometric(const base::SpaceInformationPtr &si) : base::Path(si)
66  {
67  }
68 
70  PathGeometric(const PathGeometric &path);
71 
73  PathGeometric(const base::SpaceInformationPtr &si, const base::State *state);
74 
76  PathGeometric(const base::SpaceInformationPtr &si, const base::State *state1, const base::State *state2);
77 
78  virtual ~PathGeometric()
79  {
80  freeMemory();
81  }
82 
84  PathGeometric& operator=(const PathGeometric &other);
85 
89  virtual base::Cost cost(const base::OptimizationObjectivePtr &obj) const;
90 
92  virtual double length() const;
93 
95  virtual bool check() const;
96 
110  double smoothness() const;
111 
123  double clearance() const;
124 
126  virtual void print(std::ostream &out) const;
131  virtual void printAsMatrix(std::ostream &out) const;
132 
141  void interpolate(unsigned int count);
142 
147  void interpolate();
148 
150  void subdivide();
151 
153  void reverse();
154 
166  std::pair<bool, bool> checkAndRepair(unsigned int attempts);
167 
178  void overlay(const PathGeometric &over, unsigned int startIndex = 0);
179 
181  void append(const base::State *state);
182 
194  void append(const PathGeometric &path);
195 
197  void prepend(const base::State *state);
198 
200  void keepAfter(const base::State *state);
201 
203  void keepBefore(const base::State *state);
204 
206  void random();
207 
209  bool randomValid(unsigned int attempts);
216  int getClosestIndex(const base::State *state) const;
217 
219  std::vector<base::State*>& getStates()
220  {
221  return states_;
222  }
223 
225  base::State* getState(unsigned int index)
226  {
227  return states_[index];
228  }
229 
231  const base::State* getState(unsigned int index) const
232  {
233  return states_[index];
234  }
235 
237  std::size_t getStateCount() const
238  {
239  return states_.size();
240  }
241 
244  protected:
245 
247  void freeMemory();
248 
250  void copyFrom(const PathGeometric &other);
251 
253  std::vector<base::State*> states_;
254  };
255 
256  }
257 }
258 
259 #endif
PathGeometric(const base::SpaceInformationPtr &si)
Construct a path instance for a given space information.
Definition: PathGeometric.h:65
base::State * getState(unsigned int index)
Get the state located at index along the path.
std::size_t getStateCount() const
Get the number of states (way-points) that make up this path.
Main namespace. Contains everything in this library.
Definition: Cost.h:42
std::vector< base::State * > & getStates()
Get the states that make up the path (as a reference, so it can be modified, hence the function is no...
Abstract definition of a path.
Definition: Path.h:67
A boost shared pointer wrapper for ompl::base::SpaceInformation.
Definition of an abstract state.
Definition: State.h:50
A boost shared pointer wrapper for ompl::base::OptimizationObjective.
const base::State * getState(unsigned int index) const
Get the state located at index along the path.
std::vector< base::State * > states_
The list of states that make up the path.
Definition of a geometric path.
Definition: PathGeometric.h:60
Definition of a cost value. Can represent the cost of a motion or the cost of a state.
Definition: Cost.h:47