Visual Servoing Platform  version 3.2.1 under development (2019-08-21) under development (2019-08-21)
vpMbtFaceDepthNormal.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  * Manage depth normal features for a particular face.
33  *
34  *****************************************************************************/
35 
36 #include <visp3/core/vpCPUFeatures.h>
37 #include <visp3/mbt/vpMbtFaceDepthNormal.h>
38 #include <visp3/mbt/vpMbtTukeyEstimator.h>
39 
40 #ifdef VISP_HAVE_PCL
41 #include <pcl/common/centroid.h>
42 #include <pcl/filters/extract_indices.h>
43 #include <pcl/segmentation/sac_segmentation.h>
44 #endif
45 
46 #if defined __SSE2__ || defined _M_X64 || (defined _M_IX86_FP && _M_IX86_FP >= 2)
47 #include <emmintrin.h>
48 #define VISP_HAVE_SSE2 1
49 #endif
50 
51 #define USE_SSE_CODE 1
52 #if VISP_HAVE_SSE2 && USE_SSE_CODE
53 #define USE_SSE 1
54 #else
55 #define USE_SSE 0
56 #endif
57 
59  : m_cam(), m_clippingFlag(vpPolygon3D::NO_CLIPPING), m_distFarClip(100), m_distNearClip(0.001), m_hiddenFace(NULL),
60  m_planeObject(), m_polygon(NULL), m_useScanLine(false), m_faceActivated(false),
61  m_faceCentroidMethod(GEOMETRIC_CENTROID), m_faceDesiredCentroid(), m_faceDesiredNormal(),
62  m_featureEstimationMethod(ROBUST_FEATURE_ESTIMATION), m_isTrackedDepthNormalFace(true), m_isVisible(false),
63  m_listOfFaceLines(), m_planeCamera(),
64  m_pclPlaneEstimationMethod(2), // SAC_MSAC, see pcl/sample_consensus/method_types.h
65  m_pclPlaneEstimationRansacMaxIter(200), m_pclPlaneEstimationRansacThreshold(0.001), m_polygonLines()
66 {
67 }
68 
70 {
71  for (size_t i = 0; i < m_listOfFaceLines.size(); i++) {
72  delete m_listOfFaceLines[i];
73  }
74 }
75 
90  std::string name)
91 {
92  // Build a PolygonLine to be able to easily display the lines model
93  PolygonLine polygon_line;
94 
95  // Add polygon
96  polygon_line.m_poly.setNbPoint(2);
97  polygon_line.m_poly.addPoint(0, P1);
98  polygon_line.m_poly.addPoint(1, P2);
99 
100  polygon_line.m_poly.setClipping(m_clippingFlag);
101  polygon_line.m_poly.setNearClippingDistance(m_distNearClip);
102  polygon_line.m_poly.setFarClippingDistance(m_distFarClip);
103 
104  polygon_line.m_p1 = &polygon_line.m_poly.p[0];
105  polygon_line.m_p2 = &polygon_line.m_poly.p[1];
106 
107  m_polygonLines.push_back(polygon_line);
108 
109  // suppress line already in the model
110  bool already_here = false;
112 
113  for (std::vector<vpMbtDistanceLine *>::const_iterator it = m_listOfFaceLines.begin(); it != m_listOfFaceLines.end();
114  ++it) {
115  l = *it;
116  if ((samePoint(*(l->p1), P1) && samePoint(*(l->p2), P2)) || (samePoint(*(l->p1), P2) && samePoint(*(l->p2), P1))) {
117  already_here = true;
118  l->addPolygon(polygon);
119  l->hiddenface = faces;
121  }
122  }
123 
124  if (!already_here) {
125  l = new vpMbtDistanceLine;
126 
128  l->buildFrom(P1, P2);
129  l->addPolygon(polygon);
130  l->hiddenface = faces;
132 
133  l->setIndex((unsigned int)m_listOfFaceLines.size());
134  l->setName(name);
135 
138 
139  if ((m_clippingFlag & vpPolygon3D::NEAR_CLIPPING) == vpPolygon3D::NEAR_CLIPPING)
141 
142  if ((m_clippingFlag & vpPolygon3D::FAR_CLIPPING) == vpPolygon3D::FAR_CLIPPING)
144 
145  m_listOfFaceLines.push_back(l);
146  }
147 }
148 
149 #ifdef VISP_HAVE_PCL
150 bool vpMbtFaceDepthNormal::computeDesiredFeatures(const vpHomogeneousMatrix &cMo, const unsigned int width,
151  const unsigned int height,
152  const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &point_cloud,
153  vpColVector &desired_features, const unsigned int stepX,
154  const unsigned int stepY
155 #if DEBUG_DISPLAY_DEPTH_NORMAL
156  ,
157  vpImage<unsigned char> &debugImage,
158  std::vector<std::vector<vpImagePoint> > &roiPts_vec
159 #endif
160  , const vpImage<bool> *mask
161 )
162 {
163  m_faceActivated = false;
164 
165  if (width == 0 || height == 0)
166  return false;
167 
168  std::vector<vpImagePoint> roiPts;
169  vpColVector desired_normal(3);
170 
171  computeROI(cMo, width, height, roiPts
172 #if DEBUG_DISPLAY_DEPTH_NORMAL
173  ,
174  roiPts_vec
175 #endif
176  );
177 
178  if (roiPts.size() <= 2) {
179 #ifndef NDEBUG
180  std::cerr << "Error: roiPts.size() <= 2 in computeDesiredFeatures" << std::endl;
181 #endif
182  return false;
183  }
184 
185  vpPolygon polygon_2d(roiPts);
186  vpRect bb = polygon_2d.getBoundingBox();
187 
188  unsigned int top = (unsigned int)std::max(0.0, bb.getTop());
189  unsigned int bottom = (unsigned int)std::min((double)height, std::max(0.0, bb.getBottom()));
190  unsigned int left = (unsigned int)std::max(0.0, bb.getLeft());
191  unsigned int right = (unsigned int)std::min((double)width, std::max(0.0, bb.getRight()));
192 
193  bb.setTop(top);
194  bb.setBottom(bottom);
195  bb.setLeft(left);
196  bb.setRight(right);
197 
198  // Keep only 3D points inside the projected polygon face
199  pcl::PointCloud<pcl::PointXYZ>::Ptr point_cloud_face(new pcl::PointCloud<pcl::PointXYZ>);
200  std::vector<double> point_cloud_face_vec, point_cloud_face_custom;
201 
203  point_cloud_face_custom.reserve((size_t)(3 * bb.getWidth() * bb.getHeight()));
204  point_cloud_face_vec.reserve((size_t)(3 * bb.getWidth() * bb.getHeight()));
206  point_cloud_face_vec.reserve((size_t)(3 * bb.getWidth() * bb.getHeight()));
208  point_cloud_face->reserve((size_t)(bb.getWidth() * bb.getHeight()));
209  }
210 
211  bool checkSSE2 = vpCPUFeatures::checkSSE2();
212 #if !USE_SSE
213  checkSSE2 = false;
214 #else
215  bool push = false;
216  double prev_x, prev_y, prev_z;
217 #endif
218 
219  double x = 0.0, y = 0.0;
220  for (unsigned int i = top; i < bottom; i += stepY) {
221  for (unsigned int j = left; j < right; j += stepX) {
222  if (vpMeTracker::inMask(mask, i, j) && pcl::isFinite((*point_cloud)(j, i)) && (*point_cloud)(j, i).z > 0 &&
223  (m_useScanLine ? (i < m_hiddenFace->getMbScanLineRenderer().getPrimitiveIDs().getHeight() &&
224  j < m_hiddenFace->getMbScanLineRenderer().getPrimitiveIDs().getWidth() &&
225  m_hiddenFace->getMbScanLineRenderer().getPrimitiveIDs()[i][j] == m_polygon->getIndex())
226  : polygon_2d.isInside(vpImagePoint(i, j)))) {
227 
229  point_cloud_face->push_back((*point_cloud)(j, i));
232  point_cloud_face_vec.push_back((*point_cloud)(j, i).x);
233  point_cloud_face_vec.push_back((*point_cloud)(j, i).y);
234  point_cloud_face_vec.push_back((*point_cloud)(j, i).z);
235 
237  // Add point for custom method for plane equation estimation
239 
240  if (checkSSE2) {
241 #if USE_SSE
242  if (!push) {
243  push = true;
244  prev_x = x;
245  prev_y = y;
246  prev_z = (*point_cloud)(j, i).z;
247  } else {
248  push = false;
249  point_cloud_face_custom.push_back(prev_x);
250  point_cloud_face_custom.push_back(x);
251 
252  point_cloud_face_custom.push_back(prev_y);
253  point_cloud_face_custom.push_back(y);
254 
255  point_cloud_face_custom.push_back(prev_z);
256  point_cloud_face_custom.push_back((*point_cloud)(j, i).z);
257  }
258 #endif
259  } else {
260  point_cloud_face_custom.push_back(x);
261  point_cloud_face_custom.push_back(y);
262  point_cloud_face_custom.push_back((*point_cloud)(j, i).z);
263  }
264  }
265  }
266 
267 #if DEBUG_DISPLAY_DEPTH_NORMAL
268  debugImage[i][j] = 255;
269 #endif
270  }
271  }
272  }
273 
274 #if USE_SSE
275  if (checkSSE2 && push) {
276  point_cloud_face_custom.push_back(prev_x);
277  point_cloud_face_custom.push_back(prev_y);
278  point_cloud_face_custom.push_back(prev_z);
279  }
280 #endif
281 
282  if (point_cloud_face->empty() && point_cloud_face_custom.empty() && point_cloud_face_vec.empty()) {
283  return false;
284  }
285 
286  // Face centroid computed by the different methods
287  vpColVector centroid_point(3);
288 
290  if (!computeDesiredFeaturesPCL(point_cloud_face, desired_features, desired_normal, centroid_point)) {
291  return false;
292  }
294  computeDesiredFeaturesSVD(point_cloud_face_vec, cMo, desired_features, desired_normal, centroid_point);
296  computeDesiredFeaturesRobustFeatures(point_cloud_face_custom, point_cloud_face_vec, cMo, desired_features,
297  desired_normal, centroid_point);
298  } else {
299  throw vpException(vpException::badValue, "Unknown feature estimation method!");
300  }
301 
302  computeDesiredNormalAndCentroid(cMo, desired_normal, centroid_point);
303 
304  m_faceActivated = true;
305 
306  return true;
307 }
308 #endif
309 
310 bool vpMbtFaceDepthNormal::computeDesiredFeatures(const vpHomogeneousMatrix &cMo, const unsigned int width,
311  const unsigned int height,
312  const std::vector<vpColVector> &point_cloud,
313  vpColVector &desired_features, const unsigned int stepX,
314  const unsigned int stepY
315 #if DEBUG_DISPLAY_DEPTH_NORMAL
316  ,
317  vpImage<unsigned char> &debugImage,
318  std::vector<std::vector<vpImagePoint> > &roiPts_vec
319 #endif
320  , const vpImage<bool> *mask
321 )
322 {
323  m_faceActivated = false;
324 
325  if (width == 0 || height == 0)
326  return false;
327 
328  std::vector<vpImagePoint> roiPts;
329  vpColVector desired_normal(3);
330 
331  computeROI(cMo, width, height, roiPts
332 #if DEBUG_DISPLAY_DEPTH_NORMAL
333  ,
334  roiPts_vec
335 #endif
336  );
337 
338  if (roiPts.size() <= 2) {
339 #ifndef NDEBUG
340  std::cerr << "Error: roiPts.size() <= 2 in computeDesiredFeatures" << std::endl;
341 #endif
342  return false;
343  }
344 
345  vpPolygon polygon_2d(roiPts);
346  vpRect bb = polygon_2d.getBoundingBox();
347 
348  unsigned int top = (unsigned int)std::max(0.0, bb.getTop());
349  unsigned int bottom = (unsigned int)std::min((double)height, std::max(0.0, bb.getBottom()));
350  unsigned int left = (unsigned int)std::max(0.0, bb.getLeft());
351  unsigned int right = (unsigned int)std::min((double)width, std::max(0.0, bb.getRight()));
352 
353  bb.setTop(top);
354  bb.setBottom(bottom);
355  bb.setLeft(left);
356  bb.setRight(right);
357 
358  // Keep only 3D points inside the projected polygon face
359  std::vector<double> point_cloud_face, point_cloud_face_custom;
360 
361  point_cloud_face.reserve((size_t)(3 * bb.getWidth() * bb.getHeight()));
363  point_cloud_face_custom.reserve((size_t)(3 * bb.getWidth() * bb.getHeight()));
364  }
365 
366  bool checkSSE2 = vpCPUFeatures::checkSSE2();
367 #if !USE_SSE
368  checkSSE2 = false;
369 #else
370  bool push = false;
371  double prev_x, prev_y, prev_z;
372 #endif
373 
374  double x = 0.0, y = 0.0;
375  for (unsigned int i = top; i < bottom; i += stepY) {
376  for (unsigned int j = left; j < right; j += stepX) {
377  if (vpMeTracker::inMask(mask, i, j) && point_cloud[i * width + j][2] > 0 &&
378  (m_useScanLine ? (i < m_hiddenFace->getMbScanLineRenderer().getPrimitiveIDs().getHeight() &&
379  j < m_hiddenFace->getMbScanLineRenderer().getPrimitiveIDs().getWidth() &&
380  m_hiddenFace->getMbScanLineRenderer().getPrimitiveIDs()[i][j] == m_polygon->getIndex())
381  : polygon_2d.isInside(vpImagePoint(i, j)))) {
382  // Add point
383  point_cloud_face.push_back(point_cloud[i * width + j][0]);
384  point_cloud_face.push_back(point_cloud[i * width + j][1]);
385  point_cloud_face.push_back(point_cloud[i * width + j][2]);
386 
388  // Add point for custom method for plane equation estimation
390 
391  if (checkSSE2) {
392 #if USE_SSE
393  if (!push) {
394  push = true;
395  prev_x = x;
396  prev_y = y;
397  prev_z = point_cloud[i * width + j][2];
398  } else {
399  push = false;
400  point_cloud_face_custom.push_back(prev_x);
401  point_cloud_face_custom.push_back(x);
402 
403  point_cloud_face_custom.push_back(prev_y);
404  point_cloud_face_custom.push_back(y);
405 
406  point_cloud_face_custom.push_back(prev_z);
407  point_cloud_face_custom.push_back(point_cloud[i * width + j][2]);
408  }
409 #endif
410  } else {
411  point_cloud_face_custom.push_back(x);
412  point_cloud_face_custom.push_back(y);
413  point_cloud_face_custom.push_back(point_cloud[i * width + j][2]);
414  }
415  }
416 
417 #if DEBUG_DISPLAY_DEPTH_NORMAL
418  debugImage[i][j] = 255;
419 #endif
420  }
421  }
422  }
423 
424 #if USE_SSE
425  if (checkSSE2 && push) {
426  point_cloud_face_custom.push_back(prev_x);
427  point_cloud_face_custom.push_back(prev_y);
428  point_cloud_face_custom.push_back(prev_z);
429  }
430 #endif
431 
432  if (point_cloud_face.empty() && point_cloud_face_custom.empty()) {
433  return false;
434  }
435 
436  // Face centroid computed by the different methods
437  vpColVector centroid_point(3);
438 
439 #ifdef VISP_HAVE_PCL
441  pcl::PointCloud<pcl::PointXYZ>::Ptr point_cloud_face_pcl(new pcl::PointCloud<pcl::PointXYZ>);
442  point_cloud_face_pcl->reserve(point_cloud_face.size() / 3);
443 
444  for (size_t i = 0; i < point_cloud_face.size() / 3; i++) {
445  point_cloud_face_pcl->push_back(
446  pcl::PointXYZ(point_cloud_face[3 * i], point_cloud_face[3 * i + 1], point_cloud_face[3 * i + 2]));
447  }
448 
449  computeDesiredFeaturesPCL(point_cloud_face_pcl, desired_features, desired_normal, centroid_point);
450  } else
451 #endif
453  computeDesiredFeaturesSVD(point_cloud_face, cMo, desired_features, desired_normal, centroid_point);
455  computeDesiredFeaturesRobustFeatures(point_cloud_face_custom, point_cloud_face, cMo, desired_features,
456  desired_normal, centroid_point);
457  } else {
458  throw vpException(vpException::badValue, "Unknown feature estimation method!");
459  }
460 
461  computeDesiredNormalAndCentroid(cMo, desired_normal, centroid_point);
462 
463  m_faceActivated = true;
464 
465  return true;
466 }
467 
468 #ifdef VISP_HAVE_PCL
469 bool vpMbtFaceDepthNormal::computeDesiredFeaturesPCL(const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &point_cloud_face,
470  vpColVector &desired_features, vpColVector &desired_normal,
471  vpColVector &centroid_point)
472 {
473  try {
474  // Compute plane equation for this subset of point cloud
475  pcl::ModelCoefficients::Ptr coefficients(new pcl::ModelCoefficients);
476  pcl::PointIndices::Ptr inliers(new pcl::PointIndices);
477  // Create the segmentation object
478  pcl::SACSegmentation<pcl::PointXYZ> seg;
479  // Optional
480  seg.setOptimizeCoefficients(true);
481  // Mandatory
482  seg.setModelType(pcl::SACMODEL_PLANE);
483  seg.setMethodType(m_pclPlaneEstimationMethod);
484  seg.setDistanceThreshold(m_pclPlaneEstimationRansacThreshold);
485  seg.setMaxIterations(m_pclPlaneEstimationRansacMaxIter);
486 
487  seg.setInputCloud(point_cloud_face);
488  seg.segment(*inliers, *coefficients);
489 
490  pcl::PointCloud<pcl::PointXYZ>::Ptr point_cloud_face_extracted(new pcl::PointCloud<pcl::PointXYZ>);
491  // Create the filtering object
492  pcl::ExtractIndices<pcl::PointXYZ> extract;
493 
494  // Extract the inliers
495  extract.setInputCloud(point_cloud_face);
496  extract.setIndices(inliers);
497  extract.setNegative(false);
498  extract.filter(*point_cloud_face_extracted);
499 
500  pcl::PointXYZ centroid_point_pcl;
501  if (pcl::computeCentroid(*point_cloud_face_extracted, centroid_point_pcl)) {
502  pcl::PointXYZ face_normal;
503  computeNormalVisibility(coefficients->values[0], coefficients->values[1], coefficients->values[2],
504  centroid_point_pcl, face_normal);
505 
506  desired_features.resize(3, false);
507  desired_features[0] = -coefficients->values[0] / coefficients->values[3];
508  desired_features[1] = -coefficients->values[1] / coefficients->values[3];
509  desired_features[2] = -coefficients->values[2] / coefficients->values[3];
510 
511  desired_normal[0] = face_normal.x;
512  desired_normal[1] = face_normal.y;
513  desired_normal[2] = face_normal.z;
514 
515  centroid_point[0] = centroid_point_pcl.x;
516  centroid_point[1] = centroid_point_pcl.y;
517  centroid_point[2] = centroid_point_pcl.z;
518  } else {
519  std::cerr << "Cannot compute centroid!" << std::endl;
520  return false;
521  }
522  } catch (const pcl::PCLException &e) {
523  std::cerr << "Catch a PCL exception: " << e.what() << std::endl;
524  throw;
525  }
526 
527  return true;
528 }
529 #endif
530 
531 void vpMbtFaceDepthNormal::computeDesiredFeaturesRobustFeatures(const std::vector<double> &point_cloud_face_custom,
532  const std::vector<double> &point_cloud_face,
533  const vpHomogeneousMatrix &cMo,
534  vpColVector &desired_features,
535  vpColVector &desired_normal,
536  vpColVector &centroid_point)
537 {
538  std::vector<double> weights;
539  double den = 0.0;
540  estimateFeatures(point_cloud_face_custom, cMo, desired_features, weights);
541 
542  // Compute face centroid
543  for (size_t i = 0; i < point_cloud_face.size() / 3; i++) {
544  centroid_point[0] += weights[i] * point_cloud_face[3 * i];
545  centroid_point[1] += weights[i] * point_cloud_face[3 * i + 1];
546  centroid_point[2] += weights[i] * point_cloud_face[3 * i + 2];
547 
548  den += weights[i];
549  }
550 
551  centroid_point[0] /= den;
552  centroid_point[1] /= den;
553  centroid_point[2] /= den;
554 
555  computeNormalVisibility(-desired_features[0], -desired_features[1], -desired_features[2], centroid_point,
556  desired_normal);
557 }
558 
559 void vpMbtFaceDepthNormal::computeDesiredFeaturesSVD(const std::vector<double> &point_cloud_face,
560  const vpHomogeneousMatrix &cMo, vpColVector &desired_features,
561  vpColVector &desired_normal, vpColVector &centroid_point)
562 {
563  vpColVector plane_equation_SVD;
564  estimatePlaneEquationSVD(point_cloud_face, cMo, plane_equation_SVD, centroid_point);
565 
566  desired_features.resize(3, false);
567  desired_features[0] = -plane_equation_SVD[0] / plane_equation_SVD[3];
568  desired_features[1] = -plane_equation_SVD[1] / plane_equation_SVD[3];
569  desired_features[2] = -plane_equation_SVD[2] / plane_equation_SVD[3];
570 
571  computeNormalVisibility(-desired_features[0], -desired_features[1], -desired_features[2], centroid_point,
572  desired_normal);
573 }
574 
576  const vpColVector &desired_normal,
577  const vpColVector &centroid_point)
578 {
579  // Compute desired centroid in the object frame
580  vpColVector centroid_cam(4);
581  centroid_cam[0] = centroid_point[0];
582  centroid_cam[1] = centroid_point[1];
583  centroid_cam[2] = centroid_point[2];
584  centroid_cam[3] = 1;
585 
586  vpColVector centroid_obj = cMo.inverse() * centroid_cam;
587  m_faceDesiredCentroid.setWorldCoordinates(centroid_obj[0], centroid_obj[1], centroid_obj[2]);
588 
589  // Compute desired face normal in the object frame
590  vpColVector face_normal_cam(4);
591  face_normal_cam[0] = desired_normal[0];
592  face_normal_cam[1] = desired_normal[1];
593  face_normal_cam[2] = desired_normal[2];
594  face_normal_cam[3] = 1;
595 
596  vpColVector face_normal_obj = cMo.inverse() * face_normal_cam;
597  m_faceDesiredNormal.setWorldCoordinates(face_normal_obj[0], face_normal_obj[1], face_normal_obj[2]);
598 }
599 
600 bool vpMbtFaceDepthNormal::computePolygonCentroid(const std::vector<vpPoint> &points_, vpPoint &centroid)
601 {
602  if (points_.empty()) {
603  return false;
604  }
605 
606  if (points_.size() < 2) {
607  centroid = points_[0];
608  return true;
609  }
610 
611  std::vector<vpPoint> points = points_;
612  points.push_back(points_.front());
613 
614  double A1 = 0.0, A2 = 0.0, c_x1 = 0.0, c_x2 = 0.0, c_y = 0.0, c_z = 0.0;
615 
616  for (size_t i = 0; i < points.size() - 1; i++) {
617  // projection onto xy plane
618  c_x1 += (points[i].get_X() + points[i + 1].get_X()) *
619  (points[i].get_X() * points[i + 1].get_Y() - points[i + 1].get_X() * points[i].get_Y());
620  c_y += (points[i].get_Y() + points[i + 1].get_Y()) *
621  (points[i].get_X() * points[i + 1].get_Y() - points[i + 1].get_X() * points[i].get_Y());
622  A1 += points[i].get_X() * points[i + 1].get_Y() - points[i + 1].get_X() * points[i].get_Y();
623 
624  // projection onto xz plane
625  c_x2 += (points[i].get_X() + points[i + 1].get_X()) *
626  (points[i].get_X() * points[i + 1].get_Z() - points[i + 1].get_X() * points[i].get_Z());
627  c_z += (points[i].get_Z() + points[i + 1].get_Z()) *
628  (points[i].get_X() * points[i + 1].get_Z() - points[i + 1].get_X() * points[i].get_Z());
629  A2 += points[i].get_X() * points[i + 1].get_Z() - points[i + 1].get_X() * points[i].get_Z();
630  }
631 
632  c_x1 /= 3.0 * A1;
633  c_y /= 3.0 * A1;
634  c_x2 /= 3.0 * A2;
635  c_z /= 3.0 * A2;
636 
637  if (A1 > A2) {
638  centroid.set_X(c_x1);
639  } else {
640  centroid.set_X(c_x2);
641  }
642 
643  centroid.set_Y(c_y);
644  centroid.set_Z(c_z);
645 
646  return true;
647 }
648 
649 void vpMbtFaceDepthNormal::computeROI(const vpHomogeneousMatrix &cMo, const unsigned int width,
650  const unsigned int height, std::vector<vpImagePoint> &roiPts
651 #if DEBUG_DISPLAY_DEPTH_NORMAL
652  ,
653  std::vector<std::vector<vpImagePoint> > &roiPts_vec
654 #endif
655 )
656 {
657  if (m_useScanLine || m_clippingFlag > 2)
658  m_cam.computeFov(width, height);
659 
660  if (m_useScanLine) {
661  for (std::vector<PolygonLine>::iterator it = m_polygonLines.begin(); it != m_polygonLines.end(); ++it) {
662  it->m_p1->changeFrame(cMo);
663  it->m_p2->changeFrame(cMo);
664 
665  vpImagePoint ip1, ip2;
666 
667  it->m_poly.changeFrame(cMo);
668  it->m_poly.computePolygonClipped(m_cam);
669 
670  if (it->m_poly.polyClipped.size() == 2 &&
671  ((it->m_poly.polyClipped[1].second & it->m_poly.polyClipped[0].second & vpPolygon3D::NEAR_CLIPPING) == 0) &&
672  ((it->m_poly.polyClipped[1].second & it->m_poly.polyClipped[0].second & vpPolygon3D::FAR_CLIPPING) == 0) &&
673  ((it->m_poly.polyClipped[1].second & it->m_poly.polyClipped[0].second & vpPolygon3D::DOWN_CLIPPING) == 0) &&
674  ((it->m_poly.polyClipped[1].second & it->m_poly.polyClipped[0].second & vpPolygon3D::UP_CLIPPING) == 0) &&
675  ((it->m_poly.polyClipped[1].second & it->m_poly.polyClipped[0].second & vpPolygon3D::LEFT_CLIPPING) == 0) &&
676  ((it->m_poly.polyClipped[1].second & it->m_poly.polyClipped[0].second & vpPolygon3D::RIGHT_CLIPPING) == 0)) {
677 
678  std::vector<std::pair<vpPoint, vpPoint> > linesLst;
679  m_hiddenFace->computeScanLineQuery(it->m_poly.polyClipped[0].first, it->m_poly.polyClipped[1].first, linesLst,
680  true);
681 
682  for (unsigned int i = 0; i < linesLst.size(); i++) {
683  linesLst[i].first.project();
684  linesLst[i].second.project();
685 
686  vpMeterPixelConversion::convertPoint(m_cam, linesLst[i].first.get_x(), linesLst[i].first.get_y(), ip1);
687  vpMeterPixelConversion::convertPoint(m_cam, linesLst[i].second.get_x(), linesLst[i].second.get_y(), ip2);
688 
689  it->m_imPt1 = ip1;
690  it->m_imPt2 = ip2;
691 
692  roiPts.push_back(ip1);
693  roiPts.push_back(ip2);
694 
695 #if DEBUG_DISPLAY_DEPTH_NORMAL
696  std::vector<vpImagePoint> roiPts_;
697  roiPts_.push_back(ip1);
698  roiPts_.push_back(ip2);
699  roiPts_vec.push_back(roiPts_);
700 #endif
701  }
702  }
703  }
704  } else {
705  // Get polygon clipped
706  m_polygon->getRoiClipped(m_cam, roiPts, cMo);
707 
708 #if DEBUG_DISPLAY_DEPTH_NORMAL
709  roiPts_vec.push_back(roiPts);
710 #endif
711  }
712 }
713 
715 
717 {
718  // Compute lines visibility, only for display
719  vpMbtDistanceLine *line;
720  for (std::vector<vpMbtDistanceLine *>::const_iterator it = m_listOfFaceLines.begin(); it != m_listOfFaceLines.end();
721  ++it) {
722  line = *it;
723  bool isvisible = false;
724 
725  for (std::list<int>::const_iterator itindex = line->Lindex_polygon.begin(); itindex != line->Lindex_polygon.end();
726  ++itindex) {
727  int index = *itindex;
728  if (index == -1) {
729  isvisible = true;
730  } else {
731  if (line->hiddenface->isVisible((unsigned int)index)) {
732  isvisible = true;
733  }
734  }
735  }
736 
737  // Si la ligne n'appartient a aucune face elle est tout le temps visible
738  if (line->Lindex_polygon.empty())
739  isvisible = true; // Not sure that this can occur
740 
741  if (isvisible) {
742  line->setVisible(true);
743  } else {
744  line->setVisible(false);
745  }
746  }
747 }
748 
749 void vpMbtFaceDepthNormal::computeNormalVisibility(const double nx, const double ny, const double nz,
750  const vpHomogeneousMatrix &cMo, const vpCameraParameters &camera,
751  vpColVector &correct_normal, vpPoint &centroid)
752 {
753  vpColVector faceNormal(3);
754  faceNormal[0] = nx;
755  faceNormal[1] = ny;
756  faceNormal[2] = nz;
757  faceNormal.normalize();
758 
759  // Get polygon clipped
760  std::vector<vpImagePoint> roiPts;
761  m_polygon->getRoiClipped(camera, roiPts, cMo);
762 
763  std::vector<vpPoint> polyPts;
764  m_polygon->getPolygonClipped(polyPts);
765 
766  vpColVector e4(3);
768  computePolygonCentroid(polyPts, centroid);
769  centroid.project();
770 
771  e4[0] = -centroid.get_X();
772  e4[1] = -centroid.get_Y();
773  e4[2] = -centroid.get_Z();
774  e4.normalize();
775  } else {
776  double centroid_x = 0.0;
777  double centroid_y = 0.0;
778  double centroid_z = 0.0;
779 
780  for (size_t i = 0; i < polyPts.size(); i++) {
781  centroid_x += polyPts[i].get_X();
782  centroid_y += polyPts[i].get_Y();
783  centroid_z += polyPts[i].get_Z();
784  }
785 
786  centroid_x /= polyPts.size();
787  centroid_y /= polyPts.size();
788  centroid_z /= polyPts.size();
789 
790  e4[0] = -centroid_x;
791  e4[1] = -centroid_y;
792  e4[2] = -centroid_z;
793  e4.normalize();
794 
795  centroid.set_X(centroid_x);
796  centroid.set_Y(centroid_y);
797  centroid.set_Z(centroid_z);
798  }
799 
800  correct_normal.resize(3, false);
801  double angle = acos(vpColVector::dotProd(e4, faceNormal));
802  if (angle < M_PI_2) {
803  correct_normal = faceNormal;
804  } else {
805  correct_normal[0] = -faceNormal[0];
806  correct_normal[1] = -faceNormal[1];
807  correct_normal[2] = -faceNormal[2];
808  }
809 }
810 
811 #ifdef VISP_HAVE_PCL
812 void vpMbtFaceDepthNormal::computeNormalVisibility(const float nx, const float ny, const float nz,
813  const pcl::PointXYZ &centroid_point, pcl::PointXYZ &face_normal)
814 {
815  vpColVector faceNormal(3);
816  faceNormal[0] = nx;
817  faceNormal[1] = ny;
818  faceNormal[2] = nz;
819  faceNormal.normalize();
820 
821  vpColVector e4(3);
822  e4[0] = -centroid_point.x;
823  e4[1] = -centroid_point.y;
824  e4[2] = -centroid_point.z;
825  e4.normalize();
826 
827  double angle = acos(vpColVector::dotProd(e4, faceNormal));
828  if (angle < M_PI_2) {
829  face_normal = pcl::PointXYZ(faceNormal[0], faceNormal[1], faceNormal[2]);
830  } else {
831  face_normal = pcl::PointXYZ(-faceNormal[0], -faceNormal[1], -faceNormal[2]);
832  }
833 }
834 #endif
835 
836 void vpMbtFaceDepthNormal::computeNormalVisibility(const double nx, const double ny, const double nz,
837  const vpColVector &centroid_point, vpColVector &face_normal)
838 {
839  face_normal.resize(3, false);
840  face_normal[0] = nx;
841  face_normal[1] = ny;
842  face_normal[2] = nz;
843  face_normal.normalize();
844 
845  vpColVector e4 = -centroid_point;
846  e4.normalize();
847 
848  double angle = acos(vpColVector::dotProd(e4, face_normal));
849  if (angle >= M_PI_2) {
850  face_normal[0] = -face_normal[0];
851  face_normal[1] = -face_normal[1];
852  face_normal[2] = -face_normal[2];
853  }
854 }
855 
857 {
858  L.resize(3, 6, false, false);
859 
860  // Transform the plane equation for the current pose
863 
864  double ux = m_planeCamera.getA();
865  double uy = m_planeCamera.getB();
866  double uz = m_planeCamera.getC();
867  double D = m_planeCamera.getD();
868  double D2 = D * D;
869 
870  // Features
871  features.resize(3, false);
872  features[0] = -ux / D;
873  features[1] = -uy / D;
874  features[2] = -uz / D;
875 
876  // L_A
877  L[0][0] = ux * ux / D2;
878  L[0][1] = ux * uy / D2;
879  L[0][2] = ux * uz / D2;
880  L[0][3] = 0.0;
881  L[0][4] = uz / D;
882  L[0][5] = -uy / D;
883 
884  // L_B
885  L[1][0] = ux * uy / D2;
886  L[1][1] = uy * uy / D2;
887  L[1][2] = uy * uz / D2;
888  L[1][3] = -uz / D;
889  L[1][4] = 0.0;
890  L[1][5] = ux / D;
891 
892  // L_C
893  L[2][0] = ux * uz / D2;
894  L[2][1] = uy * uz / D2;
895  L[2][2] = uz * uz / D2;
896  L[2][3] = uy / D;
897  L[2][4] = -ux / D;
898  L[2][5] = 0.0;
899 }
900 
902  const vpCameraParameters &cam, const vpColor &col, const unsigned int thickness,
903  const bool displayFullModel)
904 {
905  std::vector<std::vector<double> > models = getModelForDisplay(I.getWidth(), I.getHeight(), cMo, cam, displayFullModel);
906 
907  for (size_t i = 0; i < models.size(); i++) {
908  vpImagePoint ip1(models[i][1], models[i][2]);
909  vpImagePoint ip2(models[i][3], models[i][4]);
910  vpDisplay::displayLine(I, ip1, ip2, col, thickness);
911  }
912 }
913 
915  const vpCameraParameters &cam, const vpColor &col, const unsigned int thickness,
916  const bool displayFullModel)
917 {
918  std::vector<std::vector<double> > models = getModelForDisplay(I.getWidth(), I.getHeight(), cMo, cam, displayFullModel);
919 
920  for (size_t i = 0; i < models.size(); i++) {
921  vpImagePoint ip1(models[i][1], models[i][2]);
922  vpImagePoint ip2(models[i][3], models[i][4]);
923  vpDisplay::displayLine(I, ip1, ip2, col, thickness);
924  }
925 }
926 
928  const vpCameraParameters &cam, const double scale,
929  const unsigned int thickness)
930 {
932  // Desired feature
933  vpPoint pt_centroid = m_faceDesiredCentroid;
934  pt_centroid.changeFrame(cMo);
935  pt_centroid.project();
936 
937  vpImagePoint im_centroid;
938  vpMeterPixelConversion::convertPoint(cam, pt_centroid.get_x(), pt_centroid.get_y(), im_centroid);
939 
940  vpPoint pt_normal = m_faceDesiredNormal;
941  pt_normal.changeFrame(cMo);
942  pt_normal.project();
943 
944  vpPoint pt_extremity;
945  pt_extremity.set_X(pt_centroid.get_X() + pt_normal.get_X() * scale);
946  pt_extremity.set_Y(pt_centroid.get_Y() + pt_normal.get_Y() * scale);
947  pt_extremity.set_Z(pt_centroid.get_Z() + pt_normal.get_Z() * scale);
948  pt_extremity.project();
949 
950  vpImagePoint im_extremity;
951  vpMeterPixelConversion::convertPoint(cam, pt_extremity.get_x(), pt_extremity.get_y(), im_extremity);
952 
953  vpDisplay::displayArrow(I, im_centroid, im_extremity, vpColor::blue, 4, 2, thickness);
954 
955  // Current feature
956  // Transform the plane equation for the current pose
959 
960  double ux = m_planeCamera.getA();
961  double uy = m_planeCamera.getB();
962  double uz = m_planeCamera.getC();
963 
964  vpColVector correct_normal;
965  vpCameraParameters cam_copy = cam;
966  cam_copy.computeFov(I.getWidth(), I.getHeight());
967  computeNormalVisibility(ux, uy, uz, cMo, cam_copy, correct_normal, pt_centroid);
968 
969  pt_centroid.project();
970  vpMeterPixelConversion::convertPoint(cam_copy, pt_centroid.get_x(), pt_centroid.get_y(), im_centroid);
971 
972  pt_extremity.set_X(pt_centroid.get_X() + correct_normal[0] * scale);
973  pt_extremity.set_Y(pt_centroid.get_Y() + correct_normal[1] * scale);
974  pt_extremity.set_Z(pt_centroid.get_Z() + correct_normal[2] * scale);
975  pt_extremity.project();
976 
977  vpMeterPixelConversion::convertPoint(cam_copy, pt_extremity.get_x(), pt_extremity.get_y(), im_extremity);
978 
979  vpDisplay::displayArrow(I, im_centroid, im_extremity, vpColor::red, 4, 2, thickness);
980  }
981 }
982 
984  const vpCameraParameters &cam, const double scale,
985  const unsigned int thickness)
986 {
988  // Desired feature
989  vpPoint pt_centroid = m_faceDesiredCentroid;
990  pt_centroid.changeFrame(cMo);
991  pt_centroid.project();
992 
993  vpImagePoint im_centroid;
994  vpMeterPixelConversion::convertPoint(cam, pt_centroid.get_x(), pt_centroid.get_y(), im_centroid);
995 
996  vpPoint pt_normal = m_faceDesiredNormal;
997  pt_normal.changeFrame(cMo);
998  pt_normal.project();
999 
1000  vpPoint pt_extremity;
1001  pt_extremity.set_X(pt_centroid.get_X() + pt_normal.get_X() * scale);
1002  pt_extremity.set_Y(pt_centroid.get_Y() + pt_normal.get_Y() * scale);
1003  pt_extremity.set_Z(pt_centroid.get_Z() + pt_normal.get_Z() * scale);
1004  pt_extremity.project();
1005 
1006  vpImagePoint im_extremity;
1007  vpMeterPixelConversion::convertPoint(cam, pt_extremity.get_x(), pt_extremity.get_y(), im_extremity);
1008 
1009  vpDisplay::displayArrow(I, im_centroid, im_extremity, vpColor::blue, 4, 2, thickness);
1010 
1011  // Current feature
1012  // Transform the plane equation for the current pose
1015 
1016  double ux = m_planeCamera.getA();
1017  double uy = m_planeCamera.getB();
1018  double uz = m_planeCamera.getC();
1019 
1020  vpColVector correct_normal;
1021  vpCameraParameters cam_copy = cam;
1022  cam_copy.computeFov(I.getWidth(), I.getHeight());
1023  computeNormalVisibility(ux, uy, uz, cMo, cam_copy, correct_normal, pt_centroid);
1024 
1025  pt_centroid.project();
1026  vpMeterPixelConversion::convertPoint(cam_copy, pt_centroid.get_x(), pt_centroid.get_y(), im_centroid);
1027 
1028  pt_extremity.set_X(pt_centroid.get_X() + correct_normal[0] * scale);
1029  pt_extremity.set_Y(pt_centroid.get_Y() + correct_normal[1] * scale);
1030  pt_extremity.set_Z(pt_centroid.get_Z() + correct_normal[2] * scale);
1031  pt_extremity.project();
1032 
1033  vpMeterPixelConversion::convertPoint(cam_copy, pt_extremity.get_x(), pt_extremity.get_y(), im_extremity);
1034 
1035  vpDisplay::displayArrow(I, im_centroid, im_extremity, vpColor::red, 4, 2, thickness);
1036  }
1037 }
1038 
1039 void vpMbtFaceDepthNormal::estimateFeatures(const std::vector<double> &point_cloud_face, const vpHomogeneousMatrix &cMo,
1040  vpColVector &x_estimated, std::vector<double> &w)
1041 {
1042  vpMbtTukeyEstimator<double> tukey_robust;
1043  std::vector<double> residues(point_cloud_face.size() / 3);
1044 
1045  w.resize(point_cloud_face.size() / 3, 1.0);
1046 
1047  unsigned int max_iter = 30, iter = 0;
1048  double error = 0.0, prev_error = -1.0;
1049  double A = 0.0, B = 0.0, C = 0.0;
1050 
1051  Mat33<double> ATA_3x3;
1052 
1053  bool checkSSE2 = vpCPUFeatures::checkSSE2();
1054 #if !USE_SSE
1055  checkSSE2 = false;
1056 #endif
1057 
1058  if (checkSSE2) {
1059 #if USE_SSE
1060  while (std::fabs(error - prev_error) > 1e-6 && (iter < max_iter)) {
1061  if (iter == 0) {
1062  // Transform the plane equation for the current pose
1065 
1066  double ux = m_planeCamera.getA();
1067  double uy = m_planeCamera.getB();
1068  double uz = m_planeCamera.getC();
1069  double D = m_planeCamera.getD();
1070 
1071  // Features
1072  A = -ux / D;
1073  B = -uy / D;
1074  C = -uz / D;
1075 
1076  size_t cpt = 0;
1077  if (point_cloud_face.size() / 3 >= 2) {
1078  const double *ptr_point_cloud = &point_cloud_face[0];
1079  const __m128d vA = _mm_set1_pd(A);
1080  const __m128d vB = _mm_set1_pd(B);
1081  const __m128d vC = _mm_set1_pd(C);
1082  const __m128d vones = _mm_set1_pd(1.0);
1083 
1084  double *ptr_residues = &residues[0];
1085 
1086  for (; cpt <= point_cloud_face.size() - 6; cpt += 6, ptr_point_cloud += 6, ptr_residues += 2) {
1087  const __m128d vxi = _mm_loadu_pd(ptr_point_cloud);
1088  const __m128d vyi = _mm_loadu_pd(ptr_point_cloud + 2);
1089  const __m128d vZi = _mm_loadu_pd(ptr_point_cloud + 4);
1090  const __m128d vinvZi = _mm_div_pd(vones, vZi);
1091 
1092  const __m128d tmp =
1093  _mm_add_pd(_mm_add_pd(_mm_mul_pd(vA, vxi), _mm_mul_pd(vB, vyi)), _mm_sub_pd(vC, vinvZi));
1094  _mm_storeu_pd(ptr_residues, tmp);
1095  }
1096  }
1097 
1098  for (; cpt < point_cloud_face.size(); cpt += 3) {
1099  double xi = point_cloud_face[cpt];
1100  double yi = point_cloud_face[cpt + 1];
1101  double Zi = point_cloud_face[cpt + 2];
1102 
1103  residues[cpt / 3] = (A * xi + B * yi + C - 1 / Zi);
1104  }
1105  }
1106 
1107  tukey_robust.MEstimator(residues, w, 1e-2);
1108 
1109  __m128d vsum_wi2_xi2 = _mm_setzero_pd();
1110  __m128d vsum_wi2_yi2 = _mm_setzero_pd();
1111  __m128d vsum_wi2 = _mm_setzero_pd();
1112  __m128d vsum_wi2_xi_yi = _mm_setzero_pd();
1113  __m128d vsum_wi2_xi = _mm_setzero_pd();
1114  __m128d vsum_wi2_yi = _mm_setzero_pd();
1115 
1116  __m128d vsum_wi2_xi_Zi = _mm_setzero_pd();
1117  __m128d vsum_wi2_yi_Zi = _mm_setzero_pd();
1118  __m128d vsum_wi2_Zi = _mm_setzero_pd();
1119 
1120  // Estimate A, B, C
1121  size_t cpt = 0;
1122  if (point_cloud_face.size() / 3 >= 2) {
1123  const double *ptr_point_cloud = &point_cloud_face[0];
1124  double *ptr_w = &w[0];
1125 
1126  const __m128d vones = _mm_set1_pd(1.0);
1127 
1128  for (; cpt <= point_cloud_face.size() - 6; cpt += 6, ptr_point_cloud += 6, ptr_w += 2) {
1129  const __m128d vwi2 = _mm_mul_pd(_mm_loadu_pd(ptr_w), _mm_loadu_pd(ptr_w));
1130 
1131  const __m128d vxi = _mm_loadu_pd(ptr_point_cloud);
1132  const __m128d vyi = _mm_loadu_pd(ptr_point_cloud + 2);
1133  const __m128d vZi = _mm_loadu_pd(ptr_point_cloud + 4);
1134  const __m128d vinvZi = _mm_div_pd(vones, vZi);
1135 
1136  vsum_wi2_xi2 = _mm_add_pd(vsum_wi2_xi2, _mm_mul_pd(vwi2, _mm_mul_pd(vxi, vxi)));
1137  vsum_wi2_yi2 = _mm_add_pd(vsum_wi2_yi2, _mm_mul_pd(vwi2, _mm_mul_pd(vyi, vyi)));
1138  vsum_wi2 = _mm_add_pd(vsum_wi2, vwi2);
1139  vsum_wi2_xi_yi = _mm_add_pd(vsum_wi2_xi_yi, _mm_mul_pd(vwi2, _mm_mul_pd(vxi, vyi)));
1140  vsum_wi2_xi = _mm_add_pd(vsum_wi2_xi, _mm_mul_pd(vwi2, vxi));
1141  vsum_wi2_yi = _mm_add_pd(vsum_wi2_yi, _mm_mul_pd(vwi2, vyi));
1142 
1143  const __m128d vwi2_invZi = _mm_mul_pd(vwi2, vinvZi);
1144  vsum_wi2_xi_Zi = _mm_add_pd(vsum_wi2_xi_Zi, _mm_mul_pd(vxi, vwi2_invZi));
1145  vsum_wi2_yi_Zi = _mm_add_pd(vsum_wi2_yi_Zi, _mm_mul_pd(vyi, vwi2_invZi));
1146  vsum_wi2_Zi = _mm_add_pd(vsum_wi2_Zi, vwi2_invZi);
1147  }
1148  }
1149 
1150  double vtmp[2];
1151  _mm_storeu_pd(vtmp, vsum_wi2_xi2);
1152  double sum_wi2_xi2 = vtmp[0] + vtmp[1];
1153 
1154  _mm_storeu_pd(vtmp, vsum_wi2_yi2);
1155  double sum_wi2_yi2 = vtmp[0] + vtmp[1];
1156 
1157  _mm_storeu_pd(vtmp, vsum_wi2);
1158  double sum_wi2 = vtmp[0] + vtmp[1];
1159 
1160  _mm_storeu_pd(vtmp, vsum_wi2_xi_yi);
1161  double sum_wi2_xi_yi = vtmp[0] + vtmp[1];
1162 
1163  _mm_storeu_pd(vtmp, vsum_wi2_xi);
1164  double sum_wi2_xi = vtmp[0] + vtmp[1];
1165 
1166  _mm_storeu_pd(vtmp, vsum_wi2_yi);
1167  double sum_wi2_yi = vtmp[0] + vtmp[1];
1168 
1169  _mm_storeu_pd(vtmp, vsum_wi2_xi_Zi);
1170  double sum_wi2_xi_Zi = vtmp[0] + vtmp[1];
1171 
1172  _mm_storeu_pd(vtmp, vsum_wi2_yi_Zi);
1173  double sum_wi2_yi_Zi = vtmp[0] + vtmp[1];
1174 
1175  _mm_storeu_pd(vtmp, vsum_wi2_Zi);
1176  double sum_wi2_Zi = vtmp[0] + vtmp[1];
1177 
1178  for (; cpt < point_cloud_face.size(); cpt += 3) {
1179  double wi2 = w[cpt / 3] * w[cpt / 3];
1180 
1181  double xi = point_cloud_face[cpt];
1182  double yi = point_cloud_face[cpt + 1];
1183  double Zi = point_cloud_face[cpt + 2];
1184  double invZi = 1.0 / Zi;
1185 
1186  sum_wi2_xi2 += wi2 * xi * xi;
1187  sum_wi2_yi2 += wi2 * yi * yi;
1188  sum_wi2 += wi2;
1189  sum_wi2_xi_yi += wi2 * xi * yi;
1190  sum_wi2_xi += wi2 * xi;
1191  sum_wi2_yi += wi2 * yi;
1192 
1193  sum_wi2_xi_Zi += wi2 * xi * invZi;
1194  sum_wi2_yi_Zi += wi2 * yi * invZi;
1195  sum_wi2_Zi += wi2 * invZi;
1196  }
1197 
1198  ATA_3x3[0] = sum_wi2_xi2;
1199  ATA_3x3[1] = sum_wi2_xi_yi;
1200  ATA_3x3[2] = sum_wi2_xi;
1201  ATA_3x3[3] = sum_wi2_xi_yi;
1202  ATA_3x3[4] = sum_wi2_yi2;
1203  ATA_3x3[5] = sum_wi2_yi;
1204  ATA_3x3[6] = sum_wi2_xi;
1205  ATA_3x3[7] = sum_wi2_yi;
1206  ATA_3x3[8] = sum_wi2;
1207 
1208  Mat33<double> minv = ATA_3x3.inverse();
1209 
1210  A = minv[0] * sum_wi2_xi_Zi + minv[1] * sum_wi2_yi_Zi + minv[2] * sum_wi2_Zi;
1211  B = minv[3] * sum_wi2_xi_Zi + minv[4] * sum_wi2_yi_Zi + minv[5] * sum_wi2_Zi;
1212  C = minv[6] * sum_wi2_xi_Zi + minv[7] * sum_wi2_yi_Zi + minv[8] * sum_wi2_Zi;
1213 
1214  cpt = 0;
1215 
1216  // Compute error
1217  prev_error = error;
1218  error = 0.0;
1219 
1220  __m128d verror = _mm_set1_pd(0.0);
1221  if (point_cloud_face.size() / 3 >= 2) {
1222  const double *ptr_point_cloud = &point_cloud_face[0];
1223  const __m128d vA = _mm_set1_pd(A);
1224  const __m128d vB = _mm_set1_pd(B);
1225  const __m128d vC = _mm_set1_pd(C);
1226  const __m128d vones = _mm_set1_pd(1.0);
1227 
1228  double *ptr_residues = &residues[0];
1229 
1230  for (; cpt <= point_cloud_face.size() - 6; cpt += 6, ptr_point_cloud += 6, ptr_residues += 2) {
1231  const __m128d vxi = _mm_loadu_pd(ptr_point_cloud);
1232  const __m128d vyi = _mm_loadu_pd(ptr_point_cloud + 2);
1233  const __m128d vZi = _mm_loadu_pd(ptr_point_cloud + 4);
1234  const __m128d vinvZi = _mm_div_pd(vones, vZi);
1235 
1236  const __m128d tmp = _mm_add_pd(_mm_add_pd(_mm_mul_pd(vA, vxi), _mm_mul_pd(vB, vyi)), _mm_sub_pd(vC, vinvZi));
1237  verror = _mm_add_pd(verror, _mm_mul_pd(tmp, tmp));
1238 
1239  _mm_storeu_pd(ptr_residues, tmp);
1240  }
1241  }
1242 
1243  _mm_storeu_pd(vtmp, verror);
1244  error = vtmp[0] + vtmp[1];
1245 
1246  for (size_t idx = cpt; idx < point_cloud_face.size(); idx += 3) {
1247  double xi = point_cloud_face[idx];
1248  double yi = point_cloud_face[idx + 1];
1249  double Zi = point_cloud_face[idx + 2];
1250 
1251  error += vpMath::sqr(A * xi + B * yi + C - 1 / Zi);
1252  residues[idx / 3] = (A * xi + B * yi + C - 1 / Zi);
1253  }
1254 
1255  error /= point_cloud_face.size() / 3;
1256 
1257  iter++;
1258  } // while ( std::fabs(error - prev_error) > 1e-6 && (iter < max_iter) )
1259 #endif
1260  } else {
1261  while (std::fabs(error - prev_error) > 1e-6 && (iter < max_iter)) {
1262  if (iter == 0) {
1263  // Transform the plane equation for the current pose
1266 
1267  double ux = m_planeCamera.getA();
1268  double uy = m_planeCamera.getB();
1269  double uz = m_planeCamera.getC();
1270  double D = m_planeCamera.getD();
1271 
1272  // Features
1273  A = -ux / D;
1274  B = -uy / D;
1275  C = -uz / D;
1276 
1277  for (size_t i = 0; i < point_cloud_face.size() / 3; i++) {
1278  double xi = point_cloud_face[3 * i];
1279  double yi = point_cloud_face[3 * i + 1];
1280  double Zi = point_cloud_face[3 * i + 2];
1281 
1282  residues[i] = (A * xi + B * yi + C - 1 / Zi);
1283  }
1284  }
1285 
1286  tukey_robust.MEstimator(residues, w, 1e-2);
1287 
1288  // Estimate A, B, C
1289  double sum_wi2_xi2 = 0.0, sum_wi2_yi2 = 0.0, sum_wi2 = 0.0;
1290  double sum_wi2_xi_yi = 0.0, sum_wi2_xi = 0.0, sum_wi2_yi = 0.0;
1291 
1292  double sum_wi2_xi_Zi = 0.0, sum_wi2_yi_Zi = 0.0, sum_wi2_Zi = 0.0;
1293 
1294  for (size_t i = 0; i < point_cloud_face.size() / 3; i++) {
1295  double wi2 = w[i] * w[i];
1296 
1297  double xi = point_cloud_face[3 * i];
1298  double yi = point_cloud_face[3 * i + 1];
1299  double Zi = point_cloud_face[3 * i + 2];
1300  double invZi = 1 / Zi;
1301 
1302  sum_wi2_xi2 += wi2 * xi * xi;
1303  sum_wi2_yi2 += wi2 * yi * yi;
1304  sum_wi2 += wi2;
1305  sum_wi2_xi_yi += wi2 * xi * yi;
1306  sum_wi2_xi += wi2 * xi;
1307  sum_wi2_yi += wi2 * yi;
1308 
1309  sum_wi2_xi_Zi += wi2 * xi * invZi;
1310  sum_wi2_yi_Zi += wi2 * yi * invZi;
1311  sum_wi2_Zi += wi2 * invZi;
1312  }
1313 
1314  ATA_3x3[0] = sum_wi2_xi2;
1315  ATA_3x3[1] = sum_wi2_xi_yi;
1316  ATA_3x3[2] = sum_wi2_xi;
1317  ATA_3x3[3] = sum_wi2_xi_yi;
1318  ATA_3x3[4] = sum_wi2_yi2;
1319  ATA_3x3[5] = sum_wi2_yi;
1320  ATA_3x3[6] = sum_wi2_xi;
1321  ATA_3x3[7] = sum_wi2_yi;
1322  ATA_3x3[8] = sum_wi2;
1323 
1324  Mat33<double> minv = ATA_3x3.inverse();
1325 
1326  A = minv[0] * sum_wi2_xi_Zi + minv[1] * sum_wi2_yi_Zi + minv[2] * sum_wi2_Zi;
1327  B = minv[3] * sum_wi2_xi_Zi + minv[4] * sum_wi2_yi_Zi + minv[5] * sum_wi2_Zi;
1328  C = minv[6] * sum_wi2_xi_Zi + minv[7] * sum_wi2_yi_Zi + minv[8] * sum_wi2_Zi;
1329 
1330  prev_error = error;
1331  error = 0.0;
1332 
1333  // Compute error
1334  for (size_t i = 0; i < point_cloud_face.size() / 3; i++) {
1335  double xi = point_cloud_face[3 * i];
1336  double yi = point_cloud_face[3 * i + 1];
1337  double Zi = point_cloud_face[3 * i + 2];
1338 
1339  error += vpMath::sqr(A * xi + B * yi + C - 1 / Zi);
1340  residues[i] = (A * xi + B * yi + C - 1 / Zi);
1341  }
1342 
1343  error /= point_cloud_face.size() / 3;
1344 
1345  iter++;
1346  } // while ( std::fabs(error - prev_error) > 1e-6 && (iter < max_iter) )
1347  }
1348 
1349  x_estimated.resize(3, false);
1350  x_estimated[0] = A;
1351  x_estimated[1] = B;
1352  x_estimated[2] = C;
1353 }
1354 
1355 void vpMbtFaceDepthNormal::estimatePlaneEquationSVD(const std::vector<double> &point_cloud_face,
1356  const vpHomogeneousMatrix &cMo,
1357  vpColVector &plane_equation_estimated, vpColVector &centroid)
1358 {
1359  const unsigned int max_iter = 10;
1360  double prev_error = 1e3;
1361  double error = 1e3 - 1;
1362 
1363  std::vector<double> weights(point_cloud_face.size() / 3, 1.0);
1364  std::vector<double> residues(point_cloud_face.size() / 3);
1365  vpMatrix M((unsigned int)(point_cloud_face.size() / 3), 3);
1366  vpMbtTukeyEstimator<double> tukey;
1367  vpColVector normal;
1368 
1369  for (unsigned int iter = 0; iter < max_iter && std::fabs(error - prev_error) > 1e-6; iter++) {
1370  if (iter != 0) {
1371  tukey.MEstimator(residues, weights, 1e-4);
1372  } else {
1373  // Transform the plane equation for the current pose
1376 
1377  double A = m_planeCamera.getA();
1378  double B = m_planeCamera.getB();
1379  double C = m_planeCamera.getC();
1380  double D = m_planeCamera.getD();
1381 
1382  // Compute distance point to estimated plane
1383  for (size_t i = 0; i < point_cloud_face.size() / 3; i++) {
1384  residues[i] = std::fabs(A * point_cloud_face[3 * i] + B * point_cloud_face[3 * i + 1] +
1385  C * point_cloud_face[3 * i + 2] + D) /
1386  sqrt(A * A + B * B + C * C);
1387  }
1388 
1389  tukey.MEstimator(residues, weights, 1e-4);
1390  plane_equation_estimated.resize(4, false);
1391  }
1392 
1393  // Compute centroid
1394  double centroid_x = 0.0, centroid_y = 0.0, centroid_z = 0.0;
1395  double total_w = 0.0;
1396 
1397  for (size_t i = 0; i < point_cloud_face.size() / 3; i++) {
1398  centroid_x += weights[i] * point_cloud_face[3 * i];
1399  centroid_y += weights[i] * point_cloud_face[3 * i + 1];
1400  centroid_z += weights[i] * point_cloud_face[3 * i + 2];
1401  total_w += weights[i];
1402  }
1403 
1404  centroid_x /= total_w;
1405  centroid_y /= total_w;
1406  centroid_z /= total_w;
1407 
1408  // Minimization
1409  for (size_t i = 0; i < point_cloud_face.size() / 3; i++) {
1410  M[(unsigned int)i][0] = weights[i] * (point_cloud_face[3 * i] - centroid_x);
1411  M[(unsigned int)i][1] = weights[i] * (point_cloud_face[3 * i + 1] - centroid_y);
1412  M[(unsigned int)i][2] = weights[i] * (point_cloud_face[3 * i + 2] - centroid_z);
1413  }
1414 
1415  vpMatrix J = M.t() * M;
1416 
1417  vpColVector W;
1418  vpMatrix V;
1419  J.svd(W, V);
1420 
1421  double smallestSv = W[0];
1422  unsigned int indexSmallestSv = 0;
1423  for (unsigned int i = 1; i < W.size(); i++) {
1424  if (W[i] < smallestSv) {
1425  smallestSv = W[i];
1426  indexSmallestSv = i;
1427  }
1428  }
1429 
1430  normal = V.getCol(indexSmallestSv);
1431 
1432  // Compute plane equation
1433  double A = normal[0], B = normal[1], C = normal[2];
1434  double D = -(A * centroid_x + B * centroid_y + C * centroid_z);
1435 
1436  // Update plane equation
1437  plane_equation_estimated[0] = A;
1438  plane_equation_estimated[1] = B;
1439  plane_equation_estimated[2] = C;
1440  plane_equation_estimated[3] = D;
1441 
1442  // Compute error points to estimated plane
1443  prev_error = error;
1444  error = 0.0;
1445  for (size_t i = 0; i < point_cloud_face.size() / 3; i++) {
1446  residues[i] = std::fabs(A * point_cloud_face[3 * i] + B * point_cloud_face[3 * i + 1] +
1447  C * point_cloud_face[3 * i + 2] + D) /
1448  sqrt(A * A + B * B + C * C);
1449  error += residues[i] * residues[i];
1450  }
1451  error /= sqrt(error / total_w);
1452  }
1453 
1454  // Update final weights
1455  tukey.MEstimator(residues, weights, 1e-4);
1456 
1457  // Update final centroid
1458  centroid.resize(3, false);
1459  double total_w = 0.0;
1460 
1461  for (size_t i = 0; i < point_cloud_face.size() / 3; i++) {
1462  centroid[0] += weights[i] * point_cloud_face[3 * i];
1463  centroid[1] += weights[i] * point_cloud_face[3 * i + 1];
1464  centroid[2] += weights[i] * point_cloud_face[3 * i + 2];
1465  total_w += weights[i];
1466  }
1467 
1468  centroid[0] /= total_w;
1469  centroid[1] /= total_w;
1470  centroid[2] /= total_w;
1471 
1472  // Compute final plane equation
1473  double A = normal[0], B = normal[1], C = normal[2];
1474  double D = -(A * centroid[0] + B * centroid[1] + C * centroid[2]);
1475 
1476  // Update final plane equation
1477  plane_equation_estimated[0] = A;
1478  plane_equation_estimated[1] = B;
1479  plane_equation_estimated[2] = C;
1480  plane_equation_estimated[3] = D;
1481 }
1482 
1488 std::vector<std::vector<double> > vpMbtFaceDepthNormal::getFeaturesForDisplay(const vpHomogeneousMatrix &cMo,
1489  const vpCameraParameters &cam,
1490  const double scale)
1491 {
1492  std::vector<std::vector<double> > features;
1493 
1495  // Desired feature
1496  vpPoint pt_centroid = m_faceDesiredCentroid;
1497  pt_centroid.changeFrame(cMo);
1498  pt_centroid.project();
1499 
1500  vpImagePoint im_centroid;
1501  vpMeterPixelConversion::convertPoint(cam, pt_centroid.get_x(), pt_centroid.get_y(), im_centroid);
1502 
1503  vpPoint pt_normal = m_faceDesiredNormal;
1504  pt_normal.changeFrame(cMo);
1505  pt_normal.project();
1506 
1507  vpPoint pt_extremity;
1508  pt_extremity.set_X(pt_centroid.get_X() + pt_normal.get_X() * scale);
1509  pt_extremity.set_Y(pt_centroid.get_Y() + pt_normal.get_Y() * scale);
1510  pt_extremity.set_Z(pt_centroid.get_Z() + pt_normal.get_Z() * scale);
1511  pt_extremity.project();
1512 
1513  vpImagePoint im_extremity;
1514  vpMeterPixelConversion::convertPoint(cam, pt_extremity.get_x(), pt_extremity.get_y(), im_extremity);
1515 
1516  {
1517 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
1518  std::vector<double> params = {2, //desired normal
1519  im_centroid.get_i(),
1520  im_centroid.get_j(),
1521  im_extremity.get_i(),
1522  im_extremity.get_j()};
1523 #else
1524  std::vector<double> params;
1525  params.push_back(2); //desired normal
1526  params.push_back(im_centroid.get_i());
1527  params.push_back(im_centroid.get_j());
1528  params.push_back(im_extremity.get_i());
1529  params.push_back(im_extremity.get_j());
1530 #endif
1531  features.push_back(params);
1532  }
1533 
1534  // Current feature
1535  // Transform the plane equation for the current pose
1538 
1539  double ux = m_planeCamera.getA();
1540  double uy = m_planeCamera.getB();
1541  double uz = m_planeCamera.getC();
1542 
1543  vpColVector correct_normal;
1544  computeNormalVisibility(ux, uy, uz, cMo, cam, correct_normal, pt_centroid);
1545 
1546  pt_centroid.project();
1547  vpMeterPixelConversion::convertPoint(cam, pt_centroid.get_x(), pt_centroid.get_y(), im_centroid);
1548 
1549  pt_extremity.set_X(pt_centroid.get_X() + correct_normal[0] * scale);
1550  pt_extremity.set_Y(pt_centroid.get_Y() + correct_normal[1] * scale);
1551  pt_extremity.set_Z(pt_centroid.get_Z() + correct_normal[2] * scale);
1552  pt_extremity.project();
1553 
1554  vpMeterPixelConversion::convertPoint(cam, pt_extremity.get_x(), pt_extremity.get_y(), im_extremity);
1555 
1556  {
1557 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
1558  std::vector<double> params = {3, //normal at current pose
1559  im_centroid.get_i(),
1560  im_centroid.get_j(),
1561  im_extremity.get_i(),
1562  im_extremity.get_j()};
1563 #else
1564  std::vector<double> params;
1565  params.push_back(3); //normal at current pose
1566  params.push_back(im_centroid.get_i());
1567  params.push_back(im_centroid.get_j());
1568  params.push_back(im_extremity.get_i());
1569  params.push_back(im_extremity.get_j());
1570 #endif
1571  features.push_back(params);
1572  }
1573  }
1574 
1575  return features;
1576 }
1577 
1589 std::vector<std::vector<double> > vpMbtFaceDepthNormal::getModelForDisplay(unsigned int width, unsigned int height,
1590  const vpHomogeneousMatrix &cMo,
1591  const vpCameraParameters &cam,
1592  const bool displayFullModel)
1593 {
1594  std::vector<std::vector<double> > models;
1595 
1596  if ((m_polygon->isVisible() && m_isTrackedDepthNormalFace) || displayFullModel) {
1598 
1599  for (std::vector<vpMbtDistanceLine *>::const_iterator it = m_listOfFaceLines.begin(); it != m_listOfFaceLines.end();
1600  ++it) {
1601  vpMbtDistanceLine *line = *it;
1602  std::vector<std::vector<double> > lineModels = line->getModelForDisplay(width, height, cMo, cam, displayFullModel);
1603  models.insert(models.end(), lineModels.begin(), lineModels.end());
1604  }
1605  }
1606 
1607  return models;
1608 }
1609 
1619 bool vpMbtFaceDepthNormal::samePoint(const vpPoint &P1, const vpPoint &P2) const
1620 {
1621  double dx = fabs(P1.get_oX() - P2.get_oX());
1622  double dy = fabs(P1.get_oY() - P2.get_oY());
1623  double dz = fabs(P1.get_oZ() - P2.get_oZ());
1624 
1625  if (dx <= std::numeric_limits<double>::epsilon() && dy <= std::numeric_limits<double>::epsilon() &&
1626  dz <= std::numeric_limits<double>::epsilon())
1627  return true;
1628  else
1629  return false;
1630 }
1631 
1633 {
1634  m_cam = camera;
1635 
1636  for (std::vector<vpMbtDistanceLine *>::const_iterator it = m_listOfFaceLines.begin(); it != m_listOfFaceLines.end();
1637  ++it) {
1638  (*it)->setCameraParameters(camera);
1639  }
1640 }
1641 
1643 {
1644  m_useScanLine = v;
1645 
1646  for (std::vector<vpMbtDistanceLine *>::const_iterator it = m_listOfFaceLines.begin(); it != m_listOfFaceLines.end();
1647  ++it) {
1648  (*it)->useScanLine = v;
1649  }
1650 }
vpFeatureEstimationType m_featureEstimationMethod
Method to estimate the desired features.
void svd(vpColVector &w, vpMatrix &V)
Definition: vpMatrix.cpp:1874
Used to indicate that a value is not in the allowed range.
Definition: vpException.h:97
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:164
double get_i() const
Definition: vpImagePoint.h:204
double getTop() const
Definition: vpRect.h:181
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:424
Implements a 3D polygon with render functionnalities like clipping.
Definition: vpPolygon3D.h:59
void setVisible(bool _isvisible)
int getIndex() const
Definition: vpMbtPolygon.h:101
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)
Implementation of an homogeneous matrix and operations on such kind of matrices.
std::list< int > Lindex_polygon
Index of the faces which contain the line.
void setFarClippingDistance(const double &dist)
Definition: vpPolygon3D.h:194
int m_pclPlaneEstimationMethod
PCL plane estimation method.
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true, const bool recopy_=true)
Definition: vpArray2D.h:305
unsigned int m_clippingFlag
Flags specifying which clipping to used.
Class to define colors available for display functionnalities.
Definition: vpColor.h:120
void setLeft(double pos)
Definition: vpRect.h:265
int m_pclPlaneEstimationRansacMaxIter
PCL pane estimation max number of iterations.
vpPoint * p1
The first extremity.
void computeDesiredFeaturesRobustFeatures(const std::vector< double > &point_cloud_face_custom, const std::vector< double > &point_cloud_face, const vpHomogeneousMatrix &cMo, vpColVector &desired_features, vpColVector &desired_normal, vpColVector &centroid_point)
error that can be emited by ViSP classes.
Definition: vpException.h:71
vpMbScanLine & getMbScanLineRenderer()
vpHomogeneousMatrix inverse() const
Manage the line of a polygon used in the model-based tracker.
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
unsigned int size() const
Return the number of elements of the 2D array.
Definition: vpArray2D.h:291
double m_distNearClip
Distance for near clipping.
void addLine(vpPoint &p1, vpPoint &p2, vpMbHiddenFaces< vpMbtPolygon > *const faces, int polygon=-1, std::string name="")
void set_X(const double X)
Set the point X coordinate in the camera frame.
Definition: vpPoint.cpp:454
vpMbtPolygon & getPolygon()
bool samePoint(const vpPoint &P1, const vpPoint &P2) const
double get_oX() const
Get the point X coordinate in the object frame.
Definition: vpPoint.cpp:422
bool m_useScanLine
Scan line visibility.
double getRight() const
Definition: vpRect.h:168
vpCameraParameters m_cam
Camera intrinsic parameters.
static bool inMask(const vpImage< bool > *mask, const unsigned int i, const unsigned int j)
vpRect getBoundingBox() const
Definition: vpPolygon.h:177
static const vpColor red
Definition: vpColor.h:180
Class that defines what is a point.
Definition: vpPoint.h:58
void computeROI(const vpHomogeneousMatrix &cMo, const unsigned int width, const unsigned int height, std::vector< vpImagePoint > &roiPts)
void setScanLineVisibilityTest(const bool v)
bool computePolygonCentroid(const std::vector< vpPoint > &points, vpPoint &centroid)
void setCameraParameters(const vpCameraParameters &camera)
bool computeDesiredFeatures(const vpHomogeneousMatrix &cMo, const unsigned int width, const unsigned int height, const pcl::PointCloud< pcl::PointXYZ >::ConstPtr &point_cloud, vpColVector &desired_features, const unsigned int stepX, const unsigned int stepY, const vpImage< bool > *mask=NULL)
bool m_faceActivated
True if the face should be considered by the tracker.
vpMbtPolygon * m_polygon
Polygon defining the face.
Defines a generic 2D polygon.
Definition: vpPolygon.h:103
vpMatrix t() const
Definition: vpMatrix.cpp:375
vpColVector & normalize()
void set_Z(const double Z)
Set the point Z coordinate in the camera frame.
Definition: vpPoint.cpp:458
void setTop(double pos)
Definition: vpRect.h:300
void computeInteractionMatrix(const vpHomogeneousMatrix &cMo, vpMatrix &L, vpColVector &features)
double getWidth() const
Definition: vpRect.h:203
double getD() const
Definition: vpPlane.h:108
vpPoint * p2
The second extremity.
void changeFrame(const vpHomogeneousMatrix &cMo)
Definition: vpPlane.cpp:354
static void displayArrow(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color=vpColor::white, unsigned int w=4, unsigned int h=2, unsigned int thickness=1)
static double sqr(double x)
Definition: vpMath.h:114
std::vector< std::vector< double > > getFeaturesForDisplay(const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const double scale=0.05)
bool computeDesiredFeaturesPCL(const pcl::PointCloud< pcl::PointXYZ >::ConstPtr &point_cloud_face, vpColVector &desired_features, vpColVector &desired_normal, vpColVector &centroid_point)
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 get_j() const
Definition: vpImagePoint.h:215
void getPolygonClipped(std::vector< std::pair< vpPoint, unsigned int > > &poly)
vpMbHiddenFaces< vpMbtPolygon > * m_hiddenFace
Pointer to the list of faces.
Generic class defining intrinsic camera parameters.
void setIndex(const unsigned int i)
void set_Y(const double Y)
Set the point Y coordinate in the camera frame.
Definition: vpPoint.cpp:456
double get_oZ() const
Get the point Z coordinate in the object frame.
Definition: vpPoint.cpp:426
vpPoint m_faceDesiredNormal
Face (normalized) normal (computed from the sensor)
double getLeft() const
Definition: vpRect.h:162
double m_distFarClip
Distance for near clipping.
std::vector< vpMbtDistanceLine * > m_listOfFaceLines
void displayFeature(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const double scale=0.05, const unsigned int thickness=1)
void setClipping(const unsigned int &flags)
Definition: vpPolygon3D.h:187
std::vector< PolygonLine > m_polygonLines
double getA() const
Definition: vpPlane.h:102
vpFaceCentroidType m_faceCentroidMethod
Method to compute the face centroid for the current features.
void setName(const std::string &line_name)
std::vector< std::vector< double > > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const bool displayFullModel=false)
void setCameraParameters(const vpCameraParameters &camera)
double get_X() const
Get the point X coordinate in the camera frame.
Definition: vpPoint.cpp:413
void computeScanLineQuery(const vpPoint &a, const vpPoint &b, std::vector< std::pair< vpPoint, vpPoint > > &lines, const bool &displayResults=false)
void setWorldCoordinates(const double oX, const double oY, const double oZ)
Definition: vpPoint.cpp:113
void estimatePlaneEquationSVD(const std::vector< double > &point_cloud_face, const vpHomogeneousMatrix &cMo, vpColVector &plane_equation_estimated, vpColVector &centroid)
unsigned int getHeight() const
Definition: vpImage.h:186
void computeDesiredFeaturesSVD(const std::vector< double > &point_cloud_face, const vpHomogeneousMatrix &cMo, vpColVector &desired_features, vpColVector &desired_normal, vpColVector &centroid_point)
void computeDesiredNormalAndCentroid(const vpHomogeneousMatrix &cMo, const vpColVector &desired_normal, const vpColVector &centroid_point)
virtual bool isVisible(const vpHomogeneousMatrix &cMo, const double alpha, const bool &modulo=false, const vpCameraParameters &cam=vpCameraParameters(), unsigned int width=0, unsigned int height=0)
Implementation of column vector and the associated operations.
Definition: vpColVector.h:130
static double dotProd(const vpColVector &a, const vpColVector &b)
double get_x() const
Get the point x coordinate in the image plane.
Definition: vpPoint.cpp:431
void setRight(double pos)
Definition: vpRect.h:291
vpMbHiddenFaces< vpMbtPolygon > * hiddenface
Pointer to the list of faces.
double getHeight() const
Definition: vpRect.h:155
double get_y() const
Get the point y coordinate in the image plane.
Definition: vpPoint.cpp:433
bool isVisible(const unsigned int i)
double getC() const
Definition: vpPlane.h:106
void addPolygon(const int &index)
void setNearClippingDistance(const double &dist)
Definition: vpPolygon3D.h:207
vpPoint m_faceDesiredCentroid
Desired centroid (computed from the sensor)
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
Compute the geometric centroid.
std::vector< std::vector< double > > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const bool displayFullModel=false)
double get_Z() const
Get the point Z coordinate in the camera frame.
Definition: vpPoint.cpp:417
vpPlane m_planeObject
Plane equation described in the object frame.
void changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &_cP)
Definition: vpPoint.cpp:233
double get_Y() const
Get the point Y coordinate in the camera frame.
Definition: vpPoint.cpp:415
vpColVector getCol(const unsigned int j) const
Definition: vpMatrix.cpp:3880
void estimateFeatures(const std::vector< double > &point_cloud_face, const vpHomogeneousMatrix &cMo, vpColVector &x_estimated, std::vector< double > &weights)
unsigned int getWidth() const
Definition: vpImage.h:244
double getBottom() const
Definition: vpRect.h:100
static void displayLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1, bool segment=true)
void setBottom(double pos)
Definition: vpRect.h:232
bool useScanLine
Use scanline rendering.
void buildFrom(vpPoint &_p1, vpPoint &_p2)
static const vpColor blue
Definition: vpColor.h:186
void computeNormalVisibility(const double nx, const double ny, const double nz, const vpColVector &centroid_point, vpColVector &face_normal)
double m_pclPlaneEstimationRansacThreshold
PCL plane estimation RANSAC threshold.
void resize(const unsigned int i, const bool flagNullify=true)
Definition: vpColVector.h:310
void computeFov(const unsigned int &w, const unsigned int &h)