ProjectionEvaluator.h
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2010, Rice University
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 Rice University 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_BASE_PROJECTION_EVALUATOR_
38 #define OMPL_BASE_PROJECTION_EVALUATOR_
39 
40 #include "ompl/base/State.h"
41 #include "ompl/util/ClassForward.h"
42 #include "ompl/util/Console.h"
43 #include "ompl/base/GenericParam.h"
44 #include "ompl/base/spaces/RealVectorBounds.h"
45 
46 #include <vector>
47 #include <valarray>
48 #include <iostream>
49 #include <boost/numeric/ublas/matrix.hpp>
50 
51 namespace ompl
52 {
53  namespace base
54  {
56  typedef std::vector<int> ProjectionCoordinates;
57 
59  typedef boost::numeric::ublas::vector<double> EuclideanProjection;
63  class ProjectionMatrix
64  {
65  public:
67  typedef boost::numeric::ublas::matrix<double> Matrix;
68 
85  static Matrix ComputeRandom(unsigned int from, unsigned int to,
86  const std::vector<double> &scale);
87 
97  static Matrix ComputeRandom(unsigned int from, unsigned int to);
98 
100  void computeRandom(unsigned int from, unsigned int to, const std::vector<double> &scale);
101 
103  void computeRandom(unsigned int from, unsigned int to);
104 
106  void project(const double *from, EuclideanProjection &to) const;
107 
109  void print(std::ostream &out = std::cout) const;
110 
112  Matrix mat;
113  };
114 
116  OMPL_CLASS_FORWARD(StateSpace);
118 
120 
121  OMPL_CLASS_FORWARD(ProjectionEvaluator);
123 
133  class ProjectionEvaluator
134  {
135  public:
136  // non-copyable
137  ProjectionEvaluator(const ProjectionEvaluator &) = delete;
138  ProjectionEvaluator &operator=(const ProjectionEvaluator &) = delete;
139 
141  ProjectionEvaluator(const StateSpace *space);
142 
144  ProjectionEvaluator(const StateSpacePtr &space);
145 
146  virtual ~ProjectionEvaluator();
147 
149  virtual unsigned int getDimension() const = 0;
150 
152  virtual void project(const State *state, EuclideanProjection &projection) const = 0;
153 
161  virtual void setCellSizes(const std::vector<double> &cellSizes);
162 
167  void setCellSizes(unsigned int dim, double cellSize);
168 
175  void mulCellSizes(double factor);
176 
179  bool userConfigured() const;
180 
182  const std::vector<double> &getCellSizes() const
183  {
184  return cellSizes_;
185  }
186 
188  double getCellSizes(unsigned int dim) const;
189 
191  void checkCellSizes() const;
192 
198  void inferCellSizes();
199 
204  virtual void defaultCellSizes();
205 
207  void checkBounds() const;
208 
210  bool hasBounds() const
211  {
212  return !bounds_.low.empty();
213  }
214 
218  void setBounds(const RealVectorBounds &bounds);
219 
221  const RealVectorBounds &getBounds() const
222  {
223  return bounds_;
224  }
225 
228  void inferBounds();
229 
231  virtual void setup();
232 
234  void computeCoordinates(const EuclideanProjection &projection, ProjectionCoordinates &coord) const;
235 
237  void computeCoordinates(const State *state, ProjectionCoordinates &coord) const
238  {
239  EuclideanProjection projection(getDimension());
240  project(state, projection);
241  computeCoordinates(projection, coord);
242  }
243 
245  ParamSet &params()
246  {
247  return params_;
248  }
249 
251  const ParamSet &params() const
252  {
253  return params_;
254  }
255 
257  virtual void printSettings(std::ostream &out = std::cout) const;
258 
260  virtual void printProjection(const EuclideanProjection &projection, std::ostream &out = std::cout) const;
261 
262  protected:
264  void estimateBounds();
265 
267  const StateSpace *space_;
268 
272  std::vector<double> cellSizes_;
273 
275  RealVectorBounds bounds_;
276 
280  RealVectorBounds estimatedBounds_;
281 
286  bool defaultCellSizes_;
287 
291 
293  ParamSet params_;
294  };
295 
300  class SubspaceProjectionEvaluator : public ProjectionEvaluator
301  {
302  public:
309  SubspaceProjectionEvaluator(const StateSpace *space, unsigned int index,
311 
312  void setup() override;
313 
314  unsigned int getDimension() const override;
315 
316  void project(const State *state, EuclideanProjection &projection) const override;
317 
318  protected:
320  unsigned int index_;
321 
327 
331  };
332  }
333 }
334 
335 #endif
void mulCellSizes(double factor)
Multiply the cell sizes in each dimension by a specified factor factor. This function does nothing if...
void inferCellSizes()
Sample the state space and decide on default cell sizes. This function is called by setup() if no cel...
void setBounds(const RealVectorBounds &bounds)
Set bounds on the projection. The PDST planner needs to known the bounds on the projection....
Maintain a set of parameters.
Definition: GenericParam.h:290
void project(const double *from, EuclideanProjection &to) const
Multiply the vector from by the contained projection matrix to obtain the vector to.
Representation of a space in which planning can be performed. Topology specific sampling,...
Definition: StateSpace.h:134
virtual void project(const State *state, EuclideanProjection &projection) const =0
Compute the projection as an array of double values.
void computeRandom(unsigned int from, unsigned int to, const std::vector< double > &scale)
Wrapper for ComputeRandom(from, to, scale)
std::vector< int > ProjectionCoordinates
Grid cells corresponding to a projection value are described in terms of their coordinates.
Definition of an abstract state.
Definition: State.h:113
virtual void printSettings(std::ostream &out=std::cout) const
Print settings about this projection.
std::vector< double > low
Lower bound.
virtual void printProjection(const EuclideanProjection &projection, std::ostream &out=std::cout) const
Print a euclidean projection.
virtual void setCellSizes(const std::vector< double > &cellSizes)
Define the size (in each dimension) of a grid cell. The number of sizes set here must be the same as ...
void computeCoordinates(const EuclideanProjection &projection, ProjectionCoordinates &coord) const
Compute integer coordinates for a projection.
void estimateBounds()
Fill estimatedBounds_ with an approximate bounding box for the projection space (via sampling)
bool hasBounds() const
Check if bounds were specified for this projection.
virtual unsigned int getDimension() const =0
Return the dimension of the projection defined by this evaluator.
void project(const State *state, EuclideanProjection &projection) const override
Compute the projection as an array of double values.
A shared pointer wrapper for ompl::base::ProjectionEvaluator.
void setup() override
Perform configuration steps, if needed.
void checkCellSizes() const
Check if cell dimensions match projection dimension.
ProjectionEvaluatorPtr proj_
The projection to use. This is either the same as specifiedProj_ or, if specifiedProj_ is not initial...
RealVectorBounds bounds_
A bounding box for projected state values.
Abstract definition for a class computing projections to Rn. Implicit integer grids are imposed on th...
void inferBounds()
Compute an approximation of the bounds for this projection space. getBounds() will then report the co...
const RealVectorBounds & getBounds() const
Get the bounds computed/set for this projection.
virtual void setup()
Perform configuration steps, if needed.
bool userConfigured() const
Return true if any user configuration has been done to this projection evaluator (setCellSizes() was ...
unsigned int index_
The index of the subspace from which to project.
ParamSet & params()
Get the parameters for this projection.
std::vector< double > cellSizes_
The size of a cell, in every dimension of the projected space, in the implicitly defined integer grid...
SubspaceProjectionEvaluator(const StateSpace *space, unsigned int index, ProjectionEvaluatorPtr projToUse=ProjectionEvaluatorPtr())
The constructor states that for space space, the projection to use is the same as the component at po...
unsigned int getDimension() const override
Return the dimension of the projection defined by this evaluator.
bool cellSizesWereInferred_
Flag indicating whether projection cell sizes were automatically inferred.
void checkBounds() const
Check if the projection dimension matched the dimension of the bounds.
boost::numeric::ublas::vector< double > EuclideanProjection
The datatype for state projections. This class contains a real vector.
ParamSet params_
The set of parameters for this projection.
RealVectorBounds estimatedBounds_
An approximate bounding box for projected state values; This is the cached result of estimateBounds()...
ProjectionEvaluatorPtr specifiedProj_
The projection that is optionally specified by the user in the constructor argument (projToUse)
A shared pointer wrapper for ompl::base::StateSpace.
const std::vector< double > & getCellSizes() const
Get the size (each dimension) of a grid cell
static Matrix ComputeRandom(unsigned int from, unsigned int to, const std::vector< double > &scale)
Compute a random projection matrix with from columns and to rows. A vector with from elements can be ...
boost::numeric::ublas::matrix< double > Matrix
Datatype for projection matrices.
const StateSpace * space_
The state space this projection operates on.
virtual void defaultCellSizes()
Set the default cell dimensions for this projection. The default implementation of this function is e...
void print(std::ostream &out=std::cout) const
Print the contained projection matrix to a stram.
Matrix mat
Projection matrix.
bool defaultCellSizes_
Flag indicating whether cell sizes have been set by the user, or whether they were inferred automatic...
Main namespace. Contains everything in this library.
Definition: Cost.h:42