GOAT (Geometrical optics application tool) 0.1
Loading...
Searching...
No Matches
xml.h
Go to the documentation of this file.
1#pragma once
2#include "tinyxml2.h"
3#include "raytrace.h"
4#include <string>
5#include "xmltoken.h"
6/*****************************************************************/
14#include <string>
15#include <vector>
16#include <sstream>
17#include <locale>
18#include <iomanip>
19namespace GOAT
20{
21 namespace XML
22 {
23 #define numXMLRootElements 3
24 #define XML_NONE -1
25 #define XML_SCENE_R0 0
26 #define XML_SCENE_NS 1
27 #define XML_SCENE_NCELLS 2
28 #define XML_SCENE_LIGHTSOURCES 3
29 #define XML_SCENE_OBJECTS 4
30 #define XML_SCENE_DETECTORS 5
31
32 #define numXML_LS_TYPES 4
33 #define XML_LS_TYPE_PLANE 0
34 #define XML_LS_TYPE_GAUSS 1
35 #define XML_LS_TYPE_PLANE_MC 2
36 #define XML_LS_TYPE_GAUSS_MC 3
37
38
39
40
41 const std::string sceneXMLElements[] = { "r0","ns","CellsPerDir","lightsources","objects","detectors"};
42 const std::string LSXMLAttributes[] = { "type","size","wavelength","numrays","numraysRT"};
43 const std::string LSXMLTYPES[] = {"plane","gaussian","plane_mc","gaussian_mc"};
44 const std::string LSTYPES[] = { "plane","gaussian","ring","tophat","line","point","plane_mc","gaussian_mc","ring_mc","line_mc","point_mc" };
45
53 bool findExtension (std::string fname, std::string extension);
84
86 {
87 public:
95 void readXML(std::string fname, bool calc_enabled=true, std::string path = "");
97 void setEnableCalculation(bool enable) { calculation_enabled=enable;}
99 private:
100 void readScene();
103 void readObjects();
117 GOAT::maths::Vector<double> readVector(tinyxml2::XMLElement* ell, double x = 0, double y = 0, double z = 0);
118
127
137
146 std::complex<double> readCmplx(tinyxml2::XMLElement* ell, double defre=0.0, double defim=0.0 );
147
155 std::complex<double> readCmplx(tinyxml2::XMLElement* ell, int& xmlError);
156
160 std::vector<GOAT::raytracing::ObjectShape*> Obj;
161 std::vector<GOAT::raytracing::Detector*> Det;
162 std::vector< GOAT::raytracing::LightSrc*> LS;
163 int numObj = 0;
164 int numLS = 0;
165 int numDet = 0;
166 std::string path;
168 };
169
170
171
172
174 {
175 public:
177 void write (std::string fname);
178 private:
179 inline std::string formatDouble(double val, int precision = 17)
180 {
181 std::ostringstream oss;
182 oss.imbue(std::locale::classic()); // Erzwingt "." statt "," als Dezimaltrennzeichen
183 oss << std::fixed << std::setprecision(precision) << val;
184 return oss.str();
185 }
186 void writeLightSrc(int i);
187 void writeObject(int i);
188 void writeDetector(int i);
189
190
199
207 tinyxml2::XMLElement* writeVectorC(std::string name, maths::Vector<std::complex<double>> v);
208
215 tinyxml2::XMLElement* writeComplex(std::string name, std::complex<double> z);
223
224 };
225 }
226}
This class provides functionality to read a XML-file This function reads the XML file ....
Definition xml.h:86
int numObj
number of objects
Definition xml.h:163
tinyxml2::XMLNode * rootElement
pointer to root element of the XML
Definition xml.h:157
void readLightSources()
(used in readScene) read the light sources from the file
GOAT::maths::Vector< std::complex< double > > readCmplxVector(tinyxml2::XMLElement *ell, int &xmlError)
read double vector from file This method reads a complex valued 3D-Vector from the XML-file represent...
void doCalculations()
(used in readScene) read and execute the commands for calculation
void setEnableCalculation(bool enable)
Definition xml.h:97
bool isCalculationEnabled()
Definition xml.h:98
std::complex< double > readCmplx(tinyxml2::XMLElement *ell, int &xmlError)
read complex value from file This method reads a complex value from file with given default values fo...
bool calculation_enabled
Definition xml.h:167
std::vector< GOAT::raytracing::Detector * > Det
vector, which carries all detectors (as pointers)
Definition xml.h:161
std::vector< GOAT::raytracing::ObjectShape * > Obj
vector, which carries all objects (as pointers)
Definition xml.h:160
std::vector< GOAT::raytracing::LightSrc * > LS
vector, which carries all light sources (as pointers)
Definition xml.h:162
void doPulseCalculation(tinyxml2::XMLElement *objEll)
(used in doCalculations) to pulsed Calculation (rt + integral)
void readObjects()
(used in readScene) read the objects from the file
tinyxml2::XMLElement * calculationElement
pointer to the calculation elemeent of the XML
Definition xml.h:159
std::string path
path of the XML-File
Definition xml.h:166
void readScene()
read the entire Scene
void readDetectors()
(used in readScene) read the detectors from the file (deprecated ?)
GOAT::raytracing::Scene S
The scene that was read from the file is saved here.
Definition xml.h:96
void readCommands()
(used in readXML) read and execute the commands for calculation
int numDet
number of detectors
Definition xml.h:165
GOAT::maths::Vector< double > readVector(tinyxml2::XMLElement *ell, double x=0, double y=0, double z=0)
read double vector from file This method reads a 3D-Vector from the XML-file represented by the corre...
int numLS
number of light sources
Definition xml.h:164
std::complex< double > readCmplx(tinyxml2::XMLElement *ell, double defre=0.0, double defim=0.0)
read complex value from file This method reads a complex value from file with given default values fo...
void readXML(std::string fname, bool calc_enabled=true, std::string path="")
read the XML-file This methode reads the XML-file
tinyxml2::XMLElement * sceneElement
pointer to the scene element of the XML
Definition xml.h:158
GOAT::maths::Vector< double > readVector(tinyxml2::XMLElement *ell, int &xmlError)
read double vector from file This method reads a 3D-Vector from the XML-file represented by the corre...
void doPulseCalculation_rt(tinyxml2::XMLElement *objEll)
do pulse Calculation with raytracing only
void writeLightSrc(int i)
write the i-th light source to the file
tinyxml2::XMLElement * root
root XML Element
Definition xml.h:218
tinyxml2::XMLElement * writeVectorC(std::string name, maths::Vector< std::complex< double > > v)
write complex vector to file This method writes a complex 3D vector to XML-file
tinyxml2::XMLElement * writeVectorD(std::string name, maths::Vector< double > v)
write double vector to file This method writes a double 3D vector to XML-file
void writeObject(int i)
write the i-th object to the file
tinyxml2::XMLElement * objects
XML Element to the Objects section.
Definition xml.h:221
void write(std::string fname)
xmlWriter(const GOAT::raytracing::Scene &S)
void writeDetector(int i)
write the i-th detector to the file
const GOAT::raytracing::Scene & S
the scene
Definition xml.h:216
tinyxml2::XMLElement * detectors
XML Element to the Detectors section.
Definition xml.h:222
tinyxml2::XMLElement * lightSrcs
XML Element to the LightSources section.
Definition xml.h:220
tinyxml2::XMLElement * writeComplex(std::string name, std::complex< double > z)
write complex number to file This method writes a complex number to the XML-file
tinyxml2::XMLDocument doc
the xml document
Definition xml.h:217
std::string formatDouble(double val, int precision=17)
Definition xml.h:179
tinyxml2::XMLElement * scene
XML Element to the Scene section.
Definition xml.h:219
Template class for threedimensional vectors.
Definition vector.h:57
Class defining a scene with lightsources and objects. This is a container used to inform the Raytrace...
Definition raytrace.h:28
const std::string LSTYPES[]
Definition xml.h:44
bool findExtension(std::string fname, std::string extension)
check if the fname has a given extension This function checks if the fname ends with a given extensio...
const std::string LSXMLAttributes[]
Definition xml.h:42
const std::string LSXMLTYPES[]
Definition xml.h:43
const std::string sceneXMLElements[]
Definition xml.h:41
This class is used for the iray class. This class is intended for internal use only....
Definition fresnel.h:7