gwnavgeneration/input/spatializedsectorinput.h Source File

spatializedsectorinput.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_SpatializedSectorInput_H
10 #define GwNavGen_SpatializedSectorInput_H
11 
17 
18 
19 namespace Kaim
20 {
21 
22 class GeneratorSystem;
23 class Triangle3i;
24 class TaggedTriangle3i;
25 class SectorInputData;
26 
27 /*
28 cells are indexed this way
29  | | | | |
30 --+-----+-----+-----+-----+--
31  |-2, 1|-1, 1| 0, 1| 1, 1|
32  | | | | |
33 --+-----+-----+-----+-----+--
34  |-2, 0|-1, 0| 0, 0| 1, 0|
35  | | | | |
36 --+-----+-----#-----+-----+--
37  |-2,-1|-1,-1| 0,-1| 1,-1|
38  | | | | |
39 --+-----+-----+-----+---- +--
40  |-2,-2|-1,-2| 0,-2| 1,-2|
41  | | | | |
42 --+-----+-----+-----+-----+--
43  | | | | |
44 
45 a cell contains at least all triangles that intersect with
46 [cell_min - enlargement, cell_max + enlargement]
47  | | | |
48  | +---------+ |
49 --+---|-+-----+-|---+--
50  | | | | | |
51  | | | | | |
52 --+---|-+-----+-|---+--
53  | +---------+ |
54  | | | |
55  >-<
56  enlargement
57 */
58 
59 class DynInputCellArrayAtTilePos
60 {
61  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_NavDataGen)
62 public:
63  DynInputCellArrayAtTilePos(KyInt32 x, KyInt32 y) : m_x(x), m_y(y) {}
64  KyArrayPOD<DynamicInputCell*> m_dynInputCells;
65  KyInt32 m_x;
66  KyInt32 m_y;
67 };
68 
69 // tile part filenames at tilePos (x, y)
70 class TilePartFileNameArrayAtTilePos
71 {
72  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_NavDataGen)
73 public:
74  TilePartFileNameArrayAtTilePos(KyInt32 x, KyInt32 y) : m_x(x), m_y(y) {}
75  KyArray<String> m_filenames;
76  KyInt32 m_x;
77  KyInt32 m_y;
78 };
79 
80 // Spatializes the input triangles into m_dynInputCellGrid.
81 // SpatializedSectorInput is a member of ClientInputConsumer. So there is one SpatializedSectorInput per Sector.
82 // Note that ClientInputConsumer is instantiated on the stack in GeneratorSectorBuilder::ProduceInputs().
83 // SpatializedSectorInput is just a temporary data, once production/consumption of the inputs are done,
84 // inputs reside in SectorInput (for each Sector).
85 // if Tiling is enabled
86 // DynamicInputCells are spatialized into m_dynInputCellArrayTileGrid;
87 // When a given number of triangles are pushed, m_dynInputCellGrid and m_dynInputCellArrayTileGrid
88 // are copied to tilePart files referenced by m_tilePartFileNameArrayTileGrid
89 class SpatializedSectorInput
90 {
91  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_NavDataGen)
92 
93 public:
94  SpatializedSectorInput(GeneratorSystem* sys);
95 
96  ~SpatializedSectorInput() { ClearAll(); }
97 
98  void SetName(const String& name) { m_sectorName = name; }
99 
100  void SetMaxTriangleCountBeforeFlush(KyUInt32 maxTriangleCountBeforeFlush) { m_maxTriangleCountBeforeFlush = maxTriangleCountBeforeFlush; }
101 
102  void ClearAll()
103  {
104  ClearCellAndTileGrids();
105  ClearFlushedTiledFileNames();
106  }
107 
108  void ClearCellAndTileGrids();
109 
110  void ClearFlushedTiledFileNames();
111 
112  void PushTriangle(const DynamicTaggedTriangle3i& inputTriangle);
113 
114  void PushTagVolume(const TagVolume& volume);
115 
116  DynamicInputCell* GetCell(CellCoord x, CellCoord y) { return m_dynInputCellGrid.Get(x, y); }
117 
118  DynamicInputCell** GetCells() { return m_dynInputCellGrid.GetElements(); }
119 
120  KyUInt32 GetCellsCount() const { return m_dynInputCellGrid.GetElementsCount(); }
121 
122  KyResult FlushTiles();
123 
124  void RemovePartsTempDirectory();
125 
126 private:
127  String GetTilePartDirName();
128  String GetTilePartFileName(KyInt32 x, KyInt32 y, KyUInt32 partIndex);
129 
130 public:
131  GeneratorSystem* m_sys;
132 
133  KyUInt32 m_nbTrianglesPushed;
134  KyUInt32 m_nbVolumesPushed;
135  KyUInt32 m_maxTriangleCountBeforeFlush;
136 
137  DenseGridAndArrayOfRawPtr<DynamicInputCell> m_dynInputCellGrid;
138 
139  DenseGridAndArrayOfRawPtr<DynInputCellArrayAtTilePos> m_dynInputCellArrayTileGrid; // grid of m_nbCellsByInputTile * cellSize
140  DenseGridAndArrayOfRawPtr<TilePartFileNameArrayAtTilePos> m_tilePartFileNameArrayTileGrid; // grid of m_nbCellsByInputTile * cellSize. Saves the parts saved so far.
141 
142  KyGuid m_sectorGuid;
143  String m_sectorName;
144 };
145 
146 }
147 
148 #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
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
KyInt32 CellCoord
A type that represents the placement of a cell on one axis of a 2D grid.
Definition: navmeshtypes.h:32