Visual Servoing Platform  version 3.0.0
vpMbtKltXmlParser.cpp
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  * Load XML parameters of the Model based tracker (using point features).
32  *
33  * Authors:
34  * Aurelien Yol
35  *
36  *****************************************************************************/
37 #include <visp3/core/vpConfig.h>
38 
39 #ifdef VISP_HAVE_XML2
40 
41 #include <iostream>
42 #include <map>
43 
44 #include <libxml/xmlmemory.h> /* Fonctions de la lib XML. */
45 
46 #include <visp3/mbt/vpMbtKltXmlParser.h>
47 
48 
54  : maskBorder(0), maxFeatures(0), winSize(0), qualityValue(0.), minDist(0.),
55  harrisParam(0.), blockSize(0), pyramidLevels(0)
56 {
57  init();
58 }
59 
64 {
65 }
66 
70 void
72 {
74 
75  nodeMap["klt"] = klt;
76  nodeMap["mask_border"] = mask_border;
77  nodeMap["max_features"] = max_features;
78  nodeMap["window_size"] = window_size;
79  nodeMap["quality"] = quality;
80  nodeMap["min_distance"] = min_distance;
81  nodeMap["harris"] = harris;
82  nodeMap["size_block"] = size_block;
83  nodeMap["pyramid_lvl"] = pyramid_lvl;
84 }
85 
92 void
93 vpMbtKltXmlParser::parse(const char * filename)
94 {
95  std::string file = filename;
96  vpXmlParser::parse(file);
97 }
98 
104 void
106 {
107  throw vpException(vpException::notImplementedError, "Not yet implemented." );
108 }
109 
117 void
118 vpMbtKltXmlParser::readMainClass(xmlDocPtr doc, xmlNodePtr node)
119 {
120  bool camera_node = false;
121  bool face_node = false;
122  bool klt_node = false;
123  bool lod_node = false;
124 
125  for(xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
126  if(dataNode->type == XML_ELEMENT_NODE){
127  std::map<std::string, int>::iterator iter_data= this->nodeMap.find((char*)dataNode->name);
128  if(iter_data != nodeMap.end()){
129  switch (iter_data->second){
130  case camera:{
131  this->read_camera (doc, dataNode);
132  camera_node = true;
133  }break;
134  case face:{
135  this->read_face(doc, dataNode);
136  face_node = true;
137  }break;
138  case klt:{
139  this->read_klt(doc, dataNode);
140  klt_node = true;
141  }break;
142  case lod:{
143  this->read_lod(doc, dataNode);
144  lod_node = true;
145  }break;
146  default:{
147 // vpTRACE("unknown tag in read_sample : %d, %s", iter_data->second, (iter_data->first).c_str());
148  }break;
149  }
150  }
151  }
152  }
153 
154  if(!camera_node) {
155  std::cout << "camera : u0 : "<< this->cam.get_u0() << " (default)" <<std::endl;
156  std::cout << "camera : v0 : "<< this->cam.get_v0() << " (default)" <<std::endl;
157  std::cout << "camera : px : "<< this->cam.get_px() << " (default)" <<std::endl;
158  std::cout << "camera : py : "<< this->cam.get_py() << " (default)" <<std::endl;
159  }
160 
161  if(!face_node) {
162  std::cout << "face : Angle Appear : "<< angleAppear <<" (default)" <<std::endl;
163  std::cout << "face : Angle Disappear : "<< angleDisappear <<" (default)" <<std::endl;
164  }
165 
166  if(!klt_node) {
167  std::cout << "klt : Mask Border : "<< maskBorder <<" (default)" <<std::endl;
168  std::cout << "klt : Max Features : "<< maxFeatures <<" (default)" <<std::endl;
169  std::cout << "klt : Windows Size : "<< winSize <<" (default)" <<std::endl;
170  std::cout << "klt : Quality : "<< qualityValue <<" (default)" <<std::endl;
171  std::cout << "klt : Min Distance : "<< minDist <<" (default)" <<std::endl;
172  std::cout << "klt : Harris Parameter : "<< harrisParam <<" (default)" <<std::endl;
173  std::cout << "klt : Block Size : "<< blockSize <<" (default)" <<std::endl;
174  std::cout << "klt : Pyramid Levels : "<< pyramidLevels <<" (default)" <<std::endl;
175  }
176 
177  if(!lod_node) {
178  std::cout << "lod : use lod : " << useLod << " (default)" << std::endl;
179  std::cout << "lod : min line length threshold : " << minLineLengthThreshold << " (default)" << std::endl;
180  std::cout << "lod : min polygon area threshold : " << minPolygonAreaThreshold << " (default)" << std::endl;
181  }
182 }
183 
192 void
193 vpMbtKltXmlParser::read_klt(xmlDocPtr doc, xmlNodePtr node)
194 {
195  bool mask_border_node = false;
196  bool max_features_node = false;
197  bool window_size_node = false;
198  bool quality_node = false;
199  bool min_distance_node = false;
200  bool harris_node = false;
201  bool size_block_node = false;
202  bool pyramid_lvl_node = false;
203 
204  for(xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
205  if(dataNode->type == XML_ELEMENT_NODE){
206  std::map<std::string, int>::iterator iter_data= this->nodeMap.find((char*)dataNode->name);
207  if(iter_data != nodeMap.end()){
208  switch (iter_data->second){
209  case mask_border:{
210  maskBorder = xmlReadUnsignedIntChild(doc, dataNode);
211  mask_border_node = true;
212  }break;
213  case max_features:{
214  maxFeatures = xmlReadUnsignedIntChild(doc, dataNode);
215  max_features_node = true;
216  }break;
217  case window_size:{
218  winSize = xmlReadUnsignedIntChild(doc, dataNode);
219  window_size_node = true;
220  }break;
221  case quality:{
222  qualityValue = xmlReadDoubleChild(doc, dataNode);
223  quality_node = true;
224  }break;
225  case min_distance:{
226  minDist = xmlReadDoubleChild(doc, dataNode);
227  min_distance_node = true;
228  }break;
229  case harris:{
230  harrisParam = xmlReadDoubleChild(doc, dataNode);
231  harris_node = true;
232  }break;
233  case size_block:{
234  blockSize = xmlReadUnsignedIntChild(doc, dataNode);
235  size_block_node = true;
236  }break;
237  case pyramid_lvl:{
238  pyramidLevels = xmlReadUnsignedIntChild(doc, dataNode);
239  pyramid_lvl_node = true;
240  }break;
241  default:{
242 // vpTRACE("unknown tag in read_camera : %d, %s", iter_data->second, (iter_data->first).c_str());
243  }break;
244  }
245  }
246  }
247  }
248 
249  if(!mask_border_node)
250  std::cout << "klt : Mask Border : "<< maskBorder <<" (default)" <<std::endl;
251  else
252  std::cout << "klt : Mask Border : "<< maskBorder <<std::endl;
253 
254  if(!max_features_node)
255  std::cout << "klt : Max Features : "<< maxFeatures <<" (default)" <<std::endl;
256  else
257  std::cout << "klt : Max Features : "<< maxFeatures <<std::endl;
258 
259  if(!window_size_node)
260  std::cout << "klt : Windows Size : "<< winSize <<" (default)" <<std::endl;
261  else
262  std::cout << "klt : Windows Size : "<< winSize <<std::endl;
263 
264  if(!quality_node)
265  std::cout << "klt : Quality : "<< qualityValue <<" (default)" <<std::endl;
266  else
267  std::cout << "klt : Quality : "<< qualityValue <<std::endl;
268 
269  if(!min_distance_node)
270  std::cout << "klt : Min Distance : "<< minDist <<" (default)" <<std::endl;
271  else
272  std::cout << "klt : Min Distance : "<< minDist <<std::endl;
273 
274  if(!harris_node)
275  std::cout << "klt : Harris Parameter : "<< harrisParam <<" (default)" <<std::endl;
276  else
277  std::cout << "klt : Harris Parameter : "<< harrisParam <<std::endl;
278 
279  if(!size_block_node)
280  std::cout << "klt : Block Size : "<< blockSize <<" (default)" <<std::endl;
281  else
282  std::cout << "klt : Block Size : "<< blockSize <<std::endl;
283 
284  if(!pyramid_lvl_node)
285  std::cout << "klt : Pyramid Levels : "<< pyramidLevels <<" (default)" <<std::endl;
286  else
287  std::cout << "klt : Pyramid Levels : "<< pyramidLevels <<std::endl;
288 }
289 
290 #elif !defined(VISP_BUILD_SHARED_LIBS)
291 // Work arround to avoid warning: libvisp_mbt.a(vpMbtKltXmlParser.cpp.o) has no symbols
292 void dummy_vpMbtKltXmlParser() {};
293 #endif
294 
unsigned int winSize
Windows size.
vpCameraParameters cam
Camera parameters.
Definition: vpMbXmlParser.h:67
double get_u0() const
void parse(const char *filename)
void read_lod(xmlDocPtr doc, xmlNodePtr node)
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:69
error that can be emited by ViSP classes.
Definition: vpException.h:73
double minLineLengthThreshold
Minimum line length to track a segment when LOD is enabled.
Definition: vpMbXmlParser.h:85
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:71
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:193
double minPolygonAreaThreshold
Minimum polygon area to track a face when LOD is enabled.
Definition: vpMbXmlParser.h:87
void writeMainClass(xmlNodePtr node)
bool useLod
If true, the LOD is enabled, otherwise it is not.
Definition: vpMbXmlParser.h:83
void parse(const std::string &filename)