Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpPointMap.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file LICENSE.txt at the root directory of this source
10 * distribution for additional information about the GNU GPL.
11 *
12 * For using ViSP with software that can not be combined with the GNU
13 * GPL, please contact Inria about acquiring a ViSP Professional
14 * Edition License.
15 *
16 * See https://visp.inria.fr for more information.
17 *
18 * This software was developed at:
19 * Inria Rennes - Bretagne Atlantique
20 * Campus Universitaire de Beaulieu
21 * 35042 Rennes Cedex
22 * France
23 *
24 * If you have questions regarding the use of this file, please contact
25 * Inria at visp@inria.fr
26 *
27 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 */
30
31#ifndef VP_POINT_MAP_H
32#define VP_POINT_MAP_H
33
34#include <visp3/core/vpConfig.h>
35#include <visp3/core/vpMatrix.h>
36#include <visp3/core/vpHomogeneousMatrix.h>
37#include <visp3/core/vpCameraParameters.h>
38#include <visp3/core/vpMeterPixelConversion.h>
39#include <visp3/core/vpPixelMeterConversion.h>
40
41#include <list>
42
44
45class VISP_EXPORT vpPointMap
46{
47public:
48 vpPointMap(unsigned maxPoints, double minDistNewPoints, double maxDepthErrorVisibility, double maxDepthErrorCandidate, double outlierThreshold)
49 {
50 m_maxPoints = maxPoints;
51 m_minDistNewPoint = minDistNewPoints;
52 m_maxDepthErrorVisible = maxDepthErrorVisibility;
53 m_maxDepthErrorCandidate = maxDepthErrorCandidate;
54 m_outlierThreshold = outlierThreshold;
55 m_normalThresholdVisible = 0.0;
56 }
57
62 unsigned int getNumMaxPoints() const { return m_maxPoints; }
63 void setNumMaxPoints(unsigned int maxNumPoints)
64 {
65 m_maxPoints = maxNumPoints;
66 }
67
68 double getMinDistanceAddNewPoints() const { return m_minDistNewPoint; }
69 void setMinDistanceAddNewPoints(double distance) { m_minDistNewPoint = distance; }
70
71 double getMaxDepthErrorVisibilityCriterion() const { return m_maxDepthErrorVisible; }
72 void setMaxDepthErrorVisibilityCriterion(double depthError) { m_maxDepthErrorVisible = depthError; }
73
74 double getThresholdNormalVisibiltyCriterion() const { return m_normalThresholdVisible; }
75 void setThresholdNormalVisibiltyCriterion(double normalDegThreshold) { m_normalThresholdVisible = normalDegThreshold; }
76
77 double getMaxDepthErrorCandidate() const { return m_maxDepthErrorCandidate; }
78 void setMaxDepthErrorCandidate(double depthError) { m_maxDepthErrorCandidate = depthError; }
79
80 double getOutlierReprojectionErrorThreshold() const { return m_outlierThreshold; }
81 void setOutlierReprojectionErrorThreshold(double thresholdPx) { m_outlierThreshold = thresholdPx; }
82
86
87 const vpMatrix &getPoints() { return m_X; }
88 void setPoints(const vpMatrix &X) { m_X = X; }
89
90 void getPoints(const vpArray2D<int> &indices, vpMatrix &X);
91
92 void project(const vpHomogeneousMatrix &cTw, vpMatrix &cX);
93 void project(const vpArray2D<int> &indices, const vpHomogeneousMatrix &cTw, vpMatrix &cX);
94 void project(const vpArray2D<int> &indices, const vpHomogeneousMatrix &cTw, vpMatrix &cX, vpMatrix &xs);
95 void project(const vpCameraParameters &cam, const vpArray2D<int> &indices, const vpHomogeneousMatrix &cTw, vpMatrix &cX, vpMatrix &xs, vpMatrix &uvs);
96
97
98 void getVisiblePoints(const unsigned int h, const unsigned int w, const vpMatrix &cX, const vpMatrix &uvs, const vpColVector &expectedZ, std::vector<int> &indices);
99 void getVisiblePoints(const unsigned int h, const unsigned int w, const vpCameraParameters &cam, const vpHomogeneousMatrix &cTw, const vpImage<float> &depth, std::vector<int> &indices);
100
101 void getOutliers(const vpArray2D<int> &originalIndices, const vpMatrix &uvs,
102 const vpMatrix &observations, std::vector<int> &indices);
103
104 void selectValidNewCandidates(const vpCameraParameters &cam, const vpHomogeneousMatrix &cTw,
105 const vpArray2D<int> &originalIndices, const vpMatrix &uvs,
106 const vpImage<float> &modelDepth, const vpImage<float> &depth, const vpImage<vpRGBf> &normals,
107 vpMatrix &oXs, vpMatrix &oNs, std::vector<int> &validCandidateIndices);
108
109 void updatePoints(const vpArray2D<int> &indicesToRemove, const vpMatrix &pointsToAdd, const vpMatrix &normalsToAdd, std::vector<int> &removedIndices, unsigned int &numAddedPoints);
110 void updatePoint(unsigned int index, double X, double Y, double Z)
111 {
112 m_X[index][0] = X;
113 m_X[index][1] = Y;
114 m_X[index][2] = Z;
115 }
116 void clear();
117
118 void computeReprojectionErrorAndJacobian(const vpArray2D<int> &indices, const vpHomogeneousMatrix &cTw, const vpMatrix &observations, vpMatrix &J, vpColVector &e) const
119 {
120 J.resize(indices.getRows() * 2, 6, false, false);
121 e.resize(indices.getRows() * 2, 1, false);
122
123 vpColVector cX(3);
124 vpColVector wX(3);
125 const vpRotationMatrix cRw = cTw.getRotationMatrix();
126 const vpTranslationVector t = cTw.getTranslationVector();
127 for (unsigned int i = 0; i < indices.getRows(); ++i) {
128 const unsigned int pointIndex = indices[i][0];
129 const double *p = m_X[pointIndex];
130 wX[0] = p[0]; wX[1] = p[1]; wX[2] = p[2];
131 cX = cRw * wX;
132 cX += t;
133 const double Z = cX[2];
134 const double x = cX[0] / Z;
135 const double y = cX[1] / Z;
136
137 e[i * 2] = x - observations[i][0];
138 e[i * 2 + 1] = y - observations[i][1];
139
140 J[i * 2][0] = -1.0 / Z; J[i * 2][1] = 0.0; J[i * 2][2] = x / Z;
141 J[i * 2][3] = x * y; J[i * 2][4] = -(1.0 + x * x); J[i * 2][5] = y;
142
143 J[i * 2 + 1][0] = 0.0; J[i * 2 + 1][1] = -1.0 / Z; J[i * 2 + 1][2] = y / Z;
144 J[i * 2 + 1][3] = 1.0 + y * y; J[i * 2 + 1][4] = -(x * y); J[i * 2 + 1][5] = -x;
145 }
146 }
147
148 void compute3DErrorAndJacobian(const vpArray2D<int> &indices, const vpHomogeneousMatrix &cTw, const vpMatrix &observations, vpMatrix &J, vpColVector &e) const
149 {
150 J.resize(indices.getRows() * 3, 6, false, false);
151 e.resize(indices.getRows() * 3, 1, false);
152
153 vpColVector cX(3);
154 vpColVector wX(3);
155 const vpRotationMatrix cRw = cTw.getRotationMatrix();
156 const vpTranslationVector t = cTw.getTranslationVector();
157 for (unsigned int i = 0; i < indices.getRows(); ++i) {
158 const unsigned int pointIndex = indices[i][0];
159 const double *p = m_X[pointIndex];
160 wX[0] = p[0]; wX[1] = p[1]; wX[2] = p[2];
161 cX = cRw * wX;
162 cX += t;
163
164 const double X = cX[0], Y = cX[1], Z = cX[2];
165
166 e[i * 3] = X - observations[i][0];
167 e[i * 3 + 1] = Y - observations[i][1];
168 e[i * 3 + 2] = Z - observations[i][2];
169
170 J[i * 3][0] = -1;
171 J[i * 3 + 1][1] = -1;
172 J[i * 3 + 2][2] = -1;
173
174 J[i * 3][4] = -Z;
175 J[i * 3][5] = Y;
176
177 J[i * 3 + 1][3] = Z;
178 J[i * 3 + 1][5] = -X;
179
180 J[i * 3 + 2][3] = -Y;
181 J[i * 3 + 2][4] = X;
182 }
183 }
184
185private:
186 vpMatrix m_X; // N x 3, points expressed in world frame
187 vpMatrix m_normals; // N x 3, points expressed in world frame
188
189 unsigned m_maxPoints;
190 double m_minDistNewPoint;
191 double m_maxDepthErrorVisible;
192 double m_normalThresholdVisible;
193 double m_maxDepthErrorCandidate;
194 double m_outlierThreshold;
195
196};
197
198END_VISP_NAMESPACE
199
200#endif
Implementation of a generic 2D array used as base class for matrices and vectors.
Definition vpArray2D.h:146
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
Definition vpArray2D.h:448
unsigned int getRows() const
Definition vpArray2D.h:433
Generic class defining intrinsic camera parameters.
Implementation of column vector and the associated operations.
Implementation of an homogeneous matrix and operations on such kind of matrices.
Definition of the vpImage class member functions.
Definition vpImage.h:131
Implementation of a matrix and operations on matrices.
Definition vpMatrix.h:175
void setOutlierReprojectionErrorThreshold(double thresholdPx)
Definition vpPointMap.h:81
void setMaxDepthErrorVisibilityCriterion(double depthError)
Definition vpPointMap.h:72
unsigned int getNumMaxPoints() const
Definition vpPointMap.h:62
void setMaxDepthErrorCandidate(double depthError)
Definition vpPointMap.h:78
double getMinDistanceAddNewPoints() const
Definition vpPointMap.h:68
vpPointMap(unsigned maxPoints, double minDistNewPoints, double maxDepthErrorVisibility, double maxDepthErrorCandidate, double outlierThreshold)
Definition vpPointMap.h:48
double getMaxDepthErrorCandidate() const
Definition vpPointMap.h:77
void setMinDistanceAddNewPoints(double distance)
Definition vpPointMap.h:69
void setPoints(const vpMatrix &X)
Definition vpPointMap.h:88
double getOutlierReprojectionErrorThreshold() const
Definition vpPointMap.h:80
void setNumMaxPoints(unsigned int maxNumPoints)
Definition vpPointMap.h:63
double getThresholdNormalVisibiltyCriterion() const
Definition vpPointMap.h:74
void updatePoint(unsigned int index, double X, double Y, double Z)
Definition vpPointMap.h:110
void setThresholdNormalVisibiltyCriterion(double normalDegThreshold)
Definition vpPointMap.h:75
void computeReprojectionErrorAndJacobian(const vpArray2D< int > &indices, const vpHomogeneousMatrix &cTw, const vpMatrix &observations, vpMatrix &J, vpColVector &e) const
Definition vpPointMap.h:118
const vpMatrix & getPoints()
Definition vpPointMap.h:87
void compute3DErrorAndJacobian(const vpArray2D< int > &indices, const vpHomogeneousMatrix &cTw, const vpMatrix &observations, vpMatrix &J, vpColVector &e) const
Definition vpPointMap.h:148
double getMaxDepthErrorVisibilityCriterion() const
Definition vpPointMap.h:71
Implementation of a rotation matrix and operations on such kind of matrices.
Class that consider the case of a translation vector.