Skip to content

Commit 11f5a30

Browse files
authored
Examples (#62)
* update README * fix exclude path for doxygen
1 parent 7b95ffb commit 11f5a30

File tree

4 files changed

+64
-9
lines changed

4 files changed

+64
-9
lines changed

README.md

+27-2
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ sudo make install
4646
#### Install from [PyPI](https://pypi.org/project/small-gicp/)
4747

4848
```bash
49-
pip install small_gicp --user
49+
pip install small_gicp
5050
```
5151

5252
#### Install from source
5353

5454
```bash
5555
cd small_gicp
56-
pip install . --user
56+
pip install .
5757

5858
# [Optional (linux)] Install stubs for autocomplete (If you know a better way, let me know...)
5959
pip install pybind11-stubgen
@@ -404,6 +404,31 @@ open3d.visualization.draw_geometries([target_o3d, source_o3d])
404404

405405
- [Scan-to-scan and scan-to-model GICP matching odometry on KITTI](src/example/kitti_odometry.py)
406406

407+
## Running examples
408+
409+
### C++
410+
411+
```bash
412+
cd small_gicp
413+
mkdir build && cd build
414+
cmake .. -DBUILD_EXAMPLES=ON && make -j
415+
416+
cd ..
417+
./build/01_basic_registration
418+
./build/02_basic_registration_pcl
419+
./build/03_registration_template
420+
```
421+
422+
423+
### Python
424+
425+
```bash
426+
cd small_gicp
427+
pip install .
428+
429+
python3 src/example/basic_registration.py
430+
```
431+
407432
## [Benchmark](BENCHMARK.md)
408433

409434
Processing speed comparison between small_gicp and Open3D ([youtube]((https://youtu.be/LNESzGXPr4c?feature=shared))).

docs/Doxyfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ RECURSIVE = YES
917917
# Note that relative paths are relative to the directory from which doxygen is
918918
# run.
919919

920-
EXCLUDE = include/small_gicp/benchmark
920+
EXCLUDE = ../include/small_gicp/benchmark/
921921

922922
# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
923923
# directories that are symbolic links (a Unix file system feature) are excluded

include/small_gicp/ann/traits.hpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ struct Traits;
1616
/// @param tree Nearest neighbor search (e.g., KdTree)
1717
/// @param point Query point
1818
/// @param k Number of neighbors
19-
/// @param k_index [out] Index of the nearest neighbor
20-
/// @param k_sq_dist [out] Squared distance to the nearest neighbor
19+
/// @param k_indices [out] Indices of k-nearest neighbors
20+
/// @param k_sq_dists [out] Squared distances to k-nearest neighbors
2121
/// @return Number of found neighbors
2222
template <typename T>
2323
size_t knn_search(const T& tree, const Eigen::Vector4d& point, size_t k, size_t* k_indices, double* k_sq_dists) {
2424
return Traits<T>::knn_search(tree, point, k, k_indices, k_sq_dists);
2525
}
2626

27+
/// @brief Check if T has nearest_neighbor_search method.
2728
template <typename T>
2829
struct has_nearest_neighbor_search {
2930
template <typename U, int = (&Traits<U>::nearest_neighbor_search, 0)>
@@ -33,7 +34,7 @@ struct has_nearest_neighbor_search {
3334
static constexpr bool value = decltype(test((T*)nullptr))::value;
3435
};
3536

36-
/// @brief Find the nearest neighbor.
37+
/// @brief Find the nearest neighbor. If Traits<T>::nearest_neighbor_search is not defined, fallback to knn_search with k=1.
3738
/// @param tree Nearest neighbor search (e.g., KdTree)
3839
/// @param point Query point
3940
/// @param k_index [out] Index of the nearest neighbor

src/example/basic_registration.py

+32-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
# Basic registation example with numpy arrays
1111
def example_numpy1(target_raw_numpy : numpy.ndarray, source_raw_numpy : numpy.ndarray):
12+
print('*** example_numpy1 ***')
13+
1214
# Example A : Perform registration with numpy arrays
1315
# Arguments
1416
# - target_points : Nx4 or Nx3 numpy array of the target point cloud
@@ -22,10 +24,15 @@ def example_numpy1(target_raw_numpy : numpy.ndarray, source_raw_numpy : numpy.nd
2224
# - num_threads : Number of threads
2325
result = small_gicp.align(target_raw_numpy, source_raw_numpy, downsampling_resolution=0.25)
2426

27+
print('--- registration result ---')
28+
print(result)
29+
2530
return result.T_target_source
2631

2732
# Example to perform preprocessing and registration separately
2833
def example_numpy2(target_raw_numpy : numpy.ndarray, source_raw_numpy : numpy.ndarray):
34+
print('*** example_numpy2 ***')
35+
2936
# Example B : Perform preprocessing and registration separately
3037

3138
# Preprocess point clouds
@@ -38,6 +45,9 @@ def example_numpy2(target_raw_numpy : numpy.ndarray, source_raw_numpy : numpy.nd
3845
target, target_tree = small_gicp.preprocess_points(target_raw_numpy, downsampling_resolution=0.25)
3946
source, source_tree = small_gicp.preprocess_points(source_raw_numpy, downsampling_resolution=0.25)
4047

48+
print('preprocessed target=', target)
49+
print('preprocessed source=', source)
50+
4151
# Align point clouds
4252
# Arguments
4353
# - target : Target point cloud (small_gicp.PointCloud)
@@ -48,26 +58,39 @@ def example_numpy2(target_raw_numpy : numpy.ndarray, source_raw_numpy : numpy.nd
4858
# - max_correspondence_distance : Maximum correspondence distance
4959
# - num_threads : Number of threads
5060
result = small_gicp.align(target, source, target_tree)
51-
61+
62+
print('--- registration result ---')
63+
print(result)
64+
5265
return result.T_target_source
5366

5467

5568
# Basic registation example with small_gicp.PointCloud
5669
def example_small1(target_raw_numpy : numpy.ndarray, source_raw_numpy : numpy.ndarray):
70+
print('*** example_small1 ***')
71+
5772
# Convert numpy arrays (Nx3 or Nx4) to small_gicp.PointCloud
5873
target_raw = small_gicp.PointCloud(target_raw_numpy)
5974
source_raw = small_gicp.PointCloud(source_raw_numpy)
6075

6176
# Preprocess point clouds
6277
target, target_tree = small_gicp.preprocess_points(target_raw, downsampling_resolution=0.25)
6378
source, source_tree = small_gicp.preprocess_points(source_raw, downsampling_resolution=0.25)
64-
79+
80+
print('preprocessed target=', target)
81+
print('preprocessed source=', source)
82+
6583
result = small_gicp.align(target, source, target_tree)
84+
85+
print('--- registration result ---')
86+
print(result)
6687

6788
return result.T_target_source
6889

6990
# Example to perform each preprocessing and registration separately
7091
def example_small2(target_raw_numpy : numpy.ndarray, source_raw_numpy : numpy.ndarray):
92+
print('*** example_small2 ***')
93+
7194
# Convert numpy arrays (Nx3 or Nx4) to small_gicp.PointCloud
7295
target_raw = small_gicp.PointCloud(target_raw_numpy)
7396
source_raw = small_gicp.PointCloud(source_raw_numpy)
@@ -79,13 +102,19 @@ def example_small2(target_raw_numpy : numpy.ndarray, source_raw_numpy : numpy.nd
79102
# KdTree construction
80103
target_tree = small_gicp.KdTree(target)
81104
source_tree = small_gicp.KdTree(source)
82-
105+
83106
# Estimate covariances
84107
small_gicp.estimate_covariances(target, target_tree)
85108
small_gicp.estimate_covariances(source, source_tree)
86109

110+
print('preprocessed target=', target)
111+
print('preprocessed source=', source)
112+
87113
# Align point clouds
88114
result = small_gicp.align(target, source, target_tree)
115+
116+
print('--- registration result ---')
117+
print(result)
89118

90119
return result.T_target_source
91120

0 commit comments

Comments
 (0)