tools/NavGenProj/include/NavGenProjSector.h Source File

NavGenProjSector.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: MAMU - secondary contact: NOBODY
9 #ifndef GwNavGen_NavGenProjSector_H
10 #define GwNavGen_NavGenProjSector_H
11 
12 #include "tinyxml.h"
13 #include <string>
14 #include "NavGenProj.h"
16 #include "NavGenProjGeometry.h"
17 #include "NavGenProjClientInput.h"
18 #include "NavGenProjTagVolume.h"
19 
20 namespace Kaim
21 {
22 
23 
28 {
29 public:
31  : m_doBuild(true)
32  , m_doSaveClientInput(true)
33  , m_doGenerateColData(false)
34  , m_navGenProjConfig(config)
35  , m_mirroredPos(KyInt32MAXVAL, KyInt32MAXVAL)
36  , m_guid(KyGuid::GetInvalidGuid())
37  {}
38 
40  {
41  for (unsigned int i = 0; i < m_geometries.size(); ++i)
42  delete m_geometries[i];
43  m_geometries.clear();
44 
45  for (unsigned int i = 0; i < m_clientInputs.size(); ++i)
46  delete m_clientInputs[i];
47  m_clientInputs.clear();
48 
49  for (unsigned int i = 0; i < m_tagVolumes.size(); ++i)
50  delete m_tagVolumes[i];
51  m_tagVolumes.clear();
52  }
53 
54  void SetName(const char* name) { m_name.assign(name); }
55  void SetGuid(const Kaim::KyGuid& guid) { m_guid = guid; }
56  void SetDoBuild(bool doBuild) { m_doBuild = doBuild; }
57  void SetDoSaveClientInput(bool doSaveClientInput) { m_doSaveClientInput = doSaveClientInput; }
58  void SetDoGenerateColData(bool doGenerateColData) { m_doGenerateColData = doGenerateColData; }
59  void SetCellBox(const Kaim::CellBox& cellBox) { m_cellBox = cellBox; }
60 
61  NavGenProjGeometry* AddObjFilePath(const char* fileName)
62  {
63  NavGenProjGeometry* geometry = new NavGenProjGeometry();
64  geometry->SetFileName(fileName);
65  m_geometries.push_back(geometry);
66  return geometry;
67  }
68 
69  NavGenProjClientInput* AddClientInputFilePath(const char* fileName)
70  {
72  input->SetFileName(fileName);
73  m_clientInputs.push_back(input);
74  return input;
75  }
76 
77  void AddSeedPoint(float x, float y, float z)
78  {
79  NavGenProjSeedPoint seedPoint;
80  seedPoint.m_seedPoint = Kaim::Vec3f(x, y, z);
81  m_seedPoints.push_back(seedPoint);
82  }
83 
84  KyResult AddTagVolume(
85  const Vec3f* polylinePoints, int pointArraySize, const Kaim::DynamicNavTag& navTag, float minAltitude, float maxAltitude)
86  {
87  NavGenProjTagVolume* navGenTagVolume = new NavGenProjTagVolume(&m_navGenProjConfig.m_coordSystem);
88  if (navGenTagVolume->m_tagVolume.InitInClientCoordinates(
89  polylinePoints, pointArraySize, minAltitude, maxAltitude,
90  navTag, m_navGenProjConfig.m_coordSystem) == KY_ERROR)
91  {
92  delete navGenTagVolume;
93  return KY_ERROR;
94  }
95 
96  m_tagVolumes.push_back(navGenTagVolume);
97  return KY_SUCCESS;
98  }
99 
100  int GetGeometryFileCount() const { return (int)m_geometries.size(); }
101  std::string GetGeometryFileName(int index) { return m_geometries[index]->m_fileName; }
102 
103  int GetClientInputFileCount() const { return (int)m_clientInputs.size(); }
104  std::string GetClientInputFileName(int index) { return m_clientInputs[index]->m_fileName; }
105 
106  bool Write(TiXmlNode* folderNode)
107  {
108  TiXmlElement* sectorNode = new TiXmlElement("sector");
109  folderNode->LinkEndChild(sectorNode);
110  return WriteContent(sectorNode);
111  }
112 
113 
114  bool Read(TiXmlNode* node)
115  {
116  for (TiXmlNode* child = node->FirstChild(); child != 0; child = child->NextSibling())
117  {
118  NavGenProj::GetParam(child, "name", m_name);
119 
120  std::string guidAsString;
121  if (NavGenProj::GetParam(child, "guid", guidAsString) == true)
122  m_guid.InitFromString(guidAsString.c_str());
123 
124  NavGenProj::GetParam(child, "doBuild", m_doBuild);
125  NavGenProj::GetParam(child, "doSaveClientInput", m_doSaveClientInput);
126  NavGenProj::GetParam(child, "doGenerateColData", m_doGenerateColData);
127 
128  if (strcmp(child->Value(), "geometries") == 0)
129  {
130  ReadGeometries(child);
131  }
132 
133  if (strcmp(child->Value(), "clientInputs") == 0)
134  {
135  ReadClientInputs(child);
136  }
137 
138  if (strcmp(child->Value(), "cellBox") == 0)
139  {
140  ReadCellBox(child);
141  }
142 
143  if (strcmp(child->Value(), "seedpoints") == 0)
144  {
145  ReadSeedPoints(child);
146  }
147 
148  if (strcmp(child->Value(), "tagVolumes") == 0)
149  {
150  ReadTagVolumes(child);
151  }
152  }
153  return true;
154  }
155 
156 
157 public: // internal
158 
159  bool ReadGeometry(TiXmlNode* node)
160  {
161  NavGenProjGeometry* geometry = new NavGenProjGeometry();
162  if (geometry->Read(node))
163  {
164  m_geometries.push_back(geometry);
165  return true;
166  }
167  else
168  {
169  delete geometry;
170  return false;
171  }
172  }
173 
174  void ReadGeometries(TiXmlNode* node)
175  {
176  for (TiXmlNode* child = node->FirstChild(); child != 0; child = child->NextSibling())
177  {
178  if (strcmp(child->Value(), "geometry") == 0)
179  {
180  ReadGeometry(child);
181  }
182  }
183  }
184 
185  bool ReadClientInput(TiXmlNode* node)
186  {
188  if (input->Read(node))
189  {
190  m_clientInputs.push_back(input);
191  return true;
192  }
193  else
194  {
195  delete input;
196  return false;
197  }
198  }
199 
200  void ReadClientInputs(TiXmlNode* node)
201  {
202  TiXmlNode* child;
203  for (child = node->FirstChild(); child != 0; child = child->NextSibling())
204  {
205  if (strcmp(child->Value(), "clientInput") == 0)
206  {
207  ReadClientInput(child);
208  }
209  }
210  }
211 
212  void ReadCellBox(TiXmlNode* node)
213  {
214  m_cellBox.Clear();
215  Kaim::CellPos min, max;
216  bool foundMin = false;
217  bool foundMax = false;
218  for (TiXmlNode* child = node->FirstChild(); child != 0; child = child->NextSibling())
219  {
220  foundMin |= NavGenProj::GetParam(child, "min", min);
221  foundMax |= NavGenProj::GetParam(child, "max", max);
222  }
223  if (foundMax && foundMin)
224  m_cellBox.SetSafe(min, max);
225  }
226 
227  void ReadSeedPoints(TiXmlNode* seedpointsNode)
228  {
229  for (TiXmlNode* pChild = seedpointsNode->FirstChild(); pChild != 0; pChild = pChild->NextSibling())
230  {
231  if (pChild->Type() != TiXmlNode::ELEMENT)
232  continue;
233 
234  if (strcmp(pChild->Value(), "seedpoint") == 0)
235  {
236  NavGenProjSeedPoint seedPoint;
237  if (seedPoint.Read(pChild))
238  m_seedPoints.push_back(seedPoint);
239  }
240  }
241  }
242 
243  void ReadTagVolumes(TiXmlNode* tagVolumesNode)
244  {
245  for (TiXmlNode* pChild = tagVolumesNode->FirstChild(); pChild != 0; pChild = pChild->NextSibling())
246  {
247  if (pChild->Type() != TiXmlNode::ELEMENT)
248  continue;
249 
250  if (strcmp(pChild->Value(), "tagVolume") == 0)
251  {
252  NavGenProjTagVolume* navGenProjTagVolume = new NavGenProjTagVolume(&m_navGenProjConfig.m_coordSystem);
253  if (navGenProjTagVolume->Read(pChild))
254  m_tagVolumes.push_back(navGenProjTagVolume);
255  else
256  delete navGenProjTagVolume;
257  }
258  }
259  }
260 
261  void WriteCellBox(TiXmlNode* node)
262  {
263  // Get geometry folder node
264  TiXmlNode* cellBoxFolderNode = NavGenProj::GetOrCreateFolderNode(node, "cellBox");
265 
266  // Min
267  TiXmlElement* minNode = new TiXmlElement("min");
268  minNode->SetAttribute("x", m_cellBox.m_min.x);
269  minNode->SetAttribute("y", m_cellBox.m_min.y);
270  cellBoxFolderNode->LinkEndChild(minNode);
271 
272  // Max
273  TiXmlElement* maxNode = new TiXmlElement("max");
274  maxNode->SetAttribute("x", m_cellBox.m_max.x);
275  maxNode->SetAttribute("y", m_cellBox.m_max.y);
276  cellBoxFolderNode->LinkEndChild(maxNode);
277  }
278 
279  bool WriteContent(TiXmlNode* sectorNode)
280  {
281  NavGenProj::SetParam(sectorNode, "name", m_name);
282 
283  char guidString[37];
284  m_guid.ToString(guidString);
285  NavGenProj::SetParam(sectorNode, "guid", std::string(guidString));
286 
287  NavGenProj::SetParam(sectorNode, "doBuild", m_doBuild);
288  NavGenProj::SetParam(sectorNode, "doSaveClientInput", m_doSaveClientInput);
289  NavGenProj::SetParam(sectorNode, "doGenerateColData", m_doGenerateColData);
290 
291  if (m_cellBox.IsValid())
292  WriteCellBox(sectorNode);
293 
294  // Write geometries
295  for (int i = 0; i < (int)m_geometries.size(); i++)
296  {
297  if (m_geometries[i]->Write(sectorNode) == false)
298  return KY_ERROR;
299  }
300 
301  // Write clientInputs
302  for (int i = 0; i < (int)m_clientInputs.size(); i++)
303  {
304  if (m_clientInputs[i]->Write(sectorNode) == false)
305  return KY_ERROR;
306  }
307 
308  // Write seedPoints
309  for (int i = 0; i < (int)m_seedPoints.size(); i++)
310  {
311  if (m_seedPoints[i].Write(sectorNode) == false)
312  return KY_ERROR;
313  }
314 
315  // Write tagVolumes
316  for (int i = 0; i < (int)m_tagVolumes.size(); i++)
317  {
318  if (m_tagVolumes[i]->Write(sectorNode) == false)
319  return KY_ERROR;
320  }
321 
322  return true;
323  }
324 
325 public:
326  NavGenProjConfig& m_navGenProjConfig;
327  std::string m_name;
328  Kaim::KyGuid m_guid;
329  bool m_doBuild;
330  bool m_doSaveClientInput;
331  bool m_doGenerateColData;
333  std::vector<NavGenProjGeometry*> m_geometries;
334  std::vector<NavGenProjClientInput*> m_clientInputs;
335  std::vector<NavGenProjSeedPoint> m_seedPoints;
336  std::vector<NavGenProjTagVolume*> m_tagVolumes;
337  Kaim::CellBox m_cellBox;
338  Vec2i m_mirroredPos;
339 };
340 
341 
342 }
343 
344 
345 #endif
This class represents a two-dimensional axis-aligned bounding box whose dimensions are stored using 3...
Definition: box2i.h:119
KyInt32 KyResult
Defines a type that can be returned by methods or functions in the Gameware Navigation SDK to indicat...
Definition: types.h:254
An instance of this class is used to represent each input geometry file in a NavGenProj.
Definition: NavGenProjGeometry.h:23
This class is used by the NavGenProj to store configuration parameters required by the NavData genera...
Definition: NavGenProjConfig.h:24
void SetSafe(const Vec2i &min_, const Vec2i &max_)
Sets the extents of the bounding box to the specified values.
Definition: box2i.h:169
An instance of this class is used to represent each seedpoint in a NavGenProj.
Definition: NavGenProjSeedPoint.h:23
KyInt32 x
The size of the vector along the X axis.
Definition: vec2i.h:283
KyInt32 y
The size of the vector along the Y axis.
Definition: vec2i.h:284
An instance of this class is used to represent each input geometry file in a NavGenProj.
Definition: NavGenProjClientInput.h:26
std::vector< NavGenProjGeometry * > m_geometries
Stores the list of input geometry files. Do not modify directly. Use AddObjFilePath().
Definition: NavGenProjSector.h:338
static const KyGuid & GetInvalidGuid()
Returns the invalid KyGuid value.
An instance of this class is used to represent each input geometry file in a NavGenProj.
Definition: NavGenProjSector.h:27
#define KyInt32MAXVAL
The maximum value that can be stored in the KyInt32 variable type.
Definition: types.h:224
This class defines a two-dimensional vector whose coordinates are stored using 32-bit integers...
Definition: vec2i.h:26
Definition: gamekitcrowddispersion.h:20
The KyGuid class represents a globally unique ID.
Definition: kyguid.h:22
#define KY_SUCCESS
Shorthand for Kaim::Result::Success.
Definition: types.h:273
#define KY_ERROR
Shorthand for Kaim::Result::Failure.
Definition: types.h:272
void InitFromString(const char guidString[])
Initializes this GUID using the specified string.
void ToString(char guidString[]) const
Converts this GUID to a string.
An instance of this class is used to represent each tag volume in a NavGenProj.
Definition: NavGenProjTagVolume.h:23
bool IsValid() const
Indicates whether or not the extents of the bounding box are valid.
Definition: box2i.h:154
void Clear()
Clears all information maintained by this object.
Definition: box2i.h:235
This class defines a three-dimensional vector whose coordinates are stored using floating-point numbe...
Definition: vec3f.h:23