50 if (m_points.size() == 0) {
54#ifdef VISP_HAVE_OPENMP
55#pragma omp parallel for
57 for (
int i = 0; i < static_cast<int>(m_points.size()); ++i) {
67 std::vector<vpStored3DSurfaceColorPoint *> visiblePoints;
68#ifdef VISP_HAVE_OPENMP
72 std::vector<vpStored3DSurfaceColorPoint *> visiblePointsLocal;
73#ifdef VISP_HAVE_OPENMP
76 for (
int i = 0; i < static_cast<int>(m_points.size()); ++i) {
80 p.projRenderPx[0] < 2 ||
static_cast<unsigned int>(p.projRenderPx[0]) >= frame.
IRGB.
getWidth() - 2
81 || p.projRenderPx[1] < 2 ||
static_cast<unsigned int>(p.projRenderPx[1]) >= frame.
IRGB.
getHeight() - 2
82 || p.projCurrPx[0] < 2 ||
static_cast<unsigned int>(p.projCurrPx[0]) >= frame.
IRGB.
getWidth() - 2
83 || p.projCurrPx[1] < 2 ||
static_cast<unsigned int>(p.projCurrPx[1]) >= frame.
IRGB.
getHeight() - 2) {
88 float ZrenderMap = frame.
renders.
depth[p.projRenderPx[1]][p.projRenderPx[0]];
90 if (ZrenderMap == 0.f || fabs(p.renderX[2] - ZrenderMap) > m_maxError3D) {
95 bool validZMap = frame.
hasDepth() && frame.
depth[p.projCurrPx[1]][p.projCurrPx[0]] > 0.f;
98 float actualZ = frame.
depth[p.projCurrPx[1]][p.projCurrPx[0]];
101 if (p.currX[2] - actualZ > 3.f * m_depthSigma) {
121 if (std::pow(
static_cast<double>(sp.
i) - p.projRenderPx[1], 2) + std::pow(
static_cast<double>(sp.
j) - p.projRenderPx[0], 2) <
vpMath::sqr(2)) {
132 visiblePointsLocal.push_back(&p);
135#ifdef VISP_HAVE_OPENMP
139 visiblePoints.insert(visiblePoints.end(), visiblePointsLocal.begin(), visiblePointsLocal.end());
142 if (visiblePoints.size() > 0) {
143 bool useMedian =
false;
145 std::vector<double> scores;
146 scores.reserve(visiblePoints.size());
148 double weightSum = 0.0;
150#ifdef VISP_HAVE_OPENMP
154 std::vector<double> scoresLocal;
155 double weightSumLocal = 0.0;
156 double scoreLocal = 0.0;
157#ifdef VISP_HAVE_OPENMP
160 for (
int i = 0; i < static_cast<int>(visiblePoints.size()); ++i) {
163 const bool hasCorrectDepth = frame.
hasDepth() && frame.
depth[p->projCurrPx[1]][p->projCurrPx[0]] > 0.f;
164 const double Z = hasCorrectDepth ? frame.
depth[p->projCurrPx[1]][p->projCurrPx[0]] : 0.0;
165 double depthError = Z > 0 ? fabs(p->currX[2] - Z) : 0.0;
166 double probaDepth = 1.0;
167 double scaleFactor = p->stats.covarianceScaleFactor();
168 double weight = 1.0 - std::min(1.0, scaleFactor / std::pow((m_initialColorSigma + 20.0), 2));
169 weightSumLocal += weight;
172 if (hasCorrectDepth) {
173 probaDepth = 1.0 - erf((depthError) / (m_depthSigma * sqrt(2.0)));
176 vpRGBf averageColor(0.f, 0.f, 0.f);
178 for (
int j = -1; j < 2; ++j) {
179 for (
int k = -1; k < 2; ++k) {
180 const vpRGBa currentColor = frame.
IRGB[p->projCurrPx[1] + j][p->projCurrPx[0] + k];
181 averageColor.
R +=
static_cast<float>(currentColor.
R);
182 averageColor.
G +=
static_cast<float>(currentColor.
G);
183 averageColor.
B +=
static_cast<float>(currentColor.
B);
193 averageColor = averageColor * (1.f / 9.f);
195 const double proba = p->stats.probability(averageColor) * probaDepth;
197 scoresLocal.push_back(proba);
198 scoreLocal += proba * weight;
199 p->updateColor(averageColor,
static_cast<float>(m_colorUpdateRate * probaDepth));
201#ifdef VISP_HAVE_OPENMP
205 scores.insert(scores.end(), scoresLocal.begin(), scoresLocal.end());
207 weightSum += weightSumLocal;
212 if (weightSum > 0.0) {
235 m_score =
score(frame, cTo);
253 for (
unsigned int i = top; i < bottom; i += m_sampleStep) {
254 for (
unsigned int j = left; j < right; j += m_sampleStep) {
255 double u =
static_cast<double>(j), v =
static_cast<double>(i);
256 double x = 0.0, y = 0.0;
257 double Z =
static_cast<double>(frame.
renders.
depth[i][j]);
264 cX = cprevTrender * renderX;
265 x = cX[0] / cX[2], y = cX[1] / cX[2];
267 int prevI =
static_cast<int>(v), prevJ =
static_cast<int>(u);
268 if (prevI < 0 || prevI >=
static_cast<int>(previousFrame.
IRGB.
getHeight()) || prevJ < 0 || prevJ >=
static_cast<int>(previousFrame.
IRGB.
getWidth())) {
273 newPoint.
X[0] = oX[0] / oX[3];
274 newPoint.
X[1] = oX[1] / oX[3];
275 newPoint.
X[2] = oX[2] / oX[3];
276 const vpRGBa &c = previousFrame.
IRGB[prevI][prevJ];
277 const float colorVariance = std::pow(
static_cast<float>(m_initialColorSigma), 2.f);
281 if (p.squaredDist(newPoint.
X) <
vpMath::sqr(m_minDist3DNewPoint)) {
287 m_points.push_back(newPoint);