gwnavgeneration/navraster/dynamicnavrastercell.h Source File

dynamicnavrastercell.h
Go to the documentation of this file.
1 /*
2 * Copyright 2015 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 
8 // primary contact: LASI - secondary contact: GUAL
9 #ifndef GwNavGen_DynamicNavRasterCell_H
10 #define GwNavGen_DynamicNavRasterCell_H
11 
12 
15 
23 
24 namespace Kaim
25 {
26 
27 class GeneratorSystem;
28 
29 class NavRasterWorkingPixel;
30 
31 // used in NavRasterWorkingPixel and NavRasterPixelNeighborhood
32 class NavRasterNeighbor
33 {
34 public:
35  NavRasterNeighbor() { Clear(); }
36 
37  void Clear()
38  {
39  m_neighborFloorIndex = NavRasterFloorIdx_Invalid;
40  m_connectionType = NavRasterConnectionType_NO_TAG;
41  m_neighborPtr = KY_NULL;
42  }
43 
44 public:
45  NavRasterFloorIdx m_neighborFloorIndex;
46  NavRasterConnectionType m_connectionType;
47  NavRasterWorkingPixel* m_neighborPtr;
48 };
49 
50 // Dynamic version (non blob) of NavRasterPixel
51 class NavRasterWorkingPixel
52 {
53  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
54 public:
55  NavRasterWorkingPixel() { Clear(); }
56  void Clear();
57 
58  // remove the pointer to the neighbor pixel and make sure we update
59  // the symmetric neighbor connections as well.
60  void DisconnectFromNeighbors();
61 
62  void TagNeighbors(KyUInt32 tag);
63 
64  NavRasterWorkingPixel* GetNeighborPixel(CardinalDir dir) const { return m_neighbors[dir].m_neighborPtr; }
65  bool HasAtLeastOneValidNeighborLink() const;
66 
67  bool IsWalkable() const { return m_navTagIdx != KyUInt32MAXVAL; }
68 
69 public:
70  KyFloat32 m_altitude;
71  KyFloat32 m_distanceFromWall;
72  KyFloat32 m_distanceFromHole;
73  NavRasterFloorIdx m_floorIdx;
74  KyUInt32 m_navTagIdx;
75  KyUInt32 m_featureBitField;
76 
77  // connections are indexed as follow:
78  // +-----------+
79  // | 1 |
80  // | |
81  // |2 + 0|
82  // | |
83  // | 3 |
84  // +-----------+
85 
86  // 0 corresponds to East (+1;0) and index increases CCW
87  // Stores index of neighbor position if reachable, 0xFFFFFFFF otherwise
88  NavRasterNeighbor m_neighbors[4];
89 };
90 
91 // Working: Contains non-walkable pixels
92 class DynamicNavRasterWorkingColumn
93 {
94 public:
95  DynamicNavRasterWorkingColumn() : m_floorCount(0), m_pixels(KY_NULL) {}
96 
97  void Init(KyUInt32 floorCount, NavRasterWorkingPixel* pixels)
98  {
99  m_floorCount = floorCount;
100  m_pixels = pixels;
101  }
102 
103  KyUInt32 GetFloorCount() const { return m_floorCount; }
104 
105  NavRasterWorkingPixel& GetPixelAtFloor(KyUInt32 index) { KY_ASSERT(index < m_floorCount); return m_pixels[index]; }
106  const NavRasterWorkingPixel& GetPixelAtFloor(KyUInt32 index) const { KY_ASSERT(index < m_floorCount); return m_pixels[index]; }
107 
108 private:
109  KyUInt32 m_floorCount;
110  NavRasterWorkingPixel* m_pixels;
111 };
112 
113 // Final: Does not contain any non-walkable pixels
114 class DynamicNavRasterFinalColumn
115 {
116 public:
117  DynamicNavRasterFinalColumn() : m_floorCount(0), m_pixels(KY_NULL) {}
118  KyUInt32 m_floorCount;
119  NavRasterPixel* m_pixels;
120 };
121 
122 class DynamicNavRasterCell
123 {
124  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
125 public:
126  DynamicNavRasterCell(GeneratorSystem* sys, const DynamicRasterCell* inputRasterCell, const CellDesc& cellDesc, KyArrayTLS_POD<KyUInt32>* connexIdxToNavTagIdxArray);
127  ~DynamicNavRasterCell() {}
128 
129  void CreateNavRaster();
130 
131  DynamicNavRasterFinalColumn GetFinalColumnFromLocalPixelPos(const PixelPos& localPixelPos) const;
132 
133  // Write NavRaster file file if specified in the Generator RunOptions, for debug purpose.
134  KyResult WriteIntermediateNavRasterFile();
135 
136  bool IsEmpty() const { return m_isEmpty; }
137  bool HasMultipleNavTags() const { return m_hasMultipleNavTags; }
138 
139  DynamicNavRasterWorkingColumn* GetWorkingNeighborColumn(const PixelPos& pos, CardinalDir dir);
140 
141  NavRasterWorkingPixel* GetWorkingNeighborPixel(const NavRasterWorkingPixel& pixel, NavRasterCardinalDir dir) const;
142 
143 private:
144  void CreateUnpaintNavRaster();
145  void InitFromInputRasterCell();
146  void RemoveIsolatedNonWalkablePixels();
147  void ComputeConnectedNeighbors();
148  void EnforceSymetry();
149  void ComputeDistanceMap();
150  void ErodePixels();
151 
152  void MakeFinalColumns();
153 
154  void ComputeManhattanDistanceMap();
155  void InitBorderPixelDistance();
156  void UpdateManhattanDistForPixelsOnDir(const PixelPos& posInRaster, CardinalDir dir1, CardinalDir dir2);
157  void UpdateChessBoardDistForPixelsOnDir(const PixelPos& posInRaster, NavRasterCardinalDir* navRasterDirs);
158 
159  void ComputeChessboardDistanceMap();
160 
161  void ReleaseWorkingColumns();
162 
163  NavRasterWorkingPixel* GetWorkingDiagonalNeighbor(const NavRasterWorkingPixel& pixel, NavRasterCardinalDir dir) const;
164  NavRasterWorkingPixel* GetWorkingDiagonalNeighbor(const NavRasterWorkingPixel& pixel, CardinalDir dir1, CardinalDir dir2) const;
165 
166 public:
167  GeneratorSystem* m_sys;
168  CellDesc m_cellDesc;
169  KyUInt32 m_highestFloorCount;
170 
171 public:
172  const DynamicRasterCell* m_rasterCell;
173 
174  PixelBox m_enlargedPixelBox;
175  PixelBox m_navPixelBox;
176 
177  //coloring
178  NavRasterCellScanlinePainter m_painter;
179 
180  // final columns
181  KyArrayTLS<DynamicNavRasterFinalColumn> m_finalColumns;
182  GrowingSmallBufferPool m_finalColumnsPool;
183 
184  KyArrayTLS<DynamicNavRasterWorkingColumn> m_workingColumns;
185  GrowingSmallBufferPool m_workingColumnsPool;
186 
187  bool m_isEmpty;
188  bool m_hasMultipleNavTags; //extracted from the rasterCell
189 
190  KyFloat32* m_navRasterMs; // profiling
191  KyFloat32* m_paintingMs; // profiling
192 
193  friend class DynamicNavRasterCellBlobBuilder;
194 };
195 
196 
197 KY_INLINE DynamicNavRasterFinalColumn DynamicNavRasterCell::GetFinalColumnFromLocalPixelPos(const PixelPos& localPixelPos) const
198 {
199  const KyInt32 idx = m_navPixelBox.GetRowMajorIndexFromLocalPos(localPixelPos);
200  return m_finalColumns[idx];
201 }
202 
203 KY_INLINE NavRasterWorkingPixel* DynamicNavRasterCell::GetWorkingNeighborPixel(const NavRasterWorkingPixel& pixel, NavRasterCardinalDir dir) const
204 {
205  return dir < 4 ? pixel.GetNeighborPixel(dir) : GetWorkingDiagonalNeighbor(pixel, dir);
206 }
207 
208 KY_INLINE NavRasterWorkingPixel* DynamicNavRasterCell::GetWorkingDiagonalNeighbor(const NavRasterWorkingPixel& pos, NavRasterCardinalDir dir) const
209 {
210  KY_ASSERT(dir >= 4 && dir < 8);
211 
212  switch(dir)
213  {
214  case NavRasterCardinalDir_NORTH_EAST:
215  return GetWorkingDiagonalNeighbor(pos, CardinalDir_NORTH, CardinalDir_EAST);
216  case NavRasterCardinalDir_NORTH_WEST:
217  return GetWorkingDiagonalNeighbor(pos, CardinalDir_NORTH, CardinalDir_WEST);
218  case NavRasterCardinalDir_SOUTH_WEST:
219  return GetWorkingDiagonalNeighbor(pos, CardinalDir_SOUTH, CardinalDir_WEST);
220  case NavRasterCardinalDir_SOUTH_EAST:
221  return GetWorkingDiagonalNeighbor(pos, CardinalDir_SOUTH, CardinalDir_EAST);
222  default: return KY_NULL;
223  }
224 }
225 
226 KY_INLINE void DynamicNavRasterCell::ReleaseWorkingColumns()
227 {
228  m_workingColumns.ClearAndRelease();
229  m_workingColumnsPool.Release();
230 }
231 
232 }
233 
234 #endif
static const CardinalDir CardinalDir_NORTH
Identifies North, defined as the positive direction of the Y axis.
Definition: cardinaldir.h:26
KyInt32 KyResult
Defines a type that can be returned by methods or functions in the Gameware Navigation SDK to indicat...
Definition: types.h:254
int KyInt32
Type used internally to represent a 32-bit integer.
Definition: types.h:35
#define KY_NULL
Null value.
Definition: types.h:247
KyUInt32 CardinalDir
Defines a type that refers to one of the cardinal points on the compass:
Definition: cardinaldir.h:23
static const CardinalDir CardinalDir_SOUTH
Identifies South, defined as the negative direction of the Y axis.
Definition: cardinaldir.h:28
static const CardinalDir CardinalDir_EAST
Identifies East, defined as the positive direction of the X axis.
Definition: cardinaldir.h:25
static const CardinalDir CardinalDir_WEST
Identifies West, defined as the negative direction of the X axis.
Definition: cardinaldir.h:27
Definition: gamekitcrowddispersion.h:20
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
#define KyUInt32MAXVAL
The maximum value that can be stored in the KyUInt32 variable type.
Definition: types.h:226
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43