Skip to content

Commit

Permalink
Merge branch 'main' of github.com:libigl/libigl-python-bindings into …
Browse files Browse the repository at this point in the history
…alecjacobson/bump-libigl
  • Loading branch information
alecjacobson committed Feb 7, 2023
2 parents eb19b72 + 57746d5 commit facf32e
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 130 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ jobs:
# This is very dubious... It *may* work because these are just cpp libraries that should not depend on the python version. Still, super-dubious.
CIBW_BEFORE_BUILD_WINDOWS: "python -m pip install delvewheel"
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: "python -m delvewheel repair --no-mangle-all --add-path build\\temp.win-amd64-3.6\\Release;build\\temp.win-amd64-3.6\\Release\\Release;build\\temp.win-amd64-3.6\\Release\\_deps\\gmp-src\\lib;build\\temp.win-amd64-3.6\\Release\\_deps\\mpfr-src\\lib -w {dest_dir} {wheel} "
CIBW_TEST_COMMAND: "python {project}/tests/test_basic.py {project}/data/"
CIBW_TEST_REQUIRES: "gitpython"
CIBW_TEST_COMMAND: "python {project}/tests/test_basic.py"
CIBW_BUILD: "${{ matrix.cpversion }}-${{ matrix.os.cibw-arch }}"
CIBW_TEST_SKIP: "*-macosx_arm64"
CIBW_ENVIRONMENT: "MAX_JOBS=2"
CIBW_ENVIRONMENT: "MAX_JOBS=${{ matrix.os.runs-on == 'macos-latest' && 3 || 2 }}"
# Why universal2 here? It's not included above in CIBW_BUILD
CIBW_ARCHS_MACOS: "x86_64 arm64 universal2"
CIBW_ENVIRONMENT_MACOS: "CMAKE_OSX_ARCHITECTURES=\"${{ matrix.os.cibw-arch == 'macosx_x86_64' && 'x86_64' || matrix.os.cibw-arch == 'macosx_arm64' && 'arm64' || matrix.os.cibw-arch == 'macosx_universal2' && 'arm64;x86_64' || '' }}\""
Expand Down
25 changes: 0 additions & 25 deletions .travis.yml

This file was deleted.

3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ include(Warnings)
# Use C++11/14
include(CXXFeatures)

option(PY_IGL_DOWNLOAD_TEST_DATA "Download test data" ON)
option(PY_IGL_DOWNLOAD_TUTORIAL_DATA "Download tutorial data" ON)

# Generate position independent code by default
set(CMAKE_POSITION_INDEPENDENT_CODE ON CACHE INTERNAL "")

Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# libigl Python Bindings
[![PyPI version](https://badge.fury.io/py/libigl.svg)](https://badge.fury.io/py/libigl)
[![Build Status](https://travis-ci.com/libigl/libigl-python-bindings.svg?branch=master)](https://travis-ci.com/libigl/libigl-python-bindings)
[![Build Status](https://dev.azure.com/libigl/Libigl/_apis/build/status/libigl.libigl-python-bindings?branchName=master)](https://dev.azure.com/libigl/Libigl/_build/latest?definitionId=1&branchName=master)
[![PyPI version](https://badge.fury.io/py/libigl.svg)](https://pypi.org/project/libigl/)
[![buildwheels](https://github.com/libigl/libigl-python-bindings/actions/workflows/wheels.yml/badge.svg)](https://github.com/libigl/libigl-python-bindings/actions/workflows/wheels.yml?query=branch%3Amain)


This repository contains the source code for the libigl Python bindings. These bindings are fully compatible with NumPy and SciPy and offer a convenient interface similar to functions in those libraries.

Expand Down Expand Up @@ -53,3 +53,9 @@ or
python tests/test_basic.py
```

and if developing and trying to run from this directory. You could use:

```
PYTHONPATH=. python tests/test_basic.py
```

71 changes: 0 additions & 71 deletions azure-pipelines.yml

This file was deleted.

17 changes: 0 additions & 17 deletions cmake/PyiglDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,3 @@ SET(NPE_WITH_EIGEN "${libigl_SOURCE_DIR}/../eigen-src/" CACHE INTERNAL "")
include(numpyeigen)
# Pop CMAKE_MODULE_PATH
set(CMAKE_MODULE_PATH ${PREV_CMAKE_MODULE_PATH})

if(${PY_IGL_DOWNLOAD_TEST_DATA})
FetchContent_Declare(test_data
SOURCE_DIR "${PYLIBIGL_EXTERNAL}/../data"
GIT_REPOSITORY https://github.com/libigl/libigl-tests-data.git
GIT_TAG 19cedf96d70702d8b3a83eb27934780c542356fe)
FetchContent_MakeAvailable(test_data)
endif()

if(${PY_IGL_DOWNLOAD_TUTORIAL_DATA})
FetchContent_Declare(tutorial_data
SOURCE_DIR "${PYLIBIGL_EXTERNAL}/../tutorial/data"
GIT_REPOSITORY https://github.com/libigl/libigl-tutorial-data.git
GIT_TAG c1f9ede366d02e3531ecbaec5e3769312f31cccd)
FetchContent_MakeAvailable(tutorial_data)
endif()

56 changes: 56 additions & 0 deletions src/blue_noise.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//TODO: __example
#include <common.h>
#include <npe.h>
#include <typedefs.h>
#include <igl/blue_noise.h>

const char* ds_blue_noise = R"igl_Qu8mg5v7(
"Fast Poisson Disk Sampling in Arbitrary Dimensions" [Bridson 2007]
For very dense samplings this is faster than (up to 2x) cyCodeBase's
implementation of "Sample Elimination for Generating Poisson Disk Sample
Sets" [Yuksel 2015]. YMMV
Parameters
----------
V #V by dim list of mesh vertex positions
F #F by 3 list of mesh triangle indices into rows of V
r Poisson disk radius (evaluated according to Euclidean distance on V)
Returns
-------
B #P by 3 list of barycentric coordinates, ith row are coordinates of
ith sampled point in face FI(i)
FI #P list of indices into F
P #P by dim list of sample positions.
See also
--------
random_points_on_mesh
Notes
-----
None
Examples
--------
)igl_Qu8mg5v7";

npe_function(blue_noise)
npe_doc(ds_blue_noise)

npe_arg(v, dense_float, dense_double)
npe_arg(f, dense_int, dense_long, dense_longlong)
npe_arg(r, double)


npe_begin_code()

assert_valid_23d_tri_mesh(v, f);
EigenDenseLike<npe_Matrix_v> b;
Eigen::VectorXi fi;
EigenDenseLike<npe_Matrix_v> p;
igl::blue_noise(v, f, r, b, fi, p);
return std::make_tuple(npe::move(b), npe::move(fi), npe::move(p));

npe_end_code()
50 changes: 50 additions & 0 deletions src/fit_cubic_bezier.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <npe.h>
#include <common.h>
#include <typedefs.h>
// On macos with cp36, termios.h is getting included for some reason and it
// defines B0
#ifdef B0
# undef B0
#endif
#include <igl/fit_cubic_bezier.h>
#include <pybind11/stl_bind.h>
#include <pybind11/stl.h>


const char *ds_fit_cubic_bezier = R"igl_Qu8mg5v7(
Fit a cubic bezier spline (G1 continuous) to an ordered list of input
points in any dimension, according to "An algorithm for automatically
fitting digitized curves" [Schneider 1990].
Parameters
----------
d #d by dim list of points along a curve to be fit with a cubic bezier
spline (should probably be roughly uniformly spaced). If d(0)==d(end),
then will treat as a closed curve.
error maximum squared distance allowed
Returns
-------
cubics #cubics list of 4 by dim lists of cubic control points
)igl_Qu8mg5v7";

npe_function(fit_cubic_bezier)
npe_doc(ds_fit_cubic_bezier)

npe_arg(d, dense_float, dense_double)
npe_arg(error, double)

npe_begin_code()
// igl::fit_cubic_bezier is hard-coded to double, so for now copy.
Eigen::MatrixXd d_cpy = d.template cast<double>();
std::vector<Eigen::MatrixXd> c_cpy;
igl::fit_cubic_bezier(d_cpy,error,c_cpy);
std::vector<EigenDenseLike<npe_Matrix_d>> c(c_cpy.size());
std::transform (c_cpy.begin(), c_cpy.end(), c.begin(),
[](const Eigen::MatrixXd & ci){ return ci.cast<npe_Scalar_d>();});
// numpyeigen's pybind11 fork `numpy_hacks_stable` is printing "Encapsulate move!"
// https://github.com/fwilliams/numpyeigen/issues/58
return pybind11::detail::type_caster<decltype(c)>::cast(c, pybind11::return_value_policy::move, pybind11::none());

npe_end_code()

17 changes: 9 additions & 8 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import scipy.sparse as csc
import math
import sys
from git import Repo




Expand All @@ -18,14 +20,17 @@


class TestBasic(unittest.TestCase):
test_data_path = None

def setUp(self):
# This is called once for every sub-test.

# Some global datastructures to use in the tests
np.random.seed(42)
if self.test_data_path is None:
self.test_data_path = os.path.join(os.path.dirname(
os.path.realpath(__file__)), "../data/")
# https://stackoverflow.com/a/45230996/148668
self.test_data_path = os.path.join("./data","")
if not os.path.isdir(self.test_data_path):
Repo.clone_from("https://github.com/libigl/libigl-tests-data.git", self.test_data_path)

self.v1, self.f1 = igl.read_triangle_mesh(
os.path.join(self.test_data_path, "bunny_small.off"))
self.v2, self.f2 = igl.read_triangle_mesh(
Expand Down Expand Up @@ -490,7 +495,6 @@ def test_read_dmat(self):
# sparse matrix, no flag attribute
def test_vector_area_matrix(self):
a = igl.vector_area_matrix(self.f)
self.assertEqual(a.dtype, self.f.dtype)
self.assertEqual(a.shape[0], a.shape[1])
self.assertEqual(a.shape[0], self.v.shape[0]*2)

Expand Down Expand Up @@ -2463,8 +2467,5 @@ def test_flip_edge(self):
emap.dtype == self.f1.dtype)
self.assertTrue(np.array(ue2e).dtype == self.f1.dtype)


if __name__ == '__main__':
if len(sys.argv) > 1:
TestBasic.test_data_path = os.path.join(sys.argv.pop(),'')
unittest.main()
8 changes: 7 additions & 1 deletion tutorial/tutorials.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@
"\n",
"import os\n",
"root_folder = os.getcwd()\n",
"#root_folder = os.path.join(os.getcwd(), \"tutorial\")"
"#root_folder = os.path.join(os.getcwd(), \"tutorial\")",
"data_folder = os.path.join(root_folder,\"/data\")\n",
"# pip install gitpython\n",
"from git import Repo\n",
"if not os.path.isdir(data_folder):\n"
" Repo.clone_from(\"https://github.com/libigl/libigl-tutorial-data.git\", data_folder)\n",
"\n"
]
},
{
Expand Down

0 comments on commit facf32e

Please sign in to comment.