tools/navgenproj/ProjSector.h Source File

ProjSector.h
Go to the documentation of this file.
1 /*
2 * Copyright 2017 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 #pragma once
8 
13 #include "navgenproj/ProjTypes.h"
15 #include <memory>
16 #include <string>
17 
18 namespace Kaim
19 {
20 
25 {
27 public:
28  ProjSector(ProjConfig& config)
29  : m_projConfig(config)
30  , m_guid(KyGuid::GetInvalidGuid())
31  , m_doBuild(true)
32  , m_doSaveClientInput(true)
33  , m_doGenerateColData(false)
34  , m_mirroredPos(KyInt32MAXVAL, KyInt32MAXVAL)
35  {
36  }
37 
38  void SetName(const char* name) { m_name.assign(name); }
39  void SetGuid(const Kaim::KyGuid& guid) { m_guid = guid; }
40  void SetDoBuild(bool doBuild) { m_doBuild = doBuild; }
41  void SetDoSaveClientInput(bool doSaveClientInput) { m_doSaveClientInput = doSaveClientInput; }
42  void SetDoGenerateColData(bool doGenerateColData) { m_doGenerateColData = doGenerateColData; }
43  void SetCellBox(const Kaim::CellBox& cellBox) { m_cellBox = cellBox; }
44 
45  void AddObjFilePath(const char* fileName)
46  {
47  ProjGeometry geometry;
48  geometry.SetFileName(fileName);
49  m_geometries.push_back(geometry);
50  }
51 
52  void AddClientInputFilePath(const char* fileName)
53  {
54  m_clientInputs.push_back(ProjClientInput(fileName));
55  }
56 
57  void AddSeedPoint(float x, float y, float z)
58  {
59  ProjSeedPoint seedPoint;
60  seedPoint.m_pos = Kaim::Vec3f(x, y, z);
61  m_seedPoints.push_back(seedPoint);
62  }
63 
64  KyResult AddTagVolume(const Vec3f* polylinePoints, int pointArraySize, const Kaim::DynamicNavTag& navTag, float minAltitude, float maxAltitude)
65  {
66  std::unique_ptr<ProjTagVolume> projTagVolume(new ProjTagVolume(&m_projConfig.m_coordSystem));
67  if (projTagVolume->m_tagVolume.InitInClientCoordinates(polylinePoints, pointArraySize, minAltitude, maxAltitude, navTag, m_projConfig.m_coordSystem) == KY_ERROR)
68  return KY_ERROR;
69 
70  m_tagVolumes.push_back(std::move(projTagVolume));
71  return KY_SUCCESS;
72  }
73 
74  int GetGeometryFileCount() const { return (int)m_geometries.size(); }
75  std::string GetGeometryFileName(int index) { return m_geometries[index].m_fileName; }
76 
77  int GetClientInputFileCount() const { return (int)m_clientInputs.size(); }
78  std::string GetClientInputFileName(int index) { return m_clientInputs[index].m_fileName; }
79 
80  void Write(XmlNode node) const
81  {
82  node.WriteChild("name", m_name);
83  node.WriteChild("guid", m_guid);
84 
85  node.WriteChild("doBuild", m_doBuild);
86  node.WriteChild("doSaveClientInput", m_doSaveClientInput);
87  node.WriteChild("doGenerateColData", m_doGenerateColData);
88 
89  if (m_cellBox.IsValid())
90  node.WriteChild("cellBox", m_cellBox);
91 
92  node.WriteChild("produceInputMask", m_produceInputMask);
93 
94  // Write geometries
95  if (m_geometries.size() > 0)
96  {
97  XmlNode n = node.CreateChild("geometries");
98  for (const auto& e : m_geometries)
99  n.WriteChild("geometry", e);
100  }
101 
102  // Write clientInputs
103  if (m_clientInputs.size() > 0)
104  {
105  XmlNode n = node.CreateChild("clientInputs");
106  for (const auto& e : m_clientInputs)
107  n.WriteChild("clientInput", e);
108  }
109 
110  // Write seedPoints
111  if (m_seedPoints.size() > 0)
112  {
113  XmlNode n = node.CreateChild("seedPoints");
114  for (const auto& e : m_seedPoints)
115  n.WriteChild("seedPoint", e);
116  }
117 
118  // Write tagVolumes
119  if (m_tagVolumes.size() > 0)
120  {
121  XmlNode tagVolumesNode = node.CreateChild("tagVolumes");
122  for (const auto& e : m_tagVolumes)
123  Kaim::Write(tagVolumesNode.CreateChild("tagVolume"), *e);
124  }
125  }
126 
127  bool Read(XmlNode node)
128  {
129  for (XmlNode child = node.FirstChild(); child; child = child.NextSibling())
130  {
131  if (child.IsElement() == false)
132  continue;
133 
134  KY_READ_CHILD_VALUE(child, "name", m_name);
135  KY_READ_CHILD_VALUE(child, "guid", m_guid);
136 
137  KY_READ_CHILD_VALUE(child, "doBuild", m_doBuild);
138  KY_READ_CHILD_VALUE(child, "doSaveClientInput", m_doSaveClientInput);
139  KY_READ_CHILD_VALUE(child, "doGenerateColData", m_doGenerateColData);
140 
141  KY_READ_CHILD_VALUE(child, "cellBox", m_cellBox);
142 
143  KY_READ_CHILD_VALUE(child, "produceInputMask", m_produceInputMask);
144 
145  KY_READ_CHILD_FUNC(child, "geometries", ReadGeometries(child));
146  KY_READ_CHILD_FUNC(child, "clientInputs", ReadClientInputs(child));
147 
148  KY_READ_CHILD_FUNC(child, "seedpoints", ReadSeedPoints(child));
149  KY_READ_CHILD_FUNC(child, "tagVolumes", ReadTagVolumes(child));
150 
151  KY_LOG_WARNING(("[NavGenProj] unknown child <%s> in node <%s>", child.GetName(), node.GetName()));
152  }
153  return true;
154  }
155 
156 
157 public: // internal
158 
159  bool ReadGeometries(XmlNode node)
160  {
161  for (XmlNode child = node.FirstChild(); child; child = child.NextSibling())
162  {
163  if (child.HasName("geometry") == false)
164  return false;
165 
166  ProjGeometry geometry;
167  if (child.ReadNode(geometry) == false)
168  return false;
169 
170  m_geometries.push_back(geometry);
171  }
172  return true;
173  }
174 
175  bool ReadClientInputs(XmlNode node)
176  {
177  for (XmlNode child = node.FirstChild(); child; child = child.NextSibling())
178  {
179  if (child.HasName("clientInput") == false)
180  return false;
181 
182  ProjClientInput projClientInput;
183  if (child.ReadNode(projClientInput) == false)
184  return false;
185 
186  m_clientInputs.push_back(projClientInput);
187  }
188  return true;
189  }
190 
191  bool ReadSeedPoints(XmlNode node)
192  {
193  for (XmlNode child = node.FirstChild(); child; child = child.NextSibling())
194  {
195  if (child.HasName("seedpoint") == false)
196  return false;
197 
198  ProjSeedPoint projSeedPoint;
199  if (Kaim::Read(child, projSeedPoint) == false)
200  return false;
201 
202  m_seedPoints.push_back(projSeedPoint);
203  }
204  return true;
205  }
206 
207  bool ReadTagVolumes(XmlNode node)
208  {
209  for (XmlNode child = node.FirstChild(); child; child = child.NextSibling())
210  {
211  if (child.HasName("tagVolume") == false)
212  return false;
213 
214  std::unique_ptr<ProjTagVolume> projTagVolume(new ProjTagVolume(&m_projConfig.m_coordSystem));
215  if (child.ReadNode(*projTagVolume) == false)
216  return false;
217 
218  m_tagVolumes.push_back(std::move(projTagVolume));
219  }
220  return true;
221  }
222 
223 public:
224  ProjConfig& m_projConfig;
225  std::string m_name;
226  Kaim::KyGuid m_guid;
227  bool m_doBuild;
228  bool m_doSaveClientInput;
229  bool m_doGenerateColData;
230  ProjProduceInputMask m_produceInputMask;
231  std::vector<ProjGeometry> m_geometries;
232  std::vector<ProjClientInput> m_clientInputs;
233  std::vector<ProjSeedPoint> m_seedPoints;
234  std::vector<std::unique_ptr<ProjTagVolume>> m_tagVolumes;
235  Kaim::CellBox m_cellBox;
236  Vec2i m_mirroredPos;
237 };
238 
239 inline bool Read(XmlNode node, ProjSector& value) { return value.Read(node); }
240 inline void Write(XmlNode node, const ProjSector& value) { value.Write(node); }
241 
242 
243 }
244 
245 
This class is used by the NavGenProj to store configuration parameters required by the NavData genera...
Definition: ProjConfig.h:23
2d axis aligned box of 32bits integers. Very Important: CountX() returns m_max.x - m_min...
Definition: box2i.h:17
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:196
#define KyInt32MAXVAL
KyInt32 max value
Definition: types.h:60
Navigation return code class.
Definition: types.h:108
An instance of this class is used to represent each input geometry file in a NavGenProj.
Definition: ProjSector.h:24
2d vector using KyInt32
Definition: vec2i.h:18
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
The KyGuid class represents a globally unique ID.
Definition: kyguid.h:20
static const KyGuid & GetInvalidGuid()
Returns the invalid KyGuid value.
Definition: kyguid.cpp:21
#define KY_ERROR
use result == KY_ERROR to test for error
Definition: types.h:132
3d vector using 32bits floating points.
Definition: vec3f.h:16