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

Adding Poisson surface reconstruction bindings #117

Merged
merged 4 commits into from
Jun 2, 2024
Merged
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
26 changes: 20 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.10)

project(Bindings
DESCRIPTION
"Python libigl bindings"
"Python bindings"
)

set(CMAKE_CXX_STANDARD 17)
Expand All @@ -23,10 +23,20 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
endif()


# Include libigl
option(LIBIGL_COPYLEFT_CGAL "Use CGAL" ON)
option(LIBIGL_EMBREE "Build target igl::embree" ON)
include(libigl)

# Include PoissonRecon
include(PoissonRecon)
add_library(PoissonRecon INTERFACE)
target_include_directories(PoissonRecon INTERFACE "${CMAKE_BINARY_DIR}/_deps/poissonrecon-src/Src/")

# List of all libraries to link
set(LIBRARIES_TO_LINK igl::core igl::embree PoissonRecon)
set(COPYLEFT_LIBRARIES_TO_LINK igl::core igl_copyleft::cgal)

add_library(cpytoolbox
STATIC
# SHARED
Expand All @@ -36,6 +46,7 @@ add_library(cpytoolbox
src/cpp/in_element_aabb.h
src/cpp/read_obj.h
src/cpp/write_obj.h
src/cpp/point_cloud_to_mesh.h
src/cpp/remesher/collapse_edges.h
src/cpp/remesher/equalize_valences.h
src/cpp/remesher/remesh_botsch.h
Expand All @@ -50,6 +61,7 @@ add_library(cpytoolbox
src/cpp/in_element_aabb.cpp
src/cpp/read_obj.cpp
src/cpp/write_obj.cpp
src/cpp/point_cloud_to_mesh.cpp
src/cpp/remesher/collapse_edges.cpp
src/cpp/remesher/equalize_valences.cpp
src/cpp/remesher/remesh_botsch.cpp
Expand Down Expand Up @@ -81,9 +93,10 @@ add_library(cpytoolbox
src/cpp/swept_volume/swept_volume.h
)

# target_link_libraries(cpytoolbox igl::core igl_copyleft::cgal igl::embree)
target_link_libraries(cpytoolbox igl::core igl::embree )
target_link_libraries(cpytoolbox_copyleft igl::core igl_copyleft::cgal)
target_link_libraries(cpytoolbox ${LIBRARIES_TO_LINK})
set(LIBRARIES_TO_LINK cpytoolbox ${LIBRARIES_TO_LINK})
target_link_libraries(cpytoolbox_copyleft ${COPYLEFT_LIBRARIES_TO_LINK})
set(COPYLEFT_LIBRARIES_TO_LINK cpytoolbox_copyleft ${COPYLEFT_LIBRARIES_TO_LINK})

# Otman's python bindings using pybind11
add_subdirectory(./ext/pybind11/)
Expand All @@ -106,6 +119,7 @@ pybind11_add_module(gpytoolbox_bindings
"${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/binding_read_ply.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/binding_write_ply.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/binding_curved_hessian_intrinsic.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/binding_point_cloud_to_mesh.cpp"
)

pybind11_add_module(gpytoolbox_bindings_copyleft
Expand All @@ -114,8 +128,8 @@ pybind11_add_module(gpytoolbox_bindings_copyleft
"${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/binding_booleans.cpp"
)

target_link_libraries(gpytoolbox_bindings PUBLIC cpytoolbox igl::core)
target_link_libraries(gpytoolbox_bindings_copyleft PUBLIC cpytoolbox_copyleft igl::core igl_copyleft::cgal)
target_link_libraries(gpytoolbox_bindings PUBLIC ${LIBRARIES_TO_LINK})
target_link_libraries(gpytoolbox_bindings_copyleft PUBLIC ${COPYLEFT_LIBRARIES_TO_LINK})

target_include_directories(gpytoolbox_bindings PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/")
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
Expand Down
9 changes: 8 additions & 1 deletion LICENSE.GPL
Original file line number Diff line number Diff line change
Expand Up @@ -673,4 +673,11 @@ into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
<http://www.gnu.org/philosophy/why-not-lgpl.html>.


=====================

The libraries that appear in gpytoolbox_copyleft that are licensed under GPL
are:
- CGAL (https://www.cgal.org)
7 changes: 6 additions & 1 deletion LICENSE.MIT
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Silvia Sellán and Oded Stein
Copyright (c) 2024 Silvia Sellán and Oded Stein

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -28,3 +28,8 @@ This software contains the ColorBrewer color maps by Cynthia Brewer
(Pennsylvania State University), released under the Apache 2.0 license
(http://www.personal.psu.edu/cab38/ColorBrewer/ColorBrewer_updates.html),
and modifications by AxisMaps (https://colorbrewer2.org)

========================

This software contains code written by Michael Kazhdan (Johns Hopkins University) for PoissonRecon, also released
under the MIT license (see https://github.com/mkazhdan/PoissonRecon/blob/master/LICENSE)
11 changes: 11 additions & 0 deletions cmake/PoissonRecon.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
if(TARGET PoissonRecon)
return()
endif()

include(FetchContent)
FetchContent_Declare(
PoissonRecon
GIT_REPOSITORY https://github.com/mkazhdan/PoissonRecon.git
GIT_TAG e04a91d40093dd80669afb07f7d3f586db063ee9
)
FetchContent_MakeAvailable(PoissonRecon)
79 changes: 79 additions & 0 deletions src/cpp/binding_point_cloud_to_mesh.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include "point_cloud_to_mesh.h"
#include <pybind11/stl.h>
#include <pybind11/pybind11.h>
#include <pybind11/eigen.h>
#include <pybind11/functional.h>
#include <string>
#include <iostream>

using namespace Eigen;
namespace py = pybind11;
using EigenDStride = Stride<Eigen::Dynamic, Eigen::Dynamic>;
template <typename MatrixType>
using EigenDRef = Ref<MatrixType, 0, EigenDStride>; //allows passing column/row order matrices easily

template<typename Real, typename Int>
void binding_definer_point_cloud_to_mesh(py::module& m, const char *name)
{
using Mat = Eigen::Matrix<Real, Eigen::Dynamic, Eigen::Dynamic>;
using MatI = Eigen::Matrix<Int, Eigen::Dynamic, Eigen::Dynamic>;

m.def(name,[](EigenDRef<Mat> _cloud_points,
EigenDRef<Mat> _cloud_normals,
Real screening_weight,
int depth,
const std::string& _outerBoundaryType,
bool parallel,
bool verbose)
{
Mat cloud_points(_cloud_points), cloud_normals(_cloud_normals);
Mat V;
MatI F;
const int dim = cloud_points.cols();
if(dim==2) {
if(_outerBoundaryType=="Dirichlet" ||
_outerBoundaryType=="dirichlet") {
point_cloud_to_mesh<Real,Int,
PointCloudReconstructionOuterBoundaryType::Dirichlet,2>
(cloud_points, cloud_normals,
screening_weight,
depth,
parallel, verbose,
V, F);
} else { //Neumann
point_cloud_to_mesh<Real,Int,
PointCloudReconstructionOuterBoundaryType::Neumann,2>
(cloud_points, cloud_normals,
screening_weight,
depth,
parallel, verbose,
V, F);
}
} else if(dim==3) {
if(_outerBoundaryType=="Dirichlet" ||
_outerBoundaryType=="dirichlet") {
point_cloud_to_mesh<Real,Int,
PointCloudReconstructionOuterBoundaryType::Dirichlet,3>
(cloud_points, cloud_normals,
screening_weight,
depth,
parallel, verbose,
V, F);
} else { //Neumann
point_cloud_to_mesh<Real,Int,
PointCloudReconstructionOuterBoundaryType::Neumann,3>
(cloud_points, cloud_normals,
screening_weight,
depth,
parallel, verbose,
V, F);
}
}
return std::make_tuple(V, F);
});
}

void binding_point_cloud_to_mesh(py::module& m) {
binding_definer_point_cloud_to_mesh<double, int>(m, "_point_cloud_to_mesh_cpp_impl");
}

2 changes: 2 additions & 0 deletions src/cpp/gpytoolbox_bindings_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ void binding_upper_envelope(py::module& m);
void binding_read_ply(py::module& m);
void binding_write_ply(py::module& m);
void binding_curved_hessian_intrinsic(py::module& m);
void binding_point_cloud_to_mesh(py::module& m);

PYBIND11_MODULE(gpytoolbox_bindings, m) {

Expand All @@ -48,6 +49,7 @@ PYBIND11_MODULE(gpytoolbox_bindings, m) {
binding_read_ply(m);
binding_write_ply(m);
binding_curved_hessian_intrinsic(m);
binding_point_cloud_to_mesh(m);

m.def("help", [&]() {printf("hi"); });
}
Expand Down
Loading
Loading