39 #include <visp3/core/vpXmlParserRectOriented.h>
43 #if defined(VISP_HAVE_PUGIXML)
44 #include <pugixml.hpp>
46 #include <visp3/core/vpIoTools.h>
49 #ifndef DOXYGEN_SHOULD_SKIP_THIS
50 class vpXmlParserRectOriented::Impl
65 Impl() : m_rectangle(), m_center(), m_height(), m_width(), m_theta(), m_nodeMap()
67 m_nodeMap[
"center_i"] = CODE_XML_CENTER_I;
68 m_nodeMap[
"center_j"] = CODE_XML_CENTER_J;
69 m_nodeMap[
"height"] = CODE_XML_HEIGHT;
70 m_nodeMap[
"width"] = CODE_XML_WIDTH;
71 m_nodeMap[
"theta"] = CODE_XML_THETA;
74 void parse(
const std::string &filename)
76 pugi::xml_document doc;
77 if (!doc.load_file(filename.c_str())) {
81 pugi::xml_node root_node = doc.document_element();
86 readMainClass(root_node);
89 void readMainClass(
const pugi::xml_node &node_)
91 for (pugi::xml_node dataNode = node_.first_child(); dataNode; dataNode = dataNode.next_sibling()) {
92 if (dataNode.type() == pugi::node_element) {
93 std::map<std::string, int>::iterator iter_data = m_nodeMap.find(dataNode.name());
94 if (iter_data != m_nodeMap.end()) {
95 switch (iter_data->second) {
96 case CODE_XML_CENTER_I:
97 this->m_center.set_i(dataNode.text().as_double());
99 case CODE_XML_CENTER_J:
100 this->m_center.set_j(dataNode.text().as_double());
102 case CODE_XML_HEIGHT:
103 this->m_height = dataNode.text().as_double();
106 this->m_width = dataNode.text().as_double();
109 this->m_theta = dataNode.text().as_double();
118 m_rectangle =
vpRectOriented(m_center, m_width, m_height, m_theta);
121 void save(
const std::string &filename,
bool append)
123 pugi::xml_document doc;
124 pugi::xml_node root_node;
126 if (!doc.load_file(filename.c_str(), pugi::parse_default | pugi::parse_comments)) {
127 root_node = doc.append_child(pugi::node_declaration);
128 root_node.append_attribute(
"version") =
"1.0";
129 root_node = doc.append_child(
"config");
136 root_node = doc.append_child(pugi::node_declaration);
137 root_node.append_attribute(
"version") =
"1.0";
138 root_node = doc.append_child(
"config");
141 root_node = doc.document_element();
146 writeMainClass(root_node);
148 doc.save_file(filename.c_str(), PUGIXML_TEXT(
" "));
151 void writeMainClass(pugi::xml_node &node)
153 node.append_child(
"center_i").append_child(pugi::node_pcdata).text() = m_rectangle.getCenter().get_i();
154 node.append_child(
"center_j").append_child(pugi::node_pcdata).text() = m_rectangle.getCenter().get_j();
155 node.append_child(
"height").append_child(pugi::node_pcdata).text() = m_rectangle.getHeight();
156 node.append_child(
"width").append_child(pugi::node_pcdata).text() = m_rectangle.getWidth();
157 node.append_child(
"theta").append_child(pugi::node_pcdata).text() = m_rectangle.getOrientation();
169 std::map<std::string, int> m_nodeMap;
203 #elif !defined(VISP_BUILD_SHARED_LIBS)
205 void dummy_vpXmlParserRectOriented() { };
error that can be emitted by ViSP classes.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Defines an oriented rectangle in the plane.
vpXmlParserRectOriented()
vpRectOriented getRectangle() const
void setRectangle(const vpRectOriented &rectangle)
void save(const std::string &filename, bool append=false)
void parse(const std::string &filename)
~vpXmlParserRectOriented()