Visual Servoing Platform  version 3.0.0
vpXmlParserCamera.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 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 
185 class VISP_EXPORT vpXmlParserCamera: public vpXmlParser
186 {
187 
188 public:
189 
190  /* --- XML Code------------------------------------------------------------ */
191  typedef enum
192  {
193  CODE_XML_BAD = -1,
210  CODE_XML_KDU
211  } vpXmlCodeType;
212 
213  typedef enum
214  {
216  SEQUENCE_ERROR
217  } vpXmlCodeSequenceType;
218 
219 private :
220 
221  vpCameraParameters camera;
222  std::string camera_name;
223  unsigned int image_width;
224  unsigned int image_height;
225  unsigned int subsampling_width;
226  unsigned int subsampling_height;
227  unsigned int full_width;
228  unsigned int full_height;
229 
231  static const int allowedPixelDiffOnImageSize = 15;
232 
233 public:
234 
237  vpXmlParserCamera& operator =(const vpXmlParserCamera& twinparser);
239 
240  int parse(vpCameraParameters &cam, const std::string &filename,
241  const std::string &camera_name,
243  const unsigned int image_width = 0, const unsigned int image_height = 0);
244  int save(const vpCameraParameters &cam, const std::string &filename,
245  const std::string &camera_name,
246  const unsigned int image_width = 0, const unsigned int image_height = 0);
247 
248  // get/set functions
249  std::string getCameraName(){return this->camera_name;}
250  unsigned int getWidth(){ return this->image_width; }
251  unsigned int getHeight(){ return this->image_height; }
252  unsigned int getSubsampling_width(){return this->subsampling_width;}
253  unsigned int getSubsampling_height(){return this->subsampling_height;}
254  vpCameraParameters getCameraParameters(){return this->camera;}
255 
256  void setCameraName(const std::string& name){
257  this->camera_name = name;
258  }
259  void setWidth(const unsigned int width){ this->image_width = width ; }
260  void setHeight(const unsigned int height){ this->image_height = height ; }
261  void setSubsampling_width(const unsigned int subsampling){
262  this->subsampling_width = subsampling ;
263  }
264  void setSubsampling_height(const unsigned int subsampling){
265  this->subsampling_height = subsampling ;
266  }
267 
268 private:
269  int read (xmlDocPtr doc, xmlNodePtr node,
270  const std::string& camera_name,
272  const unsigned int image_width = 0,
273  const unsigned int image_height = 0,
274  const unsigned int subsampling_width = 0,
275  const unsigned int subsampling_height = 0);
276 
277  int count (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 read_camera (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  xmlNodePtr find_camera (xmlDocPtr doc, xmlNodePtr node,
294  const std::string& camera_name,
295  const unsigned int image_width = 0,
296  const unsigned int image_height = 0,
297  const unsigned int subsampling_width = 0,
298  const unsigned int subsampling_height = 0);
299 
300  vpXmlCodeSequenceType read_camera_model (xmlDocPtr doc, xmlNodePtr node,
301  vpCameraParameters &camera);
302 
303  int read_camera_header (xmlDocPtr doc, xmlNodePtr node,
304  const std::string& camera_name,
305  const unsigned int image_width = 0,
306  const unsigned int image_height = 0,
307  const unsigned int subsampling_width = 0,
308  const unsigned int subsampling_height = 0);
309 
310  static vpXmlCodeSequenceType str2xmlcode (char * str, vpXmlCodeType & res);
311  void myXmlReadIntChild (xmlDocPtr doc,
312  xmlNodePtr node,
313  int &res,
314  vpXmlCodeSequenceType &code_error);
315 
316  void myXmlReadDoubleChild (xmlDocPtr doc,
317  xmlNodePtr node,
318  double &res,
319  vpXmlCodeSequenceType &code_error);
320 
321  void myXmlReadCharChild (xmlDocPtr doc,
322  xmlNodePtr node,
323  char **res);
324  int write (xmlNodePtr node, const std::string& camera_name,
325  const unsigned int image_width = 0,
326  const unsigned int image_height = 0,
327  const unsigned int subsampling_width = 0,
328  const unsigned int subsampling_height = 0);
329  int write_camera(xmlNodePtr node_camera);
330 
331 private:
332 
338  virtual void readMainClass(xmlDocPtr , xmlNodePtr ){};
339 
345  virtual void writeMainClass(xmlNodePtr ){};
346 
347 };
348 #endif //VISP_HAVE_XML2
349 #endif
350 /*
351  * Local variables:
352  * c-basic-offset: 2
353  * End:
354  */
355 
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:174
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()