Decomposition.h
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2011, 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: Matt Maly */
36 
37 #ifndef OMPL_CONTROL_PLANNERS_SYCLOP_DECOMPOSITION_
38 #define OMPL_CONTROL_PLANNERS_SYCLOP_DECOMPOSITION_
39 
40 #include "ompl/base/spaces/RealVectorBounds.h"
41 #include "ompl/base/StateSampler.h"
42 #include "ompl/base/State.h"
43 #include "ompl/util/Console.h"
44 #include "ompl/util/Exception.h"
45 #include "ompl/util/ClassForward.h"
46 #include "ompl/util/RandomNumbers.h"
47 
48 namespace ompl
49 {
50  namespace control
51  {
53 
54  OMPL_CLASS_FORWARD(Decomposition);
56 
62  class Decomposition
63  {
64  public:
68  Decomposition(int dim, const base::RealVectorBounds &b) : dimension_(dim), bounds_(b)
69  {
70  if (dim > static_cast<int>(b.low.size()))
71  throw Exception("Decomposition", "argument 'dim' exceeds dimension of given bounds");
72  else if (dim < static_cast<int>(b.low.size()))
73  OMPL_WARN("Decomposition: dimension of given bounds exceeds argument 'dim'. Using the first 'dim' "
74  "values of bounds");
75  }
76 
77  virtual ~Decomposition() = default;
78 
80  virtual int getNumRegions() const = 0;
81 
83  virtual int getDimension() const
84  {
85  return dimension_;
86  }
87 
89  virtual const base::RealVectorBounds &getBounds() const
90  {
91  return bounds_;
92  }
93 
95  virtual double getRegionVolume(int rid) = 0;
96 
100  virtual int locateRegion(const base::State *s) const = 0;
101 
104  virtual void project(const base::State *s, std::vector<double> &coord) const = 0;
105 
107  virtual void getNeighbors(int rid, std::vector<int> &neighbors) const = 0;
108 
110  virtual void sampleFromRegion(int rid, RNG &rng, std::vector<double> &coord) const = 0;
111 
113  virtual void sampleFullState(const base::StateSamplerPtr &sampler, const std::vector<double> &coord,
114  base::State *s) const = 0;
115 
116  protected:
117  int dimension_;
118  base::RealVectorBounds bounds_;
119  };
120  }
121 }
122 #endif
virtual int getDimension() const
Returns the dimension of this Decomposition.
virtual int locateRegion(const base::State *s) const =0
Returns the index of the region containing a given State. Most often, this is obtained by first calli...
Decomposition(int dim, const base::RealVectorBounds &b)
Constructor. Creates a Decomposition with a given dimension and a given set of bounds....
virtual double getRegionVolume(int rid)=0
Returns the volume of a given region in this Decomposition.
virtual const base::RealVectorBounds & getBounds() const
Returns the bounds of this Decomposition.
virtual void sampleFromRegion(int rid, RNG &rng, std::vector< double > &coord) const =0
Samples a projected coordinate from a given region.
virtual void sampleFullState(const base::StateSamplerPtr &sampler, const std::vector< double > &coord, base::State *s) const =0
Samples a State using a projected coordinate and a StateSampler.
virtual void getNeighbors(int rid, std::vector< int > &neighbors) const =0
Stores a given region's neighbors into a given vector.
#define OMPL_WARN(fmt,...)
Log a formatted warning string.
Definition: Console.h:66
virtual void project(const base::State *s, std::vector< double > &coord) const =0
Project a given State to a set of coordinates in R^k, where k is the dimension of this Decomposition.
virtual int getNumRegions() const =0
Returns the number of regions in this Decomposition.
Main namespace. Contains everything in this library.
Definition: AppBase.h:21