ViSP  2.10.0
vpMbXmlParser.cpp
1 /****************************************************************************
2  *
3  * $Id: vpMbXmlParser.cpp 4577 2014-01-10 16:19:41Z 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  * Load XML Parameter for Model Based Tracker.
36  *
37  * Authors:
38  * Aurelien Yol
39  *
40  *****************************************************************************/
41 #include <visp/vpConfig.h>
42 
43 
44 #ifdef VISP_HAVE_XML2
45 
46 #include <iostream>
47 #include <map>
48 
49 #include <libxml/xmlmemory.h> /* Fonctions de la lib XML. */
50 
51 #include <visp/vpMbXmlParser.h>
52 
53 
59  : cam(), angleAppear(70), angleDisappear(80),
60  hasNearClipping(false), nearClipping(false),
61  hasFarClipping(false), farClipping(false), fovClipping(false)
62 
63 {
64  init();
65 }
66 
71 {
72 }
73 
77 void
79 {
80  setMainTag("conf");
81 
82  nodeMap["conf"] = conf;
83  nodeMap["face"] = face;
84  nodeMap["angle_appear"] = angle_appear;
85  nodeMap["angle_disappear"] = angle_disappear;
86  nodeMap["near_clipping"] = near_clipping;
87  nodeMap["far_clipping"] = far_clipping;
88  nodeMap["fov_clipping"] = fov_clipping;
89  nodeMap["camera"] = camera;
90  nodeMap["height"] = height;
91  nodeMap["width"] = width;
92  nodeMap["u0"] = u0;
93  nodeMap["v0"] = v0;
94  nodeMap["px"] = px;
95  nodeMap["py"] = py;
96 }
97 
104 void
105 vpMbXmlParser::parse(const char * filename)
106 {
107  std::string file = filename;
108  vpXmlParser::parse(file);
109 }
110 
116 void
117 vpMbXmlParser::writeMainClass(xmlNodePtr /*node*/)
118 {
119  throw vpException(vpException::notImplementedError, "Not yet implemented." );
120 }
121 
129 void
130 vpMbXmlParser::readMainClass(xmlDocPtr doc, xmlNodePtr node)
131 {
132  bool camera_node = false;
133  bool face_node = false;
134 
135  for(xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
136  if(dataNode->type == XML_ELEMENT_NODE){
137  std::map<std::string, int>::iterator iter_data= this->nodeMap.find((char*)dataNode->name);
138  if(iter_data != nodeMap.end()){
139  switch (iter_data->second){
140  case camera:{
141  this->read_camera (doc, dataNode);
142  camera_node = true;
143  }break;
144  case face:{
145  this->read_face(doc, dataNode);
146  face_node = true;
147  }break;
148  default:{
149 // vpTRACE("unknown tag in read_sample : %d, %s", iter_data->second, (iter_data->first).c_str());
150  }break;
151  }
152  }
153  }
154  }
155 
156  if(!camera_node) {
157  std::cout << "camera : u0 : "<< this->cam.get_u0() << " (default)" <<std::endl;
158  std::cout << "camera : v0 : "<< this->cam.get_v0() << " (default)" <<std::endl;
159  std::cout << "camera : px : "<< this->cam.get_px() << " (default)" <<std::endl;
160  std::cout << "camera : py : "<< this->cam.get_py() << " (default)" <<std::endl;
161  }
162 
163  if(!face_node) {
164  std::cout << "face : Angle Appear : "<< angleAppear <<" (default)" <<std::endl;
165  std::cout << "face : Angle Disappear : "<< angleDisappear <<" (default)" <<std::endl;
166  }
167 }
168 
177 void
178 vpMbXmlParser::read_camera (xmlDocPtr doc, xmlNodePtr node)
179 {
180  bool u0_node = false;
181  bool v0_node = false;
182  bool px_node = false;
183  bool py_node = false;
184 
185  // current data values.
186  double d_u0 = this->cam.get_u0();
187  double d_v0 = this->cam.get_v0();
188  double d_px = this->cam.get_px();
189  double d_py = this->cam.get_py();
190 
191  for(xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
192  if(dataNode->type == XML_ELEMENT_NODE){
193  std::map<std::string, int>::iterator iter_data= this->nodeMap.find((char*)dataNode->name);
194  if(iter_data != nodeMap.end()){
195  switch (iter_data->second){
196  case u0:{
197  d_u0 = xmlReadDoubleChild(doc, dataNode);
198  u0_node = true;
199  }break;
200  case v0:{
201  d_v0 = xmlReadDoubleChild(doc, dataNode);
202  v0_node = true;
203  }break;
204  case px:{
205  d_px = xmlReadDoubleChild(doc, dataNode);
206  px_node = true;
207  }break;
208  case py:{
209  d_py = xmlReadDoubleChild(doc, dataNode);
210  py_node = true;
211  }break;
212  default:{
213 // vpTRACE("unknown tag in read_camera : %d, %s", iter_data->second, (iter_data->first).c_str());
214  }break;
215  }
216  }
217  }
218  }
219 
220  this->cam.initPersProjWithoutDistortion(d_px, d_py, d_u0, d_v0) ;
221 
222  if(!u0_node)
223  std::cout << "camera : u0 : "<< this->cam.get_u0() << " (default)" <<std::endl;
224  else
225  std::cout << "camera : u0 : "<< this->cam.get_u0() <<std::endl;
226 
227  if(!v0_node)
228  std::cout << "camera : v0 : "<< this->cam.get_v0() << " (default)" <<std::endl;
229  else
230  std::cout << "camera : v0 : "<< this->cam.get_v0() <<std::endl;
231 
232  if(!px_node)
233  std::cout << "camera : px : "<< this->cam.get_px() << " (default)" <<std::endl;
234  else
235  std::cout << "camera : px : "<< this->cam.get_px() <<std::endl;
236 
237  if(!py_node)
238  std::cout << "camera : py : "<< this->cam.get_py() << " (default)" <<std::endl;
239  else
240  std::cout << "camera : py : "<< this->cam.get_py() <<std::endl;
241 }
242 
251 void
252 vpMbXmlParser::read_face(xmlDocPtr doc, xmlNodePtr node)
253 {
254  bool angle_appear_node = false;
255  bool angle_disappear_node = false;
256  bool near_clipping_node = false;
257  bool far_clipping_node = false;
258  bool fov_clipping_node = false;
259 
260  for(xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
261  if(dataNode->type == XML_ELEMENT_NODE){
262  std::map<std::string, int>::iterator iter_data= this->nodeMap.find((char*)dataNode->name);
263  if(iter_data != nodeMap.end()){
264  switch (iter_data->second){
265  case angle_appear:{
266  angleAppear = xmlReadDoubleChild(doc, dataNode);
267  angle_appear_node = true;
268  }break;
269  case angle_disappear:{
270  angleDisappear = xmlReadDoubleChild(doc, dataNode);
271  angle_disappear_node = true;
272  }break;
273  case near_clipping:{
274  nearClipping = xmlReadDoubleChild(doc, dataNode);
275  near_clipping_node = true;
276  hasNearClipping = true;
277  }break;
278  case far_clipping:{
279  farClipping = xmlReadDoubleChild(doc, dataNode);
280  far_clipping_node = true;
281  hasFarClipping = true;
282  }break;
283  case fov_clipping:{
284  if (xmlReadIntChild(doc, dataNode))
285  fovClipping = true;
286  else
287  fovClipping = false;
288  fov_clipping_node = true;
289  }break;
290  default:{
291 // vpTRACE("unknown tag in read_camera : %d, %s", iter_data->second, (iter_data->first).c_str());
292  }break;
293  }
294  }
295  }
296  }
297 
298  if(!angle_appear_node)
299  std::cout << "face : Angle Appear : "<< angleAppear << " (default)" <<std::endl;
300  else
301  std::cout << "face : Angle Appear : "<< angleAppear <<std::endl;
302 
303  if(!angle_disappear_node)
304  std::cout << "face : Angle Disappear : "<< angleDisappear << " (default)" <<std::endl;
305  else
306  std::cout << "face : Angle Disappear : "<< angleDisappear <<std::endl;
307 
308  if(near_clipping_node)
309  std::cout << "face : Near Clipping : "<< nearClipping <<std::endl;
310 
311  if(far_clipping_node)
312  std::cout << "face : Far Clipping : "<< farClipping <<std::endl;
313 
314  if(fov_clipping_node) {
315  if(fovClipping)
316  std::cout << "face : Fov Clipping : True" <<std::endl;
317  else
318  std::cout << "face : Fov Clipping : False" <<std::endl;
319  }
320 }
321 
322 #endif
323 
vpCameraParameters cam
Camera parameters.
Definition: vpMbXmlParser.h:71
double get_u0() const
void setMainTag(const std::string &tag)
Definition: vpXmlParser.h:280
double nearClipping
Near clipping distance.
Definition: vpMbXmlParser.h:79
double angleAppear
Angle to determine if a face appeared.
Definition: vpMbXmlParser.h:73
error that can be emited by ViSP classes.
Definition: vpException.h:76
virtual void readMainClass(xmlDocPtr doc, xmlNodePtr node)
double xmlReadDoubleChild(xmlDocPtr doc, xmlNodePtr node)
double get_py() const
bool hasFarClipping
Is far clipping distance specified?
Definition: vpMbXmlParser.h:81
virtual ~vpMbXmlParser()
double angleDisappear
Angle to determine if a face disappeared.
Definition: vpMbXmlParser.h:75
void initPersProjWithoutDistortion(const double px, const double py, const double u0, const double v0)
double farClipping
Near clipping distance.
Definition: vpMbXmlParser.h:83
void read_camera(xmlDocPtr doc, xmlNodePtr node)
double get_v0() const
void writeMainClass(xmlNodePtr node)
int xmlReadIntChild(xmlDocPtr doc, xmlNodePtr node)
void read_face(xmlDocPtr doc, xmlNodePtr node)
double get_px() const
bool hasNearClipping
Is near clipping distance specified?
Definition: vpMbXmlParser.h:77
void parse(const char *filename)
bool fovClipping
Fov Clipping.
Definition: vpMbXmlParser.h:85
std::map< std::string, int > nodeMap
Definition: vpXmlParser.h:197
void parse(const std::string &filename)