Parasol Planning Library (PPL)
GridOverlay.h
Go to the documentation of this file.
1 #ifndef PMPL_GRID_OVERLAY_H_
2 #define PMPL_GRID_OVERLAY_H_
3 
5 
6 #include "Transformation.h"
7 #include "Vector.h"
8 
9 #include <array>
10 #include <memory>
11 #include <unordered_set>
12 #include <vector>
13 
14 class Boundary;
15 class GMSPolyhedron;
18 class WorkspaceRegion;
19 
20 
32 class GridOverlay {
33 
34  public:
35 
38 
40  typedef std::vector<std::vector<const WorkspaceRegion*>> DecompositionMap;
41 
43  typedef std::array<size_t, 3> IndexSet;
44 
46  enum class CellSet : unsigned char {Boundary = 1, Interior = 2, Closure = 3};
47 
51 
55  GridOverlay(const Boundary* const _b, const double _length);
56 
57  ~GridOverlay() noexcept;
58 
62 
64  size_t Size() const noexcept;
65 
69  size_t Size(const size_t _i) const noexcept;
70 
74  size_t LocateCell(const Cfg& _cfg) const;
75 
79  size_t LocateCell(const Point3d& _p) const;
80 
85  std::unordered_set<size_t> LocateCells(const Boundary* const _b,
86  const CellSet _type = CellSet::Closure) const;
87 
94  std::unordered_set<size_t> LocateCells(const GMSPolyhedron& _polyhedron,
95  const mathtool::Transformation& _transformation = {},
96  const CellSet _type = CellSet::Closure) const;
97 
101  std::unordered_set<size_t> LocateBBXCells(const Boundary* const _b) const;
102 
108  std::unordered_set<size_t> LocateBBXCells(const Point3d& _min,
109  const Point3d& _max) const;
110 
114  std::unordered_set<size_t> LocateFacetNeighbors(const size_t _index) const;
115 
119  std::unordered_set<size_t> LocateEdgeNeighbors(const size_t _index) const;
120 
125  std::unordered_set<size_t> LocateVertexNeighbors(const size_t _index) const;
126 
130  std::unordered_set<size_t> LocateAllNeighbors(const size_t _index) const;
131 
135 
137  double CellLength() const noexcept;
138 
142  Point3d CellCenter(const size_t _index) const noexcept;
143 
147 
157  const WorkspaceDecomposition* const _decomposition,
158  const bool _useCollisionDetection = false) const;
159 
161 
162  private:
163 
166 
170  IndexSet Cell(const Point3d& _p) const noexcept;
171 
173  size_t CellIndex(const size_t _x, const size_t _y, const size_t _z) const
174  noexcept;
175 
177  size_t CellIndex(const IndexSet& _indexes) const noexcept;
178 
180  size_t ZIndex(const size_t _index) const noexcept;
181 
183  size_t YIndex(const size_t _index) const noexcept;
184 
186  size_t XIndex(const size_t _index) const noexcept;
187 
191  bool InGrid(const IndexSet& _indexes) const noexcept;
192 
196 
197  const Boundary* const m_boundary;
198 
199  const double m_length;
200  size_t m_num[3];
201 
202  static constexpr bool m_debug{false};
203 
204  mutable std::unique_ptr<GMSPolyhedron> m_polyhedron;
205 
207 
208  public:
209 
212 
217  void Test(const size_t _trials = 0) const;
218 
220 
221 };
222 
223 #endif
Definition: Boundary.h:30
Definition: Cfg.h:38
Definition: GMSPolyhedron.h:42
Definition: GridOverlay.h:32
std::unordered_set< size_t > LocateFacetNeighbors(const size_t _index) const
Definition: GridOverlay.cpp:186
Point3d CellCenter(const size_t _index) const noexcept
Definition: GridOverlay.cpp:309
std::unordered_set< size_t > LocateBBXCells(const Boundary *const _b) const
Definition: GridOverlay.cpp:132
std::unordered_set< size_t > LocateCells(const Boundary *const _b, const CellSet _type=CellSet::Closure) const
Definition: GridOverlay.cpp:75
double CellLength() const noexcept
Get the length of the grid cells.
Definition: GridOverlay.cpp:302
std::unordered_set< size_t > LocateVertexNeighbors(const size_t _index) const
Definition: GridOverlay.cpp:248
size_t LocateCell(const Cfg &_cfg) const
Definition: GridOverlay.cpp:61
std::unordered_set< size_t > LocateEdgeNeighbors(const size_t _index) const
Definition: GridOverlay.cpp:214
std::array< size_t, 3 > IndexSet
A set of X, Y, Z indexes for a grid cell.
Definition: GridOverlay.h:43
GridOverlay(const Boundary *const _b, const double _length)
Definition: GridOverlay.cpp:19
std::vector< std::vector< const WorkspaceRegion * > > DecompositionMap
A mapping from a grid cell index to a set of workspace regions.
Definition: GridOverlay.h:40
std::unordered_set< size_t > LocateAllNeighbors(const size_t _index) const
Definition: GridOverlay.cpp:278
size_t Size() const noexcept
Get the number of cells in the grid.
Definition: GridOverlay.cpp:47
~GridOverlay() noexcept
DecompositionMap ComputeDecompositionMap(const WorkspaceDecomposition *const _decomposition, const bool _useCollisionDetection=false) const
Definition: GridOverlay.cpp:333
void Test(const size_t _trials=0) const
Definition: GridOverlay.cpp:422
CellSet
The types of cell sets for use with LocateCells.
Definition: GridOverlay.h:46
A two or three dimensional bounding box in workspace.
Definition: WorkspaceBoundingBox.h:10
Definition: WorkspaceDecomposition.h:24
Definition: WorkspaceRegion.h:18
Definition: Cfg.h:23