From 40e36dd42402a593229d6d5beeb3d155f5b54e5c Mon Sep 17 00:00:00 2001 From: "k.koide" Date: Mon, 1 Apr 2024 14:36:47 +0900 Subject: [PATCH] setup.py --- CMakeLists.txt | 25 ++++++++++++++----------- README.md | 12 ++++++------ docker/Dockerfile.gcc | 8 +++++++- docker/Dockerfile.llvm | 8 +++++++- setup.py | 5 +---- src/example/basic_registration.py | 5 ++--- 6 files changed, 37 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bee4997..261fb05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,16 +79,18 @@ endif() find_package(Python COMPONENTS Interpreter Development) find_package(pybind11 CONFIG) -# Python binding -pybind11_add_module(small_gicp src/python/python.cpp) -target_include_directories(small_gicp PUBLIC - include - ${EIGEN3_INCLUDE_DIR} -) -target_link_libraries(small_gicp PRIVATE - small_gicp_helper - OpenMP::OpenMP_CXX -) +# Python bindings +if(BUILD_PYTHON_BINDINGS) + pybind11_add_module(small_gicp src/python/python.cpp) + target_include_directories(small_gicp PUBLIC + include + ${EIGEN3_INCLUDE_DIR} + ) + target_link_libraries(small_gicp PRIVATE + small_gicp_helper + OpenMP::OpenMP_CXX + ) +endif() ############### ## Benchmark ## @@ -108,7 +110,8 @@ if(BUILD_BENCHMARKS) add_compile_definitions(BUILD_WITH_IRIDESCENCE) endif() if (BUILD_WITH_FAST_GICP) - set(FAST_GICP_INCLUDE_DIR /home/koide/workspace/fast_gicp/include) + # set(FAST_GICP_INCLUDE_DIR /home/koide/workspace/fast_gicp/include) + set(FAST_GICP_INCLUDE_DIR $ENV{FAST_GICP_INCLUDE_DIR}) add_compile_definitions(BUILD_WITH_FAST_GICP) endif() diff --git a/README.md b/README.md index 90485d2..c8674e2 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # small_gicp (fast_gicp2) -**small_gicp** is a header-only C++ library that provides efficient and parallelized fine point cloud registration algorithms (ICP, Point-to-Plane ICP, GICP, VGICP, etc.). It is a refined and optimized version of its predecessor, [fast_gicp](https://github.com/SMRT-AIST/fast_gicp), with the following features. +**small_gicp** is a header-only C++ library that offers efficient and parallelized algorithms for fine point cloud registration (ICP, Point-to-Plane ICP, GICP, VGICP, etc.). It is a refined and optimized version of its predecessor, [fast_gicp](https://github.com/SMRT-AIST/fast_gicp), re-written from scratch with the following features. -- **Highly Optimized** : The implementation of the core registration algorithm is further optimized from that in fast_gicp. It offers up to 2x speed up compared to fast_gicp. -- **All parallerized** : small_gicp offers parallelized implementations of several algorithms in the point cloud registration process (Downsampling, KdTree construction, Normal/covariance estimation). As a parallelism backend, either (or both) of [OpenMP](https://www.openmp.org/) and [Intel TBB](https://github.com/oneapi-src/oneTBB) can be used. -- **Minimum dependency** : Only [Eigen](https://eigen.tuxfamily.org/) (and bundled [nanoflann](https://github.com/jlblancoc/nanoflann) and [Sophus](https://github.com/strasdat/Sophus)) are required at a minimum. Optionally, it provides the [PCL](https://pointclouds.org/) registration interface so that it can be used as a drop-in replacement in many systems. -- **Customizable** : small_gicp is implemented with the trait mechanism that allows feeding any custom point cloud class to the registration algorithm. Furthermore, the template-based implementation allows customizing the regisration process with your original correspondence estimator and registration factors. -- **Python bindinds** (coming soon) : The isolation from PCL makes the small_gicp's python bindinds more portable and connectable to other libraries seamlessly. +- **Highly Optimized** : The implementation of the core registration algorithm is further optimized from that in fast_gicp. It enables up to 2x speed gain compared to fast_gicp. +- **All parallerized** : small_gicp offers parallelized implementations of several preprocessing algorithms to make the entire registration process parallelized (Downsampling, KdTree construction, Normal/covariance estimation). As a parallelism backend, either (or both) of [OpenMP](https://www.openmp.org/) and [Intel TBB](https://github.com/oneapi-src/oneTBB) can be used. +- **Minimum dependency** : Only [Eigen](https://eigen.tuxfamily.org/) (and bundled [nanoflann](https://github.com/jlblancoc/nanoflann) and [Sophus](https://github.com/strasdat/Sophus)) are required at a minimum. Optionally, it provides the [PCL](https://pointclouds.org/) registration interface so that it can be used as a drop-in replacement for registration algorithms in PCL. +- **Customizable** : small_gicp is implemented with the trait mechanism that enables feeding any custom point cloud class to the registration algorithm. Furthermore, the template-based implementation allows customizing the regisration process with your original correspondence estimator and registration factors. +- **Python bindinds** : The isolation from PCL makes small_gicp's python bindinds more portable and connectable to other libraries seamlessly. Note that GPU-based implementations are NOT included in this package. diff --git a/docker/Dockerfile.gcc b/docker/Dockerfile.gcc index 2633288..2c38447 100644 --- a/docker/Dockerfile.gcc +++ b/docker/Dockerfile.gcc @@ -6,11 +6,13 @@ ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update && apt-get install --no-install-recommends -y \ && apt-get install --no-install-recommends -y \ - wget nano build-essential git cmake \ + wget nano build-essential git cmake python3-pip pybind11-dev \ libeigen3-dev libfmt-dev libtbb-dev libomp-dev libpcl-dev libgtest-dev \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* +RUN pip install -U setuptools pytest numpy scipy + COPY . /root/small_gicp WORKDIR /root/small_gicp/build RUN rm -rf ./* @@ -22,6 +24,10 @@ RUN cmake .. -DBUILD_TESTS=ON -DBUILD_EXAMPLES=ON -DBUILD_BENCHMARKS=ON -DBUILD_ RUN cmake --build . -j$(nproc) RUN ctest -j$(nproc) +WORKDIR /root/small_gicp +RUN python3 setup.py build && python3 setup.py install +RUN pytest src/example/basic_registration.py + WORKDIR / CMD ["bash"] \ No newline at end of file diff --git a/docker/Dockerfile.llvm b/docker/Dockerfile.llvm index 0951f81..694c604 100644 --- a/docker/Dockerfile.llvm +++ b/docker/Dockerfile.llvm @@ -4,7 +4,7 @@ ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update && apt-get install --no-install-recommends -y \ && apt-get install --no-install-recommends -y \ - wget nano build-essential git cmake \ + wget nano build-essential git cmake python3-pip pybind11-dev \ libeigen3-dev libfmt-dev libtbb-dev libomp-dev libpcl-dev libgtest-dev \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* @@ -15,6 +15,8 @@ RUN apt-get update && apt-get install --no-install-recommends -y \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* +RUN pip install -U setuptools pytest numpy scipy + RUN update-alternatives --install /usr/bin/ld ld /usr/bin/ld.lld 50 ENV CC=clang ENV CXX=clang++ @@ -30,6 +32,10 @@ RUN cmake .. -DBUILD_TESTS=ON -DBUILD_EXAMPLES=ON -DBUILD_BENCHMARKS=ON -DBUILD_ RUN cmake --build . -j$(nproc) RUN ctest -j$(nproc) +WORKDIR /root/small_gicp +RUN python3 setup.py build && python3 setup.py install +RUN pytest src/example/basic_registration.py + WORKDIR / CMD ["bash"] \ No newline at end of file diff --git a/setup.py b/setup.py index 634ef47..ef71558 100755 --- a/setup.py +++ b/setup.py @@ -45,8 +45,8 @@ def build_extension(self, ext: CMakeExtension) -> None: # EXAMPLE_VERSION_INFO shows you how to pass a value into the C++ code # from Python. cmake_args = [ + f"-DBUILD_PYTHON_BINDINGS=ON", f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}", - f"-DPYTHON_EXECUTABLE={sys.executable}", f"-DCMAKE_BUILD_TYPE={cfg}", # not used on MSVC, but no harm ] build_args = [] @@ -55,9 +55,6 @@ def build_extension(self, ext: CMakeExtension) -> None: if "CMAKE_ARGS" in os.environ: cmake_args += [item for item in os.environ["CMAKE_ARGS"].split(" ") if item] - # In this example, we pass in the version to C++. You might not need to. - cmake_args += [f"-DEXAMPLE_VERSION_INFO={self.distribution.get_version()}"] - if self.compiler.compiler_type != "msvc": # Using Ninja-build since it a) is available as a wheel and b) # multithreads automatically. MSVC would require all variables be diff --git a/src/example/basic_registration.py b/src/example/basic_registration.py index 152e299..32d2e99 100755 --- a/src/example/basic_registration.py +++ b/src/example/basic_registration.py @@ -3,7 +3,6 @@ from scipy.spatial.transform import Rotation import small_gicp -from pyridescence import * # Basic registation example with numpy arrays @@ -97,8 +96,8 @@ def verify_result(T_target_source, gt_T_target_source): error_trans = numpy.linalg.norm(error[:3, 3]) error_rot = Rotation.from_matrix(error[:3, :3]).magnitude() - assert error_trans < 0.01 - assert error_rot < 0.01 + assert error_trans < 0.05 + assert error_rot < 0.05 import pytest