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 <memory>
42 #include <unordered_map>
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  {
53  class GridDecomposition : public Decomposition
54  {
55  public:
60  GridDecomposition(int len, int dim, const base::RealVectorBounds &b);
61 
62  ~GridDecomposition() override = default;
63 
64  int getNumRegions() const override
65  {
66  return numGridCells_;
67  }
68 
69  double getRegionVolume(int /*rid*/) override
70  {
71  return cellVolume_;
72  }
73 
74  void getNeighbors(int rid, std::vector<int> &neighbors) const override;
75 
76  int locateRegion(const base::State *s) const override;
77 
78  void sampleFromRegion(int rid, RNG &rng, std::vector<double> &coord) const override;
79 
80  protected:
82  virtual const base::RealVectorBounds &getRegionBounds(int rid) const;
83 
85  void regionToGridCoord(int rid, std::vector<int> &coord) const;
86 
88  int gridCoordToRegion(const std::vector<int> &coord) const;
89 
91  int coordToRegion(const std::vector<double> &coord) const;
92 
94  void coordToGridCoord(const std::vector<double> &coord, std::vector<int> &gridCoord) const;
95 
97  void computeGridNeighbors(int rid, std::vector<int> &neighbors) const;
98 
100  void computeGridNeighborsSub(const std::vector<int> &coord, std::vector<int> &neighbors, int dim,
101  std::vector<int> &candidate) const;
102 
103  int length_;
104  double cellVolume_;
105  mutable std::unordered_map<int, std::shared_ptr<base::RealVectorBounds>> regToBounds_;
106 
107  private:
108  const int numGridCells_;
109  };
110  }
111 }
112 #endif
void sampleFromRegion(int rid, RNG &rng, std::vector< double > &coord) const override
Samples a projected coordinate from a given region.
int getNumRegions() const override
Returns the number of regions in this Decomposition.
void coordToGridCoord(const std::vector< double > &coord, std::vector< int > &gridCoord) const
Converts a decomposition space coordinate to a grid coordinate.
void getNeighbors(int rid, std::vector< int > &neighbors) const override
Stores a given region's neighbors into a given vector.
double getRegionVolume(int) override
Returns the volume of a given region in this Decomposition.
void computeGridNeighbors(int rid, std::vector< int > &neighbors) const
Computes the neighbors of the given region in a n-dimensional grid.
virtual const base::RealVectorBounds & getRegionBounds(int rid) const
Helper method to return the bounds of a given region.
int coordToRegion(const std::vector< double > &coord) const
Converts a decomposition space coordinate to the ID of the region that contains iit.
void regionToGridCoord(int rid, std::vector< int > &coord) const
Converts a given region to a coordinate in the grid.
int gridCoordToRegion(const std::vector< int > &coord) const
Converts the given grid coordinate to its corresponding region ID.
int locateRegion(const base::State *s) const override
Returns the index of the region containing a given State. Most often, this is obtained by first calli...
GridDecomposition(int len, int dim, const base::RealVectorBounds &b)
Constructor. Creates a GridDecomposition as a hypercube with a given dimension, side length,...
void computeGridNeighborsSub(const std::vector< int > &coord, std::vector< int > &neighbors, int dim, std::vector< int > &candidate) const
Main namespace. Contains everything in this library.
Definition: AppBase.h:21