Visual Servoing Platform  version 3.1.0
vpMbtFaceDepthDense.h
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 #ifndef __vpMbtFaceDepthDense_h_
37 #define __vpMbtFaceDepthDense_h_
38 
39 #include <iostream>
40 
41 #include <visp3/core/vpConfig.h>
42 #ifdef VISP_HAVE_PCL
43 #include <pcl/point_cloud.h>
44 #include <pcl/point_types.h>
45 #endif
46 
47 #include <visp3/core/vpPlane.h>
48 #include <visp3/mbt/vpMbTracker.h>
49 #include <visp3/mbt/vpMbtDistanceLine.h>
50 
51 #define DEBUG_DISPLAY_DEPTH_DENSE 0
52 
53 class VISP_EXPORT vpMbtFaceDepthDense
54 {
55 public:
57  NO_FILTERING = 0,
58  DEPTH_OCCUPANCY_RATIO_FILTERING = 1 << 1,
59  MIN_DISTANCE_FILTERING = 1 << 2,
62  MAX_DISTANCE_FILTERING = 1 << 3
64  };
66 
70  unsigned int m_clippingFlag;
72  double m_distFarClip;
83 
85  virtual ~vpMbtFaceDepthDense();
86 
87  void addLine(vpPoint &p1, vpPoint &p2, vpMbHiddenFaces<vpMbtPolygon> *const faces, int polygon = -1,
88  std::string name = "");
89 
90 #ifdef VISP_HAVE_PCL
91  bool computeDesiredFeatures(const vpHomogeneousMatrix &cMo,
92  const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &point_cloud, const unsigned int stepX,
93  const unsigned int stepY
94 #if DEBUG_DISPLAY_DEPTH_DENSE
95  ,
96  vpImage<unsigned char> &debugImage, std::vector<std::vector<vpImagePoint> > &roiPts_vec
97 #endif
98  );
99 #endif
100  bool computeDesiredFeatures(const vpHomogeneousMatrix &cMo, const unsigned int width, const unsigned int height,
101  const std::vector<vpColVector> &point_cloud, const unsigned int stepX,
102  const unsigned int stepY
103 #if DEBUG_DISPLAY_DEPTH_DENSE
104  ,
105  vpImage<unsigned char> &debugImage, std::vector<std::vector<vpImagePoint> > &roiPts_vec
106 #endif
107  );
108 
109  void computeInteractionMatrixAndResidu(const vpHomogeneousMatrix &cMo, vpMatrix &L, vpColVector &error);
110 
111  void computeVisibility();
112  void computeVisibilityDisplay();
113 
114  void display(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
115  const vpColor &col, const unsigned int thickness = 1, const bool displayFullModel = false);
116  void display(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
117  const vpColor &col, const unsigned int thickness = 1, const bool displayFullModel = false);
118 
119  void displayFeature(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
120  const double scale = 0.05, const unsigned int thickness = 1);
121  void displayFeature(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
122  const double scale = 0.05, const unsigned int thickness = 1);
123 
124  inline unsigned int getNbFeatures() const { return (unsigned int)(m_pointCloudFace.size() / 3); }
125 
126  inline bool isVisible() const { return m_polygon->isvisible; }
127 
128  void setCameraParameters(const vpCameraParameters &camera);
129 
130  void setScanLineVisibilityTest(const bool v);
131 
132  inline void setDepthDenseFilteringMaxDistance(const double maxDistance)
133  {
134  m_depthDenseFilteringMaxDist = maxDistance;
135  }
136 
137  inline void setDepthDenseFilteringMethod(const int method) { m_depthDenseFilteringMethod = method; }
138 
139  inline void setDepthDenseFilteringMinDistance(const double minDistance)
140  {
141  m_depthDenseFilteringMinDist = minDistance;
142  }
143 
144  inline void setDepthDenseFilteringOccupancyRatio(const double occupancyRatio)
145  {
146  if (occupancyRatio < 0.0 || occupancyRatio > 1.0) {
147  std::cerr << "occupancyRatio < 0.0 || occupancyRatio > 1.0" << std::endl;
148  } else {
149  m_depthDenseFilteringOccupancyRatio = occupancyRatio;
150  }
151  }
152 
153 private:
154  class PolygonLine
155  {
156  public:
158  vpPoint *m_p1;
160  vpPoint *m_p2;
162  vpMbtPolygon m_poly;
164  vpImagePoint m_imPt1;
166  vpImagePoint m_imPt2;
167 
168  PolygonLine() : m_p1(NULL), m_p2(NULL), m_poly(), m_imPt1(), m_imPt2() {}
169 
170  PolygonLine(const PolygonLine &polyLine)
171  : m_p1(NULL), m_p2(NULL), m_poly(polyLine.m_poly), m_imPt1(polyLine.m_imPt1), m_imPt2(polyLine.m_imPt2)
172  {
173  m_p1 = &m_poly.p[0];
174  m_p2 = &m_poly.p[1];
175  }
176 
177  PolygonLine &operator=(PolygonLine other)
178  {
179  swap(*this, other);
180 
181  return *this;
182  }
183 
184  void swap(PolygonLine &first, PolygonLine &second)
185  {
186  using std::swap;
187  swap(first.m_p1, second.m_p1);
188  swap(first.m_p2, second.m_p2);
189  swap(first.m_poly, second.m_poly);
190  swap(first.m_imPt1, second.m_imPt1);
191  swap(first.m_imPt2, second.m_imPt2);
192  }
193  };
194 
195 protected:
208  std::vector<vpMbtDistanceLine *> m_listOfFaceLines;
213  std::vector<double> m_pointCloudFace;
215  std::vector<PolygonLine> m_polygonLines;
216 
217 protected:
218  void computeROI(const vpHomogeneousMatrix &cMo, const unsigned int width, const unsigned int height,
219  std::vector<vpImagePoint> &roiPts
220 #if DEBUG_DISPLAY_DEPTH_DENSE
221  ,
222  std::vector<std::vector<vpImagePoint> > &roiPts_vec
223 #endif
224  ,
225  double &distanceToFace);
226 
227  bool samePoint(const vpPoint &P1, const vpPoint &P2) const;
228 };
229 #endif
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:104
double m_distNearClip
Distance for near clipping.
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.
Class to define colors available for display functionnalities.
Definition: vpColor.h:120
bool m_useScanLine
Scan line visibility.
void setDepthDenseFilteringMinDistance(const double minDistance)
vpPoint * p
corners in the object frame
Definition: vpPolygon3D.h:81
double m_depthDenseFilteringMinDist
Minimum distance threshold.
void setDepthDenseFilteringMaxDistance(const double maxDistance)
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.
Implementation of a polygon of the model used by the model-based tracker.
Definition: vpMbtPolygon.h:66
unsigned int m_clippingFlag
Flags specifying which clipping to used.
void setDepthDenseFilteringOccupancyRatio(const double occupancyRatio)
double m_distFarClip
Distance for near clipping.
Generic class defining intrinsic camera parameters.
void setDepthDenseFilteringMethod(const int method)
double m_depthDenseFilteringOccupancyRatio
Ratio between available depth points and theoretical number of points.
std::vector< vpMbtDistanceLine * > m_listOfFaceLines
unsigned int getNbFeatures() const
bool m_isTracked
Flag to define if the face should be tracked or not.
double m_depthDenseFilteringMaxDist
Maximum distance threshold.
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
std::vector< PolygonLine > m_polygonLines
Polygon lines used for scan-line visibility.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
This class defines the container for a plane geometrical structure.
Definition: vpPlane.h:58
vpMbHiddenFaces< vpMbtPolygon > * m_hiddenFace
Pointer to the list of faces.
bool isvisible
flag to specify whether the face is visible or not
Definition: vpMbtPolygon.h:73