From 90db101622f9e0aa1e0076065bd82f667908b823 Mon Sep 17 00:00:00 2001 From: crvs Date: Wed, 13 Jun 2018 16:33:35 +0200 Subject: [PATCH 1/6] corrected CMake to mimic changes --- CMakeLists.txt | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0fa1003..59addd7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,18 +5,14 @@ project(coefficient-flow CXX) # * Gudhi under /usr/include/gudhi # * Eigen3 under /usr/include/eigen3 # * boost under /usr/include/boost -# * CGAL under /usr/include/CGAL # * libyaml under /usr/local/include/libyaml -# * pcl 1.8 under /usr/include/pcl-1.8 # -# in case Eigen, and/or CGAL, and/or GUDHI are not found by find_package +# in case Eigen, and/or GUDHI are not found by find_package # try setting the paths to them manually # # set(EIGEN3_INCLUDE_DIR "/usr/local/include/eigen3") # include_directories(${EIGEN3_INCLUDE_DIR}) -# set(CGAL_INCLUDE_DIR "/usr/local/include/eigen3") -# include_directories(${CGAL_INCLUDE_DIR}) # # GUDHI version should be 1.3 or higher, provided they don't break the @@ -25,9 +21,14 @@ project(coefficient-flow CXX) # libyaml-cpp this should actually be found in "/usr/include" so there is no # real need for the find_package, but it's always nice to make sure # -# pcl-1.8 version 1.7 doesn't let one read ply files into meshes which is -# rather strange, but it is a thing. -# + +add_subdirectory(KDTree) + +add_subdirectory(tinyply) +include_directories("./tinyply/source/") + +add_subdirectory(tinyobjloader) +include_directories("./tinyobjloader") find_package(Boost REQUIRED) message(STATUS "Boost version: ${Boost_VERSION}") @@ -39,20 +40,11 @@ message(STATUS "Eigen3 version: ${EIGEN3_VERSION}") message(STATUS "Eigen3 directory: ${EIGEN3_INCLUDE_DIR}") include_directories(${EIGEN3_INCLUDE_DIR}) -find_package(CGAL REQUIRED QUIET) -message(STATUS "CGAL version: ${CGAL_VERSION}") -message(STATUS "CGAL directory: ${CGAL_INCLUDE_DIRS}") - find_package(yaml-cpp REQUIRED QUIET) message(STATUS "yaml-cpp version: ${YAML_CPP_VERSION}") message(STATUS "yaml-cpp directory: ${YAML_CPP_INCLUDE_DIR}") include_directories(${YAML_CPP_INCLUDE_DIR}) -find_package(PCL 1.8 REQUIRED QUIET COMPONENTS io) -message(STATUS "PCL version: ${PCL_VERSION}") -message(STATUS "PCL directory: ${PCL_INCLUDE_DIRS}") -include_directories(${PCL_INCLUDE_DIRS}) - find_package(GUDHI 1.3 REQUIRED QUIET) message(STATUS "Gudhi version: ${GUDHI_VERSION}") string(REGEX MATCH "^/home/" LOCAL_INSTALLED "${GUDHI_DIR}") @@ -80,16 +72,22 @@ set(CMAKE_OBJDUMP "/usr/bin/llvm-objdump") set(CMAKE_RANLIB "/usr/bin/llvm-ranlib") set(CMAKE_BUILD_TYPE Release) +# set(CMAKE_BUILD_TYPE Debug) + +include_directories( + "./lib" # where all the library files are + "KDTree" # for the KDTree library + ) -include_directories("./lib") # where all the library files are add_library(scomplex SHARED "./lib/scomplex/simplicial_complex.cpp") add_library(pathsnap SHARED "./lib/scomplex/path_snapper.cpp") +target_link_libraries(pathsnap KDTree) add_executable(qhull2ply "src/make_mesh.cpp") add_executable(yamltest "src/testing_facility.cpp") -target_link_libraries(yamltest yaml-cpp scomplex pathsnap ${PCL_LIBRARIES}) +target_link_libraries(yamltest yaml-cpp scomplex pathsnap tinyply tinyobjloader) message(INFO ${CMAKE_CURRENT_SOURCE_DIR}) message(INFO ${CMAKE_CURRENT_BINARY_DIR}) From 72511e0bc491bbb68a9dba965ff17d3275592fca Mon Sep 17 00:00:00 2001 From: crvs Date: Wed, 13 Jun 2018 16:38:27 +0200 Subject: [PATCH 2/6] retrieved diffs from python --- CMakeLists.txt | 41 +++++++++++++++++++++++++++++++++++++++-- python/bindings.cpp | 20 ++++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 python/bindings.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index bbbbcaf..59addd7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,10 +22,8 @@ project(coefficient-flow CXX) # real need for the find_package, but it's always nice to make sure # -# TODO remove add_subdirectory(KDTree) - add_subdirectory(tinyply) include_directories("./tinyply/source/") @@ -100,3 +98,42 @@ add_custom_target(timing_test COMMAND "${CMAKE_CURRENT_BINARY_DIR}/run_dumb_tests.sh" "1" DEPENDS yamltest qhull2ply "test/run_dumb_tests.sh" "test/dumbexample.yaml") +# this compiles it against python 2.7 +#find_package(PythonInterp REQUIRED) +#find_package(PythonLibs REQUIRED) +#find_package(Boost REQUIRED COMPONENTS python3) + +#set(PYTHON_INCLUDE_DIRS /usr/include/python3.6m ) +#set(PYTHON_LIBRARIES /usr/lib/libpython3.6m.so /usr/lib/libpython3.6m.so.1.0 /usr/lib/libpython3.so) + +#include_directories(${PYTHON_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}) +#link_directories(${Boost_LIBRARY_DIR}) + +#message(STATUS "python version: ${PYTHON_VERSION} ") +#message(STATUS "python dirs: ${PYTHON_INCLUDE_DIRS}") +#message(STATUS "python libs: ${PYTHON_LIBRARIES}") +#message(STATUS "boost dirs: ${Boost_INCLUDE_DIRS}") + +find_package(pybind11 REQUIRED) +add_library(coeffflow MODULE python/bindings.cpp) +target_link_libraries(coeffflow PRIVATE scomplex pybind11::module) + +set_target_properties(coeffflow PROPERTIES PREFIX "" SUFFIX .so) + +#set_target_properties(coeffflow PROPERTIES SUFFIX .so) +#set_target_properties(coeffflow PROPERTIES PREFIX "") + +#target_link_libraries(coeffflow "python2.7" "boost_python" ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} scomplex) + + +# This should really work, but it doesnt +#set(Python_ADDITIONAL_VERSIONS 3.6) +#find_package(PythonLibs REQUIRED) +# +#set(PYTHON_INCLUDE_DIR /usr/include/python3.6m) +#set(PYTHON_LIBRARY libpython3.6m.so libpython3.6m.so.1.0 libpython3.so) +# +#include_directories(${PYTHON_INCLUDE_DIR} ${Boost_INCLUDE_DIRS}) +#python_add_module(coeffflow python/bindings.cpp) +#target_link_libraries(coeffflow "boost_python3" "python3.6m" ${Boost_LIBRARIES} ${PYTHON_LIBRARY} scomplex) +# diff --git a/python/bindings.cpp b/python/bindings.cpp new file mode 100644 index 0000000..f76b083 --- /dev/null +++ b/python/bindings.cpp @@ -0,0 +1,20 @@ +#include + +#include +#include + +#include "scomplex/coeff_flow.hpp" +#include "scomplex/simplicial_complex.hpp" +#include "scomplex/types.hpp" + +using namespace gsimp; + +namespace py = pybind11; + +PYBIND11_MODULE(coeffflow, m) { + py::class_< simplicial_complex >(m, "simplicial_complex") // + .def(py::init< std::vector< cell_t >& >()) // + .def("cell_to_index", &simplicial_complex::cell_to_index); + + m.def("coeff_flow", coeff_flow); +} From f280315711945b2203471bb7b26ca414eced2ca8 Mon Sep 17 00:00:00 2001 From: crvs Date: Wed, 13 Jun 2018 16:33:35 +0200 Subject: [PATCH 3/6] corrected CMake to mimic changes --- CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ac89c90..0cf5254 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,6 @@ project(coefficient-flow CXX) # * Gudhi under /usr/include/gudhi # * Eigen3 under /usr/include/eigen3 # * boost under /usr/include/boost -# # in case Eigen, and/or GUDHI are not found by find_package # try setting the paths to them manually @@ -56,7 +55,6 @@ set(CMAKE_BUILD_TYPE Release) include_directories( "./lib" ) - add_library(scomplex SHARED "./lib/scomplex/simplicial_complex.cpp") add_library(pathsnap SHARED "./lib/scomplex/path_snapper.cpp") target_link_libraries(pathsnap KDTree) From 1cc7d4c2d33acbc23a9f587546088dd0620cc1d7 Mon Sep 17 00:00:00 2001 From: crvs Date: Wed, 13 Jun 2018 16:38:27 +0200 Subject: [PATCH 4/6] retrieved diffs from python --- CMakeLists.txt | 39 +++++++++++++++++++++++++++++++++++++++ python/bindings.cpp | 20 ++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 python/bindings.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 0cf5254..e5ad6d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,3 +73,42 @@ add_custom_target(timing_test COMMAND "${CMAKE_CURRENT_BINARY_DIR}/run_dumb_tests.sh" "1" DEPENDS yamltest qhull2ply "test/run_dumb_tests.sh" "test/dumbexample.yaml") +# this compiles it against python 2.7 +#find_package(PythonInterp REQUIRED) +#find_package(PythonLibs REQUIRED) +#find_package(Boost REQUIRED COMPONENTS python3) + +#set(PYTHON_INCLUDE_DIRS /usr/include/python3.6m ) +#set(PYTHON_LIBRARIES /usr/lib/libpython3.6m.so /usr/lib/libpython3.6m.so.1.0 /usr/lib/libpython3.so) + +#include_directories(${PYTHON_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}) +#link_directories(${Boost_LIBRARY_DIR}) + +#message(STATUS "python version: ${PYTHON_VERSION} ") +#message(STATUS "python dirs: ${PYTHON_INCLUDE_DIRS}") +#message(STATUS "python libs: ${PYTHON_LIBRARIES}") +#message(STATUS "boost dirs: ${Boost_INCLUDE_DIRS}") + +find_package(pybind11 REQUIRED) +add_library(coeffflow MODULE python/bindings.cpp) +target_link_libraries(coeffflow PRIVATE scomplex pybind11::module) + +set_target_properties(coeffflow PROPERTIES PREFIX "" SUFFIX .so) + +#set_target_properties(coeffflow PROPERTIES SUFFIX .so) +#set_target_properties(coeffflow PROPERTIES PREFIX "") + +#target_link_libraries(coeffflow "python2.7" "boost_python" ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} scomplex) + + +# This should really work, but it doesnt +#set(Python_ADDITIONAL_VERSIONS 3.6) +#find_package(PythonLibs REQUIRED) +# +#set(PYTHON_INCLUDE_DIR /usr/include/python3.6m) +#set(PYTHON_LIBRARY libpython3.6m.so libpython3.6m.so.1.0 libpython3.so) +# +#include_directories(${PYTHON_INCLUDE_DIR} ${Boost_INCLUDE_DIRS}) +#python_add_module(coeffflow python/bindings.cpp) +#target_link_libraries(coeffflow "boost_python3" "python3.6m" ${Boost_LIBRARIES} ${PYTHON_LIBRARY} scomplex) +# diff --git a/python/bindings.cpp b/python/bindings.cpp new file mode 100644 index 0000000..f76b083 --- /dev/null +++ b/python/bindings.cpp @@ -0,0 +1,20 @@ +#include + +#include +#include + +#include "scomplex/coeff_flow.hpp" +#include "scomplex/simplicial_complex.hpp" +#include "scomplex/types.hpp" + +using namespace gsimp; + +namespace py = pybind11; + +PYBIND11_MODULE(coeffflow, m) { + py::class_< simplicial_complex >(m, "simplicial_complex") // + .def(py::init< std::vector< cell_t >& >()) // + .def("cell_to_index", &simplicial_complex::cell_to_index); + + m.def("coeff_flow", coeff_flow); +} From e2c5a15c68ce1a891b2fa6df216ce2aab5d7e08b Mon Sep 17 00:00:00 2001 From: crvs Date: Thu, 28 Jun 2018 15:46:24 +0200 Subject: [PATCH 5/6] added pybind11 as a submodule --- .gitignore | 3 --- .gitmodules | 3 +++ CMakeLists.txt | 40 ++++------------------------------------ pybind11 | 1 + python/bindings.cpp | 4 +++- 5 files changed, 11 insertions(+), 40 deletions(-) create mode 160000 pybind11 diff --git a/.gitignore b/.gitignore index 66de543..988d148 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ -# ignore all files -* - # tags file tags diff --git a/.gitmodules b/.gitmodules index 696f36a..0ff90eb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "yaml-cpp"] path = yaml-cpp url = https://github.com/jbeder/yaml-cpp +[submodule "pybind11"] + path = pybind11 + url = https://github.com/pybind/pybind11 diff --git a/CMakeLists.txt b/CMakeLists.txt index e5ad6d3..fe3d872 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,9 @@ project(coefficient-flow CXX) add_subdirectory(yaml-cpp) include_directories("./yaml-cpp/include/") +add_subdirectory(pybind11) +include_directories("./pybind11/include/") + add_subdirectory(KDTree) include_directories("./KDTree") @@ -73,42 +76,7 @@ add_custom_target(timing_test COMMAND "${CMAKE_CURRENT_BINARY_DIR}/run_dumb_tests.sh" "1" DEPENDS yamltest qhull2ply "test/run_dumb_tests.sh" "test/dumbexample.yaml") -# this compiles it against python 2.7 -#find_package(PythonInterp REQUIRED) -#find_package(PythonLibs REQUIRED) -#find_package(Boost REQUIRED COMPONENTS python3) - -#set(PYTHON_INCLUDE_DIRS /usr/include/python3.6m ) -#set(PYTHON_LIBRARIES /usr/lib/libpython3.6m.so /usr/lib/libpython3.6m.so.1.0 /usr/lib/libpython3.so) - -#include_directories(${PYTHON_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}) -#link_directories(${Boost_LIBRARY_DIR}) - -#message(STATUS "python version: ${PYTHON_VERSION} ") -#message(STATUS "python dirs: ${PYTHON_INCLUDE_DIRS}") -#message(STATUS "python libs: ${PYTHON_LIBRARIES}") -#message(STATUS "boost dirs: ${Boost_INCLUDE_DIRS}") - -find_package(pybind11 REQUIRED) +#Python bindings: add_library(coeffflow MODULE python/bindings.cpp) target_link_libraries(coeffflow PRIVATE scomplex pybind11::module) - set_target_properties(coeffflow PROPERTIES PREFIX "" SUFFIX .so) - -#set_target_properties(coeffflow PROPERTIES SUFFIX .so) -#set_target_properties(coeffflow PROPERTIES PREFIX "") - -#target_link_libraries(coeffflow "python2.7" "boost_python" ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} scomplex) - - -# This should really work, but it doesnt -#set(Python_ADDITIONAL_VERSIONS 3.6) -#find_package(PythonLibs REQUIRED) -# -#set(PYTHON_INCLUDE_DIR /usr/include/python3.6m) -#set(PYTHON_LIBRARY libpython3.6m.so libpython3.6m.so.1.0 libpython3.so) -# -#include_directories(${PYTHON_INCLUDE_DIR} ${Boost_INCLUDE_DIRS}) -#python_add_module(coeffflow python/bindings.cpp) -#target_link_libraries(coeffflow "boost_python3" "python3.6m" ${Boost_LIBRARIES} ${PYTHON_LIBRARY} scomplex) -# diff --git a/pybind11 b/pybind11 new file mode 160000 index 0000000..534b756 --- /dev/null +++ b/pybind11 @@ -0,0 +1 @@ +Subproject commit 534b756cb3244aca959359c07d44e4fed3498ba8 diff --git a/python/bindings.cpp b/python/bindings.cpp index f76b083..f85e0ec 100644 --- a/python/bindings.cpp +++ b/python/bindings.cpp @@ -17,4 +17,6 @@ PYBIND11_MODULE(coeffflow, m) { .def("cell_to_index", &simplicial_complex::cell_to_index); m.def("coeff_flow", coeff_flow); -} + + m.def("coeff_flow_embedded",coeff_flow_embedded); +}; From 242bba5bd74a692f5af27756ed3a7c91e9986d75 Mon Sep 17 00:00:00 2001 From: crvs Date: Thu, 28 Jun 2018 15:58:39 +0200 Subject: [PATCH 6/6] added python bindings to the readme --- README.md | 17 +++++++++++++++++ python/bindings.cpp | 9 +++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a4a0fa4..6a2e658 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,23 @@ make timing-test to run the timing tests, the files for the other tests, are still not provided. +### Using Python bindings + +In the python bindings we provide bindings for the `simplicial_complex` which uses only cells to for construction, and provides also bindings for the functions `cell_to_index` and `index_to_cell`. Furthermore we provide bindings for `coeff_flow` and `coeff_flow_embedded`. Below is a toy example run: + +```{python} +>>> import coeffflow +>>> a = coeffflow.simplicial_complex([[0,1,2]]) +>>> a.cell_to_index([0,2]) +1 +>>> a.index_to_cell(0,1) +[1] +>>> a.index_to_cell(1,2) +[2, 1] +>>> coeffflow.coeff_flow_embedded(a ,(1, [1,-1,1])) +(2, [1.0]) +``` + ### References/links [1]: Carvalho JF, Vejdemo-Johansson M, Kragic D, Pokorny FT. _An algorithm for calculating top-dimensional bounding chains._ 2017 [PeerJ Preprints 5:e3151v1](https://doi.org/10.7287/peerj.preprints.3151v1) diff --git a/python/bindings.cpp b/python/bindings.cpp index f85e0ec..d8c2132 100644 --- a/python/bindings.cpp +++ b/python/bindings.cpp @@ -12,11 +12,12 @@ using namespace gsimp; namespace py = pybind11; PYBIND11_MODULE(coeffflow, m) { - py::class_< simplicial_complex >(m, "simplicial_complex") // - .def(py::init< std::vector< cell_t >& >()) // - .def("cell_to_index", &simplicial_complex::cell_to_index); + py::class_< simplicial_complex >(m, "simplicial_complex") // + .def(py::init< std::vector< cell_t >& >()) // + .def("cell_to_index", &simplicial_complex::cell_to_index) // + .def("index_to_cell", &simplicial_complex::index_to_cell); m.def("coeff_flow", coeff_flow); - m.def("coeff_flow_embedded",coeff_flow_embedded); + m.def("coeff_flow_embedded", coeff_flow_embedded); };