Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
igl::xml Namespace Reference

Namespaces

namespace  serialization_xml
 

Classes

class  XMLSerializable
 
struct  XMLSerializableBase
 

Functions

IGL_INLINE bool save_ReAntTweakBar (::igl::anttweakbar::ReTwBar *bar, const char *file_name)
 
IGL_INLINE bool load_ReAntTweakBar (::igl::anttweakbar::ReTwBar *bar, const char *file_name)
 
template<typename T >
IGL_INLINE void serialize_xml (const T &obj, const std::string &filename)
 
template<typename T >
IGL_INLINE void serialize_xml (const T &obj, const std::string &objectName, const std::string &filename, bool binary, bool overwrite)
 
template<typename T >
IGL_INLINE void serialize_xml (const T &obj, const std::string &objectName, tinyxml2::XMLDocument *doc, tinyxml2::XMLElement *element, bool binary)
 
template<typename T >
IGL_INLINE void deserialize_xml (T &obj, const std::string &filename)
 
template<typename T >
IGL_INLINE void deserialize_xml (T &obj, const std::string &objectName, const std::string &filename)
 
template<typename T >
IGL_INLINE void deserialize_xml (T &obj, const std::string &objectName, const tinyxml2::XMLDocument *doc, const tinyxml2::XMLElement *element)
 
template<typename DerivedV , typename DerivedF >
IGL_INLINE bool write_triangle_mesh (const std::string str, const Eigen::PlainObjectBase< DerivedV > &V, const Eigen::PlainObjectBase< DerivedF > &F, const bool ascii=true)
 
template<typename DerivedV , typename DerivedF >
IGL_INLINE bool writeDAE (const std::string &filename, const Eigen::PlainObjectBase< DerivedV > &V, const Eigen::PlainObjectBase< DerivedF > &F)
 

Function Documentation

◆ deserialize_xml() [1/3]

template<typename T >
IGL_INLINE void igl::xml::deserialize_xml ( T &  obj,
const std::string &  filename 
)
113 {
114 deserialize_xml(obj,"object",filename);
115 }
IGL_INLINE void deserialize_xml(T &obj, const std::string &filename)
Definition serialize_xml.cpp:112

References deserialize_xml().

Referenced by igl::xml::XMLSerializable::XMLSerializationObject< T >::Deserialize(), deserialize_xml(), and deserialize_xml().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deserialize_xml() [2/3]

template<typename T >
IGL_INLINE void igl::xml::deserialize_xml ( T &  obj,
const std::string &  objectName,
const std::string &  filename 
)
119 {
120 tinyxml2::XMLDocument* doc = new tinyxml2::XMLDocument();
121
122 tinyxml2::XMLError error = doc->LoadFile(filename.c_str());
123 if(error != tinyxml2::XML_SUCCESS)
124 {
125 std::cerr << "File not found!" << std::endl;
126 doc->PrintError();
127 doc = NULL;
128 }
129 else
130 {
131 tinyxml2::XMLElement* element = doc->FirstChildElement("serialization");
132 if(element == NULL)
133 {
134 std::cerr << "Name of object not found! Initialized with default value." << std::endl;
135 obj = T();
136 }
137 else
138 {
139 deserialize_xml(obj,objectName,doc,element);
140 }
141
142 delete doc;
143 }
144 }
static char error[256]
Definition tga.cpp:50

References deserialize_xml(), and error.

+ Here is the call graph for this function:

◆ deserialize_xml() [3/3]

template<typename T >
IGL_INLINE void igl::xml::deserialize_xml ( T &  obj,
const std::string &  objectName,
const tinyxml2::XMLDocument *  doc,
const tinyxml2::XMLElement *  element 
)
148 {
149 static_assert(serialization::is_serializable<T>::value,"'igl::xml::deserialize_xml': type is not deserializable");
150
151 std::string name(objectName);
152 serialization_xml::encodeXMLElementName(name);
153
154 const tinyxml2::XMLElement* child = element->FirstChildElement(name.c_str());
155 if(child != NULL)
156 {
157 bool isBinary = false;
158 const tinyxml2::XMLAttribute* attr = child->FindAttribute("binary");
159 if(attr != NULL)
160 {
161 std::string code;
162 serialization_xml::deserialize(code,doc,element,name);
163 std::string decoded = serialization_xml::base64_decode(code);
164
165 std::vector<char> buffer;
166 std::copy(decoded.c_str(),decoded.c_str()+decoded.length(),std::back_inserter(buffer));
167
168 deserialize(obj,name,buffer);
169 }
170 else
171 {
172 serialization_xml::deserialize(obj,doc,element,name);
173 }
174 }
175 }
Definition serialize.h:264

References igl::xml::serialization_xml::base64_decode(), igl::deserialize(), igl::xml::serialization_xml::deserialize(), and igl::xml::serialization_xml::encodeXMLElementName().

+ Here is the call graph for this function:

◆ load_ReAntTweakBar()

IGL_INLINE bool igl::xml::load_ReAntTweakBar ( ::igl::anttweakbar::ReTwBar bar,
const char *  file_name 
)
134 {
135 char type_str[REANTTWEAKBAR_MAX_WORD];
136 char value_str[REANTTWEAKBAR_MAX_WORD];
137 TwType type;
138
139 const char * name_chars = TwGetBarName(bar->bar);
140 std::string name = std::string(name_chars) + "_AntTweakBar";
141
142 const std::vector< ::igl::anttweakbar::ReTwRWItem>& rw_items = bar->get_rw_items();
143 for(std::vector< ::igl::anttweakbar::ReTwRWItem>::const_iterator it = rw_items.begin(); it != rw_items.end(); it++)
144 {
145 char* val;
146 //::igl::XMLSerializer::LoadObject(val,it->name,name,file_name);
147 ::igl::deserialize_xml(val,it->name,file_name);
148 sscanf(val,"%s %[^\n]",type_str,value_str);
149
150 if(!bar->type_from_string(type_str,type))
151 {
152 printf("ERROR: %s type not found... Skipping...\n",type_str);
153 continue;
154 }
155
156 bar->set_value_from_string(it->name.c_str(),type,value_str);
157 delete[] val;
158 }
159
160 const std::vector< ::igl::anttweakbar::ReTwCBItem>& cb_items = bar->get_cb_items();
161 for(std::vector< ::igl::anttweakbar::ReTwCBItem>::const_iterator it = cb_items.begin(); it != cb_items.end(); it++)
162 {
163 char* val;
164 //::igl::XMLSerializer::LoadObject(val,it->name,name,file_name);
165 ::igl::deserialize_xml(val,it->name,file_name);
166 sscanf(val,"%s %[^\n]",type_str,value_str);
167
168 if(!bar->type_from_string(type_str,type))
169 {
170 printf("ERROR: %s type not found... Skipping...\n",type_str);
171 continue;
172 }
173
174 bar->set_value_from_string(it->name.c_str(),type,value_str);
175 delete[] val;
176 }
177
178 return true;
179 }
#define REANTTWEAKBAR_MAX_WORD
Definition ReAntTweakBar.h:59
IGL_INLINE const std::vector< ReTwRWItem > & get_rw_items()
Definition ReAntTweakBar.cpp:925
IGL_INLINE bool set_value_from_string(const char *name, TwType type, const char *value_str)
Definition ReAntTweakBar.cpp:576
IGL_INLINE const std::vector< ReTwCBItem > & get_cb_items()
Definition ReAntTweakBar.cpp:931
IGL_INLINE bool type_from_string(const char *type_str, TwType &type)
Definition ReAntTweakBar.cpp:546
TwBar * bar
Definition ReAntTweakBar.h:166

References igl::anttweakbar::ReTwBar::bar, igl::anttweakbar::ReTwBar::get_cb_items(), igl::anttweakbar::ReTwBar::get_rw_items(), REANTTWEAKBAR_MAX_WORD, igl::anttweakbar::ReTwBar::set_value_from_string(), and igl::anttweakbar::ReTwBar::type_from_string().

+ Here is the call graph for this function:

◆ save_ReAntTweakBar()

IGL_INLINE bool igl::xml::save_ReAntTweakBar ( ::igl::anttweakbar::ReTwBar bar,
const char *  file_name 
)
44 {
45 const char * name_chars = TwGetBarName(bar->bar);
46 std::string name = std::string(name_chars) + "_AntTweakBar";
47
48 const std::vector< ::igl::anttweakbar::ReTwRWItem>& rw_items = bar->get_rw_items();
49 for(std::vector< ::igl::anttweakbar::ReTwRWItem>::const_iterator it = rw_items.begin(); it != rw_items.end(); it++)
50 {
51 std::string val = bar->get_value_as_string(it->var,it->type);
52 //::igl::XMLSerializer::SaveObject(val,it->name,name,file_name,false);
53 ::igl::serialize_xml(val,it->name,file_name,false,false);
54 }
55
57 // Print all CB variables
58 const std::vector< ::igl::anttweakbar::ReTwCBItem>& cb_items = bar->get_cb_items();
59 for(std::vector< ::igl::anttweakbar::ReTwCBItem>::const_iterator it = cb_items.begin(); it != cb_items.end(); it++)
60 {
61 TwType type = it->type;
62 //TwSetVarCallback setCallback = it->setCallback;
63 TwGetVarCallback getCallback = it->getCallback;
64 void * clientData = it->clientData;
65 // I'm not sure how to do what I want to do. getCallback needs to be sure
66 // that it can write to var. So var needs to point to a valid and big
67 // enough chunk of memory
68 getCallback(var,clientData);
69
70 std::string val = bar->get_value_as_string(var,type);
71 //::igl::XMLSerializer::SaveObject(val,it->name,name,file_name,false);
72 ::igl::serialize_xml(val,it->name,file_name,false,false);
73 }
74
75 return true;
76 }
#define REANTTWEAKBAR_MAX_CB_VAR_SIZE
Definition ReAntTweakBar.h:56
std::string get_value_as_string(void *var, TwType type)
Definition ReAntTweakBar.cpp:347

References igl::anttweakbar::ReTwBar::bar, igl::anttweakbar::ReTwBar::get_cb_items(), igl::anttweakbar::ReTwBar::get_rw_items(), igl::anttweakbar::ReTwBar::get_value_as_string(), and REANTTWEAKBAR_MAX_CB_VAR_SIZE.

+ Here is the call graph for this function:

◆ serialize_xml() [1/3]

template<typename T >
IGL_INLINE void igl::xml::serialize_xml ( const T &  obj,
const std::string &  filename 
)
26 {
27 serialize_xml(obj,"object",filename,false,true);
28 }
IGL_INLINE void serialize_xml(const T &obj, const std::string &filename)
Definition serialize_xml.cpp:23

References serialize_xml().

Referenced by igl::xml::XMLSerializable::XMLSerializationObject< T >::Serialize(), serialize_xml(), and serialize_xml().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serialize_xml() [2/3]

template<typename T >
IGL_INLINE void igl::xml::serialize_xml ( const T &  obj,
const std::string &  objectName,
const std::string &  filename,
bool  binary,
bool  overwrite 
)
37 {
38 tinyxml2::XMLDocument* doc = new tinyxml2::XMLDocument();
39
40 if(overwrite == false)
41 {
42 // Check if file exists
43 tinyxml2::XMLError error = doc->LoadFile(filename.c_str());
44 if(error != tinyxml2::XML_SUCCESS)
45 {
46 doc->Clear();
47 }
48 }
49
50 tinyxml2::XMLElement* element = doc->FirstChildElement("serialization");
51 if(element == NULL)
52 {
53 element = doc->NewElement("serialization");
54 doc->InsertEndChild(element);
55 }
56
57 serialize_xml(obj,objectName,doc,element,binary);
58
59 // Save
60 tinyxml2::XMLError error = doc->SaveFile(filename.c_str());
61 if(error != tinyxml2::XML_SUCCESS)
62 {
63 doc->PrintError();
64 }
65
66 delete doc;
67 }
@ binary
Definition stl.h:70

References binary, error, and serialize_xml().

+ Here is the call graph for this function:

◆ serialize_xml() [3/3]

template<typename T >
IGL_INLINE void igl::xml::serialize_xml ( const T &  obj,
const std::string &  objectName,
tinyxml2::XMLDocument *  doc,
tinyxml2::XMLElement *  element,
bool  binary 
)
76 {
77 static_assert(
79 "'igl::xml::serialize_xml': type is not serializable");
80
81 std::string name(objectName);
82 serialization_xml::encodeXMLElementName(name);
83
84 tinyxml2::XMLElement* child = element->FirstChildElement(name.c_str());
85
86 if(child != NULL)
87 element->DeleteChild(child);
88
89 child = doc->NewElement(name.c_str());
90 element->InsertEndChild(child);
91
92 if(binary)
93 {
94 std::vector<char> buffer;
95 serialize(obj,name,buffer);
96 std::string data =
97 serialization_xml::base64_encode(
98 reinterpret_cast<const unsigned char*>(
99 buffer.data()),buffer.size());
100
101 child->SetAttribute("binary",true);
102
103 serialization_xml::serialize(data,doc,element,name);
104 }
105 else
106 {
107 serialization_xml::serialize(obj,doc,element,name);
108 }
109 }
void serialize(Archive &ar, FacenamesSerializer &t, const std::uint32_t version)
Definition GLGizmoEmboss.cpp:1562
Definition serialize_xml.h:234

References igl::xml::serialization_xml::base64_encode(), binary, igl::xml::serialization_xml::encodeXMLElementName(), igl::serialize(), and igl::xml::serialization_xml::serialize().

+ Here is the call graph for this function:

◆ write_triangle_mesh()

template<typename DerivedV , typename DerivedF >
IGL_INLINE bool igl::xml::write_triangle_mesh ( const std::string  str,
const Eigen::PlainObjectBase< DerivedV > &  V,
const Eigen::PlainObjectBase< DerivedF > &  F,
const bool  ascii = true 
)
19{
20 using namespace std;
21 // dirname, basename, extension and filename
22 string d,b,e,f;
23 pathinfo(str,d,b,e,f);
24 // Convert extension to lower case
25 std::transform(e.begin(), e.end(), e.begin(), ::tolower);
26 if(e == "dae")
27 {
28 return writeDAE(str,V,F);
29 }else
30 {
31 return igl::write_triangle_mesh(str,V,F,ascii);
32 }
33}
IGL_INLINE bool writeDAE(const std::string &filename, const Eigen::PlainObjectBase< DerivedV > &V, const Eigen::PlainObjectBase< DerivedF > &F)
Definition writeDAE.cpp:15
IGL_INLINE void pathinfo(const std::string &path, std::string &dirname, std::string &basename, std::string &extension, std::string &filename)
Definition pathinfo.cpp:16
IGL_INLINE bool write_triangle_mesh(const std::string str, const Eigen::PlainObjectBase< DerivedV > &V, const Eigen::PlainObjectBase< DerivedF > &F, const bool force_ascii=true)
Definition write_triangle_mesh.cpp:20
STL namespace.
@ ascii
Definition stl.h:70

References ascii, igl::pathinfo(), igl::write_triangle_mesh(), and writeDAE().

+ Here is the call graph for this function:

◆ writeDAE()

template<typename DerivedV , typename DerivedF >
IGL_INLINE bool igl::xml::writeDAE ( const std::string &  filename,
const Eigen::PlainObjectBase< DerivedV > &  V,
const Eigen::PlainObjectBase< DerivedF > &  F 
)
19{
20 using namespace std;
21 using namespace Eigen;
22 using namespace tinyxml2;
23
24 XMLDocument* doc = new XMLDocument();
25
26 const auto & ele = [&doc](
27 const std::string tag,
28 // Can't just use `{}` as the default argument because of a clang-bug
29 // http://stackoverflow.com/questions/17264067/
30 const std::map<std::string,std::string> attribs =
31 std::map<std::string,std::string>(),
32 const std::string text="",
33 const std::list<XMLElement *> children =
34 std::list<XMLElement *>()
35 )->XMLElement *
36 {
37 XMLElement * element = doc->NewElement(tag.c_str());
38 for(const auto & key_value : attribs)
39 {
40 element->SetAttribute(key_value.first.c_str(),key_value.second.c_str());
41 }
42 if(!text.empty())
43 {
44 element->InsertEndChild(doc->NewText(text.c_str()));
45 }
46 for(auto & child : children)
47 {
48 element->InsertEndChild(child);
49 }
50 return element;
51 };
52
53 Eigen::IOFormat row_format(Eigen::FullPrecision,0," "," ","","","");
54 doc->InsertEndChild(
55 ele("COLLADA",
56 {
57 {"xmlns","http://www.collada.org/2005/11/COLLADASchema"},
58 {"version","1.4.1"}
59 },
60 "",
61 {
62 ele("asset",{},"",
63 {
64 ele("unit",{{"meter","0.0254000"},{"name","inch"}}),
65 ele("up_axis",{},"Y_UP")
66 }),
67 ele("library_visual_scenes",{},"",
68 {
69 ele("visual_scene",{{"id","ID2"}},"",
70 {
71 ele("node",{{"name","SketchUp"}},"",
72 {
73 ele("node",{{"id","ID3"},{"name","group_0"}},"",
74 {
75 ele("matrix",{},"1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1"),
76 ele("instance_geometry",{{"url","#ID4"}},"",
77 {
78 ele("bind_material",{},"",{ele("technique_common")}),
79 }),
80 }),
81 }),
82 }),
83 }),
84 ele("library_geometries",{},"",
85 {
86 ele("geometry",{{"id","ID4"}},"",
87 {
88 ele("mesh",{},"",
89 {
90 ele("source",{{"id","ID7"}},"",
91 {
92 ele(
93 "float_array",
94 {{"count",STR(V.size())},{"id","ID10"}},
95 STR(V.format(row_format))),
96 ele("technique_common",{},"",
97 {
98 ele(
99 "accessor",
100 {{"count",STR(V.rows())},{"source","#ID8"},{"stride","3"}},
101 "",
102 {
103 ele("param",{{"name","X"},{"type","float"}}),
104 ele("param",{{"name","Y"},{"type","float"}}),
105 ele("param",{{"name","Z"},{"type","float"}}),
106 })
107 })
108 }),
109 ele(
110 "vertices",
111 {{"id","ID9"}},
112 "",
113 {ele("input",{{"semantic","POSITION"},{"source","#ID7"}})}),
114 ele(
115 "triangles",
116 {{"count",STR(F.rows())}},
117 "",
118 {
119 ele("input",{{"semantic","VERTEX"},{"source","#ID9"}}),
120 ele("p",{},STR(F.format(row_format))),
121 })
122 })
123 })
124 }),
125 ele("scene",{},"",{ele("instance_visual_scene",{{"url","#ID2"}})}),
126 }));
127 // tinyxml2 seems **not** to print the <?xml ...?> header by default, but it
128 // also seems that that's OK
129 XMLError error = doc->SaveFile(filename.c_str());
130 bool ret = true;
131 if(error != XML_NO_ERROR)
132 {
133 doc->PrintError();
134 ret = false;
135 }
136 delete doc;
137 return ret;
138}
#define STR(X)
Definition STR.h:17
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rows() const
Definition PlainObjectBase.h:151
Definition LDLT.h:16
@ FullPrecision
Definition IO.h:18
@ F
Definition libslic3r.h:102
Definition ReAntTweakBarXMLSerialization.h:25
Stores a set of parameters controlling the way matrices are printed.
Definition IO.h:51

References error, Eigen::FullPrecision, Eigen::PlainObjectBase< Derived >::rows(), and STR.

Referenced by write_triangle_mesh().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: