Skip to content

Fix Python wrapper linking & update nanoflann/pybind11 versions #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions examples/test_compare_scd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 10 additions & 1 deletion python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
8 changes: 6 additions & 2 deletions scancontext/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ struct KDTreeVectorOfVectorsAdaptor
{
nanoflann::KNNResultSet<num_t,IndexType> 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
Expand Down
6 changes: 3 additions & 3 deletions scancontext/include/scancontext/Scancontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ std::pair<double, int> SCManager::distanceBtnScanContext( MatrixXd &_sc1, Matrix


// MatrixXd SCManager::makeScancontext( pcl::PointCloud<SCPointType> & _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);

Expand Down Expand Up @@ -264,7 +264,7 @@ std::tuple<int, double, double> SCManager::detectLoopClosureID ( void )

nanoflann::KNNResultSet<float> 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++ )
Expand Down
12 changes: 10 additions & 2 deletions scancontext/include/scancontext/Scancontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -39,12 +47,12 @@ float xy2theta( const float & _x, const float & _y );
MatrixXd circshift( MatrixXd &_mat, int _num_shift );
std::vector<float> 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 );

Expand Down