ViSP  2.9.0
vpMbtKltXmlParser.cpp
1 /****************************************************************************
2  *
3  * $Id: vpMbtKltXmlParser.cpp 4582 2014-01-14 14:02:46Z ayol $
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 parameters of the Model based tracker (using point features).
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 {
61  init();
62 }
63 
68 {
69 }
70 
74 void
76 {
78 
79  nodeMap["klt"] = klt;
80  nodeMap["mask_border"] = mask_border;
81  nodeMap["max_features"] = max_features;
82  nodeMap["window_size"] = window_size;
83  nodeMap["quality"] = quality;
84  nodeMap["min_distance"] = min_distance;
85  nodeMap["harris"] = harris;
86  nodeMap["size_block"] = size_block;
87  nodeMap["pyramid_lvl"] = pyramid_lvl;
88 }
89 
96 void
97 vpMbtKltXmlParser::parse(const char * filename)
98 {
99  std::string file = filename;
100  vpXmlParser::parse(file);
101 }
102 
108 void
110 {
111  throw vpException(vpException::notImplementedError, "Not yet implemented." );
112 }
113 
121 void
122 vpMbtKltXmlParser::readMainClass(xmlDocPtr doc, xmlNodePtr node)
123 {
124  bool camera_node = false;
125  bool face_node = false;
126  bool klt_node = false;
127 
128  for(xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
129  if(dataNode->type == XML_ELEMENT_NODE){
130  std::map<std::string, int>::iterator iter_data= this->nodeMap.find((char*)dataNode->name);
131  if(iter_data != nodeMap.end()){
132  switch (iter_data->second){
133  case camera:{
134  this->read_camera (doc, dataNode);
135  camera_node = true;
136  }break;
137  case face:{
138  this->read_face(doc, dataNode);
139  face_node = true;
140  }break;
141  case klt:{
142  this->read_klt(doc, dataNode);
143  klt_node = true;
144  }break;
145  default:{
146 // vpTRACE("unknown tag in read_sample : %d, %s", iter_data->second, (iter_data->first).c_str());
147  }break;
148  }
149  }
150  }
151  }
152 
153  if(!camera_node) {
154  std::cout << "camera : u0 : "<< this->cam.get_u0() << " (default)" <<std::endl;
155  std::cout << "camera : v0 : "<< this->cam.get_v0() << " (default)" <<std::endl;
156  std::cout << "camera : px : "<< this->cam.get_px() << " (default)" <<std::endl;
157  std::cout << "camera : py : "<< this->cam.get_py() << " (default)" <<std::endl;
158  }
159 
160  if(!face_node) {
161  std::cout << "face : Angle Appear : "<< angleAppear <<" (default)" <<std::endl;
162  std::cout << "face : Angle Disappear : "<< angleDisappear <<" (default)" <<std::endl;
163  }
164 
165  if(!klt_node) {
166  std::cout << "klt : Mask Border : "<< maskBorder <<" (default)" <<std::endl;
167  std::cout << "klt : Max Features : "<< maxFeatures <<" (default)" <<std::endl;
168  std::cout << "klt : Windows Size : "<< winSize <<" (default)" <<std::endl;
169  std::cout << "klt : Quality : "<< qualityValue <<" (default)" <<std::endl;
170  std::cout << "klt : Min Distance : "<< minDist <<" (default)" <<std::endl;
171  std::cout << "klt : Harris Parameter : "<< harrisParam <<" (default)" <<std::endl;
172  std::cout << "klt : Block Size : "<< blockSize <<" (default)" <<std::endl;
173  std::cout << "klt : Pyramid Levels : "<< pyramidLevels <<" (default)" <<std::endl;
174  }
175 }
176 
185 void
186 vpMbtKltXmlParser::read_klt(xmlDocPtr doc, xmlNodePtr node)
187 {
188  bool mask_border_node = false;
189  bool max_features_node = false;
190  bool window_size_node = false;
191  bool quality_node = false;
192  bool min_distance_node = false;
193  bool harris_node = false;
194  bool size_block_node = false;
195  bool pyramid_lvl_node = false;
196 
197  for(xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
198  if(dataNode->type == XML_ELEMENT_NODE){
199  std::map<std::string, int>::iterator iter_data= this->nodeMap.find((char*)dataNode->name);
200  if(iter_data != nodeMap.end()){
201  switch (iter_data->second){
202  case mask_border:{
203  maskBorder = xmlReadUnsignedIntChild(doc, dataNode);
204  mask_border_node = true;
205  }break;
206  case max_features:{
207  maxFeatures = xmlReadUnsignedIntChild(doc, dataNode);
208  max_features_node = true;
209  }break;
210  case window_size:{
211  winSize = xmlReadUnsignedIntChild(doc, dataNode);
212  window_size_node = true;
213  }break;
214  case quality:{
215  qualityValue = xmlReadDoubleChild(doc, dataNode);
216  quality_node = true;
217  }break;
218  case min_distance:{
219  minDist = xmlReadDoubleChild(doc, dataNode);
220  min_distance_node = true;
221  }break;
222  case harris:{
223  harrisParam = xmlReadDoubleChild(doc, dataNode);
224  harris_node = true;
225  }break;
226  case size_block:{
227  blockSize = xmlReadUnsignedIntChild(doc, dataNode);
228  size_block_node = true;
229  }break;
230  case pyramid_lvl:{
231  pyramidLevels = xmlReadUnsignedIntChild(doc, dataNode);
232  pyramid_lvl_node = true;
233  }break;
234  default:{
235 // vpTRACE("unknown tag in read_camera : %d, %s", iter_data->second, (iter_data->first).c_str());
236  }break;
237  }
238  }
239  }
240  }
241 
242  if(!mask_border_node)
243  std::cout << "klt : Mask Border : "<< maskBorder <<" (default)" <<std::endl;
244  else
245  std::cout << "klt : Mask Border : "<< maskBorder <<std::endl;
246 
247  if(!max_features_node)
248  std::cout << "klt : Max Features : "<< maxFeatures <<" (default)" <<std::endl;
249  else
250  std::cout << "klt : Max Features : "<< maxFeatures <<std::endl;
251 
252  if(!window_size_node)
253  std::cout << "klt : Windows Size : "<< winSize <<" (default)" <<std::endl;
254  else
255  std::cout << "klt : Windows Size : "<< winSize <<std::endl;
256 
257  if(!quality_node)
258  std::cout << "klt : Quality : "<< qualityValue <<" (default)" <<std::endl;
259  else
260  std::cout << "klt : Quality : "<< qualityValue <<std::endl;
261 
262  if(!min_distance_node)
263  std::cout << "klt : Min Distance : "<< minDist <<" (default)" <<std::endl;
264  else
265  std::cout << "klt : Min Distance : "<< minDist <<std::endl;
266 
267  if(!harris_node)
268  std::cout << "klt : Harris Parameter : "<< harrisParam <<" (default)" <<std::endl;
269  else
270  std::cout << "klt : Harris Parameter : "<< harrisParam <<std::endl;
271 
272  if(!size_block_node)
273  std::cout << "klt : Block Size : "<< blockSize <<" (default)" <<std::endl;
274  else
275  std::cout << "klt : Block Size : "<< blockSize <<std::endl;
276 
277  if(!pyramid_lvl_node)
278  std::cout << "klt : Pyramid Levels : "<< pyramidLevels <<" (default)" <<std::endl;
279  else
280  std::cout << "klt : Pyramid Levels : "<< pyramidLevels <<std::endl;
281 }
282 
283 #endif
284 
unsigned int winSize
Windows size.
vpCameraParameters cam
Camera parameters.
Definition: vpMbXmlParser.h:71
double get_u0() const
void parse(const char *filename)
double minDist
Minimum distance between klt points.
unsigned int maskBorder
Border of the mask used on Klt points.
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
double xmlReadDoubleChild(xmlDocPtr doc, xmlNodePtr node)
double get_py() const
double harrisParam
Harris free parameters.
double angleDisappear
Angle to determine if a face disappeared.
Definition: vpMbXmlParser.h:75
unsigned int maxFeatures
Maximum of Klt features.
virtual void readMainClass(xmlDocPtr doc, xmlNodePtr node)
void read_camera(xmlDocPtr doc, xmlNodePtr node)
double get_v0() const
unsigned int pyramidLevels
Number of pyramid levels.
void read_face(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
void writeMainClass(xmlNodePtr node)
void parse(const std::string &filename)