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 
54  namespace base
55  {
56 
58  typedef std::vector<int> ProjectionCoordinates;
59 
61  typedef boost::numeric::ublas::vector<double> EuclideanProjection;
62 
63 
68  {
69  public:
70 
72  typedef boost::numeric::ublas::matrix<double> Matrix;
73 
90  static Matrix ComputeRandom(const unsigned int from, const unsigned int to, const std::vector<double> &scale);
91 
101  static Matrix ComputeRandom(const unsigned int from, const unsigned int to);
102 
104  void computeRandom(const unsigned int from, const unsigned int to, const std::vector<double> &scale);
105 
107  void computeRandom(const unsigned int from, const unsigned int to);
108 
110  void project(const double *from, EuclideanProjection& to) const;
111 
113  void print(std::ostream &out = std::cout) const;
114 
116  Matrix mat;
117  };
118 
120  OMPL_CLASS_FORWARD(StateSpace);
122 
124 
125  OMPL_CLASS_FORWARD(ProjectionEvaluator);
127 
138  {
139  public:
140  // non-copyable
141  ProjectionEvaluator(const ProjectionEvaluator&) = delete;
142  ProjectionEvaluator& operator=(const ProjectionEvaluator&) = delete;
143 
145  ProjectionEvaluator(const StateSpace *space);
146 
148  ProjectionEvaluator(const StateSpacePtr &space);
149 
150  virtual ~ProjectionEvaluator();
151 
153  virtual unsigned int getDimension() const = 0;
154 
156  virtual void project(const State *state, EuclideanProjection &projection) const = 0;
157 
165  virtual void setCellSizes(const std::vector<double> &cellSizes);
166 
169  void setCellSizes(unsigned int dim, double cellSize);
170 
174  void mulCellSizes(double factor);
175 
177  bool userConfigured() const;
178 
180  const std::vector<double>& getCellSizes() const
181  {
182  return cellSizes_;
183  }
184 
186  double getCellSizes(unsigned int dim) const;
187 
189  void checkCellSizes() const;
190 
196  void inferCellSizes();
197 
202  virtual void defaultCellSizes();
203 
205  void checkBounds() const;
206 
208  bool hasBounds() const
209  {
210  return !bounds_.low.empty();
211  }
212 
216  void setBounds(const RealVectorBounds &bounds);
217 
220  {
221  return bounds_;
222  }
223 
225  void inferBounds();
226 
228  virtual void setup();
229 
231  void computeCoordinates(const EuclideanProjection &projection, ProjectionCoordinates &coord) const;
232 
234  void computeCoordinates(const State *state, ProjectionCoordinates &coord) const
235  {
236  EuclideanProjection projection(getDimension());
237  project(state, projection);
238  computeCoordinates(projection, coord);
239  }
240 
243  {
244  return params_;
245  }
246 
248  const ParamSet& params() const
249  {
250  return params_;
251  }
252 
254  virtual void printSettings(std::ostream &out = std::cout) const;
255 
257  virtual void printProjection(const EuclideanProjection &projection, std::ostream &out = std::cout) const;
258 
259  protected:
260 
262  void estimateBounds();
263 
266 
270  std::vector<double> cellSizes_;
271 
274 
279 
285 
289 
292  };
293 
299  {
300  public:
301 
308  SubspaceProjectionEvaluator(const StateSpace *space, unsigned int index, const ProjectionEvaluatorPtr &projToUse = ProjectionEvaluatorPtr());
309 
310  virtual void setup();
311 
312  virtual unsigned int getDimension() const;
313 
314  virtual void project(const State *state, EuclideanProjection &projection) const;
315 
316  protected:
317 
319  unsigned int index_;
320 
326 
329  };
330 
331  }
332 
333 }
334 
335 #endif
std::vector< double > cellSizes_
The size of a cell, in every dimension of the projected space, in the implicitly defined integer grid...
If the projection for a CompoundStateSpace is supposed to be the same as the one for one of its inclu...
bool cellSizesWereInferred_
Flag indicating whether projection cell sizes were automatically inferred.
A shared pointer wrapper for ompl::base::StateSpace.
void computeCoordinates(const State *state, ProjectionCoordinates &coord) const
Compute integer coordinates for a state.
static Matrix ComputeRandom(const unsigned int from, const 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 ...
ProjectionEvaluatorPtr specifiedProj_
The projection that is optionally specified by the user in the constructor argument (projToUse) ...
RealVectorBounds estimatedBounds_
An approximate bounding box for projected state values; This is the cached result of estimateBounds()...
void print(std::ostream &out=std::cout) const
Print the contained projection matrix to a stram.
ParamSet params_
The set of parameters for this projection.
Maintain a set of parameters.
Definition: GenericParam.h:233
void computeRandom(const unsigned int from, const unsigned int to, const std::vector< double > &scale)
Wrapper for ComputeRandom(from, to, scale)
const StateSpace * space_
The state space this projection operates on.
ParamSet & params()
Get the parameters for this projection.
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
unsigned int index_
The index of the subspace from which to project.
Matrix mat
Projection matrix.
const ParamSet & params() const
Get the parameters for this projection.
A shared pointer wrapper for ompl::base::ProjectionEvaluator.
std::vector< int > ProjectionCoordinates
Grid cells corresponding to a projection value are described in terms of their coordinates.
Representation of a space in which planning can be performed. Topology specific sampling, interpolation and distance are defined.
Definition: StateSpace.h:72
boost::numeric::ublas::vector< double > EuclideanProjection
The datatype for state projections. This class contains a real vector.
Definition of an abstract state.
Definition: State.h:50
A projection matrix – it allows multiplication of real vectors by a specified matrix. The matrix can also be randomly generated.
const std::vector< double > & getCellSizes() const
Get the size (each dimension) of a grid cell.
The lower and upper bounds for an Rn space.
const RealVectorBounds & getBounds() const
Get the bounds computed/set for this projection.
bool hasBounds() const
Check if bounds were specified for this projection.
void project(const double *from, EuclideanProjection &to) const
Multiply the vector from by the contained projection matrix to obtain the vector to.
boost::numeric::ublas::matrix< double > Matrix
Datatype for projection matrices.
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...
ProjectionEvaluatorPtr proj_
The projection to use. This is either the same as specifiedProj_ or, if specifiedProj_ is not initial...