38 sum_squares += match.cost;
40 return std::sqrt(sum_squares /
a.size());
47 ICP::Methods ICP::global;
48 bool ICP::builtins_registered =
false;
51 std::function<std::unique_ptr<ICP>(
const ICP::Config&)> constructor) {
52 ensure_builtins_registered();
58 register_method_internal(name, constructor);
63 ensure_builtins_registered();
65 return std::find(global.registered_method_names.begin(),
66 global.registered_method_names.end(), name)
67 != global.registered_method_names.end();
71 ensure_builtins_registered();
73 return global.registered_method_names;
78 ensure_builtins_registered();
80 auto name_it = std::find(global.registered_method_names.begin(),
81 global.registered_method_names.end(), name);
83 if (name_it == global.registered_method_names.end()) {
87 size_t index = name_it - global.registered_method_names.begin();
89 return global.registered_method_constructors[index](config);
92 void ICP::ensure_builtins_registered() {
93 if (builtins_registered) {
97 register_method_internal(
"vanilla",
98 [](
const ICP::Config& config) {
return std::make_unique<Vanilla>(config); });
99 register_method_internal(
"trimmed",
100 [](
const ICP::Config& config) {
return std::make_unique<Trimmed>(config); });
101 register_method_internal(
"feature_aware",
102 [](
const ICP::Config& config) {
return std::make_unique<FeatureAware>(config); });
104 builtins_registered =
true;
107 void ICP::register_method_internal(std::string name,
108 std::function<std::unique_ptr<ICP>(
const Config&)> constructor) {
109 global.registered_method_constructors.push_back(constructor);
110 global.registered_method_names.push_back(name);
Configuration for ICP instances.
static bool register_method(std::string name, std::function< std::unique_ptr< ICP >(const Config &)> constructor)
Registers a new ICP method that can be created with constructor, returning false if name has already ...
static std::optional< std::unique_ptr< ICP > > from_method(std::string name, const Config ¶ms=Config())
Factory constructor for the ICP method name with configuration config.
virtual void setup()=0
Per-method setup code.
RBTransform transform
The current point cloud transformation that is being optimized.
static bool is_method_registered(std::string name)
Returns true if the ICP method name is registered.
std::vector< Vector > a
The source point cloud.
static const std::vector< std::string > & registered_methods()
Returns a current list of the names of currently registered ICP methods.
std::vector< Vector > b
The destination point cloud.
std::vector< Match > matches
The pairing of each point in a to its closest in b.
void begin(const std::vector< Vector > &a, const std::vector< Vector > &b, RBTransform t)
Begins the ICP process for point clouds a and b with an initial guess for the transform t.
const RBTransform & current_transform() const
The current transform.
double calculate_cost() const
Computes the cost of the current transformation.