ViSP  2.9.0
vpXmlParserCamera.h
1 /****************************************************************************
2  *
3  * $Id: vpXmlParserCamera.h 4649 2014-02-07 14:57:11Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * XML parser to load and save camera intrinsic parameters.
36  *
37  * Authors:
38  * Anthony Saunier
39  *
40  *****************************************************************************/
41 
42 
43 
52 #ifndef vpXMLPARSERCAMERA_H
53 #define vpXMLPARSERCAMERA_H
54 
55 #include <visp/vpConfig.h>
56 
57 #ifdef VISP_HAVE_XML2
58 
59 #include <string>
60 #include <visp/vpCameraParameters.h>
61 #include <visp/vpXmlParser.h>
62 #include <libxml/xmlmemory.h> /* Functions of libxml. */
63 
189 class VISP_EXPORT vpXmlParserCamera: public vpXmlParser
190 {
191 
192 public:
193 
194  /* --- XML Code------------------------------------------------------------ */
195  typedef enum
196  {
197  CODE_XML_BAD = -1,
214  CODE_XML_KDU
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 
241  vpXmlParserCamera& operator =(const vpXmlParserCamera& twinparser);
243 
244  int parse(vpCameraParameters &cam, const char * filename,
245  const std::string &camera_name,
247  const unsigned int image_width = 0, const unsigned int image_height = 0);
248  int save(const vpCameraParameters &cam, const char * filename,
249  const std::string &camera_name,
250  const unsigned int image_width = 0, const unsigned int image_height = 0);
251 
252  // get/set functions
253  std::string getCameraName(){return this->camera_name;}
254  unsigned int getWidth(){ return this->image_width; }
255  unsigned int getHeight(){ return this->image_height; }
256  unsigned int getSubsampling_width(){return this->subsampling_width;}
257  unsigned int getSubsampling_height(){return this->subsampling_height;}
258  vpCameraParameters getCameraParameters(){return this->camera;}
259 
260  void setCameraName(const std::string& name){
261  this->camera_name = name;
262  }
263  void setWidth(const unsigned int width){ this->image_width = width ; }
264  void setHeight(const unsigned int height){ this->image_height = height ; }
265  void setSubsampling_width(const unsigned int subsampling){
266  this->subsampling_width = subsampling ;
267  }
268  void setSubsampling_height(const unsigned int subsampling){
269  this->subsampling_height = subsampling ;
270  }
271 
272 private:
273  int read (xmlDocPtr doc, xmlNodePtr node,
274  const std::string& camera_name,
276  const unsigned int image_width = 0,
277  const unsigned int image_height = 0,
278  const unsigned int subsampling_width = 0,
279  const unsigned int subsampling_height = 0);
280 
281  int count (xmlDocPtr doc, xmlNodePtr node,
282  const std::string& camera_name,
284  const unsigned int image_width = 0,
285  const unsigned int image_height = 0,
286  const unsigned int subsampling_width = 0,
287  const unsigned int subsampling_height = 0);
288 
289  int read_camera (xmlDocPtr doc, xmlNodePtr node,
290  const std::string& camera_name,
292  const unsigned int image_width = 0,
293  const unsigned int image_height = 0,
294  const unsigned int subsampling_width = 0,
295  const unsigned int subsampling_height = 0);
296 
297  xmlNodePtr find_camera (xmlDocPtr doc, xmlNodePtr node,
298  const std::string& camera_name,
299  const unsigned int image_width = 0,
300  const unsigned int image_height = 0,
301  const unsigned int subsampling_width = 0,
302  const unsigned int subsampling_height = 0);
303 
304  vpXmlCodeSequenceType read_camera_model (xmlDocPtr doc, xmlNodePtr node,
305  vpCameraParameters &camera);
306 
307  int read_camera_header (xmlDocPtr doc, xmlNodePtr node,
308  const std::string& camera_name,
309  const unsigned int image_width = 0,
310  const unsigned int image_height = 0,
311  const unsigned int subsampling_width = 0,
312  const unsigned int subsampling_height = 0);
313 
314  static vpXmlCodeSequenceType str2xmlcode (char * str, vpXmlCodeType & res);
315  void myXmlReadIntChild (xmlDocPtr doc,
316  xmlNodePtr node,
317  int &res,
318  vpXmlCodeSequenceType &code_error);
319 
320  void myXmlReadDoubleChild (xmlDocPtr doc,
321  xmlNodePtr node,
322  double &res,
323  vpXmlCodeSequenceType &code_error);
324 
325  void myXmlReadCharChild (xmlDocPtr doc,
326  xmlNodePtr node,
327  char **res);
328  int write (xmlNodePtr node, const std::string& camera_name,
329  const unsigned int image_width = 0,
330  const unsigned int image_height = 0,
331  const unsigned int subsampling_width = 0,
332  const unsigned int subsampling_height = 0);
333  int write_camera(xmlNodePtr node_camera);
334 
335 private:
336 
342  virtual void readMainClass(xmlDocPtr , xmlNodePtr ){};
343 
349  virtual void writeMainClass(xmlNodePtr ){};
350 
351 };
352 #endif //VISP_HAVE_XML2
353 #endif
354 /*
355  * Local variables:
356  * c-basic-offset: 2
357  * End:
358  */
359 
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:178
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()
unsigned int getSubsampling_width()
void parse(const std::string &filename)
unsigned int getSubsampling_height()