gwnavgeneration/raster/dynamicrastercell.h Source File

dynamicrastercell.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: GUAL - secondary contact: NOBODY
9 #ifndef GwNavGen_DynamicRasterCell_H
10 #define GwNavGen_DynamicRasterCell_H
11 
12 
21 
22 namespace Kaim
23 {
24 
25 class GeneratorSystem;
26 class SingleStagePixel;
27 class InputCellBlob;
28 class NavTag;
29 
30 enum DynamicRasterCellMergeStatus
31 {
32  DynamicRasterCellMergeStatus_MergeEnabled,
33  DynamicRasterCellMergeStatus_MergeDisabled
34 };
35 
36 class DynamicRasterCell
37 {
38  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
39  KY_CLASS_WITHOUT_COPY(DynamicRasterCell)
40 
41 public:
42  DynamicRasterCell(
43  const GeneratorParameters& config, const CellDesc& cellDesc, const KyArrayPOD<const InputCellBlob*>* inputCells,
44  const KyArrayTLS_POD<const NavTag*>* navTagArray,
45  KyFloat32 modifiedRasterPrecision = 0.0f,
46  const PixelBox* modifiedPixelBox = KY_NULL
47  )
48  : m_navTagArray(navTagArray)
49  , m_dynamicColumns(GeneratorMemory::TlsHeap())
50  , m_finalColumns(GeneratorMemory::TlsHeap())
51  , m_finalNavTagIdxColumns(GeneratorMemory::TlsHeap())
52  , m_areAllInputCellsOverlapping(true)
53  {
54  KyFloat32 rasterPrecision = config.m_normalizedParameters.m_normalizedRasterPrecision;
55  if (modifiedRasterPrecision != 0.0f)
56  rasterPrecision = modifiedRasterPrecision;
57 
58  const PixelBox* pixelBox = &cellDesc.m_enlargedPixelBox;
59  if (modifiedPixelBox != KY_NULL)
60  pixelBox = modifiedPixelBox;
61 
62  Setup(config, cellDesc, inputCells, rasterPrecision, *pixelBox);
63  }
64 
65  void Setup(const GeneratorParameters& config, const CellDesc& cellDesc,
66  const KyArrayPOD<const InputCellBlob*>* inputCells, KyFloat32 rasterPrecision, const PixelBox& pixelBox);
67 
68  /* To be called before the fill of dynamicColumns: GetDynamicColumn().PushPixel(). */
69  void BeginColumns();
70 
71  /* To be called between BeginColumns() and EndColumns(). */
72  void PushPixel(const PixelPos& pixelPos, const SingleStagePixel& pixel, KyUInt32 navTagIdx, KyUInt32 ownerIdx = KyUInt32MAXVAL);
73 
74  /* To be called between BeginColumns() and EndColumns(). */
75  void PushPixelToLocal(const PixelPos& localPixelPos, const SingleStagePixel& pixel, KyUInt32 navTagIdx);
76 
77  /* To be called between BeginColumns() and EndColumns(). */
78  void PushPixel(KyInt32 rowMajorIdx, const SingleStagePixel& pixel, KyUInt32 navTagIdx, KyUInt32 ownerIdx = KyUInt32MAXVAL);
79 
80  /*
81  To be called after the fill of dynamicColumns: GetDynamicColumn().PushPixel().
82  Copy dynamicColumns to finalColumns and release dynamicColumns.
83  If mergeStatus is DynamicRasterCellMergeStatus_MergeEnabled, merge vertically the obstacles which are
84  less than entity height from one another.
85  */
86  void EndColumns(DynamicRasterCellMergeStatus mergeStatus);
87 
88  /* Once EndColumns() has been called, read FinalColumns. */
89  const BoxOfArrays<KyFloat32>::Column& GetFinalColumnFromLocal(const PixelPos& localPixelPos) const;
90 
91  /* Once EndColumns() has been called, read FinalColumns. */
92  const BoxOfArrays<KyFloat32>::Column& GetFinalColumn(const PixelPos& pixelPos) const;
93 
94  /* Once EndColumns() has been called, read FinalColumns. */
95  const BoxOfArrays<KyUInt32>::Column& GetFinalNavTagColumnFromLocal(const PixelPos& localPixelPos) const;
96 
97  /* Once EndColumns() has been called, read FinalColumns. */
98  const BoxOfArrays<KyUInt32>::Column& GetFinalNavTagIndicesColumn(const PixelPos& pixelPos) const;
99 
100  /* Write Raster file and Raster 3d obj file if specified in the generatorConfig, for debug purpose. */
101  KyResult WriteIntermediateRasterFile(GeneratorSystem* system) const;
102 
103  bool IsEmpty() const { return m_isEmpty; }
104  bool AreAllInputCellsOverlapping() const {return m_inputCells->GetCount() == 1 || m_areAllInputCellsOverlapping; }
105  bool HasMultipleNavTags() const { return m_hasMultipleNavTags; }
106 
107  void SetHasMultipleNavTags(bool hasMultipleNavTags) { m_hasMultipleNavTags = hasMultipleNavTags; }
108 
109  const PixelBox& GetPixelBox() const { return m_pixelBox; }
110  const CellDesc& GetCellDesc() const { return m_cellDesc; }
111 
112  const BoxOfArrays<KyFloat32>& GetFinalColumns() const { return m_finalColumns; }
113  BoxOfArrays<KyFloat32>& GetFinalColumns() { return m_finalColumns; }
114 
115  const BoxOfArrays<KyUInt32>& GetFinalColorColumns() const { return m_finalNavTagIdxColumns; }
116  BoxOfArrays<KyUInt32>& GetFinalColorColumns() { return m_finalNavTagIdxColumns; }
117 
118  /* Copies the final columns from another raster. Fails if celldesc is not the same. */
119  KyResult Copy(const DynamicRasterCell& from);
120 
121  KyInt32 GetPixelSize() const { return IntCoordSystem::IntPixelSize(); }
122  KyFloat32 GetRasterPrecision() const { return m_rasterPrecision; }
123 
124  const KyArrayTLS_POD<const NavTag*>& GetNavTagArray() const { return *m_navTagArray; }
125 private:
126  void ComputeUniqueTagVolumes(KyArray<RasterCellTagVolume>& rasterVolumes);
127  void MakeFinalColumns(DynamicRasterCellMergeStatus mergeStatus);
128  void ReleaseDynamicColumns();
129 
130 private:
131  KyFloat32 m_rasterPrecision;
132  GeneratorParameters m_config;
133  CellDesc m_cellDesc;
134  PixelBox m_pixelBox;
135  const KyArrayPOD<const InputCellBlob*>* m_inputCells;
136  const KyArrayTLS_POD<const NavTag*>* m_navTagArray;
137 
138  // dynamic columns
139  DynamicRasterColumnPool m_dynamicColumns;
140 
141  // final columns
142  BoxOfArrays<KyFloat32> m_finalColumns;
143 
144  // final navTag
145  BoxOfArrays<KyUInt32> m_finalNavTagIdxColumns;
146 
147  bool m_isEmpty;
148  bool m_hasMultipleNavTags; //extracted by the CellRasterizerFromPdgInput
149  bool m_areAllInputCellsOverlapping; //this flag is set and computed during MakeFinalColumns()
150 
151  friend class DynamicRasterCellBlobBuilder;
152 };
153 
154 
155 
156 // --------------------------------- inline implementation ---------------------------------
157 
158 inline void DynamicRasterCell::PushPixelToLocal(const PixelPos& localPixelPos, const SingleStagePixel& pixel, KyUInt32 navTagIdx)
159 {
160  KyInt32 idx = m_pixelBox.GetRowMajorIndexFromLocalPos(localPixelPos);
161  PushPixel(idx, pixel, navTagIdx);
162 }
163 
164 inline void DynamicRasterCell::PushPixel(const PixelPos& pixelPos, const SingleStagePixel& pixel, KyUInt32 navTagIdx, KyUInt32 ownerIdx)
165 {
166  KyInt32 idx = m_pixelBox.GetRowMajorIndex(pixelPos);
167  PushPixel(idx, pixel, navTagIdx, ownerIdx);
168 }
169 
170 inline const BoxOfArrays<KyFloat32>::Column& DynamicRasterCell::GetFinalColumnFromLocal(const PixelPos& localPixelPos) const
171 {
172  return m_finalColumns.GetColumn(localPixelPos.x, localPixelPos.y);
173 }
174 
175 inline const BoxOfArrays<KyFloat32>::Column& DynamicRasterCell::GetFinalColumn(const PixelPos& pixelPos) const
176 {
177  KyInt32 idx = m_pixelBox.GetRowMajorIndex(pixelPos);
178  return m_finalColumns.GetColumn(idx);
179 }
180 
181 inline const BoxOfArrays<KyUInt32>::Column& DynamicRasterCell::GetFinalNavTagColumnFromLocal(const PixelPos& localPixelPos) const
182 {
183  return m_finalNavTagIdxColumns.GetColumn(localPixelPos.x, localPixelPos.y);
184 }
185 
186 inline const BoxOfArrays<KyUInt32>::Column& DynamicRasterCell::GetFinalNavTagIndicesColumn(const PixelPos& pixelPos) const
187 {
188  KyInt32 idx = m_pixelBox.GetRowMajorIndex(pixelPos);
189  return m_finalNavTagIdxColumns.GetColumn(idx);
190 }
191 
192 
193 }
194 
195 
196 #endif
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
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:387
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