Helios++
Helios software for LiDAR simulations
XmlAssetsLoader.h
1 #pragma once
2 
3 #include <memory>
4 #include <string>
5 #include <unordered_map>
6 
7 #include <tinyxml2.h>
8 
9 #include "typedef.h"
10 
11 #include "Asset.h"
12 #include "Color4f.h"
13 #include "Platform.h"
14 #include "PlatformSettings.h"
15 #include "Scanner.h"
16 #include <NoiseSource.h>
17 #include <SceneLoadingSpecification.h>
18 
23  // *** ATTRIBUTES *** //
24  // ******************** //
25 protected:
29  std::string assetsDir;
33  std::string xmlDocFilename = "unknown.xml";
37  std::string xmlDocFilePath = "";
38 
47  std::unordered_map<std::string, std::shared_ptr<ScannerSettings>>
49 
50 public:
54  tinyxml2::XMLDocument doc;
60 
61  // *** CONSTRUCTION / DESTRUCTION *** //
62  // ************************************ //
68  XmlAssetsLoader(std::string& filePath, std::string& assetsDir);
69 
70  // *** GETTERS and SETTERS *** //
71  // ***************************** //
78  std::shared_ptr<Asset> getAssetById(std::string type, std::string id);
85  std::shared_ptr<Asset> getAssetByLocation(std::string type, std::string location);
86 protected:
96  ObjectT getAttribute(
97  tinyxml2::XMLElement* element,
98  std::string attrName,
99  std::string type,
100  ObjectT defaultVal
101  );
102 
103 public:
104  // *** CREATION METHODS *** //
105  // ************************** //
113  std::shared_ptr<Asset> createAssetFromXml(
114  std::string type,
115  tinyxml2::XMLElement* assetNode
116  );
117 
124  Color4f createColorFromXml(tinyxml2::XMLElement* node);
131  std::map<std::string, ObjectT> createParamsFromXml(
132  tinyxml2::XMLElement* paramsNode
133  );
140  std::shared_ptr<Platform> createPlatformFromXml(
141  tinyxml2::XMLElement* platformNode
142  );
149  std::shared_ptr<PlatformSettings> createPlatformSettingsFromXml(
150  tinyxml2::XMLElement* node
151  );
158  std::shared_ptr<Scanner> createScannerFromXml(
159  tinyxml2::XMLElement* scannerNode
160  );
167  std::shared_ptr<ScannerSettings> createScannerSettingsFromXml(
168  tinyxml2::XMLElement* node
169  );
178  std::shared_ptr<FWFSettings> createFWFSettingsFromXml(
179  tinyxml2::XMLElement* node,
180  std::shared_ptr<FWFSettings> settings = nullptr
181  );
189  std::shared_ptr<Scene> createSceneFromXml(
190  tinyxml2::XMLElement* sceneNode,
191  std::string path
192  );
200  tinyxml2::XMLElement* rotGroupNode
201  );
210  glm::dvec3 createVec3dFromXml(
211  tinyxml2::XMLElement* node,
212  std::string attrPrefix
213  );
220  static std::shared_ptr<NoiseSource<double>>
222  tinyxml2::XMLElement *noise
223  );
224 
225 };
std::shared_ptr< Scene > createSceneFromXml(tinyxml2::XMLElement *sceneNode, std::string path)
Create scene from given XML element (node)
Definition: XmlAssetsLoader.cpp:734
std::shared_ptr< Asset > getAssetById(std::string type, std::string id)
Get asset by its identifier.
Definition: XmlAssetsLoader.cpp:946
XmlAssetsLoader(std::string &filePath, std::string &assetsDir)
Build a XmlAssetsLoader for given XML file and assets directory.
Definition: XmlAssetsLoader.cpp:44
std::shared_ptr< Asset > getAssetByLocation(std::string type, std::string location)
Get asset by location.
Definition: XmlAssetsLoader.cpp:986
Definition: Rotation.h:80
Color4f createColorFromXml(tinyxml2::XMLElement *node)
Create a color from given XML element (node)
Definition: XmlAssetsLoader.cpp:106
Rotation createRotationFromXml(tinyxml2::XMLElement *rotGroupNode)
Create a rotation from given XML element (node)
Definition: XmlAssetsLoader.cpp:891
std::shared_ptr< PlatformSettings > createPlatformSettingsFromXml(tinyxml2::XMLElement *node)
Create platform settings from given XML element (node)
Definition: XmlAssetsLoader.cpp:314
std::string xmlDocFilePath
Path to the XML file.
Definition: XmlAssetsLoader.h:37
std::shared_ptr< ScannerSettings > createScannerSettingsFromXml(tinyxml2::XMLElement *node)
Create scanner settings from given XML element (node)
Definition: XmlAssetsLoader.cpp:560
Class representing a color with 4 float components: RGBA.
Definition: Color4f.h:6
Manually specify scene transformation filters to apply when loading a scene.
Definition: SceneLoadingSpecification.h:18
std::shared_ptr< Scanner > createScannerFromXml(tinyxml2::XMLElement *scannerNode)
Create scanner from given XML element (node)
Definition: XmlAssetsLoader.cpp:383
Class for asset loading from XML file.
Definition: XmlAssetsLoader.h:22
std::string xmlDocFilename
Name of the XML file.
Definition: XmlAssetsLoader.h:33
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:713
SceneLoadingSpecification sceneSpec
Scene loading specification.
Definition: XmlAssetsLoader.h:59
std::shared_ptr< Platform > createPlatformFromXml(tinyxml2::XMLElement *platformNode)
Create a platform from given XML element (node)
Definition: XmlAssetsLoader.cpp:193
std::map< std::string, ObjectT > createParamsFromXml(tinyxml2::XMLElement *paramsNode)
Create a map of parameters from given XML element (node)
Definition: XmlAssetsLoader.cpp:123
std::string assetsDir
Assets directory.
Definition: XmlAssetsLoader.h:29
std::shared_ptr< Asset > createAssetFromXml(std::string type, tinyxml2::XMLElement *assetNode)
Create an asset from given XML element (node)
Definition: XmlAssetsLoader.cpp:59
glm::dvec3 createVec3dFromXml(tinyxml2::XMLElement *node, std::string attrPrefix)
Create a 3D vector from given XML element (node)
Definition: XmlAssetsLoader.cpp:932
ObjectT getAttribute(tinyxml2::XMLElement *element, std::string attrName, std::string type, ObjectT defaultVal)
Obtain attribute from XML.
Definition: XmlAssetsLoader.cpp:1011
tinyxml2::XMLDocument doc
XML file through tinyxml2 library.
Definition: XmlAssetsLoader.h:54
static std::shared_ptr< NoiseSource< double > > createNoiseSource(tinyxml2::XMLElement *noise)
Create a noise source from given XML element (node)
Definition: XmlAssetsLoader.cpp:1082
std::unordered_map< std::string, std::shared_ptr< ScannerSettings > > scannerTemplates
Map containing all scanner templates that were loading while building from XML file. No repetitions, each template appears only one time.
Definition: XmlAssetsLoader.h:48