Skip to content

Commit

Permalink
small_gicp: new recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Apr 10, 2024
1 parent c47e5aa commit 4c5a363
Show file tree
Hide file tree
Showing 7 changed files with 273 additions and 0 deletions.
10 changes: 10 additions & 0 deletions recipes/small_gicp/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sources:
"cci.20240408":
url: "https://github.com/koide3/small_gicp/archive/ff8269ec09c9ddccff8358a4b7cc5e4c5fda134f.zip"
sha256: "ebcc1c6c82e0d8e1e58ce8bd2e0961fb066d606663e70796aff203ef7c739736"
patches:
"cci.20240408":
- patch_file: "patches/001-fix-invalid-install.patch"
patch_description: "Fix an invalid install command in CMakeLists.txt"
patch_type: "bugfix"
patch_source: "https://github.com/koide3/small_gicp/pull/23"
123 changes: 123 additions & 0 deletions recipes/small_gicp/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm, rmdir, download
from conan.tools.scm import Version
import os

required_conan_version = ">=1.53.0"


class IridescenceConan(ConanFile):
name = "small_gicp"
description = "Efficient and parallelized algorithms for point cloud registration"
license = "MIT AND BSD" # BSD is from nanoflann
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/koide3/small_gicp"
topics = ("point-cloud", "icp", "registration", "scan-matching", "pcl")

package_type = "library" # TODO: could add a header_only option as well
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_openmp": [True, False],
"with_tbb": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"with_openmp": False, # TODO: enable by default after https://github.com/conan-io/conan-center-index/pull/22353
"with_tbb": True,
}

@property
def _min_cppstd(self):
return 17

@property
def _compilers_minimum_version(self):
return {
"gcc": "7",
"clang": "7",
"apple-clang": "10",
"Visual Studio": "15",
"msvc": "191",
}

def export_sources(self):
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")

def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
self.requires("eigen/3.4.0", transitive_headers=True)
if self.options.with_openmp:
# '#pragma omp' is used in public headers
self.requires("llvm-openmp/17.0.6", transitive_headers=True, transitive_libs=True)
if self.options.with_tbb:
self.requires("onetbb/2021.10.0", transitive_headers=True, transitive_libs=True)
# The project vendors nanoflann, but it has been heavily extended and should be kept intact

def validate(self):
if self.settings.compiler.cppstd:
check_min_cppstd(self, self._min_cppstd)
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support."
)

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
download(self, "https://github.com/jlblancoc/nanoflann/blob/568ae53f5fcd82d5398bb1b32144fa22028518d5/COPYING", "LICENSE.nanoflann")
download(self, "https://github.com/strasdat/Sophus/blob/593db47500ea1a2de5f0e6579c86147991509c59/LICENSE.txt", "LICENSE.sophus")

def generate(self):
tc = CMakeToolchain(self)
tc.variables["BUILD_HELPER"] = True
tc.variables["BUILD_WITH_OPENMP"] = self.options.with_openmp
tc.variables["BUILD_WITH_TBB"] = self.options.with_tbb
tc.generate()

deps = CMakeDeps(self)
deps.generate()

def _patch_sources(self):
apply_conandata_patches(self)

def build(self):
self._patch_sources()
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses"))
copy(self, "LICENSE.nanoflann", self.source_folder, os.path.join(self.package_folder, "licenses"))
copy(self, "LICENSE.sophus", self.source_folder, os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rm(self, "*.pdb", os.path.join(self.package_folder, "lib"))
rm(self, "*.pdb", os.path.join(self.package_folder, "bin"))

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "small_gicp")
self.cpp_info.set_property("cmake_target_name", "small_gicp::small_gicp")

self.cpp_info.libs = ["small_gicp"]

if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("m")
24 changes: 24 additions & 0 deletions recipes/small_gicp/all/patches/001-fix-invalid-install.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
From 3370aeda76edb6fc395e5f72790fa2af2ca90db1 Mon Sep 17 00:00:00 2001
From: Martin Valgur <[email protected]>
Date: Wed, 10 Apr 2024 10:29:53 +0300
Subject: [PATCH] Fix an invalid `install(cmake/FindTBB.cmake)`

---
CMakeLists.txt | 4 ----
1 file changed, 4 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index a2fd69f..094bb1a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -274,10 +274,6 @@ if(BUILD_HELPER)
"${CMAKE_CURRENT_BINARY_DIR}/small_gicp-config-version.cmake"
DESTINATION ${CMAKE_CONFIG_INSTALL_DIR}
)
- install(FILES
- "${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindTBB.cmake"
- DESTINATION ${CMAKE_CONFIG_INSTALL_DIR}
- )
endif()

if(BUILD_PYTHON_BINDINGS)
8 changes: 8 additions & 0 deletions recipes/small_gicp/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES CXX)

find_package(small_gicp REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE small_gicp::small_gicp)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
34 changes: 34 additions & 0 deletions recipes/small_gicp/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake, CMakeToolchain
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def generate(self):
tc = CMakeToolchain(self)
if self.dependencies["small_gicp"].options.with_openmp:
tc.preprocessor_definitions["WITH_OPENMP"] = ""
if self.dependencies["small_gicp"].options.with_tbb:
tc.preprocessor_definitions["WITH_TBB"] = ""
tc.generate()

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
71 changes: 71 additions & 0 deletions recipes/small_gicp/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// https://github.com/koide3/small_gicp/blob/ff8269ec09c9ddccff8358a4b7cc5e4c5fda134f/src/example/03_registration_template.cpp
// SPDX-FileCopyrightText: Copyright 2024 Kenji Koide
// SPDX-License-Identifier: MIT

/// @brief Basic point cloud registration example with small_gicp::align()
#include <iostream>
#include <small_gicp/benchmark/read_points.hpp>
#include <small_gicp/registration/registration_helper.hpp>

#ifdef WITH_OPENMP
#include <small_gicp/ann/kdtree_omp.hpp>
#endif
#ifdef WITH_TBB
#include <small_gicp/ann/kdtree_tbb.hpp>
#endif

using namespace small_gicp;

/// @brief Most basic registration example.
void example1(const std::vector<Eigen::Vector4f>& target_points, const std::vector<Eigen::Vector4f>& source_points) {
RegistrationSetting setting;
setting.num_threads = 4; // Number of threads to be used
setting.downsampling_resolution = 0.25; // Downsampling resolution
setting.max_correspondence_distance = 1.0; // Maximum correspondence distance between points (e.g., trimming threshold)

Eigen::Isometry3d init_T_target_source = Eigen::Isometry3d::Identity();
RegistrationResult result = align(target_points, source_points, init_T_target_source, setting);

std::cout << "--- T_target_source ---" << std::endl << result.T_target_source.matrix() << std::endl;
std::cout << "converged:" << result.converged << std::endl;
std::cout << "error:" << result.error << std::endl;
std::cout << "iterations:" << result.iterations << std::endl;
std::cout << "num_inliers:" << result.num_inliers << std::endl;
std::cout << "--- H ---" << std::endl << result.H << std::endl;
std::cout << "--- b ---" << std::endl << result.b.transpose() << std::endl;
}

int main(int argc, char** argv) {
std::vector<Eigen::Vector4f> target_points = {
{1.0f, 2.0f, 3.0f, 1.0f},
{4.0f, 5.0f, 6.0f, 1.0f},
{7.0f, 8.0f, 9.0f, 1.0f},
{10.0f, 11.0f, 12.0f, 1.0f},
{13.0f, 14.0f, 15.0f, 1.0f},
{16.0f, 17.0f, 18.0f, 1.0f},
{19.0f, 20.0f, 21.0f, 1.0f},
{22.0f, 23.0f, 24.0f, 1.0f}
};
std::vector<Eigen::Vector4f> source_points = {
{1.1f, 2.1f, 3.2f, 1.0f},
{4.2f, 4.9f, 6.1f, 1.0f},
{6.9f, 8.2f, 9.1f, 1.0f},
{10.2f, 10.8f, 12.2f, 1.0f},
{13.1f, 14.0f, 15.2f, 1.0f},
{15.9f, 17.2f, 18.1f, 1.0f},
{19.2f, 20.1f, 21.2f, 1.0f},
{22.1f, 23.1f, 24.2f, 1.0f}
};

example1(target_points, source_points);

// test that these compile and link
#ifdef WITH_OPENMP
KdTreeOMP<PointCloud>::Ptr kdtree_omp;
#endif
#ifdef WITH_TBB
KdTreeTBB<PointCloud>::Ptr kdtree_tbb;
#endif

return 0;
}
3 changes: 3 additions & 0 deletions recipes/small_gicp/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"cci.20240408":
folder: all

0 comments on commit 4c5a363

Please sign in to comment.