36 #include <visp3/core/vpCPUFeatures.h> 37 #include <visp3/mbt/vpMbtFaceDepthDense.h> 40 #include <pcl/common/point_tests.h> 43 #if defined __SSE2__ || defined _M_X64 || (defined _M_IX86_FP && _M_IX86_FP >= 2) 44 #include <emmintrin.h> 45 #define VISP_HAVE_SSE2 1 48 #define USE_SSE_CODE 1 49 #if VISP_HAVE_SSE2 && USE_SSE_CODE 56 : m_cam(), m_clippingFlag(
vpPolygon3D::NO_CLIPPING), m_distFarClip(100), m_distNearClip(0.001), m_hiddenFace(NULL),
57 m_planeObject(), m_polygon(NULL), m_useScanLine(false),
58 m_depthDenseFilteringMethod(DEPTH_OCCUPANCY_RATIO_FILTERING), m_depthDenseFilteringMaxDist(3.0),
59 m_depthDenseFilteringMinDist(0.8), m_depthDenseFilteringOccupancyRatio(0.3), m_isTrackedDepthDenseFace(true),
60 m_isVisible(false), m_listOfFaceLines(), m_planeCamera(), m_pointCloudFace(), m_polygonLines()
89 PolygonLine polygon_line;
92 polygon_line.m_poly.setNbPoint(2);
93 polygon_line.m_poly.addPoint(0, P1);
94 polygon_line.m_poly.addPoint(1, P2);
100 polygon_line.m_p1 = &polygon_line.m_poly.p[0];
101 polygon_line.m_p2 = &polygon_line.m_poly.p[1];
106 bool already_here =
false;
147 const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &point_cloud,
148 unsigned int stepX,
unsigned int stepY
149 #
if DEBUG_DISPLAY_DEPTH_DENSE
152 std::vector<std::vector<vpImagePoint> > &roiPts_vec
157 unsigned int width = point_cloud->width, height = point_cloud->height;
160 if (point_cloud->width == 0 || point_cloud->height == 0)
163 std::vector<vpImagePoint> roiPts;
164 double distanceToFace;
166 #
if DEBUG_DISPLAY_DEPTH_DENSE
173 if (roiPts.size() <= 2) {
175 std::cerr <<
"Error: roiPts.size() <= 2 in computeDesiredFeatures" << std::endl;
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()));
209 double prev_x = 0.0, prev_y = 0.0, prev_z = 0.0;
212 int totalTheoreticalPoints = 0, totalPoints = 0;
213 for (
unsigned int i = top; i < bottom; i += stepY) {
214 for (
unsigned int j = left; j < right; j += stepX) {
215 if ((
m_useScanLine ? (i < m_hiddenFace->getMbScanLineRenderer().getPrimitiveIDs().getHeight() &&
216 j < m_hiddenFace->getMbScanLineRenderer().getPrimitiveIDs().getWidth() &&
219 totalTheoreticalPoints++;
221 if (
vpMeTracker::inMask(mask, i, j) && pcl::isFinite((*point_cloud)(j, i)) && (*point_cloud)(j, i).z > 0) {
228 prev_x = (*point_cloud)(j, i).x;
229 prev_y = (*point_cloud)(j, i).y;
230 prev_z = (*point_cloud)(j, i).z;
249 #if DEBUG_DISPLAY_DEPTH_DENSE 250 debugImage[i][j] = 255;
258 if (checkSSE2 && push) {
275 unsigned int height,
const std::vector<vpColVector> &point_cloud,
276 unsigned int stepX,
unsigned int stepY
277 #
if DEBUG_DISPLAY_DEPTH_DENSE
280 std::vector<std::vector<vpImagePoint> > &roiPts_vec
287 if (width == 0 || height == 0)
290 std::vector<vpImagePoint> roiPts;
291 double distanceToFace;
293 #
if DEBUG_DISPLAY_DEPTH_DENSE
300 if (roiPts.size() <= 2) {
302 std::cerr <<
"Error: roiPts.size() <= 2 in computeDesiredFeatures" << std::endl;
315 unsigned int top = (
unsigned int)std::max(0.0, bb.
getTop());
316 unsigned int bottom = (
unsigned int)std::min((
double)height, std::max(0.0, bb.
getBottom()));
317 unsigned int left = (
unsigned int)std::max(0.0, bb.
getLeft());
318 unsigned int right = (
unsigned int)std::min((
double)width, std::max(0.0, bb.
getRight()));
332 double prev_x = 0.0, prev_y = 0.0, prev_z = 0.0;
335 int totalTheoreticalPoints = 0, totalPoints = 0;
336 for (
unsigned int i = top; i < bottom; i += stepY) {
337 for (
unsigned int j = left; j < right; j += stepX) {
338 if ((
m_useScanLine ? (i < m_hiddenFace->getMbScanLineRenderer().getPrimitiveIDs().getHeight() &&
339 j < m_hiddenFace->getMbScanLineRenderer().getPrimitiveIDs().getWidth() &&
342 totalTheoreticalPoints++;
351 prev_x = point_cloud[i * width + j][0];
352 prev_y = point_cloud[i * width + j][1];
353 prev_z = point_cloud[i * width + j][2];
372 #if DEBUG_DISPLAY_DEPTH_DENSE 373 debugImage[i][j] = 255;
381 if (checkSSE2 && push) {
405 bool isvisible =
false;
409 int index = *itindex;
462 double *ptr_L = L.
data;
463 double *ptr_error = error.
data;
465 const __m128d vnx = _mm_set1_pd(nx);
466 const __m128d vny = _mm_set1_pd(ny);
467 const __m128d vnz = _mm_set1_pd(nz);
468 const __m128d vd = _mm_set1_pd(D);
470 double tmp_a1[2], tmp_a2[2], tmp_a3[2];
472 for (; cpt <=
m_pointCloudFace.size() - 6; cpt += 6, ptr_point_cloud += 6) {
473 const __m128d vx = _mm_loadu_pd(ptr_point_cloud);
474 const __m128d vy = _mm_loadu_pd(ptr_point_cloud + 2);
475 const __m128d vz = _mm_loadu_pd(ptr_point_cloud + 4);
477 const __m128d va1 = _mm_sub_pd(_mm_mul_pd(vnz, vy), _mm_mul_pd(vny, vz));
478 const __m128d va2 = _mm_sub_pd(_mm_mul_pd(vnx, vz), _mm_mul_pd(vnz, vx));
479 const __m128d va3 = _mm_sub_pd(_mm_mul_pd(vny, vx), _mm_mul_pd(vnx, vy));
481 _mm_storeu_pd(tmp_a1, va1);
482 _mm_storeu_pd(tmp_a2, va2);
483 _mm_storeu_pd(tmp_a3, va3);
511 const __m128d verror =
512 _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)));
513 _mm_storeu_pd(ptr_error, verror);
523 double _a1 = (nz * y) - (ny * z);
524 double _a2 = (nx * z) - (nz * x);
525 double _a3 = (ny * x) - (nx * y);
528 L[(
unsigned int)(cpt / 3)][0] = nx;
529 L[(
unsigned int)(cpt / 3)][1] = ny;
530 L[(
unsigned int)(cpt / 3)][2] = nz;
531 L[(
unsigned int)(cpt / 3)][3] = _a1;
532 L[(
unsigned int)(cpt / 3)][4] = _a2;
533 L[(
unsigned int)(cpt / 3)][5] = _a3;
546 error[(
unsigned int)(cpt / 3)] = D + (normal.
t() * pt);
556 unsigned int idx = 0;
562 double _a1 = (nz * y) - (ny * z);
563 double _a2 = (nx * z) - (nz * x);
564 double _a3 = (ny * x) - (nx * y);
578 error[idx] = D + (normal.
t() * pt);
584 unsigned int height, std::vector<vpImagePoint> &roiPts
585 #
if DEBUG_DISPLAY_DEPTH_DENSE
587 std::vector<std::vector<vpImagePoint> > &roiPts_vec
590 double &distanceToFace)
597 it->m_p1->changeFrame(cMo);
598 it->m_p2->changeFrame(cMo);
602 it->m_poly.changeFrame(cMo);
603 it->m_poly.computePolygonClipped(
m_cam);
605 if (it->m_poly.polyClipped.size() == 2 &&
613 std::vector<std::pair<vpPoint, vpPoint> > linesLst;
619 for (
unsigned int i = 0; i < linesLst.size(); i++) {
621 linesLst[i].second.project();
629 roiPts.push_back(ip1);
630 roiPts.push_back(ip2);
632 faceCentroid.
set_X(faceCentroid.
get_X() + linesLst[i].first.get_X() + linesLst[i].second.get_X());
633 faceCentroid.
set_Y(faceCentroid.
get_Y() + linesLst[i].first.get_Y() + linesLst[i].second.get_Y());
634 faceCentroid.
set_Z(faceCentroid.
get_Z() + linesLst[i].first.get_Z() + linesLst[i].second.get_Z());
636 #if DEBUG_DISPLAY_DEPTH_DENSE 637 std::vector<vpImagePoint> roiPts_;
638 roiPts_.push_back(ip1);
639 roiPts_.push_back(ip2);
640 roiPts_vec.push_back(roiPts_);
644 if (linesLst.empty()) {
645 distanceToFace = std::numeric_limits<double>::max();
647 faceCentroid.
set_X(faceCentroid.
get_X() / (2 * linesLst.size()));
648 faceCentroid.
set_Y(faceCentroid.
get_Y() / (2 * linesLst.size()));
649 faceCentroid.
set_Z(faceCentroid.
get_Z() / (2 * linesLst.size()));
652 sqrt(faceCentroid.
get_X() * faceCentroid.
get_X() + faceCentroid.
get_Y() * faceCentroid.
get_Y() +
662 std::vector<vpPoint> polygonsClipped;
665 if (polygonsClipped.empty()) {
666 distanceToFace = std::numeric_limits<double>::max();
670 for (
size_t i = 0; i < polygonsClipped.size(); i++) {
671 faceCentroid.
set_X(faceCentroid.
get_X() + polygonsClipped[i].get_X());
672 faceCentroid.
set_Y(faceCentroid.
get_Y() + polygonsClipped[i].get_Y());
673 faceCentroid.
set_Z(faceCentroid.
get_Z() + polygonsClipped[i].get_Z());
676 faceCentroid.
set_X(faceCentroid.
get_X() / polygonsClipped.size());
677 faceCentroid.
set_Y(faceCentroid.
get_Y() / polygonsClipped.size());
678 faceCentroid.
set_Z(faceCentroid.
get_Z() / polygonsClipped.size());
680 distanceToFace = sqrt(faceCentroid.
get_X() * faceCentroid.
get_X() + faceCentroid.
get_Y() * faceCentroid.
get_Y() +
684 #if DEBUG_DISPLAY_DEPTH_DENSE 685 roiPts_vec.push_back(roiPts);
692 bool displayFullModel)
696 for (
size_t i = 0; i < models.size(); i++) {
705 bool displayFullModel)
709 for (
size_t i = 0; i < models.size(); i++) {
742 bool displayFullModel)
744 std::vector<std::vector<double> > models;
752 std::vector<std::vector<double> > lineModels = line->
getModelForDisplay(width, height, cMo, cam, displayFullModel);
753 models.insert(models.end(), lineModels.begin(), lineModels.end());
775 if (dx <= std::numeric_limits<double>::epsilon() && dy <= std::numeric_limits<double>::epsilon() &&
776 dz <= std::numeric_limits<double>::epsilon())
788 (*it)->setCameraParameters(camera);
798 (*it)->useScanLine = v;
Implementation of a matrix and operations on matrices.
double m_distNearClip
Distance for near clipping.
std::vector< std::vector< double > > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, bool displayFullModel=false)
void getRoiClipped(const vpCameraParameters &cam, std::vector< vpImagePoint > &roi)
void setScanLineVisibilityTest(bool v)
double get_oY() const
Get the point oY coordinate in the object frame.
Implements a 3D polygon with render functionnalities like clipping.
bool samePoint(const vpPoint &P1, const vpPoint &P2) const
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
void setVisible(bool _isvisible)
void buildFrom(vpPoint &_p1, vpPoint &_p2, vpUniRand &rand_gen)
bool isVisible(unsigned int i)
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)
void setCameraParameters(const vpCameraParameters &camera)
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
Class to define RGB colors available for display functionnalities.
bool m_useScanLine
Scan line visibility.
void displayFeature(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double scale=0.05, unsigned int thickness=1)
void addLine(vpPoint &p1, vpPoint &p2, vpMbHiddenFaces< vpMbtPolygon > *const faces, vpUniRand &rand_gen, int polygon=-1, std::string name="")
vpPoint * p1
The first extremity.
vpMbScanLine & getMbScanLineRenderer()
Manage the line of a polygon used in the model-based tracker.
void set_Z(double cZ)
Set the point cZ coordinate in the camera frame.
Type * data
Address of the first element of the data array.
double m_depthDenseFilteringMinDist
Minimum distance threshold.
vpMbtPolygon & getPolygon()
bool m_isTrackedDepthDenseFace
Flag to define if the face should be tracked or not.
double get_oX() const
Get the point oX coordinate in the object frame.
vpRect getBoundingBox() const
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
bool m_isVisible
Visibility flag.
void set_X(double cX)
Set the point cX coordinate in the camera frame.
vpMbtPolygon * m_polygon
Polygon defining the face.
vpPlane m_planeObject
Plane equation described in the object frame.
Defines a generic 2D polygon.
void computeVisibilityDisplay()
std::vector< std::vector< double > > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, bool displayFullModel=false)
virtual ~vpMbtFaceDepthDense()
unsigned int m_clippingFlag
Flags specifying which clipping to used.
vpPoint * p2
The second extremity.
void changeFrame(const vpHomogeneousMatrix &cMo)
void computeInteractionMatrixAndResidu(const vpHomogeneousMatrix &cMo, vpMatrix &L, vpColVector &error)
VISP_EXPORT bool checkSSE2()
bool isInside(const vpImagePoint &iP, const PointInPolygonMethod &method=PnPolyRayCasting) const
double m_distFarClip
Distance for near clipping.
void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, unsigned int thickness=1, bool displayFullModel=false)
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.
double get_oZ() const
Get the point oZ coordinate in the object frame.
std::vector< vpMbtDistanceLine * > m_listOfFaceLines
unsigned int getNbFeatures() const
virtual bool isVisible(const vpHomogeneousMatrix &cMo, double alpha, const bool &modulo=false, const vpCameraParameters &cam=vpCameraParameters(), unsigned int width=0, unsigned int height=0)
double m_depthDenseFilteringMaxDist
Maximum distance threshold.
void computeROI(const vpHomogeneousMatrix &cMo, unsigned int width, unsigned int height, std::vector< vpImagePoint > &roiPts, double &distanceToFace)
void setClipping(const unsigned int &flags)
void setName(const std::string &line_name)
void setCameraParameters(const vpCameraParameters &camera)
void resize(unsigned int i, bool flagNullify=true)
double get_X() const
Get the point cX coordinate in the camera frame.
void computeScanLineQuery(const vpPoint &a, const vpPoint &b, std::vector< std::pair< vpPoint, vpPoint > > &lines, const bool &displayResults=false)
unsigned int getHeight() const
void set_Y(double cY)
Set the point cY coordinate in the camera frame.
Implementation of column vector and the associated operations.
static bool inMask(const vpImage< bool > *mask, unsigned int i, unsigned int j)
void setRight(double pos)
bool computeDesiredFeatures(const vpHomogeneousMatrix &cMo, const pcl::PointCloud< pcl::PointXYZ >::ConstPtr &point_cloud, unsigned int stepX, unsigned int stepY, const vpImage< bool > *mask=NULL)
vpMbHiddenFaces< vpMbtPolygon > * hiddenface
Pointer to the list of faces.
std::vector< PolygonLine > m_polygonLines
Polygon lines used for scan-line visibility.
void addPolygon(const int &index)
void setNearClippingDistance(const double &dist)
Defines a rectangle in the plane.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Class for generating random numbers with uniform probability density.
double get_Z() const
Get the point cZ coordinate in the camera frame.
vpMbHiddenFaces< vpMbtPolygon > * m_hiddenFace
Pointer to the list of faces.
double get_Y() const
Get the point cY coordinate in the camera frame.
unsigned int getWidth() const
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)
bool useScanLine
Use scanline rendering.
void setIndex(unsigned int i)
void computeFov(const unsigned int &w, const unsigned int &h)