16 #include <mrpt/core/exceptions.h> 17 #include <mrpt/maps/CPointsMap.h> 18 #include <mrpt/poses/Lie/SE.h> 19 #include <mrpt/tfest/se3.h> 24 #if defined(MP2P_HAS_LIBPOINTMATCHER) 37 #if defined(MP2P_HAS_LIBPOINTMATCHER) 44 #if defined(MP2P_HAS_LIBPOINTMATCHER) 50 for (
const auto& ly : pc.
layers)
53 auto pts = std::dynamic_pointer_cast<mrpt::maps::CPointsMap>(ly.second);
56 const auto xs = pts->getPointsBufferRef_x();
57 const auto ys = pts->getPointsBufferRef_y();
58 const auto zs = pts->getPointsBufferRef_z();
59 for (
size_t i = 0; i < xs.size(); i++)
60 ss << mrpt::format(
"%f %f %f\n", xs[i], ys[i], zs[i]);
68 const mrpt::containers::yaml& params)
71 params.printAsYAML(ss);
78 [[maybe_unused]]
const mrpt::math::TPose3D& initialGuessLocalWrtGlobal,
80 [[maybe_unused]]
const mrpt::optional_ref<LogRecord>& outputDebugInfo)
82 using namespace std::string_literals;
85 #if defined(MP2P_HAS_LIBPOINTMATCHER) 87 ASSERT_EQUAL_(pcLocal.layers.size(), pcGlobal.layers.size());
88 ASSERT_(!pcLocal.empty() && !pcGlobal.empty());
92 "You must call initialize_derived() first, or initialize from a YAML " 93 "file with a `derived` section with the LibPointMathcer-specific " 99 state.currentSolution.optimalPose =
100 mrpt::poses::CPose3D(initialGuessLocalWrtGlobal);
101 auto prev_solution = state.currentSolution.optimalPose;
107 std::optional<LogRecord> currentLog;
109 const bool generateDebugRecord =
110 outputDebugInfo.has_value() || p.generateDebugFiles;
112 if (generateDebugRecord)
114 currentLog.emplace();
115 currentLog->pcGlobal = pcGlobal.get_shared_from_this_or_clone();
116 currentLog->pcLocal = pcLocal.get_shared_from_this_or_clone();
117 currentLog->initialGuessLocalWrtGlobal = initialGuessLocalWrtGlobal;
118 currentLog->icpParameters = p;
122 ASSERT_(pcLocal.size() > 0);
123 ASSERT_(pcGlobal.size() > 0);
126 using DP = PM::DataPoints;
129 const DP ptsLocal = pointsToPM(pcLocal);
130 const DP ptsGlobal = pointsToPM(pcGlobal);
140 std::stringstream ss;
143 icp.loadFromYaml(ss);
147 ASSERT_EQUAL_(cloudDimension, 3U);
151 initialGuessLocalWrtGlobal.getHomogeneousMatrix().asEigen();
158 "Initial transformation is not rigid, SE(3) identity will be used");
159 initTransfo = PM::TransformationParameters::Identity(
160 cloudDimension + 1, cloudDimension + 1);
163 const DP ptsLocalTf = rigidTrans.
compute(ptsLocal, initTransfo);
169 T = icp(ptsLocalTf, ptsGlobal);
173 state.currentSolution.optimalPose =
174 mrpt::poses::CPose3D(initialGuessLocalWrtGlobal) +
175 mrpt::poses::CPose3D(mrpt::math::CMatrixDouble44(T));
179 catch (
const PM::ConvergenceError&)
186 if (!icp.transformationCheckers.empty())
188 icp.transformationCheckers.at(0)->getConditionVariables()[0];
190 result.nIterations = 1;
195 state.currentSolution.optimalPose, result.finalPairings);
198 result.optimalScale = 1.0;
199 result.optimal_tf.mean = state.currentSolution.optimalPose;
204 result.finalPairings, result.optimal_tf.mean, covParams);
210 if (currentLog) currentLog->icpResult = result;
216 if (currentLog && outputDebugInfo.has_value())
217 outputDebugInfo.value().get() = std::move(currentLog.value());
220 THROW_EXCEPTION(
"This method requires MP2P built against libpointmatcher");
std::map< layer_name_t, mrpt::maps::CMetricMap::Ptr > layers
static void save_log_file(const LogRecord &log, const Parameters &p)
Generic container of pointcloud(s), extracted features and other maps.
Covariance estimation methods for ICP results.
unsigned getNbPoints() const
Return the number of points contained in the point cloud.
quality_eval_list_t quality_evaluators_
static DataPoints loadCSV(const std::string &fileName)
Associate an external name to a DataPoints type of information.
static bool methodAvailable()
void align(const metric_map_t &pcLocal, const metric_map_t &pcGlobal, const mrpt::math::TPose3D &initialGuessLocalWrtGlobal, const Parameters &p, Results &result, const mrpt::optional_ref< LogRecord > &outputDebugInfo=std::nullopt) override
static double evaluate_quality(const quality_eval_list_t &evaluators, const metric_map_t &pcGlobal, const metric_map_t &pcLocal, const mrpt::poses::CPose3D &localPose, const Pairings &finalPairings)
mrpt::math::CMatrixDouble66 covariance(const Pairings &finalPairings, const mrpt::poses::CPose3D &finalAlignSolution, const CovarianceParameters &p)
IMPLEMENTS_MRPT_OBJECT(metric_map_t, mrpt::serialization::CSerializable, mp2p_icp) using namespace mp2p_icp
Pointcloud matcher: fixed distance thresholds.
unsigned getEuclideanDim() const
Return the dimension of the point cloud.
ICP wrapper on libpointmatcher.
std::string pm_icp_yaml_settings_
Matrix TransformationParameters
A matrix holding the parameters a transformation.
void initialize_derived(const mrpt::containers::yaml ¶ms) override