Helios++
Helios software for LiDAR simulations
XmlAssetsLoader.h
1 #pragma once
2 
3 #include "typedef.h"
4 #include "Asset.h"
5 #include "Color4f.h"
6 #include "Platform.h"
7 #include "PlatformSettings.h"
8 #include <platform/trajectory/TrajectorySettings.h>
9 #include "Scanner.h"
10 #include <XmlSceneLoader.h>
11 
12 #include <tinyxml2.h>
13 
14 #include <memory>
15 #include <string>
16 #include <unordered_map>
17 #include <unordered_set>
18 
29 protected:
30  // *** CONSTANTS *** //
31  // ******************* //
36  static std::string const defaultScannerSettingsMsg;
41  static std::string const defaultPlatformSettingsMsg;
42 
43  // *** ATTRIBUTES *** //
44  // ******************** //
48  std::string assetsDir;
52  std::string xmlDocFilename = "unknown.xml";
56  std::string xmlDocFilePath = "";
57 
61  std::shared_ptr<ScannerSettings> defaultScannerTemplate;
65  std::shared_ptr<PlatformSettings> defaultPlatformTemplate;
66 
75  std::unordered_map<std::string, std::shared_ptr<ScannerSettings>>
85  std::unordered_map<std::string, std::shared_ptr<PlatformSettings>>
95  std::unordered_map<std::string, std::unordered_set<std::string>>
105  std::unordered_map<std::string, std::unordered_set<std::string>>
107 
108 public:
116  tinyxml2::XMLDocument doc;
117 
118  // *** CONSTRUCTION / DESTRUCTION *** //
119  // ************************************ //
125  XmlAssetsLoader(std::string& filePath, std::string& assetsDir);
126  virtual ~XmlAssetsLoader() {}
127 
128  // *** GETTERS and SETTERS *** //
129  // ***************************** //
139  std::shared_ptr<Asset> getAssetById(
140  std::string type,
141  std::string id,
142  void *extraOutput=nullptr
143  );
153  std::shared_ptr<Asset> getAssetByLocation(
154  std::string type,
155  std::string location,
156  void *extraOutput=nullptr
157  );
158 
159  // *** CREATION METHODS *** //
160  // ************************** //
171  std::shared_ptr<Asset> createAssetFromXml(
172  std::string type,
173  tinyxml2::XMLElement* assetNode,
174  void *extraOutput=nullptr
175  );
182  std::shared_ptr<Asset> createProceduralAssetFromXml(
183  std::string const &type,
184  std::string const &id,
185  void *extraOutput=nullptr
186  );
187 
194  std::shared_ptr<Platform> createPlatformFromXml(
195  tinyxml2::XMLElement* platformNode
196  );
203  std::shared_ptr<PlatformSettings> createPlatformSettingsFromXml(
204  tinyxml2::XMLElement* node,
205  std::unordered_set<std::string> *fields=nullptr
206  );
216  std::shared_ptr<Platform> procedurallyCreatePlatformFromXml(
217  string const &type,
218  string const &id
219  );
226  std::shared_ptr<Platform> createInterpolatedMovingPlatform();
227 
234  std::shared_ptr<Scanner> createScannerFromXml(
235  tinyxml2::XMLElement* scannerNode
236  );
237 
244  std::shared_ptr<AbstractBeamDeflector> createBeamDeflectorFromXml(
245  tinyxml2::XMLElement *scannerNode
246  );
247 
256  std::shared_ptr<AbstractDetector> createDetectorFromXml(
257  tinyxml2::XMLElement *scannerNode,
258  std::shared_ptr<Scanner> scanner
259  );
260 
267  std::shared_ptr<ScannerHead> createScannerHeadFromXml(
268  tinyxml2::XMLElement *scannerNode
269  );
270 
279  std::shared_ptr<ScannerSettings> createScannerSettingsFromXml(
280  tinyxml2::XMLElement* node,
281  std::unordered_set<std::string> *fields=nullptr
282  );
291  std::shared_ptr<FWFSettings> createFWFSettingsFromXml(
292  tinyxml2::XMLElement* node,
293  std::shared_ptr<FWFSettings> settings = nullptr
294  );
305  std::shared_ptr<TrajectorySettings> createTrajectorySettingsFromXml(
306  tinyxml2::XMLElement *legNode,
307  std::shared_ptr<TrajectorySettings> settings = nullptr
308  );
309 
322  std::shared_ptr<Scanner> scanner,
323  tinyxml2::XMLElement *scannerNode,
324  tinyxml2::XMLElement *channels,
325  std::shared_ptr<AbstractBeamDeflector> deflec,
326  std::shared_ptr<AbstractDetector> detec,
327  std::shared_ptr<ScannerHead> scanHead,
328  std::shared_ptr<FWFSettings> fwfSettings
329  );
330 
331 protected:
332  // *** UTIL METHODS *** //
333  // ********************** //
338  virtual void reinitLoader();
344  void makeDefaultTemplates();
354  std::shared_ptr<ScannerSettings> base,
355  std::shared_ptr<ScannerSettings> ref,
356  std::string const defaultTemplateId,
357  std::unordered_set<std::string> &fields
358  );
368  std::shared_ptr<PlatformSettings> base,
369  std::shared_ptr<PlatformSettings> ref,
370  std::string const defaultTemplateId,
371  std::unordered_set<std::string> &fields
372  );
373 
374 public:
375  // *** STATIC METHODS *** //
376  // ************************ //
391  static bool isProceduralAsset(
392  std::string const &type,
393  std::string const &id
394  );
395 };
Class for asset loading from XML file.
Definition: XmlAssetsLoader.h:28
std::unordered_map< std::string, std::shared_ptr< ScannerSettings > > scannerTemplates
Map containing all scanner templates that were loading while building from XML file....
Definition: XmlAssetsLoader.h:76
std::shared_ptr< Scanner > createScannerFromXml(tinyxml2::XMLElement *scannerNode)
Create scanner from given XML element (node)
Definition: XmlAssetsLoader.cpp:807
std::string xmlDocFilename
Name of the XML file.
Definition: XmlAssetsLoader.h:52
std::shared_ptr< AbstractBeamDeflector > createBeamDeflectorFromXml(tinyxml2::XMLElement *scannerNode)
Create a beam deflector from given XML element (node)
Definition: XmlAssetsLoader.cpp:926
std::shared_ptr< PlatformSettings > createPlatformSettingsFromXml(tinyxml2::XMLElement *node, std::unordered_set< std::string > *fields=nullptr)
Create platform settings from given XML element (node)
Definition: XmlAssetsLoader.cpp:273
std::string xmlDocFilePath
Path to the XML file.
Definition: XmlAssetsLoader.h:56
static bool isProceduralAsset(std::string const &type, std::string const &id)
Check whether the given asset is a procedural asset or not.
Definition: XmlAssetsLoader.cpp:1711
std::shared_ptr< ScannerSettings > defaultScannerTemplate
The default scanner settings template.
Definition: XmlAssetsLoader.h:61
std::shared_ptr< ScannerHead > createScannerHeadFromXml(tinyxml2::XMLElement *scannerNode)
Create a scanner head from given XML element (node)
Definition: XmlAssetsLoader.cpp:1007
XmlSceneLoader sceneLoader
The scene loader. It is used to load scenes from XML files.
Definition: XmlAssetsLoader.h:112
std::shared_ptr< AbstractDetector > createDetectorFromXml(tinyxml2::XMLElement *scannerNode, std::shared_ptr< Scanner > scanner)
Create a pulse detector from given XML element (node)
Definition: XmlAssetsLoader.cpp:986
std::shared_ptr< ScannerSettings > createScannerSettingsFromXml(tinyxml2::XMLElement *node, std::unordered_set< std::string > *fields=nullptr)
Create scanner settings from given XML element (node)
Definition: XmlAssetsLoader.cpp:1036
std::shared_ptr< TrajectorySettings > createTrajectorySettingsFromXml(tinyxml2::XMLElement *legNode, std::shared_ptr< TrajectorySettings > settings=nullptr)
Create TrajectorySettings from given XML element (node)
Definition: XmlAssetsLoader.cpp:1270
std::shared_ptr< Platform > procedurallyCreatePlatformFromXml(string const &type, string const &id)
Procedurally create the platform from given XML specification.
Definition: XmlAssetsLoader.cpp:405
void trackNonDefaultPlatformSettings(std::shared_ptr< PlatformSettings > base, std::shared_ptr< PlatformSettings > ref, std::string const defaultTemplateId, std::unordered_set< std::string > &fields)
Track non default values at base. It is, those values which are in base distinct than the reference (...
Definition: XmlAssetsLoader.cpp:1688
static std::string const defaultPlatformSettingsMsg
The message to be shown when default value is loaded for platform settings.
Definition: XmlAssetsLoader.h:41
std::shared_ptr< Asset > getAssetByLocation(std::string type, std::string location, void *extraOutput=nullptr)
Get asset by location.
Definition: XmlAssetsLoader.cpp:1595
void makeDefaultTemplates()
Definition: XmlAssetsLoader.cpp:1627
std::shared_ptr< Platform > createInterpolatedMovingPlatform()
Procedurally create an InterpolatedMovingPlatform.
Definition: XmlAssetsLoader.cpp:417
std::shared_ptr< Asset > createAssetFromXml(std::string type, tinyxml2::XMLElement *assetNode, void *extraOutput=nullptr)
Create an asset from given XML element (node)
Definition: XmlAssetsLoader.cpp:75
virtual void reinitLoader()
Reinitialize the loader so maps with scanner fields and scanner templates and their fields are empty.
Definition: XmlAssetsLoader.cpp:1622
std::shared_ptr< Asset > getAssetById(std::string type, std::string id, void *extraOutput=nullptr)
Get asset by its identifier.
Definition: XmlAssetsLoader.cpp:1546
void fillScanningDevicesFromChannels(std::shared_ptr< Scanner > scanner, tinyxml2::XMLElement *scannerNode, tinyxml2::XMLElement *channels, std::shared_ptr< AbstractBeamDeflector > deflec, std::shared_ptr< AbstractDetector > detec, std::shared_ptr< ScannerHead > scanHead, std::shared_ptr< FWFSettings > fwfSettings)
Fill vector of scanning devices with channel data.
Definition: XmlAssetsLoader.cpp:1293
std::shared_ptr< Asset > createProceduralAssetFromXml(std::string const &type, std::string const &id, void *extraOutput=nullptr)
Like XmlAssetsLoader::createAssetFromXml but creating the asset procedurally instead of simply loadin...
Definition: XmlAssetsLoader.cpp:124
std::string assetsDir
Assets directory.
Definition: XmlAssetsLoader.h:48
std::unordered_map< std::string, std::shared_ptr< PlatformSettings > > platformTemplates
Map containing all platform templates that were loading while building from XML file....
Definition: XmlAssetsLoader.h:86
std::shared_ptr< FWFSettings > createFWFSettingsFromXml(tinyxml2::XMLElement *node, std::shared_ptr< FWFSettings > settings=nullptr)
Create FWF settings from given XML element (node)
Definition: XmlAssetsLoader.cpp:1246
XmlAssetsLoader(std::string &filePath, std::string &assetsDir)
Build a XmlAssetsLoader for given XML file and assets directory.
Definition: XmlAssetsLoader.cpp:54
tinyxml2::XMLDocument doc
XML file through tinyxml2 library.
Definition: XmlAssetsLoader.h:116
std::unordered_map< std::string, std::unordered_set< std::string > > scannerTemplatesFields
Map containing the set of fields that have been overloaded by each scanner template.
Definition: XmlAssetsLoader.h:96
std::shared_ptr< PlatformSettings > defaultPlatformTemplate
The default platform settings template.
Definition: XmlAssetsLoader.h:65
std::shared_ptr< Platform > createPlatformFromXml(tinyxml2::XMLElement *platformNode)
Create a platform from given XML element (node)
Definition: XmlAssetsLoader.cpp:145
void trackNonDefaultScannerSettings(std::shared_ptr< ScannerSettings > base, std::shared_ptr< ScannerSettings > ref, std::string const defaultTemplateId, std::unordered_set< std::string > &fields)
Track non default values at base. It is, those values which are in base distinct than the reference (...
Definition: XmlAssetsLoader.cpp:1654
std::unordered_map< std::string, std::unordered_set< std::string > > platformTemplatesFields
Map containing the set of fields that have been overloaded by each platform template.
Definition: XmlAssetsLoader.h:106
static std::string const defaultScannerSettingsMsg
The message to be shown when default value is loaded for scanner settings.
Definition: XmlAssetsLoader.h:36
Class for scene loading from XML file.
Definition: XmlSceneLoader.h:23