diff --git a/CMakeLists.txt b/CMakeLists.txt index e153dfc..3e6a88b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,14 +24,14 @@ find_package(Eigen3 3.3 REQUIRED NO_MODULE) FetchContent_Declare(nanoflann GIT_REPOSITORY https://github.com/jlblancoc/nanoflann - GIT_TAG v1.4.2 + GIT_TAG v1.7.1 ) FetchContent_MakeAvailable(nanoflann) if(SC_BUILD_PYTHON_BINDING) FetchContent_Declare(pybind11 GIT_REPOSITORY https://github.com/pybind/pybind11 - GIT_TAG v2.9.2 + GIT_TAG v2.13.6 ) FetchContent_MakeAvailable(pybind11) endif() diff --git a/examples/test_compare_scd.py b/examples/test_compare_scd.py index 1275445..c5bd852 100644 --- a/examples/test_compare_scd.py +++ b/examples/test_compare_scd.py @@ -22,11 +22,10 @@ def read_bin(bin_path): def bin2scd(filepath, voxel_size=0.5): xyz = read_bin(filepath) - print( f" The poitn cloud {filepath} is loaded." ) pcd = o3d.geometry.PointCloud() pcd.points = o3d.utility.Vector3dVector(xyz) pcd_down = pcd.voxel_down_sample(voxel_size=voxel_size) - xyz_down = np.asarray(pcd_down.points) + xyz_down = np.asarray(pcd_down.points, dtype=np.float64, order='C') scd = scm.make_scancontext(xyz_down) return scd diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 9bc51fa..e5d1140 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -1,9 +1,18 @@ set(PYPKG_DIR "${CMAKE_CURRENT_BINARY_DIR}/pyscancontext") pybind11_add_module(pyscancontext wrapper.cpp) -target_link_libraries(pyscancontext PUBLIC Scancontext::scancontext) +target_link_libraries(pyscancontext PRIVATE Scancontext::scancontext) + +set_target_properties(pyscancontext PROPERTIES + BUILD_RPATH "${CMAKE_BINARY_DIR}/scancontext" + INSTALL_RPATH "$ORIGIN/../../scancontext" +) + + set_target_properties(pyscancontext PROPERTIES OUTPUT_NAME "pyscancontext") set_target_properties(pyscancontext PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${PYPKG_DIR}") +target_link_libraries(pyscancontext PUBLIC Eigen3::Eigen) +target_include_directories(pyscancontext PRIVATE ${EIGEN3_INCLUDE_DIR}) # https://github.com/pybind/pybind11/issues/1818 if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") diff --git a/scancontext/CMakeLists.txt b/scancontext/CMakeLists.txt index 9a933b2..6f2bb3e 100644 --- a/scancontext/CMakeLists.txt +++ b/scancontext/CMakeLists.txt @@ -2,16 +2,20 @@ add_library(scancontext SHARED include/scancontext/Scancontext.cpp ) +set_target_properties(scancontext PROPERTIES + VERSION ${PROJECT_VERSION}) + +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + target_include_directories(scancontext PUBLIC $ $ $ ) -set_target_properties(scancontext PROPERTIES VERSION ${PROJECT_VERSION}) target_compile_definitions(scancontext PUBLIC PROJECT_VERSION="${PROJECT_VERSION}") -target_link_libraries(scancontext +target_link_libraries(scancontext PUBLIC Eigen3::Eigen nanoflann::nanoflann ) diff --git a/scancontext/include/scancontext/KDTreeVectorOfVectorsAdaptor.h b/scancontext/include/scancontext/KDTreeVectorOfVectorsAdaptor.h index 0a56d6e..77481dc 100644 --- a/scancontext/include/scancontext/KDTreeVectorOfVectorsAdaptor.h +++ b/scancontext/include/scancontext/KDTreeVectorOfVectorsAdaptor.h @@ -81,7 +81,7 @@ struct KDTreeVectorOfVectorsAdaptor { nanoflann::KNNResultSet resultSet(num_closest); resultSet.init(out_indices, out_distances_sq); - index->findNeighbors(resultSet, query_point, nanoflann::SearchParams()); + index->findNeighbors(resultSet, query_point, nanoflann::SearchParameters()); } /** @name Interface expected by KDTreeSingleIndexAdaptor diff --git a/scancontext/include/scancontext/Scancontext.cpp b/scancontext/include/scancontext/Scancontext.cpp index 0e874e1..14e1443 100644 --- a/scancontext/include/scancontext/Scancontext.cpp +++ b/scancontext/include/scancontext/Scancontext.cpp @@ -134,8 +134,8 @@ std::pair SCManager::distanceBtnScanContext( MatrixXd &_sc1, Matrix // MatrixXd SCManager::makeScancontext( pcl::PointCloud & _scan_down ) -MatrixXd SCManager::makeScancontext( Eigen::MatrixX3d & _scan_down ) -{ +MatrixXd SCManager::makeScancontext( const Eigen::MatrixX3d & _scan_down ) +{ const int NO_POINT = -1000; MatrixXd desc = NO_POINT * MatrixXd::Ones(PC_NUM_RING, PC_NUM_SECTOR); @@ -264,7 +264,7 @@ std::tuple SCManager::detectLoopClosureID ( void ) nanoflann::KNNResultSet knnsearch_result( NUM_CANDIDATES_FROM_TREE ); knnsearch_result.init( &candidate_indexes[0], &out_dists_sqr[0] ); - polarcontext_tree_->index->findNeighbors( knnsearch_result, &curr_key[0] /* query */, nanoflann::SearchParams(10) ); + polarcontext_tree_->index->findNeighbors( knnsearch_result, &curr_key[0] /* query */, nanoflann::SearchParameters(10) ); // step 2: pairwise distance (find optimal columnwise best-fit using cosine distance) for ( int candidate_iter_idx = 0; candidate_iter_idx < NUM_CANDIDATES_FROM_TREE; candidate_iter_idx++ ) diff --git a/scancontext/include/scancontext/Scancontext.h b/scancontext/include/scancontext/Scancontext.h index f33800a..aeff659 100644 --- a/scancontext/include/scancontext/Scancontext.h +++ b/scancontext/include/scancontext/Scancontext.h @@ -15,6 +15,14 @@ #include "KDTreeVectorOfVectorsAdaptor.h" +#pragma once + +#if defined _WIN32 || defined __CYGWIN__ + #define SC_EXPORT __declspec(dllexport) +#else + #define SC_EXPORT __attribute__ ((visibility ("default"))) +#endif + using namespace Eigen; using namespace nanoflann; @@ -39,12 +47,12 @@ float xy2theta( const float & _x, const float & _y ); MatrixXd circshift( MatrixXd &_mat, int _num_shift ); std::vector eig2stdvec( MatrixXd _eigmat ); -class SCManager +class SC_EXPORT SCManager { public: SCManager( ) = default; // reserving data space (of std::vector) could be considered. but the descriptor is lightweight so don't care. - Eigen::MatrixXd makeScancontext( Eigen::MatrixX3d & _scan_down ); + Eigen::MatrixXd makeScancontext( const Eigen::MatrixX3d & _scan_down ); Eigen::MatrixXd makeRingkeyFromScancontext( Eigen::MatrixXd &_desc ); Eigen::MatrixXd makeSectorkeyFromScancontext( Eigen::MatrixXd &_desc );