ViSP
 All Classes Functions Variables Enumerations Enumerator Friends Groups Pages
vpMbtKltXmlParser.cpp
1 /****************************************************************************
2  *
3  * $Id: vpMbtKltXmlParser.cpp 4320 2013-07-17 15:37:27Z ayol $
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  hasNearClipping = false;
60  hasFarClipping = false;
61  fovClipping = false;
62  init();
63 }
64 
69 {
70 }
71 
75 void
77 {
78  setMainTag("conf");
79 
80  nodeMap["conf"] = conf;
81  nodeMap["klt"] = klt;
82  nodeMap["mask_border"] = mask_border;
83  nodeMap["max_features"] = max_features;
84  nodeMap["window_size"] = window_size;
85  nodeMap["quality"] = quality;
86  nodeMap["min_distance"] = min_distance;
87  nodeMap["harris"] = harris;
88  nodeMap["size_block"] = size_block;
89  nodeMap["pyramid_lvl"] = pyramid_lvl;
90  nodeMap["face"] = face;
91  nodeMap["angle_appear"] = angle_appear;
92  nodeMap["angle_disappear"] = angle_disappear;
93  nodeMap["near_clipping"] = near_clipping;
94  nodeMap["far_clipping"] = far_clipping;
95  nodeMap["fov_clipping"] = fov_clipping;
96  nodeMap["camera"] = camera;
97  nodeMap["height"] = height;
98  nodeMap["width"] = width;
99  nodeMap["u0"] = u0;
100  nodeMap["v0"] = v0;
101  nodeMap["px"] = px;
102  nodeMap["py"] = py;
103 }
104 
111 void
112 vpMbtKltXmlParser::parse(const char * filename)
113 {
114  std::string file = filename;
115  vpXmlParser::parse(file);
116 }
117 
123 void
125 {
126  throw vpException(vpException::notImplementedError, "Not yet implemented." );
127 }
128 
136 void
137 vpMbtKltXmlParser::readMainClass(xmlDocPtr doc, xmlNodePtr node)
138 {
139  bool klt_node = false;
140  bool camera_node = false;
141  bool face_node = false;
142 
143  for(xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
144  if(dataNode->type == XML_ELEMENT_NODE){
145  std::map<std::string, int>::iterator iter_data= this->nodeMap.find((char*)dataNode->name);
146  if(iter_data != nodeMap.end()){
147  switch (iter_data->second){
148  case klt:{
149  this->read_klt(doc, dataNode);
150  klt_node = true;
151  }break;
152  case camera:{
153  this->read_camera(doc, dataNode);
154  camera_node = true;
155  }break;
156  case face:{
157  this->read_face(doc, dataNode);
158  face_node = true;
159  }break;
160  default:{
161 // vpTRACE("unknown tag in read_sample : %d, %s", iter_data->second, (iter_data->first).c_str());
162  }break;
163  }
164  }
165  }
166  }
167 
168  if(!klt_node)
169  std::cout << "WARNING: KLT Node not specified, default values used" << std::endl;
170 
171  if(!camera_node)
172  std::cout << "WARNING: CAMERA Node not specified, default values used" << std::endl;
173 
174  if(!face_node)
175  std::cout << "WARNING: FACE Node not specified, default values used" << std::endl;
176 }
177 
186 void
187 vpMbtKltXmlParser::read_face(xmlDocPtr doc, xmlNodePtr node)
188 {
189  bool angle_appear_node = false;
190  bool angle_disappear_node = false;
191  bool near_clipping_node = false;
192  bool far_clipping_node = false;
193  bool fov_clipping_node = false;
194 
195  for(xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
196  if(dataNode->type == XML_ELEMENT_NODE){
197  std::map<std::string, int>::iterator iter_data= this->nodeMap.find((char*)dataNode->name);
198  if(iter_data != nodeMap.end()){
199  switch (iter_data->second){
200  case angle_appear:{
201  angleAppear = xmlReadDoubleChild(doc, dataNode);
202  angle_appear_node = true;
203  }break;
204  case angle_disappear:{
205  angleDisappear = xmlReadDoubleChild(doc, dataNode);
206  angle_disappear_node = true;
207  }break;
208  case near_clipping:{
209  nearClipping = xmlReadDoubleChild(doc, dataNode);
210  near_clipping_node = true;
211  hasNearClipping = true;
212  }break;
213  case far_clipping:{
214  farClipping = xmlReadDoubleChild(doc, dataNode);
215  far_clipping_node = true;
216  hasFarClipping = true;
217  }break;
218  case fov_clipping:{
219  fovClipping = (bool)xmlReadIntChild(doc, dataNode);
220  fov_clipping_node = true;
221  }break;
222  default:{
223 // vpTRACE("unknown tag in read_camera : %d, %s", iter_data->second, (iter_data->first).c_str());
224  }break;
225  }
226  }
227  }
228  }
229 
230  if(!angle_appear_node)
231  std::cout << "WARNING: In FACE Node, ANGLE_APPEAR Node not specified, default value used : " << angleAppear << std::endl;
232  else
233  std::cout << "face : Angle Appear "<< angleAppear <<std::endl;
234 
235  if(!angle_disappear_node)
236  std::cout << "WARNING: In FACE Node, ANGLE_DESAPPEAR Node not specified, default value used : " << angleDisappear << std::endl;
237  else
238  std::cout << "face : Angle Disappear : "<< angleDisappear <<std::endl;
239 
240  if(!near_clipping_node)
241  std::cout << "WARNING: In FACE Node, NEAR_CLIPPING Node not specified, no near clipping used" << std::endl;
242  else
243  std::cout << "face : Near Clipping : "<< nearClipping <<std::endl;
244 
245  if(!far_clipping_node)
246  std::cout << "WARNING: In FACE Node, FAR_CLIPPING Node not specified, no far clipping used" << std::endl;
247  else
248  std::cout << "face : Far Clipping : "<< farClipping <<std::endl;
249 
250  if(!fov_clipping_node)
251  std::cout << "WARNING: In FACE Node, FOV_CLIPPING Node not specified, no fov clipping used" << std::endl;
252  else{
253  if(fovClipping)
254  std::cout << "face : Fov Clipping : True" <<std::endl;
255  else
256  std::cout << "face : Fov Clipping : False" <<std::endl;
257  }
258 }
259 
268 void
269 vpMbtKltXmlParser::read_klt(xmlDocPtr doc, xmlNodePtr node)
270 {
271  bool mask_border_node = false;
272  bool max_features_node = false;
273  bool window_size_node = false;
274  bool quality_node = false;
275  bool min_distance_node = false;
276  bool harris_node = false;
277  bool size_block_node = false;
278  bool pyramid_lvl_node = false;
279 
280  for(xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
281  if(dataNode->type == XML_ELEMENT_NODE){
282  std::map<std::string, int>::iterator iter_data= this->nodeMap.find((char*)dataNode->name);
283  if(iter_data != nodeMap.end()){
284  switch (iter_data->second){
285  case mask_border:{
286  maskBorder = xmlReadUnsignedIntChild(doc, dataNode);
287  mask_border_node = true;
288  }break;
289  case max_features:{
290  maxFeatures = xmlReadUnsignedIntChild(doc, dataNode);
291  max_features_node = true;
292  }break;
293  case window_size:{
294  winSize = xmlReadUnsignedIntChild(doc, dataNode);
295  window_size_node = true;
296  }break;
297  case quality:{
298  qualityValue = xmlReadDoubleChild(doc, dataNode);
299  quality_node = true;
300  }break;
301  case min_distance:{
302  minDist = xmlReadDoubleChild(doc, dataNode);
303  min_distance_node = true;
304  }break;
305  case harris:{
306  harrisParam = xmlReadDoubleChild(doc, dataNode);
307  harris_node = true;
308  }break;
309  case size_block:{
310  blockSize = xmlReadUnsignedIntChild(doc, dataNode);
311  size_block_node = true;
312  }break;
313  case pyramid_lvl:{
314  pyramidLevels = xmlReadUnsignedIntChild(doc, dataNode);
315  pyramid_lvl_node = true;
316  }break;
317  default:{
318 // vpTRACE("unknown tag in read_camera : %d, %s", iter_data->second, (iter_data->first).c_str());
319  }break;
320  }
321  }
322  }
323  }
324 
325  if(!mask_border_node)
326  std::cout << "WARNING: In KLT Node, MASK_BORDER Node not specified, default value used : " << maskBorder << std::endl;
327  else
328  std::cout << "klt : Mask Border : "<< maskBorder <<std::endl;
329 
330  if(!max_features_node)
331  std::cout << "WARNING: In KLT Node, MAX_FEATURES Node not specified, default value used : " << maxFeatures << std::endl;
332  else
333  std::cout << "klt : Max Features : "<< maxFeatures <<std::endl;
334 
335  if(!window_size_node)
336  std::cout << "WARNING: In KLT Node, WINDOW_SIZE Node not specified, default value used : " << winSize << std::endl;
337  else
338  std::cout << "klt : Windows Size : "<< winSize <<std::endl;
339 
340  if(!quality_node)
341  std::cout << "WARNING: In KLT Node, QUALITY Node not specified, default value used : " << qualityValue << std::endl;
342  else
343  std::cout << "klt : Quality : "<< qualityValue <<std::endl;
344 
345  if(!min_distance_node)
346  std::cout << "WARNING: In KLT Node, MIN_DISTANCE Node not specified, default value used : " << minDist << std::endl;
347  else
348  std::cout << "klt : Min Distance : "<< minDist <<std::endl;
349 
350  if(!harris_node)
351  std::cout << "WARNING: In KLT Node, HARRIS Node not specified, default value used : " << harrisParam << std::endl;
352  else
353  std::cout << "klt : Harris Parameter : "<< harrisParam <<std::endl;
354 
355  if(!size_block_node)
356  std::cout << "WARNING: In KLT Node, SIZE_BLOCK Node not specified, default value used : " << blockSize << std::endl;
357  else
358  std::cout << "klt : Block Size : "<< blockSize <<std::endl;
359 
360  if(!pyramid_lvl_node)
361  std::cout << "WARNING: In KLT Node, PYRAMID_LVL Node not specified, default value used : " << pyramidLevels << std::endl;
362  else
363  std::cout << "klt : Pyramid Levels : "<< pyramidLevels <<std::endl;
364 }
365 
374 void
375 vpMbtKltXmlParser::read_camera (xmlDocPtr doc, xmlNodePtr node)
376 {
377  bool height_node = false;
378  bool width_node = false;
379  bool u0_node = false;
380  bool v0_node = false;
381  bool px_node = false;
382  bool py_node = false;
383 
384  // current data values.
385 // int d_height=0 ;
386 // int d_width= 0 ;
387  double d_u0 = this->cam.get_u0();
388  double d_v0 = this->cam.get_v0();
389  double d_px = this->cam.get_px();
390  double d_py = this->cam.get_py();
391 
392  for(xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
393  if(dataNode->type == XML_ELEMENT_NODE){
394  std::map<std::string, int>::iterator iter_data= this->nodeMap.find((char*)dataNode->name);
395  if(iter_data != nodeMap.end()){
396  switch (iter_data->second){
397  case height:{
398  /* d_height = */ xmlReadIntChild(doc, dataNode);
399  height_node = true;
400  }break;
401  case width:{
402  /* d_width = */ xmlReadIntChild(doc, dataNode);
403  width_node = true;
404  }break;
405  case u0:{
406  d_u0 = xmlReadDoubleChild(doc, dataNode);
407  u0_node = true;
408  }break;
409  case v0:{
410  d_v0 = xmlReadDoubleChild(doc, dataNode);
411  v0_node = true;
412  }break;
413  case px:{
414  d_px = xmlReadDoubleChild(doc, dataNode);
415  px_node = true;
416  }break;
417  case py:{
418  d_py = xmlReadDoubleChild(doc, dataNode);
419  py_node = true;
420  }break;
421  default:{
422 // vpTRACE("unknown tag in read_camera : %d, %s", iter_data->second, (iter_data->first).c_str());
423  }break;
424  }
425  }
426  }
427  }
428 
429  this->cam.initPersProjWithoutDistortion(d_px, d_py, d_u0, d_v0) ;
430 
431  if(!height_node)
432  std::cout << "WARNING: In CAMERA Node, HEIGHT Node not specified, default value used" << std::endl;
433 
434  if(!width_node)
435  std::cout << "WARNING: In CAMERA Node, WIDTH Node not specified, default value used" << std::endl;
436 
437  if(!u0_node)
438  std::cout << "WARNING: In CAMERA Node, u0 Node not specified, default value used : " << this->cam.get_u0() << std::endl;
439  else
440  std::cout << "camera : u0 "<< this->cam.get_u0() <<std::endl;
441 
442  if(!v0_node)
443  std::cout << "WARNING: In CAMERA Node, v0 Node not specified, default value used : " << this->cam.get_v0() << std::endl;
444  else
445  std::cout << "camera : v0 "<< this->cam.get_v0() <<std::endl;
446 
447  if(!px_node)
448  std::cout << "WARNING: In CAMERA Node, px Node not specified, default value used : " << this->cam.get_px() << std::endl;
449  else
450  std::cout << "camera : px "<< this->cam.get_px() <<std::endl;
451 
452  if(!py_node)
453  std::cout << "WARNING: In CAMERA Node, py Node not specified, default value used : " << this->cam.get_py() << std::endl;
454  else
455  std::cout << "camera : py "<< this->cam.get_py() <<std::endl;
456 }
457 
458 
459 #endif
460