44 #include <visp3/core/vpXmlParserRectOriented.h> 46 #ifdef VISP_HAVE_PUGIXML 49 #include <pugixml.hpp> 50 #include <visp3/core/vpIoTools.h> 52 #ifndef DOXYGEN_SHOULD_SKIP_THIS 53 class vpXmlParserRectOriented::Impl
67 Impl() : m_rectangle(), m_center(), m_height(), m_width(), m_theta(), m_nodeMap()
69 m_nodeMap[
"center_i"] = CODE_XML_CENTER_I;
70 m_nodeMap[
"center_j"] = CODE_XML_CENTER_J;
71 m_nodeMap[
"height"] = CODE_XML_HEIGHT;
72 m_nodeMap[
"width"] = CODE_XML_WIDTH;
73 m_nodeMap[
"theta"] = CODE_XML_THETA;
76 void parse(
const std::string &filename)
78 pugi::xml_document doc;
79 if (!doc.load_file(filename.c_str())) {
83 pugi::xml_node root_node = doc.document_element();
88 readMainClass(root_node);
91 void readMainClass(
const pugi::xml_node &node_)
93 for (pugi::xml_node dataNode = node_.first_child(); dataNode; dataNode = dataNode.next_sibling()) {
94 if (dataNode.type() == pugi::node_element) {
95 std::map<std::string, int>::iterator iter_data = m_nodeMap.find(dataNode.name());
96 if (iter_data != m_nodeMap.end()) {
97 switch (iter_data->second) {
98 case CODE_XML_CENTER_I:
99 this->m_center.set_i(dataNode.text().as_double());
101 case CODE_XML_CENTER_J:
102 this->m_center.set_j(dataNode.text().as_double());
104 case CODE_XML_HEIGHT:
105 this->m_height = dataNode.text().as_double();
108 this->m_width = dataNode.text().as_double();
111 this->m_theta = dataNode.text().as_double();
120 m_rectangle =
vpRectOriented(m_center, m_width, m_height, m_theta);
123 void save(
const std::string &filename,
bool append)
125 pugi::xml_document doc;
126 pugi::xml_node root_node;
128 if (!doc.load_file(filename.c_str(), pugi::parse_default | pugi::parse_comments)) {
129 root_node = doc.append_child(pugi::node_declaration);
130 root_node.append_attribute(
"version") =
"1.0";
131 root_node = doc.append_child(
"config");
132 }
else if (!append) {
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;
171 #endif //DOXYGEN_SHOULD_SKIP_THIS 192 m_impl->parse(filename);
207 m_impl->save(filename, append);
212 return m_impl->getRectangle();
217 m_impl->setRectangle(rectangle);
220 #elif !defined(VISP_BUILD_SHARED_LIBS) 223 void dummy_vpXmlParserRectOriented(){};
224 #endif //VISP_HAVE_PUGIXML void setRectangle(const vpRectOriented &rectangle)
error that can be emited by ViSP classes.
void save(const std::string &filename, bool append=false)
vpXmlParserRectOriented()
vpRectOriented getRectangle() const
void parse(const std::string &filename)
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()