44 #include <visp3/core/vpXmlParserRectOriented.h>
48 #if defined(VISP_HAVE_PUGIXML)
49 #include <pugixml.hpp>
51 #include <visp3/core/vpIoTools.h>
53 #ifndef DOXYGEN_SHOULD_SKIP_THIS
54 class vpXmlParserRectOriented::Impl
69 Impl() : m_rectangle(), m_center(), m_height(), m_width(), m_theta(), m_nodeMap()
71 m_nodeMap[
"center_i"] = CODE_XML_CENTER_I;
72 m_nodeMap[
"center_j"] = CODE_XML_CENTER_J;
73 m_nodeMap[
"height"] = CODE_XML_HEIGHT;
74 m_nodeMap[
"width"] = CODE_XML_WIDTH;
75 m_nodeMap[
"theta"] = CODE_XML_THETA;
78 void parse(
const std::string &filename)
80 pugi::xml_document doc;
81 if (!doc.load_file(filename.c_str())) {
85 pugi::xml_node root_node = doc.document_element();
90 readMainClass(root_node);
93 void readMainClass(
const pugi::xml_node &node_)
95 for (pugi::xml_node dataNode = node_.first_child(); dataNode; dataNode = dataNode.next_sibling()) {
96 if (dataNode.type() == pugi::node_element) {
97 std::map<std::string, int>::iterator iter_data = m_nodeMap.find(dataNode.name());
98 if (iter_data != m_nodeMap.end()) {
99 switch (iter_data->second) {
100 case CODE_XML_CENTER_I:
101 this->m_center.set_i(dataNode.text().as_double());
103 case CODE_XML_CENTER_J:
104 this->m_center.set_j(dataNode.text().as_double());
106 case CODE_XML_HEIGHT:
107 this->m_height = dataNode.text().as_double();
110 this->m_width = dataNode.text().as_double();
113 this->m_theta = dataNode.text().as_double();
122 m_rectangle =
vpRectOriented(m_center, m_width, m_height, m_theta);
125 void save(
const std::string &filename,
bool append)
127 pugi::xml_document doc;
128 pugi::xml_node root_node;
130 if (!doc.load_file(filename.c_str(), pugi::parse_default | pugi::parse_comments)) {
131 root_node = doc.append_child(pugi::node_declaration);
132 root_node.append_attribute(
"version") =
"1.0";
133 root_node = doc.append_child(
"config");
140 root_node = doc.append_child(pugi::node_declaration);
141 root_node.append_attribute(
"version") =
"1.0";
142 root_node = doc.append_child(
"config");
145 root_node = doc.document_element();
150 writeMainClass(root_node);
152 doc.save_file(filename.c_str(), PUGIXML_TEXT(
" "));
155 void writeMainClass(pugi::xml_node &node)
157 node.append_child(
"center_i").append_child(pugi::node_pcdata).text() = m_rectangle.getCenter().get_i();
158 node.append_child(
"center_j").append_child(pugi::node_pcdata).text() = m_rectangle.getCenter().get_j();
159 node.append_child(
"height").append_child(pugi::node_pcdata).text() = m_rectangle.getHeight();
160 node.append_child(
"width").append_child(pugi::node_pcdata).text() = m_rectangle.getWidth();
161 node.append_child(
"theta").append_child(pugi::node_pcdata).text() = m_rectangle.getOrientation();
173 std::map<std::string, int> m_nodeMap;
207 #elif !defined(VISP_BUILD_SHARED_LIBS)
209 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.
vpRectOriented getRectangle() const
vpXmlParserRectOriented()
void setRectangle(const vpRectOriented &rectangle)
void save(const std::string &filename, bool append=false)
void parse(const std::string &filename)
~vpXmlParserRectOriented()