Skip to main content
2 of 4
deleted 5 characters in body
Greg Hurst
  • 39.3k
  • 1
  • 101
  • 147

We can call libigl in Python through ExternalEvaluate:

$igl = StartExternalSession[ Association["System" -> "Python", "Evaluator" -> <|"Dependencies" -> {"libigl"}, "EnvironmentName" -> "iglenv"|>]]; ExternalEvaluate[$igl, " import igl import numpy as np import os def compute_uv(filename: str) -> np.ndarray: V, F = igl.read_triangle_mesh(filename) bnd = igl.boundary_loop(F) b = np.array([bnd[0], bnd[len(bnd) // 2]]) bc = np.array([[0.0, 0.0], [1.0, 0.0]]) UV = igl.lscm(V, F, b, bc) return UV[0] "]; 

Right now we have to pass in a file. I tried doing stuff like

def compute_uv(V: np.array, F: np.array) -> np.array:

but I couldn't figure out how to pass in arrays to python as the right type.

pts = Import["/Users/ghurst/Downloads/theX.csv"]; triangles = Import["/Users/ghurst/Downloads/theT.csv"]; Export["temp.obj", MeshRegion[pts, Polygon[triangles]]]; 

And now we get the uv data and plot:

uvs = Normal[ExternalEvaluate[$igl, "compute_uv('temp.obj')"]]; ix = Interpolation[Transpose[{pt[[All, {1, 2}]], uv[[All, 1]]}], InterpolationOrder -> 1]; iy = Interpolation[Transpose[{pt[[All, {1, 2}]], uv[[All, 2]]}], InterpolationOrder -> 1]; ListPlot3D[pt, ViewPoint -> Top, BoxRatios -> Automatic, MeshFunctions -> ({ix[#1, #2] &, iy[#1, #2] &}), Mesh -> 18, MeshShading -> {{Black, Yellow}, {Yellow, Black}}, Method -> {"RotationControl" -> "ArcBall"}, Boxed -> False, Axes -> False] 
Greg Hurst
  • 39.3k
  • 1
  • 101
  • 147