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__
karto::OccupancyGrid::IsFree
kt_bool IsFree(const Vector2i &rGridIndex) const
Definition: OccupancyGrid.h:124
kt_double
double kt_double
Definition: Types.h:160
karto::OccupancyGrid
Definition: OccupancyGrid.h:56
karto::GridStates
GridStates
Definition: OccupancyGrid.h:39
karto::OccupancyGrid::m_pMinPassThrough
SmartPointer< Parameter< kt_int32u > > m_pMinPassThrough
Definition: OccupancyGrid.h:234
SensorData.h
karto::KARTO_TYPE
KARTO_TYPE(Grid< kt_int8u >)
karto::OccupancyGrid::m_pCellPassCnt
SmartPointer< Grid< kt_int32u > > m_pCellPassCnt
Definition: OccupancyGrid.h:218
karto::CellUpdater::CellUpdater
CellUpdater(OccupancyGrid *pOccupancyGrid)
Definition: OccupancyGrid.h:269
kt_int32s
int32_t kt_int32s
Definition: Types.h:106
Grid.h
karto::Grid
Definition: Grid.h:56
karto::OpenMapper
Definition: OpenMapper.h:1531
karto::OccupancyGrid::GetCellHitsCounts
Grid< kt_int32u > * GetCellHitsCounts()
Definition: OccupancyGrid.h:144
KARTO_DEPRECATED
#define KARTO_DEPRECATED
Definition: Macros.h:39
karto::OccupancyGrid::m_pOccupancyThreshold
SmartPointer< Parameter< kt_double > > m_pOccupancyThreshold
Definition: OccupancyGrid.h:237
KARTO_EXPORT
#define KARTO_EXPORT
Definition: Macros.h:78
karto::List< LocalizedLaserScanPtr >
karto::LocalizedLaserScan
Definition: SensorData.h:567
kt_bool
bool kt_bool
Definition: Types.h:145
karto::GridStates_Free
@ GridStates_Free
Definition: OccupancyGrid.h:43
karto::CellUpdater::m_pOccupancyGrid
OccupancyGrid * m_pOccupancyGrid
Definition: OccupancyGrid.h:281
karto::OccupancyGridPtr
SmartPointer< OccupancyGrid > OccupancyGridPtr
Definition: OccupancyGrid.h:253
karto::Vector2< kt_double >
KARTO_RTTI
#define KARTO_RTTI()
Definition: Meta.h:198
karto::OccupancyGrid::m_pCellUpdater
CellUpdater * m_pCellUpdater
Definition: OccupancyGrid.h:226
kt_int32u
uint32_t kt_int32u
Definition: Types.h:111
karto::CellUpdater
Definition: OccupancyGrid.h:262
karto::SmartPointer
Definition: SmartPointer.h:39
karto::Functor
Definition: Grid.h:39
karto::Pose2
Definition: Geometry.h:2182
karto::GridStates_Occupied
@ GridStates_Occupied
Definition: OccupancyGrid.h:42
kt_int8u
uint8_t kt_int8u
Definition: Types.h:91
karto::OccupancyGrid::GetCellPassCounts
Grid< kt_int32u > * GetCellPassCounts()
Definition: OccupancyGrid.h:153
karto::GridStates_Unknown
@ GridStates_Unknown
Definition: OccupancyGrid.h:41
karto::OccupancyGrid::m_pCellHitsCnt
SmartPointer< Grid< kt_int32u > > m_pCellHitsCnt
Definition: OccupancyGrid.h:223
karto
Definition: Any.cpp:20


nav2d_karto
Author(s): Sebastian Kasperski
autogenerated on Wed Mar 2 2022 00:37:22