Visual Servoing Platform  version 3.1.0
vpMbtKltXmlParser.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Load XML parameters of the Model based tracker (using point features).
33  *
34  * Authors:
35  * Aurelien Yol
36  *
37  *****************************************************************************/
38 #include <visp3/core/vpConfig.h>
39 
40 #ifdef VISP_HAVE_XML2
41 
42 #include <iostream>
43 #include <map>
44 
45 #include <libxml/xmlmemory.h> /* Fonctions de la lib XML. */
46 
47 #include <visp3/mbt/vpMbtKltXmlParser.h>
48 
54  : maskBorder(0), maxFeatures(0), winSize(0), qualityValue(0.), minDist(0.), harrisParam(0.), blockSize(0),
55  pyramidLevels(0)
56 {
57  init();
58 }
59 
64 
69 {
71 
72  nodeMap["klt"] = klt;
73  nodeMap["mask_border"] = mask_border;
74  nodeMap["max_features"] = max_features;
75  nodeMap["window_size"] = window_size;
76  nodeMap["quality"] = quality;
77  nodeMap["min_distance"] = min_distance;
78  nodeMap["harris"] = harris;
79  nodeMap["size_block"] = size_block;
80  nodeMap["pyramid_lvl"] = pyramid_lvl;
81 }
82 
89 void vpMbtKltXmlParser::parse(const char *filename)
90 {
91  std::string file = filename;
92  vpXmlParser::parse(file);
93 }
94 
100 void vpMbtKltXmlParser::writeMainClass(xmlNodePtr /*node*/)
101 {
102  throw vpException(vpException::notImplementedError, "Not yet implemented.");
103 }
104 
112 void vpMbtKltXmlParser::readMainClass(xmlDocPtr doc, xmlNodePtr node)
113 {
114  bool camera_node = false;
115  bool face_node = false;
116  bool klt_node = false;
117  bool lod_node = false;
118 
119  for (xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
120  if (dataNode->type == XML_ELEMENT_NODE) {
121  std::map<std::string, int>::iterator iter_data = this->nodeMap.find((char *)dataNode->name);
122  if (iter_data != nodeMap.end()) {
123  switch (iter_data->second) {
124  case camera: {
125  this->read_camera(doc, dataNode);
126  camera_node = true;
127  } break;
128  case face: {
129  this->read_face(doc, dataNode);
130  face_node = true;
131  } break;
132  case klt: {
133  this->read_klt(doc, dataNode);
134  klt_node = true;
135  } break;
136  case lod: {
137  this->read_lod(doc, dataNode);
138  lod_node = true;
139  } break;
140  default: {
141  // vpTRACE("unknown tag in read_sample : %d, %s",
142  // iter_data->second, (iter_data->first).c_str());
143  } break;
144  }
145  }
146  }
147  }
148 
149  if (!camera_node) {
150  std::cout << "camera : u0 : " << this->cam.get_u0() << " (default)" << std::endl;
151  std::cout << "camera : v0 : " << this->cam.get_v0() << " (default)" << std::endl;
152  std::cout << "camera : px : " << this->cam.get_px() << " (default)" << std::endl;
153  std::cout << "camera : py : " << this->cam.get_py() << " (default)" << std::endl;
154  }
155 
156  if (!face_node) {
157  std::cout << "face : Angle Appear : " << angleAppear << " (default)" << std::endl;
158  std::cout << "face : Angle Disappear : " << angleDisappear << " (default)" << std::endl;
159  }
160 
161  if (!klt_node) {
162  std::cout << "klt : Mask Border : " << maskBorder << " (default)" << std::endl;
163  std::cout << "klt : Max Features : " << maxFeatures << " (default)" << std::endl;
164  std::cout << "klt : Windows Size : " << winSize << " (default)" << std::endl;
165  std::cout << "klt : Quality : " << qualityValue << " (default)" << std::endl;
166  std::cout << "klt : Min Distance : " << minDist << " (default)" << std::endl;
167  std::cout << "klt : Harris Parameter : " << harrisParam << " (default)" << std::endl;
168  std::cout << "klt : Block Size : " << blockSize << " (default)" << std::endl;
169  std::cout << "klt : Pyramid Levels : " << pyramidLevels << " (default)" << std::endl;
170  }
171 
172  if (!lod_node) {
173  std::cout << "lod : use lod : " << useLod << " (default)" << std::endl;
174  std::cout << "lod : min line length threshold : " << minLineLengthThreshold << " (default)" << std::endl;
175  std::cout << "lod : min polygon area threshold : " << minPolygonAreaThreshold << " (default)" << std::endl;
176  }
177 }
178 
187 void vpMbtKltXmlParser::read_klt(xmlDocPtr doc, xmlNodePtr node)
188 {
189  bool mask_border_node = false;
190  bool max_features_node = false;
191  bool window_size_node = false;
192  bool quality_node = false;
193  bool min_distance_node = false;
194  bool harris_node = false;
195  bool size_block_node = false;
196  bool pyramid_lvl_node = false;
197 
198  for (xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
199  if (dataNode->type == XML_ELEMENT_NODE) {
200  std::map<std::string, int>::iterator iter_data = this->nodeMap.find((char *)dataNode->name);
201  if (iter_data != nodeMap.end()) {
202  switch (iter_data->second) {
203  case mask_border: {
204  maskBorder = xmlReadUnsignedIntChild(doc, dataNode);
205  mask_border_node = true;
206  } break;
207  case max_features: {
208  maxFeatures = xmlReadUnsignedIntChild(doc, dataNode);
209  max_features_node = true;
210  } break;
211  case window_size: {
212  winSize = xmlReadUnsignedIntChild(doc, dataNode);
213  window_size_node = true;
214  } break;
215  case quality: {
216  qualityValue = xmlReadDoubleChild(doc, dataNode);
217  quality_node = true;
218  } break;
219  case min_distance: {
220  minDist = xmlReadDoubleChild(doc, dataNode);
221  min_distance_node = true;
222  } break;
223  case harris: {
224  harrisParam = xmlReadDoubleChild(doc, dataNode);
225  harris_node = true;
226  } break;
227  case size_block: {
228  blockSize = xmlReadUnsignedIntChild(doc, dataNode);
229  size_block_node = true;
230  } break;
231  case pyramid_lvl: {
232  pyramidLevels = xmlReadUnsignedIntChild(doc, dataNode);
233  pyramid_lvl_node = true;
234  } break;
235  default: {
236  // vpTRACE("unknown tag in read_camera : %d, %s",
237  // iter_data->second, (iter_data->first).c_str());
238  } break;
239  }
240  }
241  }
242  }
243 
244  if (!mask_border_node)
245  std::cout << "klt : Mask Border : " << maskBorder << " (default)" << std::endl;
246  else
247  std::cout << "klt : Mask Border : " << maskBorder << std::endl;
248 
249  if (!max_features_node)
250  std::cout << "klt : Max Features : " << maxFeatures << " (default)" << std::endl;
251  else
252  std::cout << "klt : Max Features : " << maxFeatures << std::endl;
253 
254  if (!window_size_node)
255  std::cout << "klt : Windows Size : " << winSize << " (default)" << std::endl;
256  else
257  std::cout << "klt : Windows Size : " << winSize << std::endl;
258 
259  if (!quality_node)
260  std::cout << "klt : Quality : " << qualityValue << " (default)" << std::endl;
261  else
262  std::cout << "klt : Quality : " << qualityValue << std::endl;
263 
264  if (!min_distance_node)
265  std::cout << "klt : Min Distance : " << minDist << " (default)" << std::endl;
266  else
267  std::cout << "klt : Min Distance : " << minDist << std::endl;
268 
269  if (!harris_node)
270  std::cout << "klt : Harris Parameter : " << harrisParam << " (default)" << std::endl;
271  else
272  std::cout << "klt : Harris Parameter : " << harrisParam << std::endl;
273 
274  if (!size_block_node)
275  std::cout << "klt : Block Size : " << blockSize << " (default)" << std::endl;
276  else
277  std::cout << "klt : Block Size : " << blockSize << std::endl;
278 
279  if (!pyramid_lvl_node)
280  std::cout << "klt : Pyramid Levels : " << pyramidLevels << " (default)" << std::endl;
281  else
282  std::cout << "klt : Pyramid Levels : " << pyramidLevels << std::endl;
283 }
284 
285 #elif !defined(VISP_BUILD_SHARED_LIBS)
286 // Work arround to avoid warning: libvisp_mbt.a(vpMbtKltXmlParser.cpp.o) has
287 // no symbols
288 void dummy_vpMbtKltXmlParser(){};
289 #endif
unsigned int winSize
Windows size.
vpCameraParameters cam
Camera parameters.
Definition: vpMbXmlParser.h:69
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:71
error that can be emited by ViSP classes.
Definition: vpException.h:71
double minLineLengthThreshold
Minimum line length to track a segment when LOD is enabled.
Definition: vpMbXmlParser.h:87
double xmlReadDoubleChild(xmlDocPtr doc, xmlNodePtr node)
double harrisParam
Harris free parameters.
double angleDisappear
Angle to determine if a face disappeared.
Definition: vpMbXmlParser.h:73
unsigned int maxFeatures
Maximum of Klt features.
virtual void readMainClass(xmlDocPtr doc, xmlNodePtr node)
void read_camera(xmlDocPtr doc, xmlNodePtr node)
unsigned int pyramidLevels
Number of pyramid levels.
void read_face(xmlDocPtr doc, xmlNodePtr node)
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:226
double minPolygonAreaThreshold
Minimum polygon area to track a face when LOD is enabled.
Definition: vpMbXmlParser.h:89
void writeMainClass(xmlNodePtr node)
bool useLod
If true, the LOD is enabled, otherwise it is not.
Definition: vpMbXmlParser.h:85
void parse(const std::string &filename)