gwnavruntime/database/databasegeometrybuildingmanager.h Source File

databasegeometrybuildingmanager.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: JUBA - secondary contact: LAPA
9 
10 #ifndef Navigation_DatabaseVisRepGrid_H
11 #define Navigation_DatabaseVisRepGrid_H
12 
16 
17 namespace Kaim
18 {
19 
20 class DatabaseGeometryBuildingManager
21 {
22  class DatabaseVisualTile
23  {
24  public:
25  DatabaseVisualTile() : m_needToBeRebuild(false) {}
26  ~DatabaseVisualTile() {}
27 
28  Ptr<IVisualGeometry> m_visualGeometry;
29  CellBox m_cellBox;
30  bool m_needToBeRebuild;
31  };
32 
33 public:
34  DatabaseGeometryBuildingManager();
35  ~DatabaseGeometryBuildingManager();
36 
37  void Clear();
38 
39 
40  void BuildGeometry(bool forceRebuildAll = false);
41 
42 
43  // Modify the VisualGeometryBuildConfig
44  void SetAltOffSet(KyFloat32 altOffset);
45  void SetDetailLevel(VisualGeometryDetailLevel detailLevel);
46 
47  VisualGeometryDetailLevel GetDetailLevel() const;
48 
49  // no tiling
50  void SetVisualGeometry(Ptr<IVisualGeometry> geometry);
51  IVisualGeometry* GetVisualGeometry() const;
52 
53  // tilling is used
54  void SetVisualGeometryFactory(Ptr<IVisualGeometryFactory> factory);
55  IVisualGeometryFactory* GetVisualGeometryFactory() const;
56 
57  // m_tileSize can be changed through this accessor only when the database is clear
58  // once at least one navdata has been added, it cannot be changed anymore until the Database is cleared again.
59  void SetTileSize(KyInt32 tileSize);
60 
61 public: // Internal
62  void OnEnlarge(const CellBox& cellBox);
63  void OnChangeAtPos(const CellPos& cellPos);
64  void OnChangeInGraph();
65 
66  KyInt32 ComputeTileCoordFromCellCoord(KyInt32 coord) const;
67  Vec2i ComputeTilePosFromCellPos(const CellPos& cellPos) const;
68  Box2i ComputeTileBoxFromCellBox(const CellBox& cellBox) const;
69  CellBox ComputeCellBoxForTilePos(const Vec2i& tilePos) const;
70 
71 private:
72  friend class Database;
73  void OnEnlarge_FactoryProvided(const CellBox& newCellBox);
74  void OnChangeAtPos_FactoryProvided(const CellPos& cellPos);
75  void OnChangeInGraph_FactoryProvided();
76 
77  void AskNewGeometryForTileIfNeeded(DatabaseVisualTile& tile);
78 private:
79  Database* m_database;
80  KyUInt32 m_databaseIdx;
81 
82  VisualGeometryBuildConfig m_buildConfig; // to be used in all tiles
83 
84  KyInt32 m_tileSize; // number of cell on x/y axis per tile
85 
86  // not a CellBox, a tileBox !
87  // tile at pos (0, 0) has cellBox [(0 ; 0) (m_tileSize-1 ;m_tileSize-1)]
88  // tile at pos (1, 0) has cellBox [(m_tileSize; 0) (2*m_tileSize-1;m_tileSize-1)]
89  // tile at pos (0,-1) has cellBox [(0 ;m_tileSize) (m_tileSize-1 ; -1)]
90  Box2i m_tileBox;
91  // array of visRep associated to m_boxOfTile. Access it through RawMajorIdx
92  DatabaseVisualTile* m_bufferOfTile;
93  KyUInt32 m_bufferSize;
94 
95  DatabaseVisualTile m_tileForGraphs;
96 
97  Ptr<IVisualGeometryFactory> m_geometryFactory;
98 
99  // Used if provided AND if no geometryFactory provided
100  // no tile mode
101  Ptr<IVisualGeometry> m_visualGeometry;
102 };
103 
104 KY_INLINE IVisualGeometryFactory* DatabaseGeometryBuildingManager::GetVisualGeometryFactory() const { return m_geometryFactory; }
105 KY_INLINE IVisualGeometry* DatabaseGeometryBuildingManager::GetVisualGeometry() const { return m_visualGeometry; }
106 KY_INLINE VisualGeometryDetailLevel DatabaseGeometryBuildingManager::GetDetailLevel() const { return m_buildConfig.m_detailLevel; }
107 
108 KY_INLINE void DatabaseGeometryBuildingManager::SetAltOffSet(KyFloat32 altOffset) { m_buildConfig.m_altitudeOffset = altOffset; }
109 KY_INLINE void DatabaseGeometryBuildingManager::SetDetailLevel(VisualGeometryDetailLevel detailLevel) { m_buildConfig.m_detailLevel = detailLevel; }
110 
111 KY_INLINE KyInt32 DatabaseGeometryBuildingManager::ComputeTileCoordFromCellCoord(KyInt32 coord) const
112 {
113  return coord >= 0 ? coord / m_tileSize : ((coord + 1) / m_tileSize) - 1;
114 }
115 
116 KY_INLINE Vec2i DatabaseGeometryBuildingManager::ComputeTilePosFromCellPos(const CellPos& cellPos) const
117 {
118  return Vec2i(ComputeTileCoordFromCellCoord(cellPos.x), ComputeTileCoordFromCellCoord(cellPos.y));
119 }
120 
121 KY_INLINE Box2i DatabaseGeometryBuildingManager::ComputeTileBoxFromCellBox(const CellBox& cellBox) const
122 {
123  return Box2i(ComputeTilePosFromCellPos(cellBox.Min()), ComputeTilePosFromCellPos(cellBox.Max()));
124 }
125 
126 KY_INLINE CellBox DatabaseGeometryBuildingManager::ComputeCellBoxForTilePos(const Vec2i& tilePos) const
127 {
128  const CellPos minCellPos(tilePos.x * m_tileSize, tilePos.y * m_tileSize);
129  return CellBox(minCellPos, minCellPos + CellPos(m_tileSize - 1, m_tileSize - 1));
130 }
131 
132 KY_INLINE void DatabaseGeometryBuildingManager::OnEnlarge(const CellBox& cellBox)
133 {
134  if (m_geometryFactory != KY_NULL)
135  OnEnlarge_FactoryProvided(cellBox);
136 }
137 KY_INLINE void DatabaseGeometryBuildingManager::OnChangeAtPos(const CellPos& cellPos)
138 {
139  if (m_geometryFactory != KY_NULL)
140  OnChangeAtPos_FactoryProvided(cellPos);
141 }
142 KY_INLINE void DatabaseGeometryBuildingManager::OnChangeInGraph()
143 {
144  if (m_geometryFactory != KY_NULL)
145  AskNewGeometryForTileIfNeeded(m_tileForGraphs);
146 }
147 
148 KY_INLINE void DatabaseGeometryBuildingManager::AskNewGeometryForTileIfNeeded(DatabaseVisualTile& tile)
149 {
150  tile.m_needToBeRebuild = true;
151  if (tile.m_visualGeometry == KY_NULL)
152  {
153  tile.m_visualGeometry = m_geometryFactory->CreateIVisualGeometryForDatabase(m_databaseIdx);
154  KY_LOG_ERROR_IF(tile.m_visualGeometry == KY_NULL,
155  ("Failed to create an IVisualGeometry from the IVisualGeometryFactory. A portion of the Database won't be displayed."));
156  }
157 }
158 
159 } // namespace Kaim
160 
161 #endif // Navigation_DatabaseVisRepGrid_H
Box2i CellBox
A type that represents a bounding box around cells in a 2D grid.
Definition: navmeshtypes.h:34
Vec2i CellPos
A type that represents the position of a cell within a 2D grid.
Definition: navmeshtypes.h:33
int KyInt32
Type used internally to represent a 32-bit integer.
Definition: types.h:35
#define KY_NULL
Null value.
Definition: types.h:247
VisualGeometryDetailLevel
Enumerates the possible levels of detail that can be set for a VisualRepresentation.
Definition: ivisualgeometrybuilder.h:35
Definition: gamekitcrowddispersion.h:20
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43