GithubHelp home page GithubHelp logo

libigl / libigl-python-bindings Goto Github PK

View Code? Open in Web Editor NEW
295.0 13.0 58.0 72.9 MB

libigl python bindings

Home Page: https://libigl.github.io/libigl-python-bindings/

License: GNU General Public License v3.0

CMake 1.68% Python 13.87% Mako 0.10% C++ 63.97% Jupyter Notebook 20.36% Shell 0.01%
conda python geometry-processing easy-to-use fast

libigl-python-bindings's Introduction

libigl Python Bindings

PyPI version buildwheels

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.

These bindings are still under active development and should still be considered alpha quality. We encourage users to post issues so we can improve the bindings!

Installation

python -m pip install libigl

If you wish to install the current development code, you can compile the library from scratch. Clone this repo and issue

python -m pip install ./
  • A tutorial on how to use the bindings can be found here
  • A function reference can be found here

Compiling and modifying the bindiings

After installing numpy & scipy and then cloning this repository, you can compile the bindings from scratch by running:

python setup.py develop

or

python setup.py build --debug develop

for debug compilation. This command will make the package igl available for import in the current shell.

To run the tests:

python setup.py test

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

License

Like libigl, the wrapper source code is licensed under MPL2. Code included via the copyleft and restricted sub-directories may have more restrictive licenses.

libigl-python-bindings's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

libigl-python-bindings's Issues

Removing python bindings?

Hi,

Is it possible to disable the building of the python bindings when running cmake?
I've tried to read through the CMakeLists.txt but I can't spot the option.

Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

applying principal curvature using the command:

v1, v2, k1, k2 = igl.principal_curvature(v, f)

but I'm getting the error:

Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

v are in this format:

[[ 56.09962091 -50.70284252 74.43154099] [ -81.66580634 31.11304083 -96.20692408] [ -63.04710378 20.05579935 -73.14550082] [ -74.68074967 -46.74132945 -125.53300517] [ -82.86191115 138.50006684 4.60130311] [ 73.56470904 -118.43376944 -71.32137773] [ -4.92233919 -159.90066014 -27.83674232] [ -75.62714176 28.23358687 -78.90299045] [ -81.53924671 121.62689731 52.15735424] [-119.16738782 84.67573099 64.81959086] [ 115.65943449 -56.67805099 -75.6967053 ] [ -80.48401851 20.7915225 -68.63223673] [-142.29170674 -108.38603014 -36.96969018] [ 98.64894284 50.12674432 58.67070153] [ -28.13477169 83.20510976 107.46559988] [-144.66277425 68.30107727 49.66061848] [ 29.54206082 143.22321321 -55.06127287] [ 4.90252259 69.73588386 -132.70296423] [-102.13321016 -67.17764799 -111.93319288] [-166.21385932 13.10544553 -15.81392708] [ -38.58577129 144.34755316 28.37260346] [ 56.31233339 -61.38765368 64.17787867] [ -90.93979735 0.38020425 -79.89511472] [ -96.76884596 21.71346256 -64.96037686] ... [ 74.58292415 -124.48759489 -5.62172548] [-174.78859069 -11.99712938 -11.00922369] [ 87.27561955 69.94477948 -108.91576776] [ 117.33246385 -69.39698438 16.03177459] [ 103.92915334 60.71174874 -89.2834191 ] [ 11.60050005 104.17767979 85.44092131] [ 45.99420387 -75.99419561 -145.5603443 ] [ -75.78031523 8.32746322 -78.40591649]

and f are:

[[ 0 165 425] [ 0 836 165] [ 0 128 836] [ 0 107 128] [ 0 542 107] .. [ 0 425 164] [425 120 834] [425 165 120] [165 726 120] [165 836 726]

As well if I used the gaussian curvature it prints out the results but with giving nan values!!!

[ nan 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 3.15422311 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 3.14159265 nan 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531 6.28318531

as well as the error in the title.
I guess it's important to mention that I'm extracting curvature on feature points of the mesh, not the complete vertices.
Please any help!

505_MIQ bindings

Hi all. Are there already bindings for all the functions used in example 505_MIQ of libigl's tutorials section? I would like to try it out in Python. Secondly, is there a forum where I could possibly follow up on questions like this? Many thanks!

problems with in types

Traceback (most recent call last):
  File "tests/test_basic.py", line 706, in test_arap2
    v0 = igl.harmonic_weights(v, f.astype(np.int32), b, np.asfortranarray(circle_b), 1)
ValueError: Invalid type (int, Row Major) for argument 'b'. Expected it to match argument 'f' which is of type (long, Row Major).
Traceback (most recent call last):
  File "tests/test_basic.py", line 145, in test_read_triangle_mesh_type_issue
    d = igl.exact_geodesic(v, f, vs, vt)
ValueError: Invalid type (long, Row Major) for argument 'vs'. Expected it to match argument 'f' which is of type (longlong, Row Major).
  File "tests/test_basic.py", line 748, in test_lscm
    success, uv = igl.lscm(self.v1, self.f1, b, bc)
ValueError: Invalid type (long, Row Major) for argument 'b'. Expected it to match argument 'f' which is of type (int, Row Major).

how to save resulting mesh after plot()

hi

I am following the tutorial provided on the website and I am trying to save the mesh after the plot() function, how do I save the mesh after applying transformations

ideally save the file in the format save(v,f,c) instead of having a .html output

signed_distance and barycentric_coordinates_tri crash kernel

I have now a problem with signed_distance() which crashes my jupyter kernel for some points. I don't get any error message I only get "The kernel appears to have died. It will restart automatically".
And for barycentric_coordinates_tri() it always crashes the kernel, even for the points for which I could identify the closest point and triangle they belong to with signed_distance().
Do you have any idea about what could be the problem ?
Thanks for your help

Problem with ARAP parameterization code (Chapter 4 in the tutorial)

I'm trying to run the code in chapter 4, for arap parameterization. All this first part is ok:

v, f  = igl.read_triangle_mesh(os.path.join(root_folder, "data", "camelhead.off"))
## Find the open boundary
bnd = igl.boundary_loop(f)
## Map the boundary to a circle, preserving edge proportions
bnd_uv = igl.map_vertices_to_circle(v, bnd)
## Harmonic parametrization for the internal vertices
uv = igl.harmonic_weights(v, f, bnd, bnd_uv, 1)
arap = igl.ARAP(v, f, 2, np.zeros((0)))

However, this last line fails:

uva = arap.solve(np.zeros((0, 0)), uv)

This is the error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-162-15f3df1c16bf> in <module>
----> 1 uva = arap.solve(np.zeros((0, 0)), uv)

ValueError: Parameter bc has invalid shape at dimension 1, expected bc.shape[1] = 2 but got bc.shape = [0, 0]

Thanks in advance for your help!

missing important bindings

  • HalfEdgeIterator.h
  • hessian_energy.h
  • min_quad_with_fixed.h
  • shapeup.h
  • slice_tets.h
  • offset_surface
  • miq
  • marching tets

can't access signed_distance function

Hi !
I have successfully installed the librairy with conda and could use without any problem, read_triangle_mesh() or adjacency_matrix() but I can't find signed_distance()
Is there any trick to be able to use this function ?
Thanks for your help !
Céline

Wrong format problem

v, f = igl.read_triangle_mesh("data/armadillo.obj")
#f = f.astype("int64") 

vs = np.array([0])
vt = np.arange(v.shape[0])

d = igl.exact_geodesic(v, f, vs, vt)

fails when f is not converted to int64. Reading function should probably return consistent types.

Ambient Occlusion - detecting outside faces

So I've combined multiple stl files (10 by 10 by 10mm cubes) to one big mesh (20 by 20 by 20mm cube). Now I'm trying to detect the outside faces of this new mesh so that I can remove everything that is on the inside.

I thought it should work with the ambient occlusion function so that every face with a brightness below a certain threshold gets removed. I came up with this code:

import igl
import numpy as np
from meshplot import plot, subplot, interact
import os
import math

v, f = igl.read_triangle_mesh("cube.stl")
print("Vertices: ", len(v))
print("Faces: ", len(f))

n = igl.per_vertex_normals(v, f)
ao = igl.ambient_occlusion(v, f, v, n, 5)
newV = []
newF = []
z = 0.8 #brightness threshold
for x in range(3,len(v),3):
    if ao[x]<=z or ao[x]<=z or ao[x]<=z: #adds the faces with its verteces with brightness above z to 'newV' and 'newF'
        #each face has 3 verteces
        newV.append(v[x-3]) #verex1
        newV.append(v[x-2]) #verex2
        newV.append(v[x-1]) #verex3
        newF.append(f[int(x/3)-1]) #face
plot(np.array(newV),np.array(newF))

Unfortunately it also detects faces that are on the inside as bright, as you can see in this picture

The mesh I'm importing (my 20 by 20 by 20mm cube) looks like this

So what am I doing wrong? Because when calculating the brightness and then plotting the mesh it looks pretty good, but it somehow detects the inside faces as bright when running my code :/

problematic bindings

  • marching_cubes - This function takes a grid array in a really annoying format because Eigen only supports 2-tensors. Ideally you should be able to pass in data stored in a 3D arrray.

missing tests

  • WARNING: Test for function biharmonic_coordinates missing.
  • WARNING: Test for function bijective_composite_harmonic_mapping missing.
  • WARNING: Test for function bijective_composite_harmonic_mapping_with_steps missing.
  • WARNING: Test for function harmonic_weights_from_laplacian_and_mass missing.
  • WARNING: Test for function harmonic_weights_integrated missing.
  • WARNING: Test for function harmonic_weights_integrated_from_laplacian_and_mass missing.
  • WARNING: Test for function harmonic_weights_uniform_laplacian missing.
  • WARNING: Test for function sparse missing.
  • WARNING: Test for function spsolve missing.
  • WARNING: Test for function unproject_in_mesh missing.
  • WARNING: Test for function unproject_onto_mesh missing.

where is tetrahedralize function in conda?

Describe your question

I am using ibigl with conda and I want to use the tetrahedralize function:

V, T, _ = igl.tetrahedralize(V, F, str(options))

However, I keep getting this error message:

AttributeError: module 'igl' has no attribute 'tetrahedralize'

Suggesting that the function does not exist in the python-conda version of libigl. Anaconda tells me I am using version 0.4.1 which seems to be the most recent version.

Is there a way to fix this?

Check all that apply (change to [x])

  • Windows
  • [ x] macOS
  • Linux

test_ambient_occlusion

ambient_occlusion has a strange output.

the result matrix s is empty.

Could it be because of the input?

ARAP energy setting

I'm trying to find where in the Python bindings I can set the energy type for the ARAP solver parametrization. I see it noted in the tutorial, but it is commented out C code, and arap_data is never actually used. Is it possible to set this anywhere in the Python bindings?

Remove COMISO

We need comiso for the NROSY.

This can be replaced with an easier implementation, dependency free

restore removed files

  • circulation
  • cut_mesh_from_singularities
  • cut_mesh
  • average_onto_faces
  • flip_avoiding_line_search

others?

problematic tests

  • bijective_composite_harmonic_mapping (and bijective_composite_harmonic_mapping_with_steps) have a wierd assertion failure in igl for a matrix not being symmetric

  • circulation missing input data, check here

  • flip_avoiding_line_search wierd data: cur_v, dst_v, energy, cur_energy

random_points_on_mesh returns out of bounds face_ids

random_points_on_mesh returns face ids that equal the total face count
A similar issue exists in c++ libigl: libigl/libigl#1531

Reproducing:

import igl

verts, faces = igl.read_triangle_mesh('D:/Data/mesh.obj')
num_samples = 1000
print(len(faces))

for i in range(100):
    _, face_ids = igl.random_points_on_mesh(num_samples, verts, faces)
    for fid in face_ids:
        if not (fid < len(faces) and fid >= 0):
            print('Failed try {} with face {}'.format(i, fid))

Output:

14886
Failed try 24 with face 14886
Failed try 31 with face 14886
Failed try 58 with face 14886
Failed try 62 with face 14886

System info:
igl 2.2.0
Python 3.6
Windows 10

"Error: Numerical issue" on LSCM

I'm trying to flatten a very simple but large mesh and cannot seem to get LSCM to work, while ARAP returns a tiny 5px circle. I'm not sure what I'm misunderstanding, but I'm thinking it might be related to the size of the mesh. LSCM errors out with a "Error: Numerical issue." in the console.

Here's a test mesh:
testtri.zip

LSCM attempt:

v, f = igl.read_triangle_mesh('data/2020-06-10/testtri.stl')
bnd = igl.boundary_loop(f)
b = np.array([2, 1])
b[0] = bnd[0]
b[1] = bnd[int(bnd.size / 2)]
bc = np.array([[0.0, 0.0], [1.0, 0.0]])
_, uv = igl.lscm(v, f, b, bc)
print(_, uv)

gives failure to converge (and console error):

False []

Similarly, ARAP pretty much fails:

bnd_uv = igl.map_vertices_to_circle(v, bnd)
uvh = igl.harmonic_weights(v, f, bnd, bnd_uv, 1)
arap = igl.ARAP(v, f, 2, np.zeros((0)))
uva = arap.solve(np.zeros((0, 0)), uvh)
print(uva)

giving tiny values:

[[-2.33385435e-310 -2.33385435e-310]
 [-3.46291313e-310 -3.46291313e-310]
 [-2.33385435e-310 -2.33385435e-310]
 ...
 [-1.90734863e-006  9.53674316e-007]
 [-1.90734863e-006  9.53674316e-007]
 [-6.71929278e-322  3.35964639e-322]]

Additionally, I get a seg fault on igl.principal_curvature.

Are there set memory limits or size limits for these functions (my computer has 192GB of RAM, so that's not it)? If so, how can I resize? I've tried decimation, but it ends up punching holes in the mesh.

Interface (buttons/picking vertices)

Hey all,

The new python bindings looks awesome!
It might be a pretty dumb question, but you removed the old viewer from the newer python bindings right? Is there still a way to pick vertices, and add a menu? Some easy way to get most/all functionality available in the C++ code or old python version?

Thanks!

'module' object has no attribute 'point_mesh_squared_distance'

Hi,

I installed the igl python binding using conda, and trying to use the function 'point_mesh_squared_distance' like this:
points_to_mesh_dist1, _, _ = igl.point_mesh_squared_distance(cad_v, scan_v, scan_f)
But I am getting the following error:
AttributeError: 'module' object has no attribute 'point_mesh_squared_distance'.
At the same time, I am able to access the other function such as 'read_triangle_mesh'.

Please help me. Thanks in advance!

ValuError for shape_diameter_function

(10242, 3) (20351, 4)


ValueError Traceback (most recent call last)
in
1 print(vertices.shape, faces.shape)
2 sdf = igl.shape_diameter_function(v=vertices, f=faces, p=vertices,
3 n=np.float32(np.array([[1., 0., 0.]])).repeat(10242,0),
----> 4 num_samples=10242)

ValueError: Invalid mesh faces, f must have shape [#faces, 4] but got f.shape = [20351, 4]

Boundary loop c++ equivalent

Hello,

Is there a reason a c++ equivalent to the boundary_loop function is not present in python bindings which returns the index's of all the loops? E.g.,

For c++ equivalent of this function (Implementation) is missing in python bindings

 template <typename DerivedF, typename Index>
  IGL_INLINE void boundary_loop(
    const Eigen::MatrixBase<DerivedF>& F, 
    std::vector<std::vector<Index> >& L);

only c++ equivalent of

template <typename DerivedF, typename DerivedL>
  IGL_INLINE void boundary_loop(
    const Eigen::MatrixBase<DerivedF>& F, 
    Eigen::PlainObjectBase<DerivedL>& L);

is provided in python bindings here :

igl::boundary_loop(f, l);

Please put this on PyPi and make binary wheels

This repository installs fine on my mac via pip:

pip3 install 'git+https://github.com/libigl/libigl-python-bindings/#egg=pyigl'

Can you please add it to PyPI and also make binary wheels available? It took a long time to compile. Also, it should specify that numpy and scipy are dependencies. In a clean environment, the installation failed (after a long compile):

$ python3 -m venv .venv
$ . .venv/bin/activate
$ pip3 install 'git+https://github.com/libigl/libigl-python-bindings/#egg=pyigl'
...
ModuleNotFoundError: No module named 'numpy'

I will open a pull request to add install_requires=[ 'numpy', 'scipy' ] to setup.py's setup() function.

handle assertions

one option is to replace assertions with exceptions, we need to verify performances

principal_curvature crash

Hello all,

I would like to use the python binding to compute mean curvatures of a point cloud.

However, when I go through this tutorial with the bunny point cloud, I find the function principal_curvature() always make the python kernel crash while gaussian_curvature() works properly.

I use the same codes as the Tutorial-igl, i.e:
v, f = igl.read_triangle_mesh(os.path.join(root_folder, "bunny.off")) v1, v2, k1, k2 = igl.principal_curvature(V, F)
I tried with other point clouds, such as the 4 points in the tutorial but it does not work either.

So, I was wondering how I could use the function to compute curvatures correctly.

My system information:
Ubuntu ---- 18.04
python ---- 3.7.6
igl ---- 0.4.1 py37h6dc7ae4_0 conda-forge (install with : conda install -c conda-forge igl)

Thank you very much for your time.

Best regards,

ARAP problem

Hello, I want to know if there is a limit on the number of iterations ( like the variation max_iter ).

Because I saw the code // Initialize ARAP arap_data.max_iter = 100;
in libigl/tutorial/503_ARAPParam/main.cpp, and I didn't see it in python codes.

So if the max_iter exists in ARAP (python), I want to know how to change it.
Thanks!!!

Feature Vector Visualizing and Matching

Hi,
Thank you for this efficient library,

Kindly I have a question please,
I'm trying to work on key points of a mesh, in order to faster the work, what I checked is that for example, I have to give all vertices and faces in order to obtain principal_curvature, is there any way to get for only my desired keypoints(interest points: vertices) from the mesh.

Second, supposing that I'm trying to make a feature vector not only one feature for the point, I mean instead of having for example value [0.342] for vertex [i] I will have vector [0.324 0.1 0.276] for vertex[i], how I may visualize this feature vector?

and the last question please: If I have 2 meshes and I would like to plot them as well plot the keypoints on them, visualizing the matching that is obtained for example using Euclidean distance, is it possible using your library?

Thank you

Autoconversion from int->double

Running

v, f = igl.read_triangle_mesh("data/bunny.obj")
n = igl.per_face_normals(v, f, np.array([0,0,0]))

produces the error ValueError: Invalid type (long, Col Major) for argument 'z'. Expected it to match argument 'v' which is of type (double, Row Major). Can we convert int arrays and remove/fix the misleading error message about the col major (in this case the array is col and row major).

Wrong return types

vc, fc = igl.read_triangle_mesh("data/camelhead.off")
bnd = igl.boundary_loop(fc)
bnd_uv = igl.map_vertices_to_circle(vc, bnd)

# bnd_uv = np.ascontiguousarray(bnd_uv)
uv = igl.harmonic_weights(vc, fc, bnd, bnd_uv, 1)

gives the error: ValueError: Invalid type (double, Col Major) for argument 'bc'. Expected it to match argument 'v' which is of type (double, Row Major). . Converting the array with numpy (see commented out function) works.

ARAP data member access

Is it possible to enable the access of data members of ARAP, e.g., the "max_iter," for better control?

Example error & plot problem

Hi i was trying some of your examples in the tutorial and unfortunately got some errors:

Module 'igl' has no 'read_triangle_mesh' member

And

anaconda3\lib\site-packages\meshplot\plot.py", line 93, in plot
display(view._renderer)
NameError: name 'display' is not defined

Do you have any idea on how i could get this running? :)

test_circulation

circulation not tested since it requires some adjacency input we dont have

average_onto_faces

The bindings compile and link. When run i get this wierd error:

ImportError: dlopen(.../python/igl/pyigl.cpython-36m-darwin.so, 2): Symbol not found: __ZN3igl18average_onto_facesIN5Eigen3MapINS1_6MatrixIiLin1ELin1ELi0ELin1ELin1EEELi16ENS1_6StrideILi0ELi0EEEEENS2_INS3_IdLin1ELin1ELi0ELin1ELin1EEELi16ES6_EES8_EEvRKNS1_10MatrixBaseIT_EERKNSA_IT0_EERNS1_15PlainObjectBaseIT1_EE
Referenced from: .../python/igl/pyigl.cpython-36m-darwin.so

This is now "fixed" by copy pasting the few lines of average_onto_faces.cpp in igl to the binding code

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.