Visual Servoing Platform  version 3.2.0 under development (2019-01-22)
vpMbtKltXmlParser.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 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 
88 void vpMbtKltXmlParser::writeMainClass(xmlNodePtr /*node*/)
89 {
90  throw vpException(vpException::notImplementedError, "Not yet implemented.");
91 }
92 
100 void vpMbtKltXmlParser::readMainClass(xmlDocPtr doc, xmlNodePtr node)
101 {
102  bool camera_node = false;
103  bool face_node = false;
104  bool klt_node = false;
105  bool lod_node = false;
106 
107  for (xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
108  if (dataNode->type == XML_ELEMENT_NODE) {
109  std::map<std::string, int>::iterator iter_data = this->nodeMap.find((char *)dataNode->name);
110  if (iter_data != nodeMap.end()) {
111  switch (iter_data->second) {
112  case camera: {
113  this->read_camera(doc, dataNode);
114  camera_node = true;
115  } break;
116  case face: {
117  this->read_face(doc, dataNode);
118  face_node = true;
119  } break;
120  case klt: {
121  this->read_klt(doc, dataNode);
122  klt_node = true;
123  } break;
124  case lod: {
125  this->read_lod(doc, dataNode);
126  lod_node = true;
127  } break;
128  default: {
129  // vpTRACE("unknown tag in read_sample : %d, %s",
130  // iter_data->second, (iter_data->first).c_str());
131  } break;
132  }
133  }
134  }
135  }
136 
137  if (!camera_node) {
138  std::cout << "camera : u0 : " << this->cam.get_u0() << " (default)" << std::endl;
139  std::cout << "camera : v0 : " << this->cam.get_v0() << " (default)" << std::endl;
140  std::cout << "camera : px : " << this->cam.get_px() << " (default)" << std::endl;
141  std::cout << "camera : py : " << this->cam.get_py() << " (default)" << std::endl;
142  }
143 
144  if (!face_node) {
145  std::cout << "face : Angle Appear : " << angleAppear << " (default)" << std::endl;
146  std::cout << "face : Angle Disappear : " << angleDisappear << " (default)" << std::endl;
147  }
148 
149  if (!klt_node) {
150  std::cout << "klt : Mask Border : " << maskBorder << " (default)" << std::endl;
151  std::cout << "klt : Max Features : " << maxFeatures << " (default)" << std::endl;
152  std::cout << "klt : Windows Size : " << winSize << " (default)" << std::endl;
153  std::cout << "klt : Quality : " << qualityValue << " (default)" << std::endl;
154  std::cout << "klt : Min Distance : " << minDist << " (default)" << std::endl;
155  std::cout << "klt : Harris Parameter : " << harrisParam << " (default)" << std::endl;
156  std::cout << "klt : Block Size : " << blockSize << " (default)" << std::endl;
157  std::cout << "klt : Pyramid Levels : " << pyramidLevels << " (default)" << std::endl;
158  }
159 
160  if (!lod_node) {
161  std::cout << "lod : use lod : " << useLod << " (default)" << std::endl;
162  std::cout << "lod : min line length threshold : " << minLineLengthThreshold << " (default)" << std::endl;
163  std::cout << "lod : min polygon area threshold : " << minPolygonAreaThreshold << " (default)" << std::endl;
164  }
165 }
166 
175 void vpMbtKltXmlParser::read_klt(xmlDocPtr doc, xmlNodePtr node)
176 {
177  bool mask_border_node = false;
178  bool max_features_node = false;
179  bool window_size_node = false;
180  bool quality_node = false;
181  bool min_distance_node = false;
182  bool harris_node = false;
183  bool size_block_node = false;
184  bool pyramid_lvl_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 mask_border: {
192  maskBorder = xmlReadUnsignedIntChild(doc, dataNode);
193  mask_border_node = true;
194  } break;
195  case max_features: {
196  maxFeatures = xmlReadUnsignedIntChild(doc, dataNode);
197  max_features_node = true;
198  } break;
199  case window_size: {
200  winSize = xmlReadUnsignedIntChild(doc, dataNode);
201  window_size_node = true;
202  } break;
203  case quality: {
204  qualityValue = xmlReadDoubleChild(doc, dataNode);
205  quality_node = true;
206  } break;
207  case min_distance: {
208  minDist = xmlReadDoubleChild(doc, dataNode);
209  min_distance_node = true;
210  } break;
211  case harris: {
212  harrisParam = xmlReadDoubleChild(doc, dataNode);
213  harris_node = true;
214  } break;
215  case size_block: {
216  blockSize = xmlReadUnsignedIntChild(doc, dataNode);
217  size_block_node = true;
218  } break;
219  case pyramid_lvl: {
220  pyramidLevels = xmlReadUnsignedIntChild(doc, dataNode);
221  pyramid_lvl_node = true;
222  } break;
223  default: {
224  // vpTRACE("unknown tag in read_camera : %d, %s",
225  // iter_data->second, (iter_data->first).c_str());
226  } break;
227  }
228  }
229  }
230  }
231 
232  if (!mask_border_node)
233  std::cout << "klt : Mask Border : " << maskBorder << " (default)" << std::endl;
234  else
235  std::cout << "klt : Mask Border : " << maskBorder << std::endl;
236 
237  if (!max_features_node)
238  std::cout << "klt : Max Features : " << maxFeatures << " (default)" << std::endl;
239  else
240  std::cout << "klt : Max Features : " << maxFeatures << std::endl;
241 
242  if (!window_size_node)
243  std::cout << "klt : Windows Size : " << winSize << " (default)" << std::endl;
244  else
245  std::cout << "klt : Windows Size : " << winSize << std::endl;
246 
247  if (!quality_node)
248  std::cout << "klt : Quality : " << qualityValue << " (default)" << std::endl;
249  else
250  std::cout << "klt : Quality : " << qualityValue << std::endl;
251 
252  if (!min_distance_node)
253  std::cout << "klt : Min Distance : " << minDist << " (default)" << std::endl;
254  else
255  std::cout << "klt : Min Distance : " << minDist << std::endl;
256 
257  if (!harris_node)
258  std::cout << "klt : Harris Parameter : " << harrisParam << " (default)" << std::endl;
259  else
260  std::cout << "klt : Harris Parameter : " << harrisParam << std::endl;
261 
262  if (!size_block_node)
263  std::cout << "klt : Block Size : " << blockSize << " (default)" << std::endl;
264  else
265  std::cout << "klt : Block Size : " << blockSize << std::endl;
266 
267  if (!pyramid_lvl_node)
268  std::cout << "klt : Pyramid Levels : " << pyramidLevels << " (default)" << std::endl;
269  else
270  std::cout << "klt : Pyramid Levels : " << pyramidLevels << std::endl;
271 }
272 
273 #elif !defined(VISP_BUILD_SHARED_LIBS)
274 // Work arround to avoid warning: libvisp_mbt.a(vpMbtKltXmlParser.cpp.o) has
275 // no symbols
276 void dummy_vpMbtKltXmlParser(){};
277 #endif
unsigned int winSize
Windows size.
vpCameraParameters cam
Camera parameters.
Definition: vpMbXmlParser.h:69
double get_u0() const
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 get_py() const
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)
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: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