Visual Servoing Platform  version 3.1.0
vpXmlParserCamera.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 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 camera intrinsic parameters.
33  *
34  * Authors:
35  * Anthony Saunier
36  *
37  *****************************************************************************/
38 
46 #ifndef vpXMLPARSERCAMERA_H
47 #define vpXMLPARSERCAMERA_H
48 
49 #include <visp3/core/vpConfig.h>
50 
51 #ifdef VISP_HAVE_XML2
52 
53 #include <libxml/xmlmemory.h> /* Functions of libxml. */
54 #include <string>
55 #include <visp3/core/vpCameraParameters.h>
56 #include <visp3/core/vpXmlParser.h>
57 
188 class VISP_EXPORT vpXmlParserCamera : public vpXmlParser
189 {
190 
191 public:
192  /* --- XML Code------------------------------------------------------------
193  */
194  typedef enum {
195  CODE_XML_BAD = -1,
213  CODE_XML_ADDITIONAL_INFO
214  } vpXmlCodeType;
215 
216  typedef enum { SEQUENCE_OK, SEQUENCE_ERROR } vpXmlCodeSequenceType;
217 
218 private:
219  vpCameraParameters camera;
220  std::string camera_name;
221  unsigned int image_width;
222  unsigned int image_height;
223  unsigned int subsampling_width;
224  unsigned int subsampling_height;
225  unsigned int full_width;
226  unsigned int full_height;
227 
230  static const int allowedPixelDiffOnImageSize = 15;
231 
232 public:
236  virtual ~vpXmlParserCamera() {}
237 
238  // get/set functions
239  std::string getCameraName() { return this->camera_name; }
240  vpCameraParameters getCameraParameters() { return this->camera; }
241  unsigned int getHeight() { return this->image_height; }
242  unsigned int getSubsampling_width() { return this->subsampling_width; }
243  unsigned int getSubsampling_height() { return this->subsampling_height; }
244  unsigned int getWidth() { return this->image_width; }
245 
246  vpXmlParserCamera &operator=(const vpXmlParserCamera &twinparser);
247 
248  int parse(vpCameraParameters &cam, const std::string &filename, const std::string &camera_name,
249  const vpCameraParameters::vpCameraParametersProjType &projModel, const unsigned int image_width = 0,
250  const unsigned int image_height = 0);
251 
252  int save(const vpCameraParameters &cam, const std::string &filename, const std::string &camera_name,
253  const unsigned int image_width = 0, const unsigned int image_height = 0,
254  const std::string &additionalInfo = "");
255 
256  void setCameraName(const std::string &name) { this->camera_name = name; }
257  void setHeight(const unsigned int height) { this->image_height = height; }
258  void setSubsampling_width(const unsigned int subsampling) { this->subsampling_width = subsampling; }
259  void setSubsampling_height(const unsigned int subsampling) { this->subsampling_height = subsampling; }
260  void setWidth(const unsigned int width) { this->image_width = width; }
261 
262 private:
263  int read(xmlDocPtr doc, xmlNodePtr node, const std::string &camera_name,
264  const vpCameraParameters::vpCameraParametersProjType &projModel, const unsigned int image_width = 0,
265  const unsigned int image_height = 0, const unsigned int subsampling_width = 0,
266  const unsigned int subsampling_height = 0);
267 
268  int count(xmlDocPtr doc, xmlNodePtr node, const std::string &camera_name,
269  const vpCameraParameters::vpCameraParametersProjType &projModel, const unsigned int image_width = 0,
270  const unsigned int image_height = 0, const unsigned int subsampling_width = 0,
271  const unsigned int subsampling_height = 0);
272 
273  int read_camera(xmlDocPtr doc, xmlNodePtr node, const std::string &camera_name,
274  const vpCameraParameters::vpCameraParametersProjType &projModel, const unsigned int image_width = 0,
275  const unsigned int image_height = 0, const unsigned int subsampling_width = 0,
276  const unsigned int subsampling_height = 0);
277 
278  xmlNodePtr find_camera(xmlDocPtr doc, xmlNodePtr node, const std::string &camera_name,
279  const unsigned int image_width = 0, const unsigned int image_height = 0,
280  const unsigned int subsampling_width = 0, const unsigned int subsampling_height = 0);
281 
282  xmlNodePtr find_additional_info(xmlNodePtr node);
283 
284  vpXmlCodeSequenceType read_camera_model(xmlDocPtr doc, xmlNodePtr node, vpCameraParameters &camera);
285 
286  int read_camera_header(xmlDocPtr doc, xmlNodePtr node, const std::string &camera_name,
287  const unsigned int image_width = 0, const unsigned int image_height = 0,
288  const unsigned int subsampling_width = 0, const unsigned int subsampling_height = 0);
289 
290  static vpXmlCodeSequenceType str2xmlcode(char *str, vpXmlCodeType &res);
291  void myXmlReadIntChild(xmlDocPtr doc, xmlNodePtr node, int &res, vpXmlCodeSequenceType &code_error);
292 
293  void myXmlReadDoubleChild(xmlDocPtr doc, xmlNodePtr node, double &res, vpXmlCodeSequenceType &code_error);
294 
295  void myXmlReadCharChild(xmlDocPtr doc, xmlNodePtr node, char **res);
296  int write(xmlNodePtr node, const std::string &camera_name, const unsigned int image_width = 0,
297  const unsigned int image_height = 0, const unsigned int subsampling_width = 0,
298  const unsigned int subsampling_height = 0);
299  int write_camera(xmlNodePtr node_camera);
300 
301 private:
307  virtual void readMainClass(xmlDocPtr, xmlNodePtr){};
308 
314  virtual void writeMainClass(xmlNodePtr){};
315 };
316 #endif // VISP_HAVE_XML2
317 #endif
void setSubsampling_width(const unsigned int subsampling)
unsigned int getWidth()
void setCameraName(const std::string &name)
unsigned int getHeight()
virtual void writeMainClass(xmlNodePtr node)=0
XML parser to load and save intrinsic camera parameters.
void save(const std::string &filename, const bool append=false)
This class intends to simplify the creation of xml parser based on the libxml2 third party library...
Definition: vpXmlParser.h:177
Generic class defining intrinsic camera parameters.
virtual void readMainClass(xmlDocPtr doc, xmlNodePtr node)=0
void setWidth(const unsigned int width)
void setSubsampling_height(const unsigned int subsampling)
void setHeight(const unsigned int height)
std::string getCameraName()
vpCameraParameters getCameraParameters()
virtual ~vpXmlParserCamera()
Default destructor.
unsigned int getSubsampling_width()
void parse(const std::string &filename)
unsigned int getSubsampling_height()