Visual Servoing Platform  version 3.1.0
vpMbtFaceDepthDense.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  * Manage depth dense features for a particular face.
33  *
34  *****************************************************************************/
35 
36 #include <visp3/core/vpCPUFeatures.h>
37 #include <visp3/mbt/vpMbtFaceDepthDense.h>
38 
39 #if defined __SSE2__ || defined _M_X64 || (defined _M_IX86_FP && _M_IX86_FP >= 2)
40 #include <emmintrin.h>
41 #define VISP_HAVE_SSE2 1
42 #endif
43 
44 #define USE_SSE_CODE 1
45 #if VISP_HAVE_SSE2 && USE_SSE_CODE
46 #define USE_SSE 1
47 #else
48 #define USE_SSE 0
49 #endif
50 
52  : m_cam(), m_clippingFlag(vpPolygon3D::NO_CLIPPING), m_distFarClip(100), m_distNearClip(0.001), m_hiddenFace(NULL),
53  m_planeObject(), m_polygon(NULL), m_useScanLine(false),
54  m_depthDenseFilteringMethod(DEPTH_OCCUPANCY_RATIO_FILTERING), m_depthDenseFilteringMaxDist(3.0),
55  m_depthDenseFilteringMinDist(0.8), m_depthDenseFilteringOccupancyRatio(0.3), m_isTracked(false), m_isVisible(false),
56  m_listOfFaceLines(), m_planeCamera(), m_pointCloudFace(), m_polygonLines()
57 {
58 }
59 
61 {
62  for (size_t i = 0; i < m_listOfFaceLines.size(); i++) {
63  delete m_listOfFaceLines[i];
64  }
65 }
66 
81  std::string name)
82 {
83  // Build a PolygonLine to be able to easily display the lines model
84  PolygonLine polygon_line;
85 
86  // Add polygon
87  polygon_line.m_poly.setNbPoint(2);
88  polygon_line.m_poly.addPoint(0, P1);
89  polygon_line.m_poly.addPoint(1, P2);
90 
91  polygon_line.m_poly.setClipping(m_clippingFlag);
92  polygon_line.m_poly.setNearClippingDistance(m_distNearClip);
93  polygon_line.m_poly.setFarClippingDistance(m_distFarClip);
94 
95  polygon_line.m_p1 = &polygon_line.m_poly.p[0];
96  polygon_line.m_p2 = &polygon_line.m_poly.p[1];
97 
98  m_polygonLines.push_back(polygon_line);
99 
100  // suppress line already in the model
101  bool already_here = false;
103 
104  for (std::vector<vpMbtDistanceLine *>::const_iterator it = m_listOfFaceLines.begin(); it != m_listOfFaceLines.end();
105  ++it) {
106  l = *it;
107  if ((samePoint(*(l->p1), P1) && samePoint(*(l->p2), P2)) || (samePoint(*(l->p1), P2) && samePoint(*(l->p2), P1))) {
108  already_here = true;
109  l->addPolygon(polygon);
110  l->hiddenface = faces;
112  }
113  }
114 
115  if (!already_here) {
116  l = new vpMbtDistanceLine;
117 
119  l->buildFrom(P1, P2);
120  l->addPolygon(polygon);
121  l->hiddenface = faces;
123 
124  l->setIndex((unsigned int)m_listOfFaceLines.size());
125  l->setName(name);
126 
129 
130  if ((m_clippingFlag & vpPolygon3D::NEAR_CLIPPING) == vpPolygon3D::NEAR_CLIPPING)
132 
133  if ((m_clippingFlag & vpPolygon3D::FAR_CLIPPING) == vpPolygon3D::FAR_CLIPPING)
135 
136  m_listOfFaceLines.push_back(l);
137  }
138 }
139 
140 #ifdef VISP_HAVE_PCL
142  const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &point_cloud,
143  const unsigned int stepX, const unsigned int stepY
144 #if DEBUG_DISPLAY_DEPTH_DENSE
145  ,
146  vpImage<unsigned char> &debugImage,
147  std::vector<std::vector<vpImagePoint> > &roiPts_vec
148 #endif
149 )
150 {
151  unsigned int width = point_cloud->width, height = point_cloud->height;
152  m_pointCloudFace.clear();
153 
154  if (point_cloud->width == 0 || point_cloud->height == 0)
155  return false;
156 
157  std::vector<vpImagePoint> roiPts;
158  double distanceToFace;
159  computeROI(cMo, width, height, roiPts
160 #if DEBUG_DISPLAY_DEPTH_DENSE
161  ,
162  roiPts_vec
163 #endif
164  ,
165  distanceToFace);
166 
167  if (roiPts.size() <= 2) {
168 #ifndef NDEBUG
169  std::cerr << "Error: roiPts.size() <= 2 in computeDesiredFeatures" << std::endl;
170 #endif
171  return false;
172  }
173 
176  return false;
177  }
178 
179  vpPolygon polygon_2d(roiPts);
180  vpRect bb = polygon_2d.getBoundingBox();
181 
182  unsigned int top = (unsigned int)std::max(0.0, bb.getTop());
183  unsigned int bottom = (unsigned int)std::min((double)height, std::max(0.0, bb.getBottom()));
184  unsigned int left = (unsigned int)std::max(0.0, bb.getLeft());
185  unsigned int right = (unsigned int)std::min((double)width, std::max(0.0, bb.getRight()));
186 
187  bb.setTop(top);
188  bb.setBottom(bottom);
189  bb.setLeft(left);
190  bb.setRight(right);
191 
192  if (bb.getHeight() < 0 || bb.getWidth() < 0) {
193  return false;
194  }
195 
196  m_pointCloudFace.reserve((size_t)(bb.getWidth() * bb.getHeight()));
197 
198  bool checkSSE2 = vpCPUFeatures::checkSSE2();
199 #if !USE_SSE
200  checkSSE2 = false;
201 #else
202  bool push = false;
203  double prev_x = 0.0, prev_y = 0.0, prev_z = 0.0;
204 #endif
205 
206  int totalTheoreticalPoints = 0, totalPoints = 0;
207  for (unsigned int i = top; i < bottom; i += stepY) {
208  for (unsigned int j = left; j < right; j += stepX) {
209  if ((m_useScanLine ? (i < m_hiddenFace->getMbScanLineRenderer().getPrimitiveIDs().getHeight() &&
210  j < m_hiddenFace->getMbScanLineRenderer().getPrimitiveIDs().getWidth() &&
211  m_hiddenFace->getMbScanLineRenderer().getPrimitiveIDs()[i][j] == m_polygon->getIndex())
212  : polygon_2d.isInside(vpImagePoint(i, j)))) {
213  totalTheoreticalPoints++;
214 
215  if (pcl::isFinite((*point_cloud)(j, i)) && (*point_cloud)(j, i).z > 0) {
216  totalPoints++;
217 
218  if (checkSSE2) {
219 #if USE_SSE
220  if (!push) {
221  push = true;
222  prev_x = (*point_cloud)(j, i).x;
223  prev_y = (*point_cloud)(j, i).y;
224  prev_z = (*point_cloud)(j, i).z;
225  } else {
226  push = false;
227  m_pointCloudFace.push_back(prev_x);
228  m_pointCloudFace.push_back((*point_cloud)(j, i).x);
229 
230  m_pointCloudFace.push_back(prev_y);
231  m_pointCloudFace.push_back((*point_cloud)(j, i).y);
232 
233  m_pointCloudFace.push_back(prev_z);
234  m_pointCloudFace.push_back((*point_cloud)(j, i).z);
235  }
236 #endif
237  } else {
238  m_pointCloudFace.push_back((*point_cloud)(j, i).x);
239  m_pointCloudFace.push_back((*point_cloud)(j, i).y);
240  m_pointCloudFace.push_back((*point_cloud)(j, i).z);
241  }
242 
243 #if DEBUG_DISPLAY_DEPTH_DENSE
244  debugImage[i][j] = 255;
245 #endif
246  }
247  }
248  }
249  }
250 
251 #if USE_SSE
252  if (checkSSE2 && push) {
253  m_pointCloudFace.push_back(prev_x);
254  m_pointCloudFace.push_back(prev_y);
255  m_pointCloudFace.push_back(prev_z);
256  }
257 #endif
258 
259  if (totalPoints == 0 || ((m_depthDenseFilteringMethod & DEPTH_OCCUPANCY_RATIO_FILTERING) &&
260  totalPoints / (double)totalTheoreticalPoints < m_depthDenseFilteringOccupancyRatio)) {
261  return false;
262  }
263 
264  return true;
265 }
266 #endif
267 
268 bool vpMbtFaceDepthDense::computeDesiredFeatures(const vpHomogeneousMatrix &cMo, const unsigned int width,
269  const unsigned int height, const std::vector<vpColVector> &point_cloud,
270  const unsigned int stepX, const unsigned int stepY
271 #if DEBUG_DISPLAY_DEPTH_DENSE
272  ,
273  vpImage<unsigned char> &debugImage,
274  std::vector<std::vector<vpImagePoint> > &roiPts_vec
275 #endif
276 )
277 {
278  m_pointCloudFace.clear();
279 
280  if (width == 0 || height == 0)
281  return 0;
282 
283  std::vector<vpImagePoint> roiPts;
284  double distanceToFace;
285  computeROI(cMo, width, height, roiPts
286 #if DEBUG_DISPLAY_DEPTH_DENSE
287  ,
288  roiPts_vec
289 #endif
290  ,
291  distanceToFace);
292 
293  if (roiPts.size() <= 2) {
294 #ifndef NDEBUG
295  std::cerr << "Error: roiPts.size() <= 2 in computeDesiredFeatures" << std::endl;
296 #endif
297  return false;
298  }
299 
302  return false;
303  }
304 
305  vpPolygon polygon_2d(roiPts);
306  vpRect bb = polygon_2d.getBoundingBox();
307 
308  unsigned int top = (unsigned int)std::max(0.0, bb.getTop());
309  unsigned int bottom = (unsigned int)std::min((double)height, std::max(0.0, bb.getBottom()));
310  unsigned int left = (unsigned int)std::max(0.0, bb.getLeft());
311  unsigned int right = (unsigned int)std::min((double)width, std::max(0.0, bb.getRight()));
312 
313  bb.setTop(top);
314  bb.setBottom(bottom);
315  bb.setLeft(left);
316  bb.setRight(right);
317 
318  m_pointCloudFace.reserve((size_t)(bb.getWidth() * bb.getHeight()));
319 
320  bool checkSSE2 = vpCPUFeatures::checkSSE2();
321 #if !USE_SSE
322  checkSSE2 = false;
323 #else
324  bool push = false;
325  double prev_x = 0.0, prev_y = 0.0, prev_z = 0.0;
326 #endif
327 
328  int totalTheoreticalPoints = 0, totalPoints = 0;
329  for (unsigned int i = top; i < bottom; i += stepY) {
330  for (unsigned int j = left; j < right; j += stepX) {
331  if ((m_useScanLine ? (i < m_hiddenFace->getMbScanLineRenderer().getPrimitiveIDs().getHeight() &&
332  j < m_hiddenFace->getMbScanLineRenderer().getPrimitiveIDs().getWidth() &&
333  m_hiddenFace->getMbScanLineRenderer().getPrimitiveIDs()[i][j] == m_polygon->getIndex())
334  : polygon_2d.isInside(vpImagePoint(i, j)))) {
335  totalTheoreticalPoints++;
336 
337  if (point_cloud[i * width + j][2] > 0) {
338  totalPoints++;
339 
340  if (checkSSE2) {
341 #if USE_SSE
342  if (!push) {
343  push = true;
344  prev_x = point_cloud[i * width + j][0];
345  prev_y = point_cloud[i * width + j][1];
346  prev_z = point_cloud[i * width + j][2];
347  } else {
348  push = false;
349  m_pointCloudFace.push_back(prev_x);
350  m_pointCloudFace.push_back(point_cloud[i * width + j][0]);
351 
352  m_pointCloudFace.push_back(prev_y);
353  m_pointCloudFace.push_back(point_cloud[i * width + j][1]);
354 
355  m_pointCloudFace.push_back(prev_z);
356  m_pointCloudFace.push_back(point_cloud[i * width + j][2]);
357  }
358 #endif
359  } else {
360  m_pointCloudFace.push_back(point_cloud[i * width + j][0]);
361  m_pointCloudFace.push_back(point_cloud[i * width + j][1]);
362  m_pointCloudFace.push_back(point_cloud[i * width + j][2]);
363  }
364 
365 #if DEBUG_DISPLAY_DEPTH_DENSE
366  debugImage[i][j] = 255;
367 #endif
368  }
369  }
370  }
371  }
372 
373 #if USE_SSE
374  if (checkSSE2 && push) {
375  m_pointCloudFace.push_back(prev_x);
376  m_pointCloudFace.push_back(prev_y);
377  m_pointCloudFace.push_back(prev_z);
378  }
379 #endif
380 
381  if (totalPoints == 0 || ((m_depthDenseFilteringMethod & DEPTH_OCCUPANCY_RATIO_FILTERING) &&
382  totalPoints / (double)totalTheoreticalPoints < m_depthDenseFilteringOccupancyRatio)) {
383  return false;
384  }
385 
386  return true;
387 }
388 
390 
392 {
393  // Compute lines visibility, only for display
394  vpMbtDistanceLine *line;
395  for (std::vector<vpMbtDistanceLine *>::const_iterator it = m_listOfFaceLines.begin(); it != m_listOfFaceLines.end();
396  ++it) {
397  line = *it;
398  bool isvisible = false;
399 
400  for (std::list<int>::const_iterator itindex = line->Lindex_polygon.begin(); itindex != line->Lindex_polygon.end();
401  ++itindex) {
402  int index = *itindex;
403  if (index == -1) {
404  isvisible = true;
405  } else {
406  if (line->hiddenface->isVisible((unsigned int)index)) {
407  isvisible = true;
408  }
409  }
410  }
411 
412  // Si la ligne n'appartient a aucune face elle est tout le temps visible
413  if (line->Lindex_polygon.empty())
414  isvisible = true; // Not sure that this can occur
415 
416  if (isvisible) {
417  line->setVisible(true);
418  } else {
419  line->setVisible(false);
420  }
421  }
422 }
423 
425  vpColVector &error)
426 {
427  if (m_pointCloudFace.empty()) {
428  L.resize(0, 0);
429  error.resize(0);
430  return;
431  }
432 
433  L.resize(getNbFeatures(), 6, false, false);
434  error.resize(getNbFeatures(), false);
435 
436  // Transform the plane equation for the current pose
439 
440  double nx = m_planeCamera.getA();
441  double ny = m_planeCamera.getB();
442  double nz = m_planeCamera.getC();
443  double D = m_planeCamera.getD();
444 
445  bool checkSSE2 = vpCPUFeatures::checkSSE2();
446 #if !USE_SSE
447  checkSSE2 = false;
448 #endif
449 
450  if (checkSSE2) {
451 #if USE_SSE
452  size_t cpt = 0;
453  if (getNbFeatures() >= 2) {
454  double *ptr_point_cloud = &m_pointCloudFace[0];
455  double *ptr_L = L.data;
456  double *ptr_error = error.data;
457 
458  const __m128d vnx = _mm_set1_pd(nx);
459  const __m128d vny = _mm_set1_pd(ny);
460  const __m128d vnz = _mm_set1_pd(nz);
461  const __m128d vd = _mm_set1_pd(D);
462 
463  double tmp_a1[2], tmp_a2[2], tmp_a3[2];
464 
465  for (; cpt <= m_pointCloudFace.size() - 6; cpt += 6, ptr_point_cloud += 6) {
466  const __m128d vx = _mm_loadu_pd(ptr_point_cloud);
467  const __m128d vy = _mm_loadu_pd(ptr_point_cloud + 2);
468  const __m128d vz = _mm_loadu_pd(ptr_point_cloud + 4);
469 
470  const __m128d va1 = _mm_sub_pd(_mm_mul_pd(vnz, vy), _mm_mul_pd(vny, vz));
471  const __m128d va2 = _mm_sub_pd(_mm_mul_pd(vnx, vz), _mm_mul_pd(vnz, vx));
472  const __m128d va3 = _mm_sub_pd(_mm_mul_pd(vny, vx), _mm_mul_pd(vnx, vy));
473 
474  _mm_storeu_pd(tmp_a1, va1);
475  _mm_storeu_pd(tmp_a2, va2);
476  _mm_storeu_pd(tmp_a3, va3);
477 
478  *ptr_L = nx;
479  ptr_L++;
480  *ptr_L = ny;
481  ptr_L++;
482  *ptr_L = nz;
483  ptr_L++;
484  *ptr_L = tmp_a1[0];
485  ptr_L++;
486  *ptr_L = tmp_a2[0];
487  ptr_L++;
488  *ptr_L = tmp_a3[0];
489  ptr_L++;
490 
491  *ptr_L = nx;
492  ptr_L++;
493  *ptr_L = ny;
494  ptr_L++;
495  *ptr_L = nz;
496  ptr_L++;
497  *ptr_L = tmp_a1[1];
498  ptr_L++;
499  *ptr_L = tmp_a2[1];
500  ptr_L++;
501  *ptr_L = tmp_a3[1];
502  ptr_L++;
503 
504  const __m128d verror =
505  _mm_add_pd(_mm_add_pd(vd, _mm_mul_pd(vnx, vx)), _mm_add_pd(_mm_mul_pd(vny, vy), _mm_mul_pd(vnz, vz)));
506  _mm_storeu_pd(ptr_error, verror);
507  ptr_error += 2;
508  }
509  }
510 
511  for (; cpt < m_pointCloudFace.size(); cpt += 3) {
512  double x = m_pointCloudFace[cpt];
513  double y = m_pointCloudFace[cpt + 1];
514  double z = m_pointCloudFace[cpt + 2];
515 
516  double _a1 = (nz * y) - (ny * z);
517  double _a2 = (nx * z) - (nz * x);
518  double _a3 = (ny * x) - (nx * y);
519 
520  // L
521  L[(unsigned int)(cpt / 3)][0] = nx;
522  L[(unsigned int)(cpt / 3)][1] = ny;
523  L[(unsigned int)(cpt / 3)][2] = nz;
524  L[(unsigned int)(cpt / 3)][3] = _a1;
525  L[(unsigned int)(cpt / 3)][4] = _a2;
526  L[(unsigned int)(cpt / 3)][5] = _a3;
527 
528  vpColVector normal(3);
529  normal[0] = nx;
530  normal[1] = ny;
531  normal[2] = nz;
532 
533  vpColVector pt(3);
534  pt[0] = x;
535  pt[1] = y;
536  pt[2] = z;
537 
538  // Error
539  error[(unsigned int)(cpt / 3)] = D + (normal.t() * pt);
540  }
541 #endif
542  } else {
543  vpColVector normal(3);
544  normal[0] = nx;
545  normal[1] = ny;
546  normal[2] = nz;
547  vpColVector pt(3);
548 
549  unsigned int idx = 0;
550  for (size_t i = 0; i < m_pointCloudFace.size(); i += 3, idx++) {
551  double x = m_pointCloudFace[i];
552  double y = m_pointCloudFace[i + 1];
553  double z = m_pointCloudFace[i + 2];
554 
555  double _a1 = (nz * y) - (ny * z);
556  double _a2 = (nx * z) - (nz * x);
557  double _a3 = (ny * x) - (nx * y);
558 
559  // L
560  L[idx][0] = nx;
561  L[idx][1] = ny;
562  L[idx][2] = nz;
563  L[idx][3] = _a1;
564  L[idx][4] = _a2;
565  L[idx][5] = _a3;
566 
567  pt[0] = x;
568  pt[1] = y;
569  pt[2] = z;
570  // Error
571  error[idx] = D + (normal.t() * pt);
572  }
573  }
574 }
575 
576 void vpMbtFaceDepthDense::computeROI(const vpHomogeneousMatrix &cMo, const unsigned int width,
577  const unsigned int height, std::vector<vpImagePoint> &roiPts
578 #if DEBUG_DISPLAY_DEPTH_DENSE
579  ,
580  std::vector<std::vector<vpImagePoint> > &roiPts_vec
581 #endif
582  ,
583  double &distanceToFace)
584 {
585  if (m_useScanLine || m_clippingFlag > 2)
586  m_cam.computeFov(width, height);
587 
588  if (m_useScanLine) {
589  for (std::vector<PolygonLine>::iterator it = m_polygonLines.begin(); it != m_polygonLines.end(); ++it) {
590  it->m_p1->changeFrame(cMo);
591  it->m_p2->changeFrame(cMo);
592 
593  vpImagePoint ip1, ip2;
594 
595  it->m_poly.changeFrame(cMo);
596  it->m_poly.computePolygonClipped(m_cam);
597 
598  if (it->m_poly.polyClipped.size() == 2 &&
599  ((it->m_poly.polyClipped[1].second & it->m_poly.polyClipped[0].second & vpPolygon3D::NEAR_CLIPPING) == 0) &&
600  ((it->m_poly.polyClipped[1].second & it->m_poly.polyClipped[0].second & vpPolygon3D::FAR_CLIPPING) == 0) &&
601  ((it->m_poly.polyClipped[1].second & it->m_poly.polyClipped[0].second & vpPolygon3D::DOWN_CLIPPING) == 0) &&
602  ((it->m_poly.polyClipped[1].second & it->m_poly.polyClipped[0].second & vpPolygon3D::UP_CLIPPING) == 0) &&
603  ((it->m_poly.polyClipped[1].second & it->m_poly.polyClipped[0].second & vpPolygon3D::LEFT_CLIPPING) == 0) &&
604  ((it->m_poly.polyClipped[1].second & it->m_poly.polyClipped[0].second & vpPolygon3D::RIGHT_CLIPPING) == 0)) {
605 
606  std::vector<std::pair<vpPoint, vpPoint> > linesLst;
607  m_hiddenFace->computeScanLineQuery(it->m_poly.polyClipped[0].first, it->m_poly.polyClipped[1].first, linesLst,
608  true);
609 
610  vpPoint faceCentroid;
611 
612  for (unsigned int i = 0; i < linesLst.size(); i++) {
613  linesLst[i].first.project();
614  linesLst[i].second.project();
615 
616  vpMeterPixelConversion::convertPoint(m_cam, linesLst[i].first.get_x(), linesLst[i].first.get_y(), ip1);
617  vpMeterPixelConversion::convertPoint(m_cam, linesLst[i].second.get_x(), linesLst[i].second.get_y(), ip2);
618 
619  it->m_imPt1 = ip1;
620  it->m_imPt2 = ip2;
621 
622  roiPts.push_back(ip1);
623  roiPts.push_back(ip2);
624 
625  faceCentroid.set_X(faceCentroid.get_X() + linesLst[i].first.get_X() + linesLst[i].second.get_X());
626  faceCentroid.set_Y(faceCentroid.get_Y() + linesLst[i].first.get_Y() + linesLst[i].second.get_Y());
627  faceCentroid.set_Z(faceCentroid.get_Z() + linesLst[i].first.get_Z() + linesLst[i].second.get_Z());
628 
629 #if DEBUG_DISPLAY_DEPTH_DENSE
630  std::vector<vpImagePoint> roiPts_;
631  roiPts_.push_back(ip1);
632  roiPts_.push_back(ip2);
633  roiPts_vec.push_back(roiPts_);
634 #endif
635  }
636 
637  if (linesLst.empty()) {
638  distanceToFace = std::numeric_limits<double>::max();
639  } else {
640  faceCentroid.set_X(faceCentroid.get_X() / (2 * linesLst.size()));
641  faceCentroid.set_Y(faceCentroid.get_Y() / (2 * linesLst.size()));
642  faceCentroid.set_Z(faceCentroid.get_Z() / (2 * linesLst.size()));
643 
644  distanceToFace =
645  sqrt(faceCentroid.get_X() * faceCentroid.get_X() + faceCentroid.get_Y() * faceCentroid.get_Y() +
646  faceCentroid.get_Z() * faceCentroid.get_Z());
647  }
648  }
649  }
650  } else {
651  // Get polygon clipped
652  m_polygon->getRoiClipped(m_cam, roiPts, cMo);
653 
654  // Get 3D polygon clipped
655  std::vector<vpPoint> polygonsClipped;
656  m_polygon->getPolygonClipped(polygonsClipped);
657 
658  if (polygonsClipped.empty()) {
659  distanceToFace = std::numeric_limits<double>::max();
660  } else {
661  vpPoint faceCentroid;
662 
663  for (size_t i = 0; i < polygonsClipped.size(); i++) {
664  faceCentroid.set_X(faceCentroid.get_X() + polygonsClipped[i].get_X());
665  faceCentroid.set_Y(faceCentroid.get_Y() + polygonsClipped[i].get_Y());
666  faceCentroid.set_Z(faceCentroid.get_Z() + polygonsClipped[i].get_Z());
667  }
668 
669  faceCentroid.set_X(faceCentroid.get_X() / polygonsClipped.size());
670  faceCentroid.set_Y(faceCentroid.get_Y() / polygonsClipped.size());
671  faceCentroid.set_Z(faceCentroid.get_Z() / polygonsClipped.size());
672 
673  distanceToFace = sqrt(faceCentroid.get_X() * faceCentroid.get_X() + faceCentroid.get_Y() * faceCentroid.get_Y() +
674  faceCentroid.get_Z() * faceCentroid.get_Z());
675  }
676 
677 #if DEBUG_DISPLAY_DEPTH_DENSE
678  roiPts_vec.push_back(roiPts);
679 #endif
680  }
681 }
682 
684  const vpCameraParameters &cam, const vpColor &col, const unsigned int thickness,
685  const bool displayFullModel)
686 {
687  if (m_polygon->isVisible() || displayFullModel) {
689 
690  for (std::vector<vpMbtDistanceLine *>::const_iterator it = m_listOfFaceLines.begin(); it != m_listOfFaceLines.end();
691  ++it) {
692  vpMbtDistanceLine *line = *it;
693  line->display(I, cMo, cam, col, thickness, displayFullModel);
694  }
695  }
696 }
697 
699  const vpCameraParameters &cam, const vpColor &col, const unsigned int thickness,
700  const bool displayFullModel)
701 {
702  if (m_polygon->isVisible() || displayFullModel) {
704 
705  for (std::vector<vpMbtDistanceLine *>::const_iterator it = m_listOfFaceLines.begin(); it != m_listOfFaceLines.end();
706  ++it) {
707  vpMbtDistanceLine *line = *it;
708  line->display(I, cMo, cam, col, thickness, displayFullModel);
709  }
710  }
711 }
712 
714  const vpCameraParameters & /*cam*/, const double /*scale*/,
715  const unsigned int /*thickness*/)
716 {
717 }
718 
720  const vpCameraParameters & /*cam*/, const double /*scale*/,
721  const unsigned int /*thickness*/)
722 {
723 }
724 
734 bool vpMbtFaceDepthDense::samePoint(const vpPoint &P1, const vpPoint &P2) const
735 {
736  double dx = fabs(P1.get_oX() - P2.get_oX());
737  double dy = fabs(P1.get_oY() - P2.get_oY());
738  double dz = fabs(P1.get_oZ() - P2.get_oZ());
739 
740  if (dx <= std::numeric_limits<double>::epsilon() && dy <= std::numeric_limits<double>::epsilon() &&
741  dz <= std::numeric_limits<double>::epsilon())
742  return true;
743  else
744  return false;
745 }
746 
748 {
749  m_cam = camera;
750 
751  for (std::vector<vpMbtDistanceLine *>::const_iterator it = m_listOfFaceLines.begin(); it != m_listOfFaceLines.end();
752  ++it) {
753  (*it)->setCameraParameters(camera);
754  }
755 }
756 
758 {
759  m_useScanLine = v;
760 
761  for (std::vector<vpMbtDistanceLine *>::const_iterator it = m_listOfFaceLines.begin(); it != m_listOfFaceLines.end();
762  ++it) {
763  (*it)->useScanLine = v;
764  }
765 }
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:104
double m_distNearClip
Distance for near clipping.
double getTop() const
Definition: vpRect.h:175
void getRoiClipped(const vpCameraParameters &cam, std::vector< vpImagePoint > &roi)
double get_oY() const
Get the point Y coordinate in the object frame.
Definition: vpPoint.cpp:422
Implements a 3D polygon with render functionnalities like clipping.
Definition: vpPolygon3D.h:59
bool samePoint(const vpPoint &P1, const vpPoint &P2) const
void setVisible(bool _isvisible)
int getIndex() const
Definition: vpMbtPolygon.h:101
std::vector< double > m_pointCloudFace
List of depth points inside the face.
vpCameraParameters m_cam
Camera intrinsic parameters.
Implementation of an homogeneous matrix and operations on such kind of matrices.
int m_depthDenseFilteringMethod
Method to use to consider or not the face.
std::list< int > Lindex_polygon
Index of the faces which contain the line.
void setFarClippingDistance(const double &dist)
Definition: vpPolygon3D.h:194
void setCameraParameters(const vpCameraParameters &camera)
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
Point coordinates conversion from normalized coordinates in meter to pixel coordinates ...
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true, const bool recopy_=true)
Definition: vpArray2D.h:171
Class to define colors available for display functionnalities.
Definition: vpColor.h:120
void setLeft(double pos)
Definition: vpRect.h:257
bool m_useScanLine
Scan line visibility.
vpPoint * p1
The first extremity.
bool computeDesiredFeatures(const vpHomogeneousMatrix &cMo, const pcl::PointCloud< pcl::PointXYZ >::ConstPtr &point_cloud, const unsigned int stepX, const unsigned int stepY)
vpMbScanLine & getMbScanLineRenderer()
Manage the line of a polygon used in the model-based tracker.
vpRowVector t() const
Type * data
Address of the first element of the data array.
Definition: vpArray2D.h:84
double m_depthDenseFilteringMinDist
Minimum distance threshold.
void set_X(const double X)
Set the point X coordinate in the camera frame.
Definition: vpPoint.cpp:452
vpMbtPolygon & getPolygon()
void addLine(vpPoint &p1, vpPoint &p2, vpMbHiddenFaces< vpMbtPolygon > *const faces, int polygon=-1, std::string name="")
double get_oX() const
Get the point X coordinate in the object frame.
Definition: vpPoint.cpp:420
double getRight() const
Definition: vpRect.h:162
vpRect getBoundingBox() const
Definition: vpPolygon.h:177
Class that defines what is a point.
Definition: vpPoint.h:58
bool m_isVisible
Visibility flag.
vpMbtPolygon * m_polygon
Polygon defining the face.
vpPlane m_planeObject
Plane equation described in the object frame.
Defines a generic 2D polygon.
Definition: vpPolygon.h:103
void set_Z(const double Z)
Set the point Z coordinate in the camera frame.
Definition: vpPoint.cpp:456
void setTop(double pos)
Definition: vpRect.h:292
double getWidth() const
Definition: vpRect.h:197
double getD() const
Definition: vpPlane.h:108
unsigned int m_clippingFlag
Flags specifying which clipping to used.
void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, const unsigned int thickness=1, const bool displayFullModel=false)
vpPoint * p2
The second extremity.
void changeFrame(const vpHomogeneousMatrix &cMo)
Definition: vpPlane.cpp:354
void computeInteractionMatrixAndResidu(const vpHomogeneousMatrix &cMo, vpMatrix &L, vpColVector &error)
VISP_EXPORT bool checkSSE2()
double getB() const
Definition: vpPlane.h:104
bool isInside(const vpImagePoint &iP, const PointInPolygonMethod &method=PnPolyRayCasting) const
Definition: vpPolygon.cpp:317
double m_distFarClip
Distance for near clipping.
void getPolygonClipped(std::vector< std::pair< vpPoint, unsigned int > > &poly)
Generic class defining intrinsic camera parameters.
double m_depthDenseFilteringOccupancyRatio
Ratio between available depth points and theoretical number of points.
void setIndex(const unsigned int i)
void set_Y(const double Y)
Set the point Y coordinate in the camera frame.
Definition: vpPoint.cpp:454
double get_oZ() const
Get the point Z coordinate in the object frame.
Definition: vpPoint.cpp:424
void setScanLineVisibilityTest(const bool v)
double getLeft() const
Definition: vpRect.h:156
virtual bool isVisible(const vpHomogeneousMatrix &cMo, const double alpha, const bool &modulo=false, const vpCameraParameters &cam=vpCameraParameters(), const vpImage< unsigned char > &I=vpImage< unsigned char >())
std::vector< vpMbtDistanceLine * > m_listOfFaceLines
unsigned int getNbFeatures() const
double m_depthDenseFilteringMaxDist
Maximum distance threshold.
void setClipping(const unsigned int &flags)
Definition: vpPolygon3D.h:187
void displayFeature(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const double scale=0.05, const unsigned int thickness=1)
double getA() const
Definition: vpPlane.h:102
void setName(const std::string &line_name)
void setCameraParameters(const vpCameraParameters &camera)
double get_X() const
Get the point X coordinate in the camera frame.
Definition: vpPoint.cpp:411
void computeScanLineQuery(const vpPoint &a, const vpPoint &b, std::vector< std::pair< vpPoint, vpPoint > > &lines, const bool &displayResults=false)
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
void setRight(double pos)
Definition: vpRect.h:283
vpMbHiddenFaces< vpMbtPolygon > * hiddenface
Pointer to the list of faces.
double getHeight() const
Definition: vpRect.h:149
bool isVisible(const unsigned int i)
double getC() const
Definition: vpPlane.h:106
std::vector< PolygonLine > m_polygonLines
Polygon lines used for scan-line visibility.
void addPolygon(const int &index)
void setNearClippingDistance(const double &dist)
Definition: vpPolygon3D.h:207
Defines a rectangle in the plane.
Definition: vpRect.h:78
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
double get_Z() const
Get the point Z coordinate in the camera frame.
Definition: vpPoint.cpp:415
vpMbHiddenFaces< vpMbtPolygon > * m_hiddenFace
Pointer to the list of faces.
double get_Y() const
Get the point Y coordinate in the camera frame.
Definition: vpPoint.cpp:413
double getBottom() const
Definition: vpRect.h:94
void computeROI(const vpHomogeneousMatrix &cMo, const unsigned int width, const unsigned int height, std::vector< vpImagePoint > &roiPts, double &distanceToFace)
void setBottom(double pos)
Definition: vpRect.h:224
void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, const unsigned int thickness=1, const bool displayFullModel=false)
bool useScanLine
Use scanline rendering.
void buildFrom(vpPoint &_p1, vpPoint &_p2)
void resize(const unsigned int i, const bool flagNullify=true)
Definition: vpColVector.h:241
void computeFov(const unsigned int &w, const unsigned int &h)