Skip to content

Commit f36dc72

Browse files
authored
Move python bindings from pybind11 to nanobind (#61)
* update ps to latest * update eigen * core nanobind switchover completed, tests pass locally * update some comments
1 parent 021eda9 commit f36dc72

23 files changed

Lines changed: 1573 additions & 1464 deletions

.gitmodules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
[submodule "deps/pybind11"]
2-
path = deps/pybind11
3-
url = https://github.com/pybind/pybind11.git
41
[submodule "deps/polyscope"]
52
path = deps/polyscope
63
url = https://github.com/nmwsharp/polyscope.git
74
[submodule "deps/eigen"]
85
path = deps/eigen
96
url = https://gitlab.com/libeigen/eigen.git
7+
[submodule "deps/nanobind"]
8+
path = deps/nanobind
9+
url = https://github.com/wjakob/nanobind

CMakeLists.txt

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,37 @@
11
cmake_minimum_required(VERSION 3.15.0) # minimum imposed by scikit-build-core
22
project(polyscope LANGUAGES CXX)
33

4+
# Default to release build
5+
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
6+
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
7+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
8+
endif()
9+
10+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
11+
set(CMAKE_CXX_STANDARD 20)
12+
413
## Gather dependencies
514

6-
# Eigen
15+
# == Eigen
716
set(EIGEN3_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/deps/eigen/")
817

9-
# Recurse in to pybind
10-
set(PYBIND11_NEWPYTHON ON)
11-
add_subdirectory(deps/pybind11)
18+
# == Nanobind
19+
if (CMAKE_VERSION VERSION_LESS 3.18)
20+
set(DEV_MODULE Development)
21+
else()
22+
set(DEV_MODULE Development.Module)
23+
endif()
1224

13-
# We need polyscope
14-
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
25+
# find python version to target for bindings
26+
find_package(Python 3.9 COMPONENTS Interpreter ${DEV_MODULE} REQUIRED)
27+
28+
# recurse into nanobind
29+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/deps/nanobind)
30+
31+
# == polyscope
1532
add_subdirectory(deps/polyscope)
1633

17-
pybind11_add_module(polyscope_bindings
34+
nanobind_add_module(polyscope_bindings
1835
src/cpp/core.cpp
1936
src/cpp/surface_mesh.cpp
2037
src/cpp/point_cloud.cpp
@@ -25,6 +42,7 @@ pybind11_add_module(polyscope_bindings
2542
src/cpp/floating_quantities.cpp
2643
src/cpp/implicit_helpers.cpp
2744
src/cpp/managed_buffer.cpp
45+
2846
src/cpp/imgui.cpp
2947
src/cpp/implot.cpp
3048

deps/eigen

Submodule eigen updated from 4fd5d14 to d71c30c

deps/nanobind

Submodule nanobind added at c5a3a37

deps/pybind11

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/cpp/camera_view.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
1-
#include <pybind11/eigen.h>
2-
#include <pybind11/numpy.h>
3-
#include <pybind11/pybind11.h>
4-
51
#include "Eigen/Dense"
62

73
#include "polyscope/camera_view.h"
84
#include "polyscope/polyscope.h"
95

106
#include "utils.h"
117

12-
namespace py = pybind11;
13-
namespace ps = polyscope;
14-
15-
168
// clang-format off
17-
void bind_camera_view(py::module& m) {
9+
void bind_camera_view(nb::module_& m) {
1810

1911
// == Helper quantity classes
2012

@@ -40,9 +32,9 @@ void bind_camera_view(py::module& m) {
4032

4133
// Static adders and getters
4234
m.def("register_camera_view", &ps::registerCameraView,
43-
py::arg("name"), py::arg("parameters"), "Register a camera view", py::return_value_policy::reference);
35+
nb::arg("name"), nb::arg("parameters"), "Register a camera view", nb::rv_policy::reference);
4436
m.def("remove_camera_view", &ps::removeCameraView, "Remove a camera view by name");
45-
m.def("get_camera_view", &ps::getCameraView, "Get a camera view by name", py::return_value_policy::reference);
37+
m.def("get_camera_view", &ps::getCameraView, "Get a camera view by name", nb::rv_policy::reference);
4638
m.def("has_camera_view", &ps::hasCameraView, "Check for a camera view by name");
4739

4840
}

0 commit comments

Comments
 (0)