From 74fd1491b60cf57739d72443ae7a8dc253b6b6ee Mon Sep 17 00:00:00 2001
From: Guillaume Cerutti <guillaume.cerutti@inria.fr>
Date: Fri, 22 Mar 2024 17:26:24 +0100
Subject: [PATCH] define cpp class + first cmake attempt

---
 CMakeLists.txt                                  | 17 +++++++++++++----
 cpp/LabelledTetrahedralMesh.cpp                 |  9 +++++++++
 cpp/LabelledTetrahedralMesh.h                   | 13 +++++++++++++
 src/pybind_example/labelled_tetrahedral_mesh.py |  1 +
 wrp/LabelledTetrahedralMeshWrapper.cpp          | 12 ++++++++++++
 5 files changed, 48 insertions(+), 4 deletions(-)
 create mode 100644 cpp/LabelledTetrahedralMesh.cpp
 create mode 100644 cpp/LabelledTetrahedralMesh.h
 create mode 100644 src/pybind_example/labelled_tetrahedral_mesh.py
 create mode 100644 wrp/LabelledTetrahedralMeshWrapper.cpp

diff --git a/CMakeLists.txt b/CMakeLists.txt
index c4b99eb..e3883b7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -9,24 +9,33 @@ project(
   VERSION ${SKBUILD_PROJECT_VERSION}
   LANGUAGES CXX)
 
+set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+
 # Find the module development requirements (requires FindPython from 3.17 or
 # scikit-build-core's built-in backport)
 find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
 find_package(pybind11 CONFIG REQUIRED)
 find_package(CGAL REQUIRED COMPONENTS ImageIO)
 
+add_library(_cpp SHARED cpp/LabelledTetrahedralMesh.h cpp/LabelledTetrahedralMesh.cpp)
+
 # Add a library using FindPython's tooling (pybind11 also provides a helper like
 # this)
-python_add_library(_core MODULE src/main.cpp WITH_SOABI)
-target_link_libraries(_core PRIVATE pybind11::headers)
+pybind11_add_module(_core MODULE src/main.cpp)
 
 # This is passing in the version as a define just as an example
 target_compile_definitions(_core PRIVATE VERSION_INFO=${PROJECT_VERSION})
 
-python_add_library(_cgal MODULE src/cgal_example.cpp WITH_SOABI)
-target_link_libraries(_cgal PRIVATE pybind11::headers)
+pybind11_add_module(_cgal MODULE src/cgal_example.cpp)
 target_link_libraries(_cgal PRIVATE CGAL::CGAL)
 
 # The install directory is the output (wheel) directory
 install(TARGETS _core DESTINATION pybind_example)
 install(TARGETS _cgal DESTINATION pybind_example)
+
+pybind11_add_module(_wrp MODULE wrp/LabelledTetrahedralMeshWrapper.cpp)
+target_include_directories(_wrp PRIVATE ${CMAKE_SOURCE_DIR}/cpp/)
+target_link_libraries(_wrp PUBLIC _cpp)
+
+install(TARGETS _wrp DESTINATION pybind_example)
\ No newline at end of file
diff --git a/cpp/LabelledTetrahedralMesh.cpp b/cpp/LabelledTetrahedralMesh.cpp
new file mode 100644
index 0000000..0f86ffb
--- /dev/null
+++ b/cpp/LabelledTetrahedralMesh.cpp
@@ -0,0 +1,9 @@
+#include "LabelledTetrahedralMesh.h"
+
+
+std::vector< std::vector<double> > LabelledTetrahedralMesh::vertexPoints(void) const
+{
+    std::vector< std::vector<double> > points;
+
+    return points;
+}
diff --git a/cpp/LabelledTetrahedralMesh.h b/cpp/LabelledTetrahedralMesh.h
new file mode 100644
index 0000000..6f9e7f9
--- /dev/null
+++ b/cpp/LabelledTetrahedralMesh.h
@@ -0,0 +1,13 @@
+#pragma once
+
+#include <vector>
+
+class LabelledTetrahedralMesh
+{
+public:
+     LabelledTetrahedralMesh(void) = default;
+    ~LabelledTetrahedralMesh(void) = default;
+
+public:
+    std::vector< std::vector<double> > vertexPoints(void) const;
+};
\ No newline at end of file
diff --git a/src/pybind_example/labelled_tetrahedral_mesh.py b/src/pybind_example/labelled_tetrahedral_mesh.py
new file mode 100644
index 0000000..0f73231
--- /dev/null
+++ b/src/pybind_example/labelled_tetrahedral_mesh.py
@@ -0,0 +1 @@
+from ._wrp import LabelledTetrahedralMesh
\ No newline at end of file
diff --git a/wrp/LabelledTetrahedralMeshWrapper.cpp b/wrp/LabelledTetrahedralMeshWrapper.cpp
new file mode 100644
index 0000000..5080741
--- /dev/null
+++ b/wrp/LabelledTetrahedralMeshWrapper.cpp
@@ -0,0 +1,12 @@
+#include <pybind11/pybind11.h>
+#include <pybind11/stl.h> // This header is needed to work with STL containers like std::vector
+
+#include "LabelledTetrahedralMesh.h"
+
+namespace py = pybind11;
+
+PYBIND11_MODULE(_wrp, m) {
+py::class_<LabelledTetrahedralMesh>(m, "LabelledTetrahedralMesh")
+    .def(py::init<>())
+    .def("vertex_points", &LabelledTetrahedralMesh::vertexPoints);
+}
\ No newline at end of file
-- 
GitLab