|
1 | | -<!-- |
2 | | -Copyright (C) 2025 Ethan Uppal. |
3 | | -SPDX-License-Identifier: MIT |
4 | | ----> |
5 | | -\page write_icp_instance Writing an ICP Instance |
| 1 | +# Contributing: Adding a New ICP Instance |
6 | 2 |
|
7 | | -\tableofcontents |
| 3 | +This section explains how to implement and document a new **ICP instance**. |
8 | 4 |
|
9 | | -To write an ICP instance, create a C++ source file with at least the following: |
| 5 | +--- |
10 | 6 |
|
11 | | -1. A `final` class that inherits from `public icp::ICP` |
12 | | -2. A static initialization variable (described below) |
| 7 | +## 1. Overview |
13 | 8 |
|
14 | | -It is highly recommended you also provide documentation for your ICP instance in the format described here. |
| 9 | +An ICP instance is a specific implementation of the Iterative Closest Point algorithm. Each instance should be: |
15 | 10 |
|
16 | | -\section core_func_sec Core Functionality |
| 11 | +- A `final` C++ class that inherits from `icp::ICP` |
| 12 | +- Properly registered so users can instantiate it |
17 | 13 |
|
18 | | -The class must define the following behavior: |
| 14 | +--- |
19 | 15 |
|
20 | | -- A constructor that calls the `icp::ICP` constructor |
21 | | -- An overridden destructor (which may do nothing) |
22 | | -- `void iterate() override` |
| 16 | +## 2. File and Class Requirements |
23 | 17 |
|
24 | | -In `iterate`, the point clouds are given by the instance variables `a` and `b`. |
25 | | -There is also the `match` instance variable, allocated to have size `a.size()`, which cannot be assumed to contain any definite values. |
26 | | -At the end of `iterate`, the `transform` instance variable should have been updated (although the update may be zero). |
| 18 | +Create a new `method_xd.cpp` file in `lib/icp/impl/`, and implement your instance class. |
27 | 19 |
|
28 | | -Optionally, the class can override: |
| 20 | +### Required |
29 | 21 |
|
30 | | -- `void setup() override` |
| 22 | +- Class must be `final` and inherit from `public icp::ICP` |
| 23 | +- Must implement `void iterate() override` |
| 24 | +- Must provide a constructor that calls the `icp::ICP` constructor |
| 25 | +- A destructor (can be empty) |
31 | 26 |
|
32 | | -`setup` is invoked upon the user call to `ICP::begin` after the internals of ICP have been readied. |
| 27 | +Example: |
33 | 28 |
|
34 | | -\section static_init_sec Static Initialization |
| 29 | +```cpp |
| 30 | +class MyICP final : public icp::ICP { |
| 31 | +public: |
| 32 | + MyICP(); |
| 33 | + MyICP(const Config& config); |
| 34 | + ~MyICP(); |
35 | 35 |
|
36 | | -TODO: update -- we do this in icp.cpp now and the documentation builder will |
37 | | -automatically search there. |
| 36 | + void setup() override; // Optional |
| 37 | + void iterate() override; |
| 38 | +}; |
| 39 | +```` |
38 | 40 |
|
39 | | -The static initialization is required so that users can instantiate your ICP instance. |
40 | | -Define |
| 41 | +--- |
41 | 42 |
|
42 | | -```cpp |
43 | | -static bool static_initialization = []() { |
44 | | - assert(ICP::register_method("name_of_instance", []() -> std::unique_ptr<ICP> { |
45 | | - return std::make_unique<NameOfClass>(); |
46 | | - })); |
47 | | - return true; |
48 | | -}(); |
49 | | -``` |
| 43 | +## 3. ICP Lifecycle |
50 | 44 |
|
51 | | -where `"name_of_instance"` is the name of your ICP implementation and `NameOfClass` is the name of the class. |
| 45 | +### Provided Instance Variables |
52 | 46 |
|
53 | | -\section icp_dpc_sec Documentation |
| 47 | +| Variable | Type | Description | |
| 48 | +| ----------- | ------------------ | ---------------------------------- | |
| 49 | +| `a` | `PointCloud` | Source point cloud | |
| 50 | +| `b` | `PointCloud` | Target point cloud | |
| 51 | +| `match` | `std::vector<int>` | Matches from `a` to `b` | |
| 52 | +| `transform` | `RBTransform` | Current accumulated transformation | |
54 | 53 |
|
55 | | -The script icp_doc_builder.py will automatically generate documentation for your ICP instances as markdown files and place them in a desired directory. The invocation format is: |
| 54 | +### Method Responsibilities |
56 | 55 |
|
57 | | -```shell |
58 | | -python3 icp_doc_builder.py dir/where/your/icps/are/ dir/where/markdown/should/go/ where/main/file/is.md |
59 | | -``` |
| 56 | +| Method | When it is Called | What to Do | |
| 57 | +| ----------- | --------------------------- | ---------------------------------------------- | |
| 58 | +| `setup()` | Once before first iteration | Initialize resources (e.g. KD-tree) | |
| 59 | +| `iterate()` | Once per iteration | Compute correspondences and update `transform` | |
60 | 60 |
|
61 | | -Notably, `where/main/file/is.md` should contain two lines of the form |
| 61 | +--- |
62 | 62 |
|
63 | | -```md |
64 | | -<!-- ICP_DOCS_BUILDER EDIT MARKER START --> |
65 | | -... |
66 | | -<!-- ICP_DOCS_BUILDER EDIT MARKER END --> |
67 | | -``` |
| 63 | +## 4. Registration |
68 | 64 |
|
69 | | -the contents between which markers will be automatically updated by the |
70 | | -documentation builder. |
71 | | - |
72 | | -If the file name is `foo_bar.cpp`, then the Doxygen page reference (from which you can refer to from other pages) will be be `foo_bar_icp Foo_bar`. Information about the file should be encoded in special block comments of the following format. |
| 65 | +To allow users to select your ICP instance by name, add it to the static methods map in `ICP2` or `ICP3` in `icp.cpp` |
73 | 66 |
|
74 | 67 | ```cpp |
75 | | -/* |
76 | | -#command values... |
77 | | -*/ |
| 68 | +#include "icp/impl/my_icp.h" |
| 69 | +
|
| 70 | +namespace icp { |
| 71 | + template<> |
| 72 | + std::unordered_map<std::string, ICPX::MethodConstructor> ICPX::methods{ |
| 73 | + {"my_icp", CONSTRUCT_CONFIG(MyICP)}, // ← Register your method here |
| 74 | + }; |
| 75 | +} |
78 | 76 | ``` |
79 | 77 |
|
80 | | -Supported commands are described below. |
81 | | - |
82 | | -- The name of the instance should be given by `/* #name Name of Instance */`. |
83 | | -- An overview of the algorithm should be provided by `/* #desc Overview of algorithm. */`. This description will be rendered as Doxygen source, so you can use markdown and Doxygen commands such as `\ref`. |
84 | | -- If your instance uses icp::ICP::Config parameters, document them as `/* #conf "name_of_param" This is a sentence. This is another sentence describing the parameter. */`. This description will be rendered as Doxygen source. |
85 | | -- Every major step your instance takes should be documented by |
86 | | - |
87 | | - ```cpp |
88 | | - /* |
89 | | - #step My Step: brief description |
90 | | -
|
91 | | - Detailed explanation. |
| 78 | +--- |
92 | 79 |
|
93 | | - Sources: |
94 | | - https://www.example.com |
95 | | - https://www.example.com |
96 | | - https://www.example.com |
97 | | - https://www.example.com |
98 | | - */ |
99 | | - ``` |
| 80 | +## 5. Examples |
100 | 81 |
|
101 | | - The `: brief description` section is optional, as are the detailed explanation and sources sections. |
102 | | - These descriptions will be rendered as Doxygen source. |
| 82 | +See the following reference implementations: |
103 | 83 |
|
104 | | -See the source code of vanilla.cpp or trimmed.cpp as examples. |
| 84 | +| File | Type | |
| 85 | +| -------------------------------------------------------- | ---------| |
| 86 | +| [`vanilla.cpp`](/lib/icp/impl/vanilla.cpp) | 2d | |
| 87 | +| [`trimmed.cpp`](/lib/icp/impl/trimmed.cpp) | 2d | |
| 88 | +| [`feature_aware.cpp`](/lib/icp/impl/feature_aware.cpp) | 2d | |
| 89 | +| [`vanilla_3d.cpp`](/lib/icp/impl/vanilla_3d.cpp) | 3d | |
| 90 | +| [`trimmed_3d.cpp`](/lib/icp/impl/trimmed_3d.cpp) | 3d. | |
0 commit comments