Visual Servoing Platform  version 3.1.0
vpMbtXmlGenericParser.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 Parameter for Model Based Tracker.
33  *
34  *****************************************************************************/
35 #include <visp3/core/vpConfig.h>
36 
37 #ifdef VISP_HAVE_XML2
38 
39 #include <iostream>
40 #include <map>
41 
42 #include <libxml/xmlmemory.h>
43 
44 #include <visp3/mbt/vpMbtXmlGenericParser.h>
45 
47  : m_parserType(type),
48  //<camera>
49  m_cam(),
50  //<face>
51  m_angleAppear(70), m_angleDisappear(80), m_hasNearClipping(false), m_nearClipping(false), m_hasFarClipping(false),
52  m_farClipping(false), m_fovClipping(false),
53  //<lod>
54  m_useLod(false), m_minLineLengthThreshold(50.0), m_minPolygonAreaThreshold(2500.0),
55  //<ecm>
56  m_ecm(),
57  //<klt>
58  m_kltMaskBorder(0), m_kltMaxFeatures(0), m_kltWinSize(0), m_kltQualityValue(0.), m_kltMinDist(0.),
59  m_kltHarrisParam(0.), m_kltBlockSize(0), m_kltPyramidLevels(0),
60  //<depth_normal>
61  m_depthNormalFeatureEstimationMethod(vpMbtFaceDepthNormal::ROBUST_FEATURE_ESTIMATION),
62  m_depthNormalPclPlaneEstimationMethod(2), m_depthNormalPclPlaneEstimationRansacMaxIter(200),
63  m_depthNormalPclPlaneEstimationRansacThreshold(0.001), m_depthNormalSamplingStepX(2), m_depthNormalSamplingStepY(2),
64  //<depth_dense>
65  m_depthDenseSamplingStepX(2), m_depthDenseSamplingStepY(2)
66 {
67  init();
68 }
69 
71 
76 {
77  setMainTag("conf");
78 
79  //<conf>
80  nodeMap["conf"] = conf;
81  //<face>
82  nodeMap["face"] = face;
83  nodeMap["angle_appear"] = angle_appear;
84  nodeMap["angle_disappear"] = angle_disappear;
85  nodeMap["near_clipping"] = near_clipping;
86  nodeMap["far_clipping"] = far_clipping;
87  nodeMap["fov_clipping"] = fov_clipping;
88  //<camera>
89  nodeMap["camera"] = camera;
90  nodeMap["height"] = height;
91  nodeMap["width"] = width;
92  nodeMap["u0"] = u0;
93  nodeMap["v0"] = v0;
94  nodeMap["px"] = px;
95  nodeMap["py"] = py;
96  //<lod>
97  nodeMap["lod"] = lod;
98  nodeMap["use_lod"] = use_lod;
99  nodeMap["min_line_length_threshold"] = min_line_length_threshold;
100  nodeMap["min_polygon_area_threshold"] = min_polygon_area_threshold;
101  //<ecm>
102  nodeMap["ecm"] = ecm;
103  nodeMap["mask"] = mask;
104  nodeMap["size"] = size;
105  nodeMap["nb_mask"] = nb_mask;
106  nodeMap["range"] = range;
107  nodeMap["tracking"] = tracking;
108  nodeMap["contrast"] = contrast;
109  nodeMap["edge_threshold"] = edge_threshold;
110  nodeMap["mu1"] = mu1;
111  nodeMap["mu2"] = mu2;
112  nodeMap["sample"] = sample;
113  nodeMap["step"] = step;
114  //<klt>
115  nodeMap["klt"] = klt;
116  nodeMap["mask_border"] = mask_border;
117  nodeMap["max_features"] = max_features;
118  nodeMap["window_size"] = window_size;
119  nodeMap["quality"] = quality;
120  nodeMap["min_distance"] = min_distance;
121  nodeMap["harris"] = harris;
122  nodeMap["size_block"] = size_block;
123  nodeMap["pyramid_lvl"] = pyramid_lvl;
124  //<depth_normal>
125  nodeMap["depth_normal"] = depth_normal;
126  nodeMap["feature_estimation_method"] = feature_estimation_method;
127  nodeMap["PCL_plane_estimation"] = PCL_plane_estimation;
129  nodeMap["ransac_max_iter"] = PCL_plane_estimation_ransac_max_iter;
130  nodeMap["ransac_threshold"] = PCL_plane_estimation_ransac_threshold;
131  nodeMap["sampling_step"] = depth_sampling_step;
132  nodeMap["step_X"] = depth_sampling_step_X;
133  nodeMap["step_Y"] = depth_sampling_step_Y;
134  //<depth_dense>
135  nodeMap["depth_dense"] = depth_dense;
136  nodeMap["sampling_step"] = depth_dense_sampling_step;
139 }
140 
147 void vpMbtXmlGenericParser::parse(const std::string &filename) { vpXmlParser::parse(filename); }
148 
154 void vpMbtXmlGenericParser::writeMainClass(xmlNodePtr /*node*/)
155 {
156  throw vpException(vpException::notImplementedError, "Not implemented.");
157 }
158 
166 void vpMbtXmlGenericParser::readMainClass(xmlDocPtr doc, xmlNodePtr node)
167 {
168  bool camera_node = false;
169  bool face_node = false;
170  bool ecm_node = false;
171  bool klt_node = false;
172  bool lod_node = false;
173  bool depth_normal_node = false;
174  bool depth_dense_node = false;
175 
176  for (xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
177  if (dataNode->type == XML_ELEMENT_NODE) {
178  std::map<std::string, int>::const_iterator iter_data = nodeMap.find((char *)dataNode->name);
179  if (iter_data != nodeMap.end()) {
180  switch (iter_data->second) {
181  case camera:
182  read_camera(doc, dataNode);
183  camera_node = true;
184  break;
185 
186  case face:
187  read_face(doc, dataNode);
188  face_node = true;
189  break;
190 
191  case lod:
192  read_lod(doc, dataNode);
193  lod_node = true;
194  break;
195 
196  case ecm:
197  if (m_parserType & EDGE_PARSER) {
198  read_ecm(doc, dataNode);
199  ecm_node = true;
200  }
201  break;
202 
203  case sample:
204  if (m_parserType & EDGE_PARSER)
205  read_sample_deprecated(doc, dataNode);
206  break;
207 
208  case klt:
209  if (m_parserType & KLT_PARSER) {
210  read_klt(doc, dataNode);
211  klt_node = true;
212  }
213  break;
214 
215  case depth_normal:
217  read_depth_normal(doc, dataNode);
218  depth_normal_node = true;
219  }
220  break;
221 
222  case depth_dense:
224  read_depth_dense(doc, dataNode);
225  depth_dense_node = true;
226  }
227  break;
228 
229  default:
230  break;
231  }
232  }
233  }
234  }
235 
236  if (!camera_node) {
237  std::cout << "camera : u0 : " << m_cam.get_u0() << " (default)" << std::endl;
238  std::cout << "camera : v0 : " << m_cam.get_v0() << " (default)" << std::endl;
239  std::cout << "camera : px : " << m_cam.get_px() << " (default)" << std::endl;
240  std::cout << "camera : py : " << m_cam.get_py() << " (default)" << std::endl;
241  }
242 
243  if (!face_node) {
244  std::cout << "face : Angle Appear : " << m_angleAppear << " (default)" << std::endl;
245  std::cout << "face : Angle Disappear : " << m_angleDisappear << " (default)" << std::endl;
246  }
247 
248  if (!lod_node) {
249  std::cout << "lod : use lod : " << m_useLod << " (default)" << std::endl;
250  std::cout << "lod : min line length threshold : " << m_minLineLengthThreshold << " (default)" << std::endl;
251  std::cout << "lod : min polygon area threshold : " << m_minPolygonAreaThreshold << " (default)" << std::endl;
252  }
253 
254  if (!ecm_node && (m_parserType & EDGE_PARSER)) {
255  std::cout << "ecm : mask : size : " << m_ecm.getMaskSize() << " (default)" << std::endl;
256  std::cout << "ecm : mask : nb_mask : " << m_ecm.getMaskNumber() << " (default)" << std::endl;
257  std::cout << "ecm : range : tracking : " << m_ecm.getRange() << " (default)" << std::endl;
258  std::cout << "ecm : contrast : threshold : " << m_ecm.getThreshold() << " (default)" << std::endl;
259  std::cout << "ecm : contrast : mu1 : " << m_ecm.getMu1() << " (default)" << std::endl;
260  std::cout << "ecm : contrast : mu2 : " << m_ecm.getMu2() << " (default)" << std::endl;
261  std::cout << "ecm : sample : sample_step : " << m_ecm.getSampleStep() << " (default)" << std::endl;
262  }
263 
264  if (!klt_node && (m_parserType & KLT_PARSER)) {
265  std::cout << "klt : Mask Border : " << m_kltMaskBorder << " (default)" << std::endl;
266  std::cout << "klt : Max Features : " << m_kltMaxFeatures << " (default)" << std::endl;
267  std::cout << "klt : Windows Size : " << m_kltWinSize << " (default)" << std::endl;
268  std::cout << "klt : Quality : " << m_kltQualityValue << " (default)" << std::endl;
269  std::cout << "klt : Min Distance : " << m_kltMinDist << " (default)" << std::endl;
270  std::cout << "klt : Harris Parameter : " << m_kltHarrisParam << " (default)" << std::endl;
271  std::cout << "klt : Block Size : " << m_kltBlockSize << " (default)" << std::endl;
272  std::cout << "klt : Pyramid Levels : " << m_kltPyramidLevels << " (default)" << std::endl;
273  }
274 
275  if (!depth_normal_node && (m_parserType & DEPTH_NORMAL_PARSER)) {
276  std::cout << "depth normal : feature_estimation_method : " << m_depthNormalFeatureEstimationMethod << " (default)"
277  << std::endl;
278  std::cout << "depth normal : PCL_plane_estimation : method : " << m_depthNormalPclPlaneEstimationMethod
279  << " (default)" << std::endl;
280  std::cout << "depth normal : PCL_plane_estimation : max_iter : " << m_depthNormalPclPlaneEstimationRansacMaxIter
281  << " (default)" << std::endl;
282  std::cout << "depth normal : PCL_plane_estimation : ransac_threshold : "
283  << m_depthNormalPclPlaneEstimationRansacThreshold << " (default)" << std::endl;
284  std::cout << "depth normal : sampling_step : step_X " << m_depthNormalSamplingStepX << " (default)" << std::endl;
285  std::cout << "depth normal : sampling_step : step_Y " << m_depthNormalSamplingStepY << " (default)" << std::endl;
286  }
287 
288  if (!depth_dense_node && (m_parserType & DEPTH_DENSE_PARSER)) {
289  std::cout << "depth dense : sampling_step : step_X " << m_depthDenseSamplingStepX << " (default)" << std::endl;
290  std::cout << "depth dense : sampling_step : step_Y " << m_depthDenseSamplingStepY << " (default)" << std::endl;
291  }
292 }
293 
302 void vpMbtXmlGenericParser::read_camera(xmlDocPtr doc, xmlNodePtr node)
303 {
304  bool u0_node = false;
305  bool v0_node = false;
306  bool px_node = false;
307  bool py_node = false;
308 
309  // current data values.
310  double d_u0 = m_cam.get_u0();
311  double d_v0 = m_cam.get_v0();
312  double d_px = m_cam.get_px();
313  double d_py = m_cam.get_py();
314 
315  for (xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
316  if (dataNode->type == XML_ELEMENT_NODE) {
317  std::map<std::string, int>::const_iterator iter_data = nodeMap.find((char *)dataNode->name);
318  if (iter_data != nodeMap.end()) {
319  switch (iter_data->second) {
320  case u0:
321  d_u0 = xmlReadDoubleChild(doc, dataNode);
322  u0_node = true;
323  break;
324 
325  case v0:
326  d_v0 = xmlReadDoubleChild(doc, dataNode);
327  v0_node = true;
328  break;
329 
330  case px:
331  d_px = xmlReadDoubleChild(doc, dataNode);
332  px_node = true;
333  break;
334 
335  case py:
336  d_py = xmlReadDoubleChild(doc, dataNode);
337  py_node = true;
338  break;
339 
340  default:
341  break;
342  }
343  }
344  }
345  }
346 
347  m_cam.initPersProjWithoutDistortion(d_px, d_py, d_u0, d_v0);
348 
349  if (!u0_node)
350  std::cout << "camera : u0 : " << m_cam.get_u0() << " (default)" << std::endl;
351  else
352  std::cout << "camera : u0 : " << m_cam.get_u0() << std::endl;
353 
354  if (!v0_node)
355  std::cout << "camera : v0 : " << m_cam.get_v0() << " (default)" << std::endl;
356  else
357  std::cout << "camera : v0 : " << m_cam.get_v0() << std::endl;
358 
359  if (!px_node)
360  std::cout << "camera : px : " << m_cam.get_px() << " (default)" << std::endl;
361  else
362  std::cout << "camera : px : " << m_cam.get_px() << std::endl;
363 
364  if (!py_node)
365  std::cout << "camera : py : " << m_cam.get_py() << " (default)" << std::endl;
366  else
367  std::cout << "camera : py : " << m_cam.get_py() << std::endl;
368 }
369 
378 void vpMbtXmlGenericParser::read_depth_normal(xmlDocPtr doc, xmlNodePtr node)
379 {
380  bool feature_estimation_method_node = false;
381  bool PCL_plane_estimation_node = false;
382  bool sampling_step_node = false;
383 
384  for (xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
385  if (dataNode->type == XML_ELEMENT_NODE) {
386  std::map<std::string, int>::const_iterator iter_data = nodeMap.find((char *)dataNode->name);
387  if (iter_data != nodeMap.end()) {
388  switch (iter_data->second) {
392  feature_estimation_method_node = true;
393  break;
394 
396  read_depth_normal_PCL(doc, dataNode);
397  PCL_plane_estimation_node = true;
398  break;
399 
400  case depth_sampling_step:
401  read_depth_normal_sampling_step(doc, dataNode);
402  sampling_step_node = true;
403  break;
404 
405  default:
406  break;
407  }
408  }
409  }
410  }
411 
412  if (!feature_estimation_method_node)
413  std::cout << "depth normal : feature_estimation_method : " << m_depthNormalFeatureEstimationMethod << " (default)"
414  << std::endl;
415  else
416  std::cout << "depth normal : feature_estimation_method : " << m_depthNormalFeatureEstimationMethod << std::endl;
417 
418  if (!PCL_plane_estimation_node) {
419  std::cout << "depth normal : PCL_plane_estimation : method : " << m_depthNormalPclPlaneEstimationMethod
420  << " (default)" << std::endl;
421  std::cout << "depth normal : PCL_plane_estimation : max_iter : " << m_depthNormalPclPlaneEstimationRansacMaxIter
422  << " (default)" << std::endl;
423  std::cout << "depth normal : PCL_plane_estimation : ransac_threshold : "
424  << m_depthNormalPclPlaneEstimationRansacThreshold << " (default)" << std::endl;
425  }
426 
427  if (!sampling_step_node) {
428  std::cout << "depth normal : sampling_step : step_X " << m_depthNormalSamplingStepX << " (default)" << std::endl;
429  std::cout << "depth normal : sampling_step : step_Y " << m_depthNormalSamplingStepY << " (default)" << std::endl;
430  }
431 }
432 
441 void vpMbtXmlGenericParser::read_depth_normal_PCL(xmlDocPtr doc, xmlNodePtr node)
442 {
443  bool PCL_plane_estimation_method_node = false;
444  bool PCL_plane_estimation_ransac_max_iter_node = false;
445  bool PCL_plane_estimation_ransac_threshold_node = false;
446 
447  for (xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
448  if (dataNode->type == XML_ELEMENT_NODE) {
449  std::map<std::string, int>::const_iterator iter_data = nodeMap.find((char *)dataNode->name);
450  if (iter_data != nodeMap.end()) {
451  switch (iter_data->second) {
454  PCL_plane_estimation_method_node = true;
455  break;
456 
459  PCL_plane_estimation_ransac_max_iter_node = true;
460  break;
461 
464  PCL_plane_estimation_ransac_threshold_node = true;
465  break;
466 
467  default:
468  break;
469  }
470  }
471  }
472  }
473 
474  if (!PCL_plane_estimation_method_node)
475  std::cout << "depth normal : PCL_plane_estimation : method : " << m_depthNormalPclPlaneEstimationMethod
476  << " (default)" << std::endl;
477  else
478  std::cout << "depth normal : PCL_plane_estimation : method : " << m_depthNormalPclPlaneEstimationMethod
479  << std::endl;
480 
481  if (!PCL_plane_estimation_ransac_max_iter_node)
482  std::cout << "depth normal : PCL_plane_estimation : max_iter : " << m_depthNormalPclPlaneEstimationRansacMaxIter
483  << " (default)" << std::endl;
484  else
485  std::cout << "depth normal : PCL_plane_estimation : max_iter : " << m_depthNormalPclPlaneEstimationRansacMaxIter
486  << std::endl;
487 
488  if (!PCL_plane_estimation_ransac_threshold_node)
489  std::cout << "depth normal : PCL_plane_estimation : ransac_threshold : "
490  << m_depthNormalPclPlaneEstimationRansacThreshold << " (default)" << std::endl;
491  else
492  std::cout << "depth normal : PCL_plane_estimation : ransac_threshold : "
494 }
495 
504 void vpMbtXmlGenericParser::read_depth_normal_sampling_step(xmlDocPtr doc, xmlNodePtr node)
505 {
506  bool sampling_step_X_node = false;
507  bool sampling_step_Y_node = false;
508 
509  for (xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
510  if (dataNode->type == XML_ELEMENT_NODE) {
511  std::map<std::string, int>::const_iterator iter_data = nodeMap.find((char *)dataNode->name);
512  if (iter_data != nodeMap.end()) {
513  switch (iter_data->second) {
516  sampling_step_X_node = true;
517  break;
518 
521  sampling_step_Y_node = true;
522  break;
523 
524  default:
525  break;
526  }
527  }
528  }
529  }
530 
531  if (!sampling_step_X_node)
532  std::cout << "depth normal : sampling_step : step_X : " << m_depthNormalSamplingStepX << " (default)" << std::endl;
533  else
534  std::cout << "depth normal : sampling_step : step_X : " << m_depthNormalSamplingStepX << std::endl;
535 
536  if (!sampling_step_Y_node)
537  std::cout << "depth normal : sampling_step : step_Y : " << m_depthNormalSamplingStepY << " (default)" << std::endl;
538  else
539  std::cout << "depth normal : sampling_step : step_Y : " << m_depthNormalSamplingStepY << std::endl;
540 }
541 
550 void vpMbtXmlGenericParser::read_depth_dense(xmlDocPtr doc, xmlNodePtr node)
551 {
552  bool sampling_step_node = false;
553 
554  for (xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
555  if (dataNode->type == XML_ELEMENT_NODE) {
556  std::map<std::string, int>::const_iterator iter_data = nodeMap.find((char *)dataNode->name);
557  if (iter_data != nodeMap.end()) {
558  switch (iter_data->second) {
560  read_depth_dense_sampling_step(doc, dataNode);
561  sampling_step_node = true;
562  break;
563 
564  default:
565  break;
566  }
567  }
568  }
569  }
570 
571  if (!sampling_step_node) {
572  std::cout << "depth dense : sampling_step : step_X " << m_depthDenseSamplingStepX << " (default)" << std::endl;
573  std::cout << "depth dense : sampling_step : step_Y " << m_depthDenseSamplingStepY << " (default)" << std::endl;
574  }
575 }
576 
585 void vpMbtXmlGenericParser::read_depth_dense_sampling_step(xmlDocPtr doc, xmlNodePtr node)
586 {
587  bool sampling_step_X_node = false;
588  bool sampling_step_Y_node = false;
589 
590  for (xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
591  if (dataNode->type == XML_ELEMENT_NODE) {
592  std::map<std::string, int>::const_iterator iter_data = nodeMap.find((char *)dataNode->name);
593  if (iter_data != nodeMap.end()) {
594  switch (iter_data->second) {
597  sampling_step_X_node = true;
598  break;
599 
602  sampling_step_Y_node = true;
603  break;
604 
605  default:
606  break;
607  }
608  }
609  }
610  }
611 
612  if (!sampling_step_X_node)
613  std::cout << "depth dense : sampling_step : step_X : " << m_depthDenseSamplingStepX << " (default)" << std::endl;
614  else
615  std::cout << "depth dense : sampling_step : step_X : " << m_depthDenseSamplingStepX << std::endl;
616 
617  if (!sampling_step_Y_node)
618  std::cout << "depth dense : sampling_step : step_Y : " << m_depthDenseSamplingStepY << " (default)" << std::endl;
619  else
620  std::cout << "depth dense : sampling_step : step_Y : " << m_depthDenseSamplingStepY << std::endl;
621 }
622 
631 void vpMbtXmlGenericParser::read_ecm(xmlDocPtr doc, xmlNodePtr node)
632 {
633  bool mask_node = false;
634  bool range_node = false;
635  bool contrast_node = false;
636  bool sample_node = false;
637 
638  for (xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
639  if (dataNode->type == XML_ELEMENT_NODE) {
640  std::map<std::string, int>::const_iterator iter_data = nodeMap.find((char *)dataNode->name);
641  if (iter_data != nodeMap.end()) {
642  switch (iter_data->second) {
643  case mask:
644  read_ecm_mask(doc, dataNode);
645  mask_node = true;
646  break;
647 
648  case range:
649  read_ecm_range(doc, dataNode);
650  range_node = true;
651  break;
652 
653  case contrast:
654  read_ecm_contrast(doc, dataNode);
655  contrast_node = true;
656  break;
657 
658  case sample:
659  read_ecm_sample(doc, dataNode);
660  sample_node = true;
661  break;
662 
663  default:
664  break;
665  }
666  }
667  }
668  }
669 
670  if (!mask_node) {
671  std::cout << "ecm : mask : size : " << m_ecm.getMaskSize() << " (default)" << std::endl;
672  std::cout << "ecm : mask : nb_mask : " << m_ecm.getMaskNumber() << " (default)" << std::endl;
673  }
674 
675  if (!range_node) {
676  std::cout << "ecm : range : tracking : " << m_ecm.getRange() << " (default)" << std::endl;
677  }
678 
679  if (!contrast_node) {
680  std::cout << "ecm : contrast : threshold " << m_ecm.getThreshold() << " (default)" << std::endl;
681  std::cout << "ecm : contrast : mu1 " << m_ecm.getMu1() << " (default)" << std::endl;
682  std::cout << "ecm : contrast : mu2 " << m_ecm.getMu2() << " (default)" << std::endl;
683  }
684 
685  if (!sample_node) {
686  std::cout << "ecm : sample : sample_step : " << m_ecm.getSampleStep() << " (default)" << std::endl;
687  }
688 }
689 
698 void vpMbtXmlGenericParser::read_ecm_contrast(xmlDocPtr doc, xmlNodePtr node)
699 {
700  bool edge_threshold_node = false;
701  bool mu1_node = false;
702  bool mu2_node = false;
703 
704  // current data values.
705  double d_edge_threshold = m_ecm.getThreshold();
706  double d_mu1 = m_ecm.getMu1();
707  double d_mu2 = m_ecm.getMu2();
708 
709  for (xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
710  if (dataNode->type == XML_ELEMENT_NODE) {
711  std::map<std::string, int>::const_iterator iter_data = nodeMap.find((char *)dataNode->name);
712  if (iter_data != nodeMap.end()) {
713  switch (iter_data->second) {
714  case edge_threshold:
715  d_edge_threshold = xmlReadDoubleChild(doc, dataNode);
716  edge_threshold_node = true;
717  break;
718 
719  case mu1:
720  d_mu1 = xmlReadDoubleChild(doc, dataNode);
721  mu1_node = true;
722  break;
723 
724  case mu2:
725  d_mu2 = xmlReadDoubleChild(doc, dataNode);
726  mu2_node = true;
727  break;
728 
729  default:
730  break;
731  }
732  }
733  }
734  }
735 
736  m_ecm.setMu1(d_mu1);
737  m_ecm.setMu2(d_mu2);
738  m_ecm.setThreshold(d_edge_threshold);
739 
740  if (!edge_threshold_node)
741  std::cout << "ecm : contrast : threshold " << m_ecm.getThreshold() << " (default)" << std::endl;
742  else
743  std::cout << "ecm : contrast : threshold " << m_ecm.getThreshold() << std::endl;
744 
745  if (!mu1_node)
746  std::cout << "ecm : contrast : mu1 " << m_ecm.getMu1() << " (default)" << std::endl;
747  else
748  std::cout << "ecm : contrast : mu1 " << m_ecm.getMu1() << std::endl;
749 
750  if (!mu2_node)
751  std::cout << "ecm : contrast : mu2 " << m_ecm.getMu2() << " (default)" << std::endl;
752  else
753  std::cout << "ecm : contrast : mu2 " << m_ecm.getMu2() << std::endl;
754 }
755 
764 void vpMbtXmlGenericParser::read_ecm_mask(xmlDocPtr doc, xmlNodePtr node)
765 {
766  bool size_node = false;
767  bool nb_mask_node = false;
768 
769  // current data values.
770  unsigned int d_size = m_ecm.getMaskSize();
771  unsigned int d_nb_mask = m_ecm.getMaskNumber();
772 
773  for (xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
774  if (dataNode->type == XML_ELEMENT_NODE) {
775  std::map<std::string, int>::const_iterator iter_data = nodeMap.find((char *)dataNode->name);
776  if (iter_data != nodeMap.end()) {
777  switch (iter_data->second) {
778  case size:
779  d_size = xmlReadUnsignedIntChild(doc, dataNode);
780  size_node = true;
781  break;
782 
783  case nb_mask:
784  d_nb_mask = xmlReadUnsignedIntChild(doc, dataNode);
785  nb_mask_node = true;
786  break;
787 
788  default:
789  break;
790  }
791  }
792  }
793  }
794 
795  m_ecm.setMaskSize(d_size);
796 
797  // Check to ensure that d_nb_mask > 0
798  if (d_nb_mask == 0)
799  throw(vpException(vpException::badValue, "Model-based tracker mask size "
800  "parameter should be different "
801  "from zero in xml file"));
802  m_ecm.setMaskNumber(d_nb_mask);
803 
804  if (!size_node)
805  std::cout << "ecm : mask : size : " << m_ecm.getMaskSize() << " (default)" << std::endl;
806  else
807  std::cout << "ecm : mask : size : " << m_ecm.getMaskSize() << std::endl;
808 
809  if (!nb_mask_node)
810  std::cout << "ecm : mask : nb_mask : " << m_ecm.getMaskNumber() << " (default)" << std::endl;
811  else
812  std::cout << "ecm : mask : nb_mask : " << m_ecm.getMaskNumber() << std::endl;
813 }
814 
823 void vpMbtXmlGenericParser::read_ecm_range(xmlDocPtr doc, xmlNodePtr node)
824 {
825  bool tracking_node = false;
826 
827  // current data values.
828  unsigned int m_range_tracking = m_ecm.getRange();
829 
830  for (xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
831  if (dataNode->type == XML_ELEMENT_NODE) {
832  std::map<std::string, int>::const_iterator iter_data = nodeMap.find((char *)dataNode->name);
833  if (iter_data != nodeMap.end()) {
834  switch (iter_data->second) {
835  case tracking:
836  m_range_tracking = xmlReadUnsignedIntChild(doc, dataNode);
837  tracking_node = true;
838  break;
839 
840  default:
841  break;
842  }
843  }
844  }
845  }
846 
847  m_ecm.setRange(m_range_tracking);
848 
849  if (!tracking_node)
850  std::cout << "ecm : range : tracking : " << m_ecm.getRange() << " (default)" << std::endl;
851  else
852  std::cout << "ecm : range : tracking : " << m_ecm.getRange() << std::endl;
853 }
854 
863 void vpMbtXmlGenericParser::read_ecm_sample(xmlDocPtr doc, xmlNodePtr node)
864 {
865  bool step_node = false;
866 
867  // current data values.
868  double d_stp = m_ecm.getSampleStep();
869 
870  for (xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
871  if (dataNode->type == XML_ELEMENT_NODE) {
872  std::map<std::string, int>::const_iterator iter_data = nodeMap.find((char *)dataNode->name);
873  if (iter_data != nodeMap.end()) {
874  switch (iter_data->second) {
875  case step:
876  d_stp = xmlReadIntChild(doc, dataNode);
877  step_node = true;
878  break;
879 
880  default:
881  break;
882  }
883  }
884  }
885  }
886 
887  m_ecm.setSampleStep(d_stp);
888 
889  if (!step_node)
890  std::cout << "ecm : sample : sample_step : " << m_ecm.getSampleStep() << " (default)" << std::endl;
891  else
892  std::cout << "ecm : sample : sample_step : " << m_ecm.getSampleStep() << std::endl;
893 }
894 
903 void vpMbtXmlGenericParser::read_face(xmlDocPtr doc, xmlNodePtr node)
904 {
905  bool angle_appear_node = false;
906  bool angle_disappear_node = false;
907  bool near_clipping_node = false;
908  bool far_clipping_node = false;
909  bool fov_clipping_node = false;
910  m_hasNearClipping = false;
911  m_hasFarClipping = false;
912 
913  for (xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
914  if (dataNode->type == XML_ELEMENT_NODE) {
915  std::map<std::string, int>::const_iterator iter_data = nodeMap.find((char *)dataNode->name);
916  if (iter_data != nodeMap.end()) {
917  switch (iter_data->second) {
918  case angle_appear:
919  m_angleAppear = xmlReadDoubleChild(doc, dataNode);
920  angle_appear_node = true;
921  break;
922 
923  case angle_disappear:
924  m_angleDisappear = xmlReadDoubleChild(doc, dataNode);
925  angle_disappear_node = true;
926  break;
927 
928  case near_clipping:
929  m_nearClipping = xmlReadDoubleChild(doc, dataNode);
930  m_hasNearClipping = true;
931  near_clipping_node = true;
932  break;
933 
934  case far_clipping:
935  m_farClipping = xmlReadDoubleChild(doc, dataNode);
936  m_hasFarClipping = true;
937  far_clipping_node = true;
938  break;
939 
940  case fov_clipping:
941  if (xmlReadIntChild(doc, dataNode))
942  m_fovClipping = true;
943  else
944  m_fovClipping = false;
945  fov_clipping_node = true;
946  break;
947 
948  default:
949  break;
950  }
951  }
952  }
953  }
954 
955  if (!angle_appear_node)
956  std::cout << "face : Angle Appear : " << m_angleAppear << " (default)" << std::endl;
957  else
958  std::cout << "face : Angle Appear : " << m_angleAppear << std::endl;
959 
960  if (!angle_disappear_node)
961  std::cout << "face : Angle Disappear : " << m_angleDisappear << " (default)" << std::endl;
962  else
963  std::cout << "face : Angle Disappear : " << m_angleDisappear << std::endl;
964 
965  if (near_clipping_node)
966  std::cout << "face : Near Clipping : " << m_nearClipping << std::endl;
967 
968  if (far_clipping_node)
969  std::cout << "face : Far Clipping : " << m_farClipping << std::endl;
970 
971  if (fov_clipping_node) {
972  if (m_fovClipping)
973  std::cout << "face : Fov Clipping : True" << std::endl;
974  else
975  std::cout << "face : Fov Clipping : False" << std::endl;
976  }
977 }
978 
987 void vpMbtXmlGenericParser::read_klt(xmlDocPtr doc, xmlNodePtr node)
988 {
989  bool mask_border_node = false;
990  bool max_features_node = false;
991  bool window_size_node = false;
992  bool quality_node = false;
993  bool min_distance_node = false;
994  bool harris_node = false;
995  bool size_block_node = false;
996  bool pyramid_lvl_node = false;
997 
998  for (xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
999  if (dataNode->type == XML_ELEMENT_NODE) {
1000  std::map<std::string, int>::const_iterator iter_data = nodeMap.find((char *)dataNode->name);
1001  if (iter_data != nodeMap.end()) {
1002  switch (iter_data->second) {
1003  case mask_border:
1004  m_kltMaskBorder = xmlReadUnsignedIntChild(doc, dataNode);
1005  mask_border_node = true;
1006  break;
1007 
1008  case max_features:
1009  m_kltMaxFeatures = xmlReadUnsignedIntChild(doc, dataNode);
1010  max_features_node = true;
1011  break;
1012 
1013  case window_size:
1014  m_kltWinSize = xmlReadUnsignedIntChild(doc, dataNode);
1015  window_size_node = true;
1016  break;
1017 
1018  case quality:
1019  m_kltQualityValue = xmlReadDoubleChild(doc, dataNode);
1020  quality_node = true;
1021  break;
1022 
1023  case min_distance:
1024  m_kltMinDist = xmlReadDoubleChild(doc, dataNode);
1025  min_distance_node = true;
1026  break;
1027 
1028  case harris:
1029  m_kltHarrisParam = xmlReadDoubleChild(doc, dataNode);
1030  harris_node = true;
1031  break;
1032 
1033  case size_block:
1034  m_kltBlockSize = xmlReadUnsignedIntChild(doc, dataNode);
1035  size_block_node = true;
1036  break;
1037 
1038  case pyramid_lvl:
1040  pyramid_lvl_node = true;
1041  break;
1042 
1043  default:
1044  break;
1045  }
1046  }
1047  }
1048  }
1049 
1050  if (!mask_border_node)
1051  std::cout << "klt : Mask Border : " << m_kltMaskBorder << " (default)" << std::endl;
1052  else
1053  std::cout << "klt : Mask Border : " << m_kltMaskBorder << std::endl;
1054 
1055  if (!max_features_node)
1056  std::cout << "klt : Max Features : " << m_kltMaxFeatures << " (default)" << std::endl;
1057  else
1058  std::cout << "klt : Max Features : " << m_kltMaxFeatures << std::endl;
1059 
1060  if (!window_size_node)
1061  std::cout << "klt : Windows Size : " << m_kltWinSize << " (default)" << std::endl;
1062  else
1063  std::cout << "klt : Windows Size : " << m_kltWinSize << std::endl;
1064 
1065  if (!quality_node)
1066  std::cout << "klt : Quality : " << m_kltQualityValue << " (default)" << std::endl;
1067  else
1068  std::cout << "klt : Quality : " << m_kltQualityValue << std::endl;
1069 
1070  if (!min_distance_node)
1071  std::cout << "klt : Min Distance : " << m_kltMinDist << " (default)" << std::endl;
1072  else
1073  std::cout << "klt : Min Distance : " << m_kltMinDist << std::endl;
1074 
1075  if (!harris_node)
1076  std::cout << "klt : Harris Parameter : " << m_kltHarrisParam << " (default)" << std::endl;
1077  else
1078  std::cout << "klt : Harris Parameter : " << m_kltHarrisParam << std::endl;
1079 
1080  if (!size_block_node)
1081  std::cout << "klt : Block Size : " << m_kltBlockSize << " (default)" << std::endl;
1082  else
1083  std::cout << "klt : Block Size : " << m_kltBlockSize << std::endl;
1084 
1085  if (!pyramid_lvl_node)
1086  std::cout << "klt : Pyramid Levels : " << m_kltPyramidLevels << " (default)" << std::endl;
1087  else
1088  std::cout << "klt : Pyramid Levels : " << m_kltPyramidLevels << std::endl;
1089 }
1090 
1091 void vpMbtXmlGenericParser::read_lod(xmlDocPtr doc, xmlNodePtr node)
1092 {
1093  bool use_lod_node = false;
1094  bool min_line_length_threshold_node = false;
1095  bool min_polygon_area_threshold_node = false;
1096 
1097  for (xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
1098  if (dataNode->type == XML_ELEMENT_NODE) {
1099  std::map<std::string, int>::const_iterator iter_data = nodeMap.find((char *)dataNode->name);
1100  if (iter_data != nodeMap.end()) {
1101  switch (iter_data->second) {
1102  case use_lod:
1103  m_useLod = (xmlReadIntChild(doc, dataNode) != 0);
1104  use_lod_node = true;
1105  break;
1106 
1109  min_line_length_threshold_node = true;
1110  break;
1111 
1114  min_polygon_area_threshold_node = true;
1115  break;
1116 
1117  default:
1118  break;
1119  }
1120  }
1121  }
1122  }
1123 
1124  if (!use_lod_node)
1125  std::cout << "lod : use lod : " << m_useLod << " (default)" << std::endl;
1126  else
1127  std::cout << "lod : use lod : " << m_useLod << std::endl;
1128 
1129  if (!min_line_length_threshold_node)
1130  std::cout << "lod : min line length threshold : " << m_minLineLengthThreshold << " (default)" << std::endl;
1131  else
1132  std::cout << "lod : min line length threshold : " << m_minLineLengthThreshold << std::endl;
1133 
1134  if (!min_polygon_area_threshold_node)
1135  std::cout << "lod : min polygon area threshold : " << m_minPolygonAreaThreshold << " (default)" << std::endl;
1136  else
1137  std::cout << "lod : min polygon area threshold : " << m_minPolygonAreaThreshold << std::endl;
1138 }
1139 
1148 void vpMbtXmlGenericParser::read_sample_deprecated(xmlDocPtr doc, xmlNodePtr node)
1149 {
1150  bool step_node = false;
1151  // bool nb_sample_node = false;
1152 
1153  // current data values.
1154  double d_stp = m_ecm.getSampleStep();
1155 
1156  for (xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
1157  if (dataNode->type == XML_ELEMENT_NODE) {
1158  std::map<std::string, int>::const_iterator iter_data = nodeMap.find((char *)dataNode->name);
1159  if (iter_data != nodeMap.end()) {
1160  switch (iter_data->second) {
1161  case step:
1162  d_stp = xmlReadIntChild(doc, dataNode);
1163  step_node = true;
1164  break;
1165 
1166  default:
1167  break;
1168  }
1169  }
1170  }
1171  }
1172 
1173  m_ecm.setSampleStep(d_stp);
1174 
1175  if (!step_node)
1176  std::cout << "[DEPRECATED] sample : sample_step : " << m_ecm.getSampleStep() << " (default)" << std::endl;
1177  else
1178  std::cout << "[DEPRECATED] sample : sample_step : " << m_ecm.getSampleStep() << std::endl;
1179 
1180  std::cout << " WARNING : This node (sample) is deprecated." << std::endl;
1181  std::cout << " It should be moved in the ecm node (ecm : sample)." << std::endl;
1182 }
1183 
1184 #elif !defined(VISP_BUILD_SHARED_LIBS)
1185 // Work arround to avoid warning: libvisp_mbt.a(vpMbtXmlGenericParser.cpp.o)
1186 // has no symbols
1187 void dummy_vpMbtXmlGenericParser(){};
1188 #endif
unsigned int m_kltWinSize
Windows size.
unsigned int m_depthDenseSamplingStepX
Sampling step in X.
bool m_hasNearClipping
Is near clipping distance specified?
double m_minLineLengthThreshold
Minimum line length to track a segment when LOD is enabled.
void read_klt(xmlDocPtr doc, xmlNodePtr node)
void setMainTag(const std::string &tag)
Definition: vpXmlParser.h:295
void parse(const std::string &filename)
virtual void readMainClass(xmlDocPtr doc, xmlNodePtr node)
void setMaskNumber(const unsigned int &a)
Definition: vpMe.cpp:454
int m_depthNormalPclPlaneEstimationMethod
PCL plane estimation method.
void read_depth_normal_sampling_step(xmlDocPtr doc, xmlNodePtr node)
double m_angleDisappear
Angle to determine if a face disappeared.
void setSampleStep(const double &s)
Definition: vpMe.h:278
error that can be emited by ViSP classes.
Definition: vpException.h:71
bool m_useLod
If true, the LOD is enabled, otherwise it is not.
double xmlReadDoubleChild(xmlDocPtr doc, xmlNodePtr node)
double m_nearClipping
Near clipping distance.
unsigned int m_depthDenseSamplingStepY
Sampling step in Y.
void writeMainClass(xmlNodePtr node)
unsigned int getMaskSize() const
Definition: vpMe.h:142
void read_lod(xmlDocPtr doc, xmlNodePtr node)
void setMu1(const double &mu_1)
Definition: vpMe.h:241
void read_depth_normal_PCL(xmlDocPtr doc, xmlNodePtr node)
double getMu1() const
Definition: vpMe.h:155
unsigned int m_kltBlockSize
Block size.
int m_depthNormalPclPlaneEstimationRansacMaxIter
PCL RANSAC maximum number of iterations.
void initPersProjWithoutDistortion(const double px, const double py, const double u0, const double v0)
void read_ecm_range(xmlDocPtr doc, xmlNodePtr node)
double m_kltMinDist
Minimum distance between klt points.
unsigned int m_depthNormalSamplingStepX
Sampling step in X.
void read_camera(xmlDocPtr doc, xmlNodePtr node)
void read_ecm_sample(xmlDocPtr doc, xmlNodePtr node)
unsigned int m_depthNormalSamplingStepY
Sampling step in Y.
double getThreshold() const
Definition: vpMe.h:193
void setMaskSize(const unsigned int &a)
Definition: vpMe.cpp:461
double getSampleStep() const
Definition: vpMe.h:285
double m_kltQualityValue
Quality of the Klt points.
void read_depth_dense_sampling_step(xmlDocPtr doc, xmlNodePtr node)
bool m_fovClipping
Fov Clipping.
vpMbtFaceDepthNormal::vpFeatureEstimationType m_depthNormalFeatureEstimationMethod
Feature estimation method.
int xmlReadIntChild(xmlDocPtr doc, xmlNodePtr node)
unsigned int getMaskNumber() const
Definition: vpMe.h:128
vpCameraParameters m_cam
Camera parameters.
double m_farClipping
Near clipping distance.
double m_minPolygonAreaThreshold
Minimum polygon area to track a face when LOD is enabled.
double m_depthNormalPclPlaneEstimationRansacThreshold
PCL RANSAC threshold.
vpParserType m_parserType
Parser type.
unsigned int xmlReadUnsignedIntChild(xmlDocPtr doc, xmlNodePtr node)
void setMu2(const double &mu_2)
Definition: vpMe.h:248
unsigned int m_kltMaskBorder
Border of the mask used on Klt points.
vpMbtXmlGenericParser(const vpParserType &type=EDGE_PARSER)
void setThreshold(const double &t)
Definition: vpMe.h:300
double getMu2() const
Definition: vpMe.h:161
unsigned int m_kltPyramidLevels
Number of pyramid levels.
void read_ecm(xmlDocPtr doc, xmlNodePtr node)
void read_sample_deprecated(xmlDocPtr doc, xmlNodePtr node)
double m_kltHarrisParam
Harris free parameters.
void read_ecm_contrast(xmlDocPtr doc, xmlNodePtr node)
void setRange(const unsigned int &r)
Definition: vpMe.h:271
void read_ecm_mask(xmlDocPtr doc, xmlNodePtr node)
unsigned int m_kltMaxFeatures
Maximum of Klt features.
void read_depth_normal(xmlDocPtr doc, xmlNodePtr node)
double m_angleAppear
Angle to determine if a face appeared.
vpMe m_ecm
Moving edges parameters.
std::map< std::string, int > nodeMap
Definition: vpXmlParser.h:226
unsigned int getRange() const
Definition: vpMe.h:179
bool m_hasFarClipping
Is far clipping distance specified?
void read_face(xmlDocPtr doc, xmlNodePtr node)
void read_depth_dense(xmlDocPtr doc, xmlNodePtr node)
void parse(const std::string &filename)