ViSP  2.7.0
vpMbtKltXmlParser.cpp
1 /****************************************************************************
2  *
3  * $Id: vpMbtKltXmlParser.cpp 4056 2013-01-05 13:04:42Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 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  * Read MBT KLT Tracker information in an XML file
36  *
37  * Authors:
38  * Aurelien Yol
39  *
40  *****************************************************************************/
41 #include <visp/vpConfig.h>
42 
43 #ifdef VISP_HAVE_XML2
44 
45 #include <iostream>
46 #include <map>
47 
48 #include <libxml/xmlmemory.h> /* Fonctions de la lib XML. */
49 
50 #include <visp/vpMbtKltXmlParser.h>
51 
52 
58 {
59  init();
60 }
61 
66 {
67 }
68 
72 void
74 {
75  setMainTag("conf");
76 
77  nodeMap["conf"] = conf;
78  nodeMap["klt"] = klt;
79  nodeMap["mask_border"] = mask_border;
80  nodeMap["max_features"] = max_features;
81  nodeMap["window_size"] = window_size;
82  nodeMap["quality"] = quality;
83  nodeMap["min_distance"] = min_distance;
84  nodeMap["harris"] = harris;
85  nodeMap["size_block"] = size_block;
86  nodeMap["pyramid_lvl"] = pyramid_lvl;
87  nodeMap["face"] = face;
88  nodeMap["angle_appear"] = angle_appear;
89  nodeMap["angle_disappear"] = angle_disappear;
90  nodeMap["camera"] = camera;
91  nodeMap["height"] = height;
92  nodeMap["width"] = width;
93  nodeMap["u0"] = u0;
94  nodeMap["v0"] = v0;
95  nodeMap["px"] = px;
96  nodeMap["py"] = py;
97 }
98 
105 void
106 vpMbtKltXmlParser::parse(const char * filename)
107 {
108  std::string file = filename;
109  vpXmlParser::parse(file);
110 }
111 
117 void
119 {
120  throw vpException(vpException::notImplementedError, "Not yet implemented." );
121 }
122 
130 void
131 vpMbtKltXmlParser::readMainClass(xmlDocPtr doc, xmlNodePtr node)
132 {
133  bool klt_node = false;
134  bool camera_node = false;
135  bool face_node = false;
136 
137  for(xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
138  if(dataNode->type == XML_ELEMENT_NODE){
139  std::map<std::string, int>::iterator iter_data= this->nodeMap.find((char*)dataNode->name);
140  if(iter_data != nodeMap.end()){
141  switch (iter_data->second){
142  case klt:{
143  this->read_klt(doc, dataNode);
144  klt_node = true;
145  }break;
146  case camera:{
147  this->read_camera(doc, dataNode);
148  camera_node = true;
149  }break;
150  case face:{
151  this->read_face(doc, dataNode);
152  face_node = true;
153  }break;
154  default:{
155 // vpTRACE("unknown tag in read_sample : %d, %s", iter_data->second, (iter_data->first).c_str());
156  }break;
157  }
158  }
159  }
160  }
161 
162  if(!klt_node)
163  std::cout << "WARNING: KLT Node not specified, default values used" << std::endl;
164 
165  if(!camera_node)
166  std::cout << "WARNING: CAMERA Node not specified, default values used" << std::endl;
167 
168  if(!face_node)
169  std::cout << "WARNING: FACE Node not specified, default values used" << std::endl;
170 }
171 
180 void
181 vpMbtKltXmlParser::read_face(xmlDocPtr doc, xmlNodePtr node)
182 {
183  bool angle_appear_node = false;
184  bool angle_disappear_node = false;
185 
186  for(xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
187  if(dataNode->type == XML_ELEMENT_NODE){
188  std::map<std::string, int>::iterator iter_data= this->nodeMap.find((char*)dataNode->name);
189  if(iter_data != nodeMap.end()){
190  switch (iter_data->second){
191  case angle_appear:{
192  angleAppear = xmlReadDoubleChild(doc, dataNode);
193  angle_appear_node = true;
194  }break;
195  case angle_disappear:{
196  angleDisappear = xmlReadDoubleChild(doc, dataNode);
197  angle_disappear_node = true;
198  }break;
199  default:{
200 // vpTRACE("unknown tag in read_camera : %d, %s", iter_data->second, (iter_data->first).c_str());
201  }break;
202  }
203  }
204  }
205  }
206 
207  if(!angle_appear_node)
208  std::cout << "WARNING: In FACE Node, ANGLE_APPEAR Node not specified, default value used : " << angleAppear << std::endl;
209  else
210  std::cout << "face : Angle Appear "<< angleAppear <<std::endl;
211 
212  if(!angle_disappear_node)
213  std::cout << "WARNING: In FACE Node, ANGLE_DESAPPEAR Node not specified, default value used : " << angleDisappear << std::endl;
214  else
215  std::cout << "face : Angle Disappear : "<< angleDisappear <<std::endl;
216 }
217 
226 void
227 vpMbtKltXmlParser::read_klt(xmlDocPtr doc, xmlNodePtr node)
228 {
229  bool mask_border_node = false;
230  bool max_features_node = false;
231  bool window_size_node = false;
232  bool quality_node = false;
233  bool min_distance_node = false;
234  bool harris_node = false;
235  bool size_block_node = false;
236  bool pyramid_lvl_node = false;
237 
238  for(xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
239  if(dataNode->type == XML_ELEMENT_NODE){
240  std::map<std::string, int>::iterator iter_data= this->nodeMap.find((char*)dataNode->name);
241  if(iter_data != nodeMap.end()){
242  switch (iter_data->second){
243  case mask_border:{
244  maskBorder = xmlReadUnsignedIntChild(doc, dataNode);
245  mask_border_node = true;
246  }break;
247  case max_features:{
248  maxFeatures = xmlReadUnsignedIntChild(doc, dataNode);
249  max_features_node = true;
250  }break;
251  case window_size:{
252  winSize = xmlReadUnsignedIntChild(doc, dataNode);
253  window_size_node = true;
254  }break;
255  case quality:{
256  qualityValue = xmlReadDoubleChild(doc, dataNode);
257  quality_node = true;
258  }break;
259  case min_distance:{
260  minDist = xmlReadDoubleChild(doc, dataNode);
261  min_distance_node = true;
262  }break;
263  case harris:{
264  harrisParam = xmlReadDoubleChild(doc, dataNode);
265  harris_node = true;
266  }break;
267  case size_block:{
268  blockSize = xmlReadUnsignedIntChild(doc, dataNode);
269  size_block_node = true;
270  }break;
271  case pyramid_lvl:{
272  pyramidLevels = xmlReadUnsignedIntChild(doc, dataNode);
273  pyramid_lvl_node = true;
274  }break;
275  default:{
276 // vpTRACE("unknown tag in read_camera : %d, %s", iter_data->second, (iter_data->first).c_str());
277  }break;
278  }
279  }
280  }
281  }
282 
283  if(!mask_border_node)
284  std::cout << "WARNING: In KLT Node, MASK_BORDER Node not specified, default value used : " << maskBorder << std::endl;
285  else
286  std::cout << "klt : Mask Border : "<< maskBorder <<std::endl;
287 
288  if(!max_features_node)
289  std::cout << "WARNING: In KLT Node, MAX_FEATURES Node not specified, default value used : " << maxFeatures << std::endl;
290  else
291  std::cout << "klt : Max Features : "<< maxFeatures <<std::endl;
292 
293  if(!window_size_node)
294  std::cout << "WARNING: In KLT Node, WINDOW_SIZE Node not specified, default value used : " << winSize << std::endl;
295  else
296  std::cout << "klt : Windows Size : "<< winSize <<std::endl;
297 
298  if(!quality_node)
299  std::cout << "WARNING: In KLT Node, QUALITY Node not specified, default value used : " << qualityValue << std::endl;
300  else
301  std::cout << "klt : Quality : "<< qualityValue <<std::endl;
302 
303  if(!min_distance_node)
304  std::cout << "WARNING: In KLT Node, MIN_DISTANCE Node not specified, default value used : " << minDist << std::endl;
305  else
306  std::cout << "klt : Min Distance : "<< minDist <<std::endl;
307 
308  if(!harris_node)
309  std::cout << "WARNING: In KLT Node, HARRIS Node not specified, default value used : " << harrisParam << std::endl;
310  else
311  std::cout << "klt : Harris Parameter : "<< harrisParam <<std::endl;
312 
313  if(!size_block_node)
314  std::cout << "WARNING: In KLT Node, SIZE_BLOCK Node not specified, default value used : " << blockSize << std::endl;
315  else
316  std::cout << "klt : Block Size : "<< blockSize <<std::endl;
317 
318  if(!pyramid_lvl_node)
319  std::cout << "WARNING: In KLT Node, PYRAMID_LVL Node not specified, default value used : " << pyramidLevels << std::endl;
320  else
321  std::cout << "klt : Pyramid Levels : "<< pyramidLevels <<std::endl;
322 }
323 
332 void
333 vpMbtKltXmlParser::read_camera (xmlDocPtr doc, xmlNodePtr node)
334 {
335  bool height_node = false;
336  bool width_node = false;
337  bool u0_node = false;
338  bool v0_node = false;
339  bool px_node = false;
340  bool py_node = false;
341 
342  // current data values.
343 // int d_height=0 ;
344 // int d_width= 0 ;
345  double d_u0 = this->cam.get_u0();
346  double d_v0 = this->cam.get_v0();
347  double d_px = this->cam.get_px();
348  double d_py = this->cam.get_py();
349 
350  for(xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
351  if(dataNode->type == XML_ELEMENT_NODE){
352  std::map<std::string, int>::iterator iter_data= this->nodeMap.find((char*)dataNode->name);
353  if(iter_data != nodeMap.end()){
354  switch (iter_data->second){
355  case height:{
356  /* d_height = */ xmlReadIntChild(doc, dataNode);
357  height_node = true;
358  }break;
359  case width:{
360  /* d_width = */ xmlReadIntChild(doc, dataNode);
361  width_node = true;
362  }break;
363  case u0:{
364  d_u0 = xmlReadDoubleChild(doc, dataNode);
365  u0_node = true;
366  }break;
367  case v0:{
368  d_v0 = xmlReadDoubleChild(doc, dataNode);
369  v0_node = true;
370  }break;
371  case px:{
372  d_px = xmlReadDoubleChild(doc, dataNode);
373  px_node = true;
374  }break;
375  case py:{
376  d_py = xmlReadDoubleChild(doc, dataNode);
377  py_node = true;
378  }break;
379  default:{
380 // vpTRACE("unknown tag in read_camera : %d, %s", iter_data->second, (iter_data->first).c_str());
381  }break;
382  }
383  }
384  }
385  }
386 
387  this->cam.initPersProjWithoutDistortion(d_px, d_py, d_u0, d_v0) ;
388 
389  if(!height_node)
390  std::cout << "WARNING: In CAMERA Node, HEIGHT Node not specified, default value used" << std::endl;
391 
392  if(!width_node)
393  std::cout << "WARNING: In CAMERA Node, WIDTH Node not specified, default value used" << std::endl;
394 
395  if(!u0_node)
396  std::cout << "WARNING: In CAMERA Node, u0 Node not specified, default value used : " << this->cam.get_u0() << std::endl;
397  else
398  std::cout << "camera : u0 "<< this->cam.get_u0() <<std::endl;
399 
400  if(!v0_node)
401  std::cout << "WARNING: In CAMERA Node, v0 Node not specified, default value used : " << this->cam.get_v0() << std::endl;
402  else
403  std::cout << "camera : v0 "<< this->cam.get_v0() <<std::endl;
404 
405  if(!px_node)
406  std::cout << "WARNING: In CAMERA Node, px Node not specified, default value used : " << this->cam.get_px() << std::endl;
407  else
408  std::cout << "camera : px "<< this->cam.get_px() <<std::endl;
409 
410  if(!py_node)
411  std::cout << "WARNING: In CAMERA Node, py Node not specified, default value used : " << this->cam.get_py() << std::endl;
412  else
413  std::cout << "camera : py "<< this->cam.get_py() <<std::endl;
414 }
415 
416 
417 #endif
418 
unsigned int winSize
Windows size.
double get_u0() const
void setMainTag(const std::string &tag)
Definition: vpXmlParser.h:280
void parse(const char *filename)
double minDist
Minimum distance between klt points.
unsigned int maskBorder
Border of the mask used on Klt points.
error that can be emited by ViSP classes.
Definition: vpException.h:75
double angleAppear
Angle to determine if a face appeared.
double xmlReadDoubleChild(xmlDocPtr doc, xmlNodePtr node)
double get_py() const
double harrisParam
Harris free parameters.
double angleDisappear
Angle to determine if a face disappeared.
unsigned int maxFeatures
Maximum of Klt features.
void readMainClass(xmlDocPtr doc, xmlNodePtr node)
void read_camera(xmlDocPtr doc, xmlNodePtr node)
void initPersProjWithoutDistortion(const double px, const double py, const double u0, const double v0)
void read_face(xmlDocPtr doc, xmlNodePtr node)
double get_v0() const
unsigned int pyramidLevels
Number of pyramid levels.
int xmlReadIntChild(xmlDocPtr doc, xmlNodePtr node)
double get_px() const
unsigned int blockSize
Block size.
unsigned int xmlReadUnsignedIntChild(xmlDocPtr doc, xmlNodePtr node)
void read_klt(xmlDocPtr doc, xmlNodePtr node)
double qualityValue
Quality of the Klt points.
std::map< std::string, int > nodeMap
Definition: vpXmlParser.h:197
vpCameraParameters cam
Camera parameters.
void writeMainClass(xmlNodePtr node)
void parse(const std::string &filename)