Visual Servoing Platform  version 3.2.0 under development (2019-01-22)
vpXmlParserRectOriented.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * XML parser to load and save oriented rectangle in a XML file
33  *
34  * Authors:
35  * Marc Pouliquen
36  *
37  *****************************************************************************/
38 
44 #include <visp3/core/vpXmlParserRectOriented.h>
45 #ifdef VISP_HAVE_XML2
46 
50 vpXmlParserRectOriented::vpXmlParserRectOriented() : m_rectangle(), m_center(), m_height(), m_width(), m_theta()
51 {
52  nodeMap["center_i"] = CODE_XML_CENTER_I;
53  nodeMap["center_j"] = CODE_XML_CENTER_J;
54  nodeMap["height"] = CODE_XML_HEIGHT;
55  nodeMap["width"] = CODE_XML_WIDTH;
56  nodeMap["theta"] = CODE_XML_THETA;
57 }
58 
63 
69 void vpXmlParserRectOriented::readMainClass(xmlDocPtr doc, xmlNodePtr node)
70 {
71  for (xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
72  if (dataNode->type == XML_ELEMENT_NODE) {
73  std::map<std::string, int>::iterator iter_data = this->nodeMap.find((char *)dataNode->name);
74  if (iter_data != nodeMap.end()) {
75  switch (iter_data->second) {
76  case CODE_XML_CENTER_I:
77  this->m_center.set_i(xmlReadDoubleChild(doc, dataNode));
78  break;
79  case CODE_XML_CENTER_J:
80  this->m_center.set_j(xmlReadDoubleChild(doc, dataNode));
81  break;
82  case CODE_XML_HEIGHT:
83  this->m_height = xmlReadDoubleChild(doc, dataNode);
84  break;
85  case CODE_XML_WIDTH:
86  this->m_width = xmlReadDoubleChild(doc, dataNode);
87  break;
88  case CODE_XML_THETA:
89  this->m_theta = xmlReadDoubleChild(doc, dataNode);
90  break;
91  default:
92  vpTRACE("unknown tag in readConfigNode : %d, %s", iter_data->second, (iter_data->first).c_str());
93  break;
94  }
95  }
96  }
97  }
98  m_rectangle = vpRectOriented(m_center, m_width, m_height, m_theta);
99 }
100 
106 {
107  xmlWriteDoubleChild(node, "center_i", this->m_rectangle.getCenter().get_i());
108  xmlWriteDoubleChild(node, "center_j", this->m_rectangle.getCenter().get_j());
109  xmlWriteDoubleChild(node, "height", this->m_rectangle.getHeight());
110  xmlWriteDoubleChild(node, "width", this->m_rectangle.getWidth());
111  xmlWriteDoubleChild(node, "theta", this->m_rectangle.getOrientation());
112 }
113 
114 #endif // VISP_HAVE_XML2
double get_i() const
Definition: vpImagePoint.h:204
double xmlReadDoubleChild(xmlDocPtr doc, xmlNodePtr node)
double getHeight() const
Get the rectangle height.
double getWidth() const
Get the rectangle width.
double get_j() const
Definition: vpImagePoint.h:215
void set_i(const double ii)
Definition: vpImagePoint.h:167
void xmlWriteDoubleChild(xmlNodePtr node, const char *label, const double value)
double getOrientation() const
Get the rectangle orientation (rad).
void readMainClass(xmlDocPtr doc, xmlNodePtr node)
#define vpTRACE
Definition: vpDebug.h:416
void writeMainClass(xmlNodePtr node)
void set_j(const double jj)
Definition: vpImagePoint.h:178
std::map< std::string, int > nodeMap
Definition: vpXmlParser.h:226
Defines an oriented rectangle in the plane.
vpImagePoint getCenter() const
Get the rectangle center point.