OccupancyGrid.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2011, SRI International (R)
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #pragma once
19 
20 #ifndef __OpenKarto_OccupancyGird_h__
21 #define __OpenKarto_OccupancyGird_h__
22 
23 #include <OpenKarto/Grid.h>
24 #include <OpenKarto/SensorData.h>
25 
26 namespace karto
27 {
28 
30 
31 
35 
39  typedef enum
40  {
44  } GridStates;
45 
49 
50  class CellUpdater;
51  class OpenMapper;
52 
56  class KARTO_EXPORT OccupancyGrid : public Grid<kt_int8u>
57  {
58  KARTO_RTTI();
59 
60  private:
61  friend class CellUpdater;
62  friend class IncrementalOccupancyGrid;
63 
64  public:
72  OccupancyGrid(kt_int32s width, kt_int32s height, const Vector2d& rOffset, kt_double resolution);
73 
74  protected:
75  //@cond EXCLUDE
79  virtual ~OccupancyGrid();
80  //@endcond
81 
82  public:
90  static OccupancyGrid* CreateFromScans(const LocalizedLaserScanList& rScans, kt_double resolution);
91 
101  static KARTO_DEPRECATED OccupancyGrid* CreateFromScans(const std::vector< SmartPointer<LocalizedRangeScan> >& rScans, kt_double resolution);
102 
110  static OccupancyGrid* CreateFromMapper(OpenMapper* pMapper, kt_double resolution);
111 
112  public:
117  OccupancyGrid* Clone() const;
118 
124  inline kt_bool IsFree(const Vector2i& rGridIndex) const
125  {
126  kt_int8u* pOffsets = (kt_int8u*)GetDataPointer(rGridIndex);
127  return (*pOffsets == GridStates_Free);
128  }
129 
137  kt_double RayCast(const Pose2& rPose2, kt_double maxRange) const;
138 
139  protected:
145  {
146  return m_pCellHitsCnt;
147  }
148 
154  {
155  return m_pCellPassCnt;
156  }
157 
166  static void ComputeDimensions(const LocalizedLaserScanList& rScans, kt_double resolution, kt_int32s& rWidth, kt_int32s& rHeight, Vector2d& rOffset);
167 
172  virtual void CreateFromScans(const LocalizedLaserScanList& rScans);
173 
181  kt_bool AddScan(LocalizedLaserScan* pScan, kt_bool doUpdate = false);
182 
192  kt_bool RayTrace(const Vector2d& rWorldFrom, const Vector2d& rWorldTo, kt_bool isEndPointValid, kt_bool doUpdate = false);
193 
200  void UpdateCell(kt_int8u* pCell, kt_int32u cellPassCnt, kt_int32u cellHitCnt);
201 
205  void UpdateGrid();
206 
212  virtual void Resize(kt_int32s width, kt_int32s height);
213 
214  protected:
219 
224 
225  private:
227 
229  // NOTE: These two values are dependent on the resolution. If the resolution is too small,
230  // then not many beams will hit the cell!
231 
232  // Number of beams that must pass through a cell before it will be considered to be occupied
233  // or unoccupied. This prevents stray beams from messing up the map.
235 
236  // Minimum ratio of beams hitting cell to beams passing through cell for cell to be marked as occupied
238 
239  private:
240  // restrict the following functions
242  const OccupancyGrid& operator=(const OccupancyGrid&);
243  }; // OccupancyGrid
244 
249 
254 
258 
263  {
264  public:
269  CellUpdater(OccupancyGrid* pOccupancyGrid)
270  : m_pOccupancyGrid(pOccupancyGrid)
271  {
272  }
273 
278  virtual void operator() (kt_int32u index);
279 
280  private:
282  }; // CellUpdater
283 
285 
286 }
287 
288 
289 #endif // __OpenKarto_OccupancyGird_h__
bool kt_bool
Definition: Types.h:145
SmartPointer< OccupancyGrid > OccupancyGridPtr
CellUpdater * m_pCellUpdater
Grid< kt_int32u > * GetCellHitsCounts()
SmartPointer< Parameter< kt_double > > m_pOccupancyThreshold
#define KARTO_EXPORT
Definition: Macros.h:78
#define KARTO_DEPRECATED
Definition: Macros.h:39
SmartPointer< Grid< kt_int32u > > m_pCellPassCnt
SmartPointer< Parameter< kt_int32u > > m_pMinPassThrough
uint8_t kt_int8u
Definition: Types.h:91
uint32_t kt_int32u
Definition: Types.h:111
kt_bool IsFree(const Vector2i &rGridIndex) const
#define KARTO_RTTI()
Definition: Meta.h:198
Grid< kt_int32u > * GetCellPassCounts()
CellUpdater(OccupancyGrid *pOccupancyGrid)
int32_t kt_int32s
Definition: Types.h:106
KARTO_TYPE(Grid< kt_int8u >)
SmartPointer< Grid< kt_int32u > > m_pCellHitsCnt
double kt_double
Definition: Types.h:160
OccupancyGrid * m_pOccupancyGrid
Definition: Any.cpp:20


nav2d_karto
Author(s): Sebastian Kasperski
autogenerated on Thu Jun 6 2019 19:20:24