Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * XML parser to load and save camera intrinsic parameters.
32  *
33  * Authors:
34  * Anthony Saunier
35  *
36  *****************************************************************************/
37 
38 
39 
48 #ifndef vpXMLPARSERCAMERA_H
49 #define vpXMLPARSERCAMERA_H
50 
51 #include <visp3/core/vpConfig.h>
52 
53 #ifdef VISP_HAVE_XML2
54 
55 #include <string>
56 #include <visp3/core/vpCameraParameters.h>
57 #include <visp3/core/vpXmlParser.h>
58 #include <libxml/xmlmemory.h> /* Functions of libxml. */
59 
188 class VISP_EXPORT vpXmlParserCamera: public vpXmlParser
189 {
190 
191 public:
192 
193  /* --- XML Code------------------------------------------------------------ */
194  typedef enum
195  {
196  CODE_XML_BAD = -1,
214  CODE_XML_ADDITIONAL_INFO
215  } vpXmlCodeType;
216 
217  typedef enum
218  {
220  SEQUENCE_ERROR
221  } vpXmlCodeSequenceType;
222 
223 private :
224 
225  vpCameraParameters camera;
226  std::string camera_name;
227  unsigned int image_width;
228  unsigned int image_height;
229  unsigned int subsampling_width;
230  unsigned int subsampling_height;
231  unsigned int full_width;
232  unsigned int full_height;
233 
235  static const int allowedPixelDiffOnImageSize = 15;
236 
237 public:
238 
242  virtual ~vpXmlParserCamera(){}
243 
244  // get/set functions
245  std::string getCameraName(){return this->camera_name;}
246  vpCameraParameters getCameraParameters(){return this->camera;}
247  unsigned int getHeight(){ return this->image_height; }
248  unsigned int getSubsampling_width(){return this->subsampling_width;}
249  unsigned int getSubsampling_height(){return this->subsampling_height;}
250  unsigned int getWidth(){ return this->image_width; }
251 
252  vpXmlParserCamera& operator =(const vpXmlParserCamera& twinparser);
253 
254  int parse(vpCameraParameters &cam, const std::string &filename,
255  const std::string &camera_name,
257  const unsigned int image_width = 0, const unsigned int image_height = 0);
258 
259  int save(const vpCameraParameters &cam, const std::string &filename,
260  const std::string &camera_name,
261  const unsigned int image_width = 0, const unsigned int image_height = 0,
262  const std::string &additionalInfo="");
263 
264  void setCameraName(const std::string& name){
265  this->camera_name = name;
266  }
267  void setHeight(const unsigned int height){ this->image_height = height ; }
268  void setSubsampling_width(const unsigned int subsampling){
269  this->subsampling_width = subsampling ;
270  }
271  void setSubsampling_height(const unsigned int subsampling){
272  this->subsampling_height = subsampling ;
273  }
274  void setWidth(const unsigned int width){ this->image_width = width ; }
275 
276 private:
277  int read (xmlDocPtr doc, xmlNodePtr node,
278  const std::string& camera_name,
280  const unsigned int image_width = 0,
281  const unsigned int image_height = 0,
282  const unsigned int subsampling_width = 0,
283  const unsigned int subsampling_height = 0);
284 
285  int count (xmlDocPtr doc, xmlNodePtr node,
286  const std::string& camera_name,
288  const unsigned int image_width = 0,
289  const unsigned int image_height = 0,
290  const unsigned int subsampling_width = 0,
291  const unsigned int subsampling_height = 0);
292 
293  int read_camera (xmlDocPtr doc, xmlNodePtr node,
294  const std::string& camera_name,
296  const unsigned int image_width = 0,
297  const unsigned int image_height = 0,
298  const unsigned int subsampling_width = 0,
299  const unsigned int subsampling_height = 0);
300 
301  xmlNodePtr find_camera (xmlDocPtr doc, xmlNodePtr node,
302  const std::string& camera_name,
303  const unsigned int image_width = 0,
304  const unsigned int image_height = 0,
305  const unsigned int subsampling_width = 0,
306  const unsigned int subsampling_height = 0);
307 
308  xmlNodePtr find_additional_info (xmlNodePtr node);
309 
310  vpXmlCodeSequenceType read_camera_model (xmlDocPtr doc, xmlNodePtr node,
311  vpCameraParameters &camera);
312 
313  int read_camera_header (xmlDocPtr doc, xmlNodePtr node,
314  const std::string& camera_name,
315  const unsigned int image_width = 0,
316  const unsigned int image_height = 0,
317  const unsigned int subsampling_width = 0,
318  const unsigned int subsampling_height = 0);
319 
320  static vpXmlCodeSequenceType str2xmlcode (char * str, vpXmlCodeType & res);
321  void myXmlReadIntChild (xmlDocPtr doc,
322  xmlNodePtr node,
323  int &res,
324  vpXmlCodeSequenceType &code_error);
325 
326  void myXmlReadDoubleChild (xmlDocPtr doc,
327  xmlNodePtr node,
328  double &res,
329  vpXmlCodeSequenceType &code_error);
330 
331  void myXmlReadCharChild (xmlDocPtr doc,
332  xmlNodePtr node,
333  char **res);
334  int write (xmlNodePtr node, const std::string& camera_name,
335  const unsigned int image_width = 0,
336  const unsigned int image_height = 0,
337  const unsigned int subsampling_width = 0,
338  const unsigned int subsampling_height = 0);
339  int write_camera(xmlNodePtr node_camera);
340 
341 private:
342 
348  virtual void readMainClass(xmlDocPtr , xmlNodePtr ){};
349 
355  virtual void writeMainClass(xmlNodePtr ){};
356 
357 };
358 #endif //VISP_HAVE_XML2
359 #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:175
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()