15 #include <mrpt/core/exceptions.h> 16 #include <mrpt/core/round.h> 17 #include <mrpt/version.h> 25 mrpt::system::COutputLogger::setLoggerName(
"Matcher_Point2Plane");
34 MCP_LOAD_REQ(params,
knn);
45 std::vector<size_t>& kddIdxs, std::vector<float>& kddSqrDist,
46 const float maxDistForCorrespondenceSquared)
49 if (!kddSqrDist.empty() &&
50 kddSqrDist.back() < maxDistForCorrespondenceSquared)
56 for (
size_t j = 0; j < kddSqrDist.size(); j++)
58 if (kddSqrDist[j] > maxDistForCorrespondenceSquared)
69 const mrpt::maps::CMetricMap& pcGlobalMap,
70 const mrpt::maps::CPointsMap& pcLocal,
71 const mrpt::poses::CPose3D& localPose,
MatchState& ms,
77 const auto* pcGlobalPtr =
78 dynamic_cast<const mrpt::maps::CPointsMap*
>(&pcGlobalMap);
81 "This class only supports global maps of point cloud types, but " 83 pcGlobalMap.GetRuntimeClass()->className);
84 const auto& pcGlobal = *pcGlobalPtr;
87 if (pcGlobal.empty() || pcLocal.empty())
return;
101 const float maxDistForCorrespondenceSquared = mrpt::square(
searchRadius);
103 const auto& gxs = pcGlobal.getPointsBufferRef_x();
104 const auto& gys = pcGlobal.getPointsBufferRef_y();
105 const auto& gzs = pcGlobal.getPointsBufferRef_z();
107 const auto& lxs = pcLocal.getPointsBufferRef_x();
108 const auto& lys = pcLocal.getPointsBufferRef_y();
109 const auto& lzs = pcLocal.getPointsBufferRef_z();
111 std::vector<float> kddSqrDist, kddSqrDistLocal;
112 std::vector<size_t> kddIdxs, kddIdxsLocal;
114 for (
size_t i = 0; i < tl.
x_locals.size(); i++)
116 const size_t localIdx = tl.
idxs.has_value() ? (*tl.
idxs)[i] : i;
135 pcGlobal.kdTreeNClosestPoint3DIdx(
138 kddIdxs, kddSqrDist);
142 kddIdxs, kddSqrDist, maxDistForCorrespondenceSquared);
148 gxs.data(), gys.data(), gzs.data(), kddIdxs);
152 std::cout <<
"eig values: " << eig.
eigVals[0] <<
" " << eig.
eigVals[1]
154 <<
" eigvec0: " << eig.
eigVectors[0].asString() <<
"\n" 155 <<
" eigvec1: " << eig.
eigVectors[1].asString() <<
"\n" 156 <<
" eigvec2: " << eig.
eigVectors[2].asString() <<
"\n";
163 const mrpt::math::TPoint3D planeCentroid = {
166 const auto thePlane = mrpt::math::TPlane(planeCentroid, normal);
167 const double ptPlaneDist = std::abs(thePlane.distance({lx, ly, lz}));
174 pcLocal.kdTreeNClosestPoint3DIdx(
176 lxs[localIdx], lys[localIdx], lzs[localIdx],
178 knn, kddIdxsLocal, kddSqrDistLocal);
181 kddIdxsLocal, kddSqrDistLocal, maxDistForCorrespondenceSquared);
195 const auto& normalLocal = eigLocal.
eigVectors[0];
197 const float dotProd = normalLocal.x * normal.x +
198 normalLocal.y * normal.y +
199 normalLocal.z * normal.z;
207 p.pt_local = {lxs[localIdx], lys[localIdx], lzs[localIdx]};
208 p.pl_global.centroid = planeCentroid;
210 p.pl_global.plane = thePlane;
uint32_t minimumPlanePoints
Output of estimate_points_eigen()
bool allowMatchAlreadyMatchedPoints_
static TransformedLocalPointCloud transform_local_to_global(const mrpt::maps::CPointsMap &pcLocal, const mrpt::poses::CPose3D &localPose, const std::size_t maxLocalPoints=0, const uint64_t localPointsSampleSeed=0)
bool localPointMustFitPlaneToo
std::array< mrpt::math::TVector3D, 3 > eigVectors
uint64_t maxLocalPointsPerLayer_
static void filterListByMaxDist(std::vector< size_t > &kddIdxs, std::vector< float > &kddSqrDist, const float maxDistForCorrespondenceSquared)
uint64_t localPointsSampleSeed_
double planeEigenThreshold
double localToGlobalPlaneMinAbsCosine
void implMatchOneLayer(const mrpt::maps::CMetricMap &pcGlobal, const mrpt::maps::CPointsMap &pcLocal, const mrpt::poses::CPose3D &localPose, MatchState &ms, const layer_name_t &globalName, const layer_name_t &localName, Pairings &out) const override
void initialize(const mrpt::containers::yaml ¶ms) override
IMPLEMENTS_MRPT_OBJECT(metric_map_t, mrpt::serialization::CSerializable, mp2p_icp) using namespace mp2p_icp
pointcloud_bitfield_t localPairedBitField
PointCloudEigen estimate_points_eigen(const float *xs, const float *ys, const float *zs, mrpt::optional_ref< const std::vector< size_t >> indices, std::optional< size_t > totalCount=std::nullopt)
std::array< double, 3 > eigVals
void initialize(const mrpt::containers::yaml ¶ms) override
Pointcloud matcher: point to plane-fit of nearby points.
mrpt::poses::CPointPDFGaussian meanCov
MatchedPointPlaneList paired_pt2pl
std::map< layer_name_t, std::vector< bool > > point_layers
Calculate eigenvectors and eigenvalues from a set of points.