51 : insertionOptions(), likelihoodOptions(), m_x(), m_y(), m_z()
60 CPointsMap::~CPointsMap() =
default;
66 bool CPointsMap::save2D_to_text_file(
const string& file)
const
71 for (
unsigned int i = 0; i < m_x.size(); i++)
83 bool CPointsMap::save3D_to_text_file(
const string& file)
const
88 for (
unsigned int i = 0; i < m_x.size(); i++)
89 os::fprintf(f,
"%f %f %f\n", m_x[i], m_y[i], m_z[i]);
100 bool CPointsMap::load2Dor3D_from_text_file(
101 const std::string& file,
const bool is_3D)
108 if (!f)
return false;
111 char *ptr, *ptr1, *ptr2, *ptr3;
120 if (!fgets(str,
sizeof(str), f))
break;
124 while (ptr[0] && (ptr[0] ==
' ' || ptr[0] ==
'\t' || ptr[0] ==
'\r' ||
129 float xx = strtod(ptr, &ptr1);
132 float yy = strtod(ptr1, &ptr2);
137 this->insertPoint(xx, yy, 0);
141 float zz = strtod(ptr2, &ptr3);
144 this->insertPoint(xx, yy, zz);
165 mxArray* CPointsMap::writeToMatlab()
const
168 MRPT_TODO(
"Create 3xN array xyz of points coordinates")
169 const
char* fields[] = {
"x",
"y",
"z"};
170 mexplus::MxArray map_struct(
171 mexplus::MxArray::Struct(
sizeof(fields) /
sizeof(fields[0]), fields));
173 map_struct.set(
"x", m_x);
174 map_struct.set(
"y", m_y);
175 map_struct.set(
"z", m_z);
176 return map_struct.release();
186 void CPointsMap::getPoint(
size_t index,
float& x,
float& y)
const
192 void CPointsMap::getPoint(
size_t index,
float& x,
float& y,
float& z)
const
199 void CPointsMap::getPoint(
size_t index,
double& x,
double& y)
const
205 void CPointsMap::getPoint(
size_t index,
double& x,
double& y,
double& z)
const
216 void CPointsMap::getPointsBuffer(
217 size_t& outPointsCount,
const float*& xs,
const float*& ys,
218 const float*& zs)
const
220 outPointsCount =
size();
222 if (outPointsCount > 0)
230 xs = ys = zs =
nullptr;
237 void CPointsMap::clipOutOfRangeInZ(
float zMin,
float zMax)
239 const size_t n =
size();
240 vector<bool> deletionMask(n);
243 for (
size_t i = 0; i < n; i++)
244 deletionMask[i] = (m_z[i] < zMin || m_z[i] > zMax);
247 applyDeletionMask(deletionMask);
255 void CPointsMap::clipOutOfRange(
const TPoint2D& p,
float maxRange)
257 size_t i, n =
size();
258 vector<bool> deletionMask;
261 deletionMask.resize(n);
263 const auto max_sq = maxRange * maxRange;
266 for (i = 0; i < n; i++)
267 deletionMask[i] =
square(p.
x - m_x[i]) +
square(p.
y - m_y[i]) > max_sq;
270 applyDeletionMask(deletionMask);
275 void CPointsMap::determineMatching2D(
286 params.offset_other_map_points,
params.decimation_other_map_points);
288 const auto* otherMap =
static_cast<const CPointsMap*
>(otherMap2);
291 otherMapPose_.
x(), otherMapPose_.
y(), otherMapPose_.
phi());
293 const size_t nLocalPoints = otherMap->size();
294 const size_t nGlobalPoints = this->
size();
295 float _sumSqrDist = 0;
296 size_t _sumSqrCount = 0;
297 size_t nOtherMapPointsWithCorrespondence =
300 float local_x_min = std::numeric_limits<float>::max(),
301 local_x_max = -std::numeric_limits<float>::max();
302 float global_x_min = std::numeric_limits<float>::max(),
303 global_x_max = -std::numeric_limits<float>::max();
304 float local_y_min = std::numeric_limits<float>::max(),
305 local_y_max = -std::numeric_limits<float>::max();
306 float global_y_min = std::numeric_limits<float>::max(),
307 global_y_max = -std::numeric_limits<float>::max();
309 double maxDistForCorrespondenceSquared;
310 float x_local, y_local;
311 unsigned int localIdx;
313 const float *x_other_it, *y_other_it, *z_other_it;
316 correspondences.clear();
317 correspondences.reserve(nLocalPoints);
318 extraResults.correspondencesRatio = 0;
321 _correspondences.reserve(nLocalPoints);
324 if (!nGlobalPoints || !nLocalPoints)
return;
326 const double sin_phi = sin(otherMapPose.
phi);
327 const double cos_phi = cos(otherMapPose.
phi);
335 size_t nPackets = nLocalPoints / 4;
337 Eigen::ArrayXf x_locals(nLocalPoints), y_locals(nLocalPoints);
340 const __m128 cos_4val = _mm_set1_ps(cos_phi);
341 const __m128 sin_4val = _mm_set1_ps(sin_phi);
342 const __m128 x0_4val = _mm_set1_ps(otherMapPose.
x);
343 const __m128 y0_4val = _mm_set1_ps(otherMapPose.
y);
346 __m128 x_mins = _mm_set1_ps(std::numeric_limits<float>::max());
347 __m128 x_maxs = _mm_set1_ps(std::numeric_limits<float>::min());
348 __m128 y_mins = x_mins;
349 __m128 y_maxs = x_maxs;
351 const float* ptr_in_x = &otherMap->m_x[0];
352 const float* ptr_in_y = &otherMap->m_y[0];
353 float* ptr_out_x = &x_locals[0];
354 float* ptr_out_y = &y_locals[0];
356 for (; nPackets; nPackets--, ptr_in_x += 4, ptr_in_y += 4, ptr_out_x += 4,
359 const __m128 xs = _mm_loadu_ps(ptr_in_x);
360 const __m128 ys = _mm_loadu_ps(ptr_in_y);
362 const __m128 lxs = _mm_add_ps(
364 _mm_sub_ps(_mm_mul_ps(xs, cos_4val), _mm_mul_ps(ys, sin_4val)));
365 const __m128 lys = _mm_add_ps(
367 _mm_add_ps(_mm_mul_ps(xs, sin_4val), _mm_mul_ps(ys, cos_4val)));
368 _mm_store_ps(ptr_out_x, lxs);
369 _mm_store_ps(ptr_out_y, lys);
371 x_mins = _mm_min_ps(x_mins, lxs);
372 x_maxs = _mm_max_ps(x_maxs, lxs);
373 y_mins = _mm_min_ps(y_mins, lys);
374 y_maxs = _mm_max_ps(y_maxs, lys);
378 alignas(MRPT_MAX_STATIC_ALIGN_BYTES)
float temp_nums[4];
380 _mm_store_ps(temp_nums, x_mins);
382 min(min(temp_nums[0], temp_nums[1]), min(temp_nums[2], temp_nums[3]));
383 _mm_store_ps(temp_nums, y_mins);
385 min(min(temp_nums[0], temp_nums[1]), min(temp_nums[2], temp_nums[3]));
386 _mm_store_ps(temp_nums, x_maxs);
388 max(max(temp_nums[0], temp_nums[1]), max(temp_nums[2], temp_nums[3]));
389 _mm_store_ps(temp_nums, y_maxs);
391 max(max(temp_nums[0], temp_nums[1]), max(temp_nums[2], temp_nums[3]));
394 for (
size_t k = 0; k < nLocalPoints % 4; k++)
396 float x = ptr_in_x[k];
397 float y = ptr_in_y[k];
398 float out_x = otherMapPose.
x + cos_phi * x - sin_phi * y;
399 float out_y = otherMapPose.
y + sin_phi * x + cos_phi * y;
401 local_x_min = std::min(local_x_min, out_x);
402 local_x_max = std::max(local_x_max, out_x);
404 local_y_min = std::min(local_y_min, out_y);
405 local_y_max = std::max(local_y_max, out_y);
407 ptr_out_x[k] = out_x;
408 ptr_out_y[k] = out_y;
414 const_cast<float*
>(&otherMap->m_x[0]), otherMap->m_x.size(), 1);
416 const_cast<float*
>(&otherMap->m_y[0]), otherMap->m_y.size(), 1);
418 Eigen::Array<float, Eigen::Dynamic, 1> x_locals =
419 otherMapPose.
x + cos_phi * x_org.array() - sin_phi * y_org.array();
420 Eigen::Array<float, Eigen::Dynamic, 1> y_locals =
421 otherMapPose.
y + sin_phi * x_org.array() + cos_phi * y_org.array();
423 local_x_min = x_locals.minCoeff();
424 local_y_min = y_locals.minCoeff();
425 local_x_max = x_locals.maxCoeff();
426 local_y_max = y_locals.maxCoeff();
430 float global_z_min, global_z_max;
432 global_x_min, global_x_max, global_y_min, global_y_max, global_z_min,
437 if (local_x_min > global_x_max || local_x_max < global_x_min ||
438 local_y_min > global_y_max || local_y_max < global_y_min)
443 for (localIdx =
params.offset_other_map_points,
444 x_other_it = &otherMap->m_x[
params.offset_other_map_points],
445 y_other_it = &otherMap->m_y[
params.offset_other_map_points],
446 z_other_it = &otherMap->m_z[
params.offset_other_map_points];
447 localIdx < nLocalPoints;
448 x_other_it +=
params.decimation_other_map_points,
449 y_other_it +=
params.decimation_other_map_points,
450 z_other_it +=
params.decimation_other_map_points,
451 localIdx +=
params.decimation_other_map_points)
454 x_local = x_locals[localIdx];
455 y_local = y_locals[localIdx];
464 float tentativ_err_sq;
465 unsigned int tentativ_this_idx = kdTreeClosestPoint2D(
471 maxDistForCorrespondenceSquared =
square(
472 params.maxAngularDistForCorrespondence *
476 params.maxDistForCorrespondence);
479 if (tentativ_err_sq < maxDistForCorrespondenceSquared)
482 _correspondences.resize(_correspondences.size() + 1);
487 p.
this_x = m_x[tentativ_this_idx];
488 p.
this_y = m_y[tentativ_this_idx];
489 p.
this_z = m_z[tentativ_this_idx];
499 nOtherMapPointsWithCorrespondence++;
512 if (
params.onlyUniqueRobust)
515 params.onlyKeepTheClosest,
516 "ERROR: onlyKeepTheClosest must be also set to true when "
517 "onlyUniqueRobust=true.");
519 nGlobalPoints, correspondences);
523 correspondences.swap(_correspondences);
529 extraResults.sumSqrDist =
530 _sumSqrDist /
static_cast<double>(_sumSqrCount);
532 extraResults.sumSqrDist = 0;
535 extraResults.correspondencesRatio =
params.decimation_other_map_points *
536 nOtherMapPointsWithCorrespondence /
545 void CPointsMap::changeCoordinatesReference(
const CPose2D& newBase)
547 const size_t N = m_x.size();
549 const CPose3D newBase3D(newBase);
551 for (
size_t i = 0; i < N; i++)
553 m_x[i], m_y[i], m_z[i],
554 m_x[i], m_y[i], m_z[i]
563 void CPointsMap::changeCoordinatesReference(
const CPose3D& newBase)
565 const size_t N = m_x.size();
567 for (
size_t i = 0; i < N; i++)
569 m_x[i], m_y[i], m_z[i],
570 m_x[i], m_y[i], m_z[i]
579 void CPointsMap::changeCoordinatesReference(
583 changeCoordinatesReference(newBase);
589 bool CPointsMap::isEmpty()
const {
return m_x.empty(); }
593 CPointsMap::TInsertionOptions::TInsertionOptions()
594 : horizontalTolerance(0.05_deg)
603 const int8_t version = 0;
606 out << minDistBetweenLaserPoints << addToExistingPointsMap
607 << also_interpolate << disableDeletion << fuseWithExisting
608 << isPlanarMap << horizontalTolerance << maxDistForInterpolatePoints
609 << insertInvalidPoints;
621 in >> minDistBetweenLaserPoints >> addToExistingPointsMap >>
622 also_interpolate >> disableDeletion >> fuseWithExisting >>
623 isPlanarMap >> horizontalTolerance >>
624 maxDistForInterpolatePoints >> insertInvalidPoints;
639 const int8_t version = 0;
641 out << sigma_dist << max_corr_distance << decimation;
653 in >> sigma_dist >> max_corr_distance >> decimation;
664 const int8_t version = 0;
678 in >> point_size >> this->color;
689 out <<
"\n----------- [CPointsMap::TInsertionOptions] ------------ \n\n";
708 out <<
"\n----------- [CPointsMap::TLikelihoodOptions] ------------ \n\n";
717 out <<
"\n----------- [CPointsMap::TRenderOptions] ------------ \n\n";
775 obj->loadFromPointsMap(
this);
778 obj->enableColorFromZ(
false);
784 obj->loadFromPointsMap(
this);
788 obj->recolorizeByCoordinate(
822 float maxDistSq = 0, d;
823 for (
auto X =
m_x.begin(), Y =
m_y.begin(), Z =
m_z.begin();
824 X !=
m_x.end(); ++X, ++Y, ++Z)
827 maxDistSq = max(d, maxDistSq);
840 vector<float>& xs, vector<float>& ys,
size_t decimation)
const
846 xs = vector<float>(
m_x.begin(),
m_x.end());
847 ys = vector<float>(
m_y.begin(),
m_y.end());
851 size_t N =
m_x.size() / decimation;
856 auto X =
m_x.begin();
857 auto Y =
m_y.begin();
858 for (
auto oX = xs.begin(), oY = ys.begin(); oX != xs.end();
859 X += decimation, Y += decimation, ++oX, ++oY)
872 float x0,
float y0)
const
880 float x1, y1, x2, y2, d1, d2;
891 if (d12 > 0.20f * 0.20f || d12 < 0.03f * 0.03f)
897 double interp_x, interp_y;
915 float& min_x,
float& max_x,
float& min_y,
float& max_y,
float& min_z,
920 const size_t nPoints =
m_x.size();
935 size_t nPackets = nPoints / 4;
938 __m128 x_mins = _mm_set1_ps(std::numeric_limits<float>::max());
939 __m128 x_maxs = _mm_set1_ps(std::numeric_limits<float>::min());
940 __m128 y_mins = x_mins, y_maxs = x_maxs;
941 __m128 z_mins = x_mins, z_maxs = x_maxs;
943 const float* ptr_in_x = &
m_x[0];
944 const float* ptr_in_y = &
m_y[0];
945 const float* ptr_in_z = &
m_z[0];
948 nPackets--, ptr_in_x += 4, ptr_in_y += 4, ptr_in_z += 4)
950 const __m128 xs = _mm_loadu_ps(ptr_in_x);
951 x_mins = _mm_min_ps(x_mins, xs);
952 x_maxs = _mm_max_ps(x_maxs, xs);
954 const __m128 ys = _mm_loadu_ps(ptr_in_y);
955 y_mins = _mm_min_ps(y_mins, ys);
956 y_maxs = _mm_max_ps(y_maxs, ys);
958 const __m128 zs = _mm_loadu_ps(ptr_in_z);
959 z_mins = _mm_min_ps(z_mins, zs);
960 z_maxs = _mm_max_ps(z_maxs, zs);
964 alignas(MRPT_MAX_STATIC_ALIGN_BYTES)
float temp_nums[4];
966 _mm_store_ps(temp_nums, x_mins);
968 min(min(temp_nums[0], temp_nums[1]),
969 min(temp_nums[2], temp_nums[3]));
970 _mm_store_ps(temp_nums, y_mins);
972 min(min(temp_nums[0], temp_nums[1]),
973 min(temp_nums[2], temp_nums[3]));
974 _mm_store_ps(temp_nums, z_mins);
976 min(min(temp_nums[0], temp_nums[1]),
977 min(temp_nums[2], temp_nums[3]));
978 _mm_store_ps(temp_nums, x_maxs);
980 max(max(temp_nums[0], temp_nums[1]),
981 max(temp_nums[2], temp_nums[3]));
982 _mm_store_ps(temp_nums, y_maxs);
984 max(max(temp_nums[0], temp_nums[1]),
985 max(temp_nums[2], temp_nums[3]));
986 _mm_store_ps(temp_nums, z_maxs);
988 max(max(temp_nums[0], temp_nums[1]),
989 max(temp_nums[2], temp_nums[3]));
992 for (
size_t k = 0; k < nPoints % 4; k++)
1006 (std::numeric_limits<float>::max)();
1009 -(std::numeric_limits<float>::max)();
1011 for (
auto xi =
m_x.begin(), yi =
m_y.begin(), zi =
m_z.begin();
1012 xi !=
m_x.end(); xi++, yi++, zi++)
1049 params.offset_other_map_points,
params.decimation_other_map_points);
1052 const auto* otherMap =
static_cast<const CPointsMap*
>(otherMap2);
1054 const size_t nLocalPoints = otherMap->
size();
1055 const size_t nGlobalPoints = this->
size();
1056 float _sumSqrDist = 0;
1057 size_t _sumSqrCount = 0;
1058 size_t nOtherMapPointsWithCorrespondence =
1061 float local_x_min = std::numeric_limits<float>::max(),
1062 local_x_max = -std::numeric_limits<float>::max();
1063 float local_y_min = std::numeric_limits<float>::max(),
1064 local_y_max = -std::numeric_limits<float>::max();
1065 float local_z_min = std::numeric_limits<float>::max(),
1066 local_z_max = -std::numeric_limits<float>::max();
1068 double maxDistForCorrespondenceSquared;
1071 correspondences.clear();
1072 correspondences.reserve(nLocalPoints);
1075 _correspondences.reserve(nLocalPoints);
1078 if (!nGlobalPoints || !nLocalPoints)
return;
1082 vector<float> x_locals(nLocalPoints), y_locals(nLocalPoints),
1083 z_locals(nLocalPoints);
1085 for (
unsigned int localIdx =
params.offset_other_map_points;
1086 localIdx < nLocalPoints;
1087 localIdx +=
params.decimation_other_map_points)
1089 float x_local, y_local, z_local;
1091 otherMap->m_x[localIdx], otherMap->m_y[localIdx],
1092 otherMap->m_z[localIdx], x_local, y_local, z_local);
1094 x_locals[localIdx] = x_local;
1095 y_locals[localIdx] = y_local;
1096 z_locals[localIdx] = z_local;
1099 local_x_min = min(local_x_min, x_local);
1100 local_x_max = max(local_x_max, x_local);
1101 local_y_min = min(local_y_min, y_local);
1102 local_y_max = max(local_y_max, y_local);
1103 local_z_min = min(local_z_min, z_local);
1104 local_z_max = max(local_z_max, z_local);
1108 float global_x_min, global_x_max, global_y_min, global_y_max, global_z_min,
1111 global_x_min, global_x_max, global_y_min, global_y_max, global_z_min,
1116 if (local_x_min > global_x_max || local_x_max < global_x_min ||
1117 local_y_min > global_y_max || local_y_max < global_y_min)
1122 for (
unsigned int localIdx =
params.offset_other_map_points;
1123 localIdx < nLocalPoints;
1124 localIdx +=
params.decimation_other_map_points)
1127 const float x_local = x_locals[localIdx];
1128 const float y_local = y_locals[localIdx];
1129 const float z_local = z_locals[localIdx];
1137 float tentativ_err_sq;
1139 x_local, y_local, z_local,
1144 maxDistForCorrespondenceSquared =
square(
1145 params.maxAngularDistForCorrespondence *
1146 params.angularDistPivotPoint.distanceTo(
1147 TPoint3D(x_local, y_local, z_local)) +
1148 params.maxDistForCorrespondence);
1151 if (tentativ_err_sq < maxDistForCorrespondenceSquared)
1154 _correspondences.resize(_correspondences.size() + 1);
1164 p.
other_x = otherMap->m_x[localIdx];
1165 p.
other_y = otherMap->m_y[localIdx];
1166 p.
other_z = otherMap->m_z[localIdx];
1171 nOtherMapPointsWithCorrespondence++;
1185 if (
params.onlyUniqueRobust)
1188 params.onlyKeepTheClosest,
1189 "ERROR: onlyKeepTheClosest must be also set to true when "
1190 "onlyUniqueRobust=true.");
1192 nGlobalPoints, correspondences);
1196 correspondences.swap(_correspondences);
1201 extraResults.sumSqrDist =
1202 (_sumSqrCount) ? _sumSqrDist /
static_cast<double>(_sumSqrCount) : 0;
1203 extraResults.correspondencesRatio =
params.decimation_other_map_points *
1204 nOtherMapPointsWithCorrespondence /
1214 const TPoint2D& center,
const double radius,
const double zmin,
1218 for (
size_t k = 0; k <
m_x.size(); k++)
1220 if ((
m_z[k] <= zmax &&
m_z[k] >= zmin) &&
1232 double R,
double G,
double B)
1235 double minX, maxX, minY, maxY, minZ, maxZ;
1236 minX = min(corner1.
x, corner2.
x);
1237 maxX = max(corner1.
x, corner2.
x);
1238 minY = min(corner1.
y, corner2.
y);
1239 maxY = max(corner1.
y, corner2.
y);
1240 minZ = min(corner1.
z, corner2.
z);
1241 maxZ = max(corner1.
z, corner2.
z);
1242 for (
size_t k = 0; k <
m_x.size(); k++)
1244 if ((
m_x[k] >= minX &&
m_x[k] <= maxX) &&
1245 (
m_y[k] >= minY &&
m_y[k] <= maxY) &&
1246 (
m_z[k] >= minZ &&
m_z[k] <= maxZ))
1256 [[maybe_unused]]
const CPose3D& otherMapPose,
1258 float& correspondencesRatio)
1262 const auto* otherMap =
static_cast<const CPointsMap*
>(otherMap2);
1264 const size_t nLocalPoints = otherMap->
size();
1265 const size_t nGlobalPoints = this->
size();
1266 size_t nOtherMapPointsWithCorrespondence =
1270 correspondences.clear();
1271 correspondences.reserve(nLocalPoints);
1272 correspondencesRatio = 0;
1276 _correspondences.reserve(nLocalPoints);
1279 if (!nGlobalPoints)
return;
1282 if (!nLocalPoints)
return;
1285 float local_x_min, local_x_max, local_y_min, local_y_max, local_z_min,
1287 otherMap->boundingBox(
1288 local_x_min, local_x_max, local_y_min, local_y_max, local_z_min,
1292 float global_x_min, global_x_max, global_y_min, global_y_max, global_z_min,
1295 global_x_min, global_x_max, global_y_min, global_y_max, global_z_min,
1300 if (local_x_min > global_x_max || local_x_max < global_x_min ||
1301 local_y_min > global_y_max || local_y_max < global_y_min)
1305 std::vector<std::vector<size_t>> vIdx;
1309 std::vector<float> outX, outY, outZ, tentativeErrSq;
1310 std::vector<size_t> outIdx;
1311 for (
unsigned int localIdx = 0; localIdx < nLocalPoints; ++localIdx)
1314 const float x_local = otherMap->m_x[localIdx];
1315 const float y_local = otherMap->m_y[localIdx];
1316 const float z_local = otherMap->m_z[localIdx];
1324 x_local, y_local, z_local,
1332 const float mX = (outX[0] + outX[1] + outX[2]) / 3.0;
1333 const float mY = (outY[0] + outY[1] + outY[2]) / 3.0;
1334 const float mZ = (outZ[0] + outZ[1] + outZ[2]) / 3.0;
1340 if (distanceForThisPoint < maxDistForCorrespondence)
1343 _correspondences.resize(_correspondences.size() + 1);
1347 p.
this_idx = nOtherMapPointsWithCorrespondence++;
1355 p.
other_x = otherMap->m_x[localIdx];
1356 p.
other_y = otherMap->m_y[localIdx];
1357 p.
other_z = otherMap->m_z[localIdx];
1362 std::sort(outIdx.begin(), outIdx.end());
1363 vIdx.push_back(outIdx);
1372 std::map<size_t, std::map<size_t, std::map<size_t, pair<size_t, float>>>>
1374 TMatchingPairList::iterator it;
1375 for (it = _correspondences.begin(); it != _correspondences.end(); ++it)
1377 const size_t i0 = vIdx[it->this_idx][0];
1378 const size_t i1 = vIdx[it->this_idx][1];
1379 const size_t i2 = vIdx[it->this_idx][2];
1381 if (best.find(i0) != best.end() &&
1382 best[i0].find(i1) != best[i0].end() &&
1383 best[i0][i1].find(i2) !=
1387 if (best[i0][i1][i2].second > it->errorSquareAfterTransformation)
1389 best[i0][i1][i2].first = it->this_idx;
1390 best[i0][i1][i2].second = it->errorSquareAfterTransformation;
1395 best[i0][i1][i2].first = it->this_idx;
1396 best[i0][i1][i2].second = it->errorSquareAfterTransformation;
1400 for (it = _correspondences.begin(); it != _correspondences.end(); ++it)
1402 const size_t i0 = vIdx[it->this_idx][0];
1403 const size_t i1 = vIdx[it->this_idx][1];
1404 const size_t i2 = vIdx[it->this_idx][2];
1406 if (best[i0][i1][i2].first == it->this_idx)
1407 correspondences.push_back(*it);
1411 correspondencesRatio =
1412 nOtherMapPointsWithCorrespondence /
d2f(nLocalPoints);
1419 const float* zs,
const std::size_t num_pts)
1423 float closest_x, closest_y, closest_z;
1426 double sumSqrDist = 0;
1428 std::size_t nPtsForAverage = 0;
1429 for (std::size_t i = 0; i < num_pts;
1435 pc_in_map.
composePoint(xs[i], ys[i], zs[i], xg, yg, zg);
1439 closest_x, closest_y,
1447 sumSqrDist +=
static_cast<double>(closest_err);
1449 if (nPtsForAverage) sumSqrDist /= nPtsForAverage;
1472 const size_t N = scanPoints->
m_x.size();
1473 if (!N || !this->
size())
return -100;
1475 const float* xs = &scanPoints->m_x[0];
1476 const float* ys = &scanPoints->m_y[0];
1477 const float* zs = &scanPoints->m_z[0];
1481 double sumSqrDist = 0;
1482 float closest_x, closest_y;
1484 const float max_sqr_err =
1490 const double ccos = cos(takenFrom2D.
phi);
1491 const double csin = sin(takenFrom2D.
phi);
1492 int nPtsForAverage = 0;
1494 for (
size_t i = 0; i < N;
1499 const float xg = takenFrom2D.
x + ccos * xs[i] - csin * ys[i];
1500 const float yg = takenFrom2D.
y + csin * xs[i] + ccos * ys[i];
1504 closest_x, closest_y,
1511 sumSqrDist +=
static_cast<double>(closest_err);
1513 sumSqrDist /= nPtsForAverage;
1521 takenFrom, xs, ys, zs, N);
1529 if (!o.point_cloud.size())
1532 const size_t N = o.point_cloud.size();
1533 if (!N || !this->
size())
return -100;
1535 const CPose3D sensorAbsPose = takenFrom + o.sensorPose;
1537 const float* xs = &o.point_cloud.
x[0];
1538 const float* ys = &o.point_cloud.y[0];
1539 const float* zs = &o.point_cloud.z[0];
1542 sensorAbsPose, xs, ys, zs, N);
1549 if (!N || !this->
size())
return -100;
1551 const CPose3D sensorAbsPose = takenFrom + o.sensorPose;
1553 auto xs = o.pointcloud->getPointsBufferRef_x();
1554 auto ys = o.pointcloud->getPointsBufferRef_y();
1555 auto zs = o.pointcloud->getPointsBufferRef_z();
1558 sensorAbsPose, &xs[0], &ys[0], &zs[0], N);
1581 if (out_map)
return;
1583 out_map = std::make_shared<CSimplePointsMap>();
1589 out_map->insertObservation(obs,
nullptr);
1629 pt_has_color =
false;
1640 const size_t nThis = this->
size();
1641 const size_t nOther = anotherMap.
size();
1643 const size_t nTot = nThis + nOther;
1647 for (
size_t i = 0, j = nThis; i < nOther; i++, j++)
1649 m_x[j] = anotherMap.
m_x[i];
1650 m_y[j] = anotherMap.
m_y[i];
1651 m_z[j] = anotherMap.
m_z[i];
1667 const size_t n = mask.size();
1670 for (i = 0, j = 0; i < n; i++)
1692 const size_t N_this =
size();
1693 const size_t N_other = otherMap->
size();
1696 this->
resize(N_this + N_other);
1700 for (src = 0, dst = N_this; src < N_other; src++, dst++)
1724 if (
this == &obj)
return;
1757 robotPose2D =
CPose2D(*robotPose);
1758 robotPose3D = (*robotPose);
1774 bool reallyInsertIt;
1780 reallyInsertIt =
true;
1784 std::vector<bool> checkForDeletion;
1815 const float *xs, *ys, *zs;
1822 for (
size_t i = 0; i < n; i++)
1824 if (checkForDeletion[i])
1832 checkForDeletion[i] =
1868 bool reallyInsertIt;
1874 reallyInsertIt =
true;
1928 this->
size() + o.sensedData.size() * 30);
1930 for (
auto it = o.begin(); it != o.end(); ++it)
1932 const CPose3D sensorPose = robotPose3D +
CPose3D(it->sensorPose);
1933 const double rang = it->sensedDistance;
1935 if (rang <= 0 || rang < o.minSensorDistance ||
1936 rang > o.maxSensorDistance)
1941 const double arc_len = o.sensorConeApperture * rang;
1942 const unsigned int nSteps =
round(1 + arc_len / 0.05);
1943 const double Aa = o.sensorConeApperture / double(nSteps);
1946 for (
double a1 = -aper_2;
a1 < aper_2;
a1 += Aa)
1948 for (
double a2 = -aper_2;
a2 < aper_2;
a2 += Aa)
1950 loc.
x = cos(
a1) * cos(
a2) * rang;
1951 loc.
y = cos(
a1) * sin(
a2) * rang;
1952 loc.
z = sin(
a1) * rang;
1971 if (!o.point_cloud.size())
2031 std::vector<bool>* notFusedPoints)
2035 const CPose2D nullPose(0, 0, 0);
2040 const size_t nOther = otherMap->
size();
2047 params.maxAngularDistForCorrespondence = 0;
2048 params.maxDistForCorrespondence = minDistForFuse;
2053 correspondences,
params, extraResults);
2058 notFusedPoints->clear();
2059 notFusedPoints->reserve(
m_x.size() + nOther);
2060 notFusedPoints->resize(
m_x.size(),
true);
2069 for (
size_t i = 0; i < nOther; i++)
2075 int closestCorr = -1;
2076 float minDist = std::numeric_limits<float>::max();
2077 for (
auto corrsIt = correspondences.begin();
2078 corrsIt != correspondences.end(); ++corrsIt)
2080 if (corrsIt->other_idx == i)
2082 float dist =
square(corrsIt->other_x - corrsIt->this_x) +
2083 square(corrsIt->other_y - corrsIt->this_y) +
2084 square(corrsIt->other_z - corrsIt->this_z);
2088 closestCorr = corrsIt->this_idx;
2093 if (closestCorr != -1)
2100 const float F = 1.0f / (w_a + w_b);
2102 m_x[closestCorr] = F * (w_a * a.
x + w_b * b.
x);
2103 m_y[closestCorr] = F * (w_a * a.
y + w_b * b.
y);
2104 m_z[closestCorr] = F * (w_a * a.
z + w_b * b.
z);
2109 if (notFusedPoints) (*notFusedPoints)[closestCorr] =
false;
2114 if (notFusedPoints) (*notFusedPoints).push_back(
false);
2137 const size_t nOldPtsCount = this->
size();
2139 const size_t nNewPtsCount = nOldPtsCount + nScanPts;
2140 this->
resize(nNewPtsCount);
2142 const float K = 1.0f / 255;
2147 sensorGlobalPose = *robotPose + scan.
sensorPose;
2154 const double m00 = HM(0, 0), m01 = HM(0, 1), m02 = HM(0, 2), m03 = HM(0, 3);
2155 const double m10 = HM(1, 0), m11 = HM(1, 1), m12 = HM(1, 2), m13 = HM(1, 3);
2156 const double m20 = HM(2, 0), m21 = HM(2, 1), m22 = HM(2, 2), m23 = HM(2, 3);
2159 for (
size_t i = 0; i < nScanPts; i++)
2166 const double gx = m00 * lx + m01 * ly + m02 * lz + m03;
2167 const double gy = m10 * lx + m11 * ly + m12 * lz + m13;
2168 const double gz = m20 * lx + m21 * ly + m22 * lz + m23;
2171 nOldPtsCount + i, gx, gy, gz,