All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
GridDecomposition.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_GRIDDECOMPOSITION_
38 #define OMPL_CONTROL_PLANNERS_SYCLOP_GRIDDECOMPOSITION_
39 
40 #include <cstdlib>
41 #include <boost/shared_ptr.hpp>
42 #include <boost/unordered_map.hpp>
43 #include "ompl/base/spaces/RealVectorBounds.h"
44 #include "ompl/base/State.h"
45 #include "ompl/control/planners/syclop/Decomposition.h"
46 #include "ompl/util/RandomNumbers.h"
47 
48 namespace ompl
49 {
50  namespace control
51  {
54  {
55  public:
59  GridDecomposition(unsigned int len, unsigned int dim, const base::RealVectorBounds& b);
60 
61  virtual ~GridDecomposition()
62  {
63  }
64 
65  virtual double getRegionVolume(unsigned int /*rid*/)
66  {
67  return cellVolume_;
68  }
69 
70  virtual void getNeighbors(unsigned int rid, std::vector<unsigned int>& neighbors) const;
71 
72  virtual int locateRegion(const base::State* s) const;
73 
74  virtual void sampleFromRegion(unsigned int rid, RNG& rng, std::vector<double>& coord) const;
75 
76  protected:
78  virtual const base::RealVectorBounds& getRegionBounds(unsigned int rid) const;
79 
81  void regionToGridCoord(unsigned int rid, std::vector<unsigned int>& coord) const;
82 
84  unsigned int gridCoordToRegion (const std::vector<unsigned int> &coord) const;
85 
87  unsigned int coordToRegion(const std::vector<double>& coord) const;
88 
90  void coordToGridCoord(const std::vector<double>& coord, std::vector<unsigned int>& gridCoord) const;
91 
93  void computeGridNeighbors (unsigned int rid, std::vector <unsigned int> &neighbors) const;
94 
96  void computeGridNeighborsSub (const std::vector <unsigned int>&coord, std::vector <unsigned int> &neighbors,
97  unsigned int dim, std::vector <unsigned int> &candidate) const;
98 
99  unsigned int length_;
100  double cellVolume_;
101  mutable boost::unordered_map<int, boost::shared_ptr<base::RealVectorBounds> > regToBounds_;
102 
103  private:
105  unsigned int calcNumRegions(unsigned int len, unsigned int dim) const;
106  };
107  }
108 }
109 #endif
void computeGridNeighbors(unsigned int rid, std::vector< unsigned int > &neighbors) const
Computes the neighbors of the given region in a n-dimensional grid.
virtual double getRegionVolume(unsigned int)
Returns the volume of a given region in this Decomposition.
virtual const base::RealVectorBounds & getRegionBounds(unsigned int rid) const
Helper method to return the bounds of a given region.
virtual void getNeighbors(unsigned int rid, std::vector< unsigned int > &neighbors) const
Stores a given region's neighbors into a given vector.
A GridDecomposition is a Decomposition implemented using a grid.
A Decomposition is a partition of a bounded Euclidean space into a fixed number of regions which are ...
Definition: Decomposition.h:62
virtual int locateRegion(const base::State *s) const
Returns the index of the region containing a given State. Most often, this is obtained by first calli...
Random number generation. An instance of this class cannot be used by multiple threads at once (membe...
Definition: RandomNumbers.h:54
virtual void sampleFromRegion(unsigned int rid, RNG &rng, std::vector< double > &coord) const
Samples a projected coordinate from a given region.
Definition of an abstract state.
Definition: State.h:50
void computeGridNeighborsSub(const std::vector< unsigned int > &coord, std::vector< unsigned int > &neighbors, unsigned int dim, std::vector< unsigned int > &candidate) const
The lower and upper bounds for an Rn space.
void regionToGridCoord(unsigned int rid, std::vector< unsigned int > &coord) const
Converts a given region to a coordinate in the grid.
unsigned int coordToRegion(const std::vector< double > &coord) const
Converts a decomposition space coordinate to the ID of the region that contains iit.
GridDecomposition(unsigned int len, unsigned int dim, const base::RealVectorBounds &b)
Constructor. Creates a GridDecomposition as a hypercube with a given dimension, side length...
void coordToGridCoord(const std::vector< double > &coord, std::vector< unsigned int > &gridCoord) const
Converts a decomposition space coordinate to a grid coordinate.
unsigned int gridCoordToRegion(const std::vector< unsigned int > &coord) const
Converts the given grid coordinate to its corresponding region ID.