ICP.h
Go to the documentation of this file.
1 /* -------------------------------------------------------------------------
2  * A repertory of multi primitive-to-primitive (MP2P) ICP algorithms in C++
3  * Copyright (C) 2018-2024 Jose Luis Blanco, University of Almeria
4  * See LICENSE for license information.
5  * ------------------------------------------------------------------------- */
12 #pragma once
13 
15 #include <mp2p_icp/LogRecord.h>
16 #include <mp2p_icp/Matcher.h>
17 #include <mp2p_icp/Parameters.h>
20 #include <mp2p_icp/Results.h>
21 #include <mp2p_icp/Solver.h>
22 #include <mp2p_icp/metricmap.h>
23 #include <mrpt/containers/yaml.h>
24 #include <mrpt/core/optional_ref.h>
25 #include <mrpt/math/TPose3D.h>
26 #include <mrpt/rtti/CObject.h>
27 #include <mrpt/system/COutputLogger.h>
28 #include <mrpt/system/CTimeLogger.h>
29 
30 #include <cstdint>
31 #include <functional>
32 
33 namespace mp2p_icp
34 {
51 class ICP : public mrpt::system::COutputLogger, public mrpt::rtti::CObject
52 {
53  DEFINE_MRPT_OBJECT(ICP, mp2p_icp)
54 
55  public:
60  virtual void align(
61  const metric_map_t& pcLocal, const metric_map_t& pcGlobal,
62  const mrpt::math::TPose3D& initialGuessLocalWrtGlobal,
63  const Parameters& p, Results& result,
64  const std::optional<mrpt::poses::CPose3DPDFGaussianInf>& prior =
65  std::nullopt,
66  const mrpt::optional_ref<LogRecord>& outputDebugInfo = std::nullopt);
67 
70  using solver_list_t = std::vector<mp2p_icp::Solver::Ptr>;
71 
91  void initialize_solvers(const mrpt::containers::yaml& params);
92 
93  static void initialize_solvers(
94  const mrpt::containers::yaml& params, ICP::solver_list_t& lst);
95 
96  const solver_list_t& solvers() const { return solvers_; }
98 
100  static bool run_solvers(
101  const solver_list_t& solvers, const Pairings& pairings,
102  OptimalTF_Result& out, const SolverContext& sc = {});
103 
125  void initialize_matchers(const mrpt::containers::yaml& params);
126 
127  static void initialize_matchers(
128  const mrpt::containers::yaml& params, matcher_list_t& lst);
129 
130  const matcher_list_t& matchers() const { return matchers_; }
132 
139  {
140  QualityEvaluatorEntry(mp2p_icp::QualityEvaluator::Ptr o, double w)
141  : obj(o), relativeWeight(w)
142  {
143  }
144 
145  mp2p_icp::QualityEvaluator::Ptr obj;
146  double relativeWeight = 1.0;
147  };
148  using quality_eval_list_t = std::vector<QualityEvaluatorEntry>;
149 
167  void initialize_quality_evaluators(const mrpt::containers::yaml& params);
168 
169  static void initialize_quality_evaluators(
170  const mrpt::containers::yaml& params, quality_eval_list_t& lst);
171 
173  {
174  return quality_evaluators_;
175  }
177 
178  static double evaluate_quality(
179  const quality_eval_list_t& evaluators, const metric_map_t& pcGlobal,
180  const metric_map_t& pcLocal, const mrpt::poses::CPose3D& localPose,
181  const Pairings& finalPairings);
182 
186  {
187  for (auto& o : matchers()) o->attachToParameterSource(source);
188  for (auto& o : solvers()) o->attachToParameterSource(source);
189  for (auto& o : quality_evaluators())
190  o.obj->attachToParameterSource(source);
191  }
192 
199  virtual void initialize_derived( //
200  [[maybe_unused]] const mrpt::containers::yaml& p)
201  {
202  // Default: do nothing
203  }
204 
206  {
207  IterationHook_Input() = default;
208 
209  const metric_map_t* pcGlobal = nullptr;
210  const metric_map_t* pcLocal = nullptr;
211  const Pairings* currentPairings = nullptr;
213  uint32_t currentIteration = 0;
214  };
216  {
217  IterationHook_Output() = default;
218 
219  bool request_stop = false;
220  };
221 
222  using iteration_hook_t =
224 
226  {
227  iteration_hook_ = ih;
228  }
229 
230  const mrpt::system::CTimeLogger& profiler() const { return profiler_; }
231  mrpt::system::CTimeLogger& profiler() { return profiler_; }
232 
233  protected:
237  {QualityEvaluator_PairedRatio::Create(), 1.0}};
238 
240 
241  mrpt::system::CTimeLogger profiler_{false /*disabled*/, "mp2p_icp::ICP"};
242 
243  static void save_log_file(const LogRecord& log, const Parameters& p);
244 
245  struct ICP_State
246  {
247  ICP_State(const metric_map_t& pcsGlobal, const metric_map_t& pcsLocal)
248  : pcGlobal(pcsGlobal), pcLocal(pcsLocal)
249  {
250  }
251 
256  uint32_t currentIteration = 0;
257  LogRecord* log = nullptr;
258  };
259 
260  private:
262 };
263 } // namespace mp2p_icp
mp2p_icp::ICP::ICP_State::log
LogRecord * log
Definition: ICP.h:257
mp2p_icp::ICP::quality_evaluators
const quality_eval_list_t & quality_evaluators() const
Definition: ICP.h:172
mp2p_icp::ICP::quality_eval_list_t
std::vector< QualityEvaluatorEntry > quality_eval_list_t
Definition: ICP.h:148
QualityEvaluator_PairedRatio.h
Matching quality evaluator: simple ratio [0,1] of paired entities.
mp2p_icp
Definition: covariance.h:17
mp2p_icp::ICP::IterationHook_Input::pcGlobal
const metric_map_t * pcGlobal
Definition: ICP.h:209
mp2p_icp::ICP::IterationHook_Input::pcLocal
const metric_map_t * pcLocal
Definition: ICP.h:210
mp2p_icp::ParameterSource
Definition: Parameterizable.h:42
mp2p_icp::ICP::profiler_
mrpt::system::CTimeLogger profiler_
Definition: ICP.h:241
mp2p_icp::ICP::evaluate_quality
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)
Definition: mp2p_icp/src/ICP.cpp:596
mp2p_icp::ICP::QualityEvaluatorEntry::relativeWeight
double relativeWeight
Definition: ICP.h:146
LogRecord.h
A record of the inputs and outputs of an ICP run.
mp2p_icp::ICP::IterationHook_Input::currentIteration
uint32_t currentIteration
Definition: ICP.h:213
mp2p_icp::ICP::IterationHook_Input::currentPairings
const Pairings * currentPairings
Definition: ICP.h:211
mp2p_icp::ICP::attachToParameterSource
void attachToParameterSource(ParameterSource &source)
Definition: ICP.h:185
mp2p_icp::Pairings
Definition: Pairings.h:78
mp2p_icp::ICP::IterationHook_Input::IterationHook_Input
IterationHook_Input()=default
mp2p_icp::ICP::ownParamSource_
ParameterSource ownParamSource_
Definition: ICP.h:261
mp2p_icp::ICP::quality_evaluators_
quality_eval_list_t quality_evaluators_
Definition: ICP.h:236
mp2p_icp::ICP::setIterationHook
void setIterationHook(const iteration_hook_t &ih)
Definition: ICP.h:225
mp2p_icp::LogRecord
Definition: LogRecord.h:30
mp2p_icp::SolverContext
Definition: Solver.h:36
mp2p_icp::ICP::ICP_State::ICP_State
ICP_State(const metric_map_t &pcsGlobal, const metric_map_t &pcsLocal)
Definition: ICP.h:247
mp2p_icp::ICP::ICP_State::currentSolution
OptimalTF_Result currentSolution
Definition: ICP.h:255
mp2p_icp::OptimalTF_Result
Definition: OptimalTF_Result.h:24
mp2p_icp::ICP::QualityEvaluatorEntry
Definition: ICP.h:138
mp2p_icp::ICP::solvers_
solver_list_t solvers_
Definition: ICP.h:234
mp2p_icp::ICP::iteration_hook_t
std::function< IterationHook_Output(const IterationHook_Input &)> iteration_hook_t
Definition: ICP.h:223
mp2p_icp::ICP::initialize_solvers
void initialize_solvers(const mrpt::containers::yaml &params)
Definition: mp2p_icp/src/ICP.cpp:494
mp2p_icp::ICP::profiler
const mrpt::system::CTimeLogger & profiler() const
Definition: ICP.h:230
mp2p_icp::ICP::matchers
matcher_list_t & matchers()
Definition: ICP.h:131
Parameters.h
mp2p_icp::ICP::solvers
solver_list_t & solvers()
Definition: ICP.h:97
mp2p_icp::ICP::ICP_State::pcGlobal
const metric_map_t & pcGlobal
Definition: ICP.h:252
mp2p_icp::ICP::solver_list_t
std::vector< mp2p_icp::Solver::Ptr > solver_list_t
Definition: ICP.h:70
Solver.h
Virtual base class for optimal alignment solvers (one step in ICP).
mp2p_icp::ICP::IterationHook_Input::currentSolution
const OptimalTF_Result * currentSolution
Definition: ICP.h:212
mp2p_icp::ICP
Definition: ICP.h:51
kitti-batch-convert.out
string out
Definition: kitti-batch-convert.py:7
IterTermReason.h
mp2p_icp::ICP::solvers
const solver_list_t & solvers() const
Definition: ICP.h:96
mp2p_icp::ICP::quality_evaluators
quality_eval_list_t & quality_evaluators()
Definition: ICP.h:176
mp2p_icp::ICP::initialize_matchers
void initialize_matchers(const mrpt::containers::yaml &params)
Definition: mp2p_icp/src/ICP.cpp:526
mp2p_icp::ICP::IterationHook_Output
Definition: ICP.h:215
mp2p_icp::ICP::ICP_State
Definition: ICP.h:245
mp2p_icp::ICP::matchers
const matcher_list_t & matchers() const
Definition: ICP.h:130
mp2p_icp::ICP::IterationHook_Output::IterationHook_Output
IterationHook_Output()=default
mp2p_icp::ICP::align
virtual void align(const metric_map_t &pcLocal, const metric_map_t &pcGlobal, const mrpt::math::TPose3D &initialGuessLocalWrtGlobal, const Parameters &p, Results &result, const std::optional< mrpt::poses::CPose3DPDFGaussianInf > &prior=std::nullopt, const mrpt::optional_ref< LogRecord > &outputDebugInfo=std::nullopt)
Definition: mp2p_icp/src/ICP.cpp:27
mp2p_icp::ICP::IterationHook_Output::request_stop
bool request_stop
Definition: ICP.h:219
Matcher.h
Pointcloud matching generic base class.
mp2p_icp::ICP::ICP_State::currentPairings
Pairings currentPairings
Definition: ICP.h:254
QualityEvaluator.h
Matching quality evaluator (virtual base class)
metricmap.h
Generic representation of pointcloud(s) and/or extracted features.
mp2p_icp::metric_map_t
Generic container of pointcloud(s), extracted features and other maps.
Definition: metricmap.h:49
mp2p_icp::ICP::iteration_hook_
iteration_hook_t iteration_hook_
Definition: ICP.h:239
mp2p_icp::ICP::QualityEvaluatorEntry::obj
mp2p_icp::QualityEvaluator::Ptr obj
Definition: ICP.h:145
mp2p_icp::Results
Definition: Results.h:21
mp2p_icp::ICP::initialize_derived
virtual void initialize_derived([[maybe_unused]] const mrpt::containers::yaml &p)
Definition: ICP.h:199
mp2p_icp::ICP::run_solvers
static bool run_solvers(const solver_list_t &solvers, const Pairings &pairings, OptimalTF_Result &out, const SolverContext &sc={})
Definition: mp2p_icp/src/ICP.cpp:482
mp2p_icp::Parameters
Definition: Parameters.h:26
mp2p_icp::ICP::ICP_State::pcLocal
const metric_map_t & pcLocal
Definition: ICP.h:253
Results.h
mp2p_icp::ICP::IterationHook_Input
Definition: ICP.h:205
mp2p_icp::ICP::initialize_quality_evaluators
void initialize_quality_evaluators(const mrpt::containers::yaml &params)
Definition: mp2p_icp/src/ICP.cpp:591
mp2p_icp::ICP::QualityEvaluatorEntry::QualityEvaluatorEntry
QualityEvaluatorEntry(mp2p_icp::QualityEvaluator::Ptr o, double w)
Definition: ICP.h:140
mp2p_icp::matcher_list_t
std::vector< mp2p_icp::Matcher::Ptr > matcher_list_t
Definition: Matcher.h:108
mp2p_icp::ICP::ICP_State::currentIteration
uint32_t currentIteration
Definition: ICP.h:256
mp2p_icp::ICP::profiler
mrpt::system::CTimeLogger & profiler()
Definition: ICP.h:231
mp2p_icp::ICP::save_log_file
static void save_log_file(const LogRecord &log, const Parameters &p)
Definition: mp2p_icp/src/ICP.cpp:391
mp2p_icp::ICP::matchers_
matcher_list_t matchers_
Definition: ICP.h:235


mp2p_icp
Author(s):
autogenerated on Wed Oct 23 2024 02:45:40