Skip to content
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

Feature/system pybind #18

Merged
merged 11 commits into from
Sep 3, 2024
11 changes: 7 additions & 4 deletions .cmake-format.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
parse:
additional_commands:
catkin_package:
Expand All @@ -9,20 +10,22 @@ parse:
LIBRARIES: '*'
catkin_add_gtest:
pargs: 1
pybind11_add_module:
pargs: 1
format:
line_width: 88
tab_size: 2
use_tabchars: false
max_subgroups_hwrap: 5
#max_pargs_hwrap: 6
max_subgroups_hwrap: 3
max_pargs_hwrap: 3
max_rows_cmdline: 2
dangle_parens: true
dangle_align: prefix
min_prefix_chars: 4
max_prefix_chars: 10
max_lines_hwrap: 2
max_lines_hwrap: 1
command_case: canonical
keyword_case: unchanged
always_wrap: [add_library]
always_wrap: [add_library, pybind11_add_module]
enable_sort: true
autosort: false
7 changes: 5 additions & 2 deletions .github/workflows/catkin.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
---
name: "ROS Noetic: Build and Test"
name: 'ROS Noetic: Build and Test'
on: [push]
jobs:
build:
runs-on: ubuntu-latest
container: ros:noetic-ros-base-focal
steps:
- name: Install Git
run: apt update && apt install -y git
# checkout the code
- uses: actions/checkout@v4
with:
path: src/spark_dsg
submodules: true
# install necessary dependences
- name: Dependencies
run: |
apt update && apt install -y python3-wstool python3-catkin-tools python3-vcstool git
apt update && apt install -y python3-wstool python3-catkin-tools python3-vcstool
rosdep update --rosdistro noetic && rosdep install --rosdistro noetic --from-paths src --ignore-src -r -y
# configure repo
- name: Configure
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "third_party/pybind11"]
path = third_party/pybind11
url = https://github.com/pybind/pybind11.git
66 changes: 43 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ option(SPARK_DSG_BUILD_ZMQ "Build zmq message interface" ON)
option(SPARK_DSG_PROFILE_BUILD "Profile build time" OFF)
option(BUILD_SHARED_LIBS "Build shared libs" ON)

configure_file(cmake/spark_dsg_version.h.in include/spark_dsg_version.h)

find_package(nlohmann_json REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(Threads REQUIRED)
Expand All @@ -27,6 +25,13 @@ if(SPARK_DSG_PROFILE_BUILD)
add_compile_options(-ftime-trace)
endif()

if(SPARK_DSG_BUILD_ZMQ AND zmq_FOUND)
set(SPARK_DSG_USE_ZMQ 1)
else()
set(SPARK_DSG_USE_ZMQ 0)
endif()
configure_file(cmake/spark_dsg_version.h.in include/spark_dsg_version.h)

add_library(
${PROJECT_NAME}
src/adjacency_matrix.cpp
Expand All @@ -50,6 +55,7 @@ add_library(
src/scene_graph_node.cpp
src/scene_graph_types.cpp
src/scene_graph_utilities.cpp
src/zmq_interface.cpp
src/serialization/attribute_serialization.cpp
src/serialization/binary_conversions.cpp
src/serialization/binary_serialization.cpp
Expand All @@ -66,8 +72,9 @@ if(NOT BUILD_SHARED_LIBS)
endif()

target_include_directories(
${PROJECT_NAME} PUBLIC $<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
${PROJECT_NAME}
PUBLIC $<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
)
target_link_libraries(
Expand All @@ -78,17 +85,22 @@ target_link_libraries(
if(SPARK_DSG_BUILD_ZMQ AND zmq_FOUND)
target_link_libraries(${PROJECT_NAME} PRIVATE ${zmq_LIBRARIES})
target_include_directories(${PROJECT_NAME} PRIVATE ${zmq_INCLUDE_DIRS})
target_sources(
${PROJECT_NAME}
PRIVATE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/zmq_interface.cpp>"
)
endif()

if(SPARK_DSG_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
if(SPARK_DSG_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

if(SPARK_DSG_BUILD_PYTHON OR SPARK_DSG_BUILD_TESTS)
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/pybind11/.git)
find_package(Git REQUIRED)
execute_process(
COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
endif()

add_subdirectory(third_party/pybind11 EXCLUDE_FROM_ALL)
add_subdirectory(python)
endif()

Expand All @@ -104,15 +116,6 @@ add_library(
spark_dsg::${PROJECT_NAME} ALIAS ${PROJECT_NAME}
)

install(TARGETS ${PROJECT_NAME} EXPORT spark_dsg-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(EXPORT spark_dsg-targets FILE spark_dsgTargets.cmake NAMESPACE spark_dsg::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/spark_dsg
)

write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/spark_dsgConfigVersion.cmake VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
Expand All @@ -124,7 +127,24 @@ configure_package_config_file(
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/spark_dsg
)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/spark_dsgConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/spark_dsgConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/spark_dsg
install(
TARGETS ${PROJECT_NAME}
EXPORT spark_dsg-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

install(
EXPORT spark_dsg-targets
FILE spark_dsgTargets.cmake
NAMESPACE spark_dsg::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/spark_dsg
)

install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/spark_dsgConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/spark_dsgConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/spark_dsg
)
4 changes: 3 additions & 1 deletion cmake/spark_dsg_version.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@
// Define variables through CMake.
#define SPARK_DSG_VERSION_MAJOR @spark_dsg_VERSION_MAJOR@
#define SPARK_DSG_VERSION_MINOR @spark_dsg_VERSION_MINOR@
#define SPARK_DSG_VERSION_PATCH @spark_dsg_VERSION_PATCH@
#define SPARK_DSG_VERSION_PATCH @spark_dsg_VERSION_PATCH@

#define SPARK_DSG_USE_ZMQ @SPARK_DSG_USE_ZMQ@
32 changes: 2 additions & 30 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,42 +1,14 @@
cmake_minimum_required(VERSION 3.16)
project(spark_dsg_python)

include(FetchContent)
FetchContent_Declare(pybind11 GIT_REPOSITORY https://github.com/pybind/pybind11.git)

FetchContent_GetProperties(pybind11)
if(NOT googletest_POPULATED)
FetchContent_Populate(pybind11)
endif()

add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR} EXCLUDE_FROM_ALL)

set(ZMQ_INTERFACE_ENABLED 0)
if(SPARK_DSG_BUILD_ZMQ AND zmq_FOUND)
set(ZMQ_INTERFACE_ENABLED 1)
endif()
configure_file(
bindings/include/spark_dsg/python/zmq_interface.h.in
bindings/include/spark_dsg/python/zmq_interface.h
)
pybind11_add_module(
_dsg_bindings
bindings/src/bounding_box.cpp
bindings/src/dynamic_scene_graph.cpp
bindings/src/edge_attributes.cpp
bindings/src/mesh.cpp
bindings/src/misc_types.cpp
bindings/src/node_attributes.cpp
bindings/src/scene_graph_edge.cpp
bindings/src/mesh_helpers.cpp
bindings/src/python_layer_view.cpp
bindings/src/scene_graph_iterators.cpp
bindings/src/scene_graph_layer.cpp
bindings/src/scene_graph_node.cpp
bindings/src/scene_graph_utilities.cpp
bindings/src/spark_dsg_bindings.cpp
bindings/src/zmq_interface.cpp
)
target_link_libraries(_dsg_bindings PRIVATE spark_dsg)
target_include_directories(
_dsg_bindings PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/bindings/include
${CMAKE_CURRENT_BINARY_DIR}/bindings/include
)
43 changes: 0 additions & 43 deletions python/bindings/include/spark_dsg/python/bounding_box.h

This file was deleted.

43 changes: 0 additions & 43 deletions python/bindings/include/spark_dsg/python/edge_attributes.h

This file was deleted.

43 changes: 0 additions & 43 deletions python/bindings/include/spark_dsg/python/mesh.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@
* Government is authorized to reproduce and distribute reprints for Government
* purposes notwithstanding any copyright notation herein.
* -------------------------------------------------------------------------- */
#pragma once
#include <spark_dsg/mesh.h>

#define INCLUDE_ZMQ() @ZMQ_INTERFACE_ENABLED@
namespace spark_dsg::python {

namespace pybind11 {
class module_;
}
Eigen::MatrixXd getEigenVertices(const Mesh& mesh);
void setEigenVertices(Mesh& mesh, const Eigen::MatrixXd& points);
Eigen::MatrixXi getEigenFaces(const Mesh& mesh);
void setEigenFaces(Mesh& mesh, const Eigen::MatrixXi& indices);

namespace spark_dsg::python::zmq_interface {
void addBindings(pybind11::module_& m);
}
} // namespace spark_dsg::python
Loading