Skip to content

Commit aae609e

Browse files
ADD boundaries wrapped method.
1 parent 1df4b7e commit aae609e

File tree

15 files changed

+73
-35
lines changed

15 files changed

+73
-35
lines changed

CMakeLists.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,14 @@ function(add_nanobind_module module_name source_file)
161161
endfunction()
162162

163163
# Add modules
164-
add_nanobind_module(nanobind src/nanobind.cpp)
165-
add_nanobind_module(types_std src/types_std.cpp)
166-
add_nanobind_module(boundaries src/boundaries.cpp)
167-
add_nanobind_module(curvature src/curvature.cpp)
168-
add_nanobind_module(geodistance src/geodistance.cpp)
169-
add_nanobind_module(intersections src/intersections.cpp)
170-
add_nanobind_module(isolines src/isolines.cpp)
171-
add_nanobind_module(massmatrix src/massmatrix.cpp)
172-
add_nanobind_module(meshing src/meshing.cpp)
173-
add_nanobind_module(parametrisation src/parametrisation.cpp)
174-
add_nanobind_module(planarize src/planarize.cpp)
164+
add_nanobind_module(_nanobind src/nanobind.cpp)
165+
add_nanobind_module(_types_std src/types_std.cpp)
166+
add_nanobind_module(_boundaries src/boundaries.cpp)
167+
add_nanobind_module(_curvature src/curvature.cpp)
168+
add_nanobind_module(_geodistance src/geodistance.cpp)
169+
add_nanobind_module(_intersections src/intersections.cpp)
170+
add_nanobind_module(_isolines src/isolines.cpp)
171+
add_nanobind_module(_massmatrix src/massmatrix.cpp)
172+
add_nanobind_module(_meshing src/meshing.cpp)
173+
add_nanobind_module(_parametrisation src/parametrisation.cpp)
174+
add_nanobind_module(_planarize src/planarize.cpp)

docs/examples/boundaries.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
)
4444

4545
for vertices in boundaries:
46+
vertices = list(vertices)
47+
vertices.append(vertices[0])
4648
points = mesh.vertices_attributes("xyz", keys=vertices)
4749
polyline = Polyline(points)
4850
viewer.scene.add(polyline, linecolor=Color.red(), linewidth=3)

src/boundaries.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,16 @@
22

33
using namespace Eigen;
44

5-
std::vector<std::vector<int>>
6-
trimesh_boundaries(
7-
compas::RowMatrixXi F)
8-
{
5+
std::vector<std::vector<int>> trimesh_boundaries(const MatrixXi& F) {
96
std::vector<std::vector<int>> L;
10-
11-
igl::boundary_loop(F, L);
12-
7+
igl::boundary_loop(F, L);
138
return L;
149
}
1510

16-
NB_MODULE(compas_libigl_boundaries, m) {
11+
NB_MODULE(_boundaries, m) {
1712
m.def(
1813
"trimesh_boundaries",
1914
&trimesh_boundaries,
2015
"Compute list of ordered boundary loops for a manifold mesh.",
21-
"F"_a
22-
);
16+
"F"_a);
2317
}

src/compas_libigl/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import compas
3-
from .nanobind import add, __doc__
3+
from ._nanobind import add, __doc__
4+
from .boundaries import trimesh_boundaries
45

56
# from .boundaries import trimesh_boundaries
67
# from .curvature import trimesh_gaussian_curvature, trimesh_principal_curvature
@@ -83,7 +84,7 @@ def get_armadillo():
8384

8485

8586
__all_plugins__ = [
86-
"compas_libigl.nanobind"
87+
"compas_libigl._nanobindcompas_libigl._boundaries",
8788
# "compas_libigl.curvature",
8889
# "compas_libigl.geodistance",
8990
# "compas_libigl.intersections",
@@ -101,7 +102,7 @@ def get_armadillo():
101102
"TEMP",
102103
add,
103104
__doc__,
104-
105+
trimesh_boundaries,
105106
# "get",
106107
# "get_beetle",
107108
# "get_armadillo",

src/compas_libigl/boundaries.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import numpy as np
2+
3+
from compas_libigl import _boundaries
4+
from compas_libigl._types_std import VectorVectorInt
5+
6+
7+
def trimesh_boundaries(M):
8+
"""Compute all (ordered) boundary loops of a manifold triangle mesh.
9+
10+
Parameters
11+
----------
12+
M : (list, list)
13+
A mesh represented by a list of vertices and a list of faces.
14+
15+
Returns
16+
-------
17+
array
18+
The ordered boundary loops of the triangle mesh.
19+
Each loop is a sequence of vertex indices.
20+
21+
Notes
22+
-----
23+
The input mesh should be manifold.
24+
25+
Examples
26+
--------
27+
>>> import compas
28+
>>> import compas_libigl
29+
>>> from compas.datastructures import Mesh
30+
>>> mesh = Mesh.from_off(compas.get("tubemesh.off"))
31+
>>> mesh.quads_to_triangles()
32+
>>> M = mesh.to_vertices_and_faces()
33+
>>> boundaries = compas_libigl.trimesh_boundaries(M)
34+
>>> len(boundaries) == 1
35+
True
36+
37+
"""
38+
V, F = M
39+
F = np.asarray(F, dtype=np.int32)
40+
result: VectorVectorInt = _boundaries.trimesh_boundaries(F)
41+
return [list(loop) for loop in result]

src/curvature.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
void function(const Eigen::MatrixXd& V, const Eigen::MatrixXi& F) {}
44

5-
NB_MODULE(curvature, m) {
5+
NB_MODULE(_curvature, m) {
66

77
m.def(
88
"function_name",

src/geodistance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
void function(const Eigen::MatrixXd& V, const Eigen::MatrixXi& F) {}
44

5-
NB_MODULE(geodistance, m) {
5+
NB_MODULE(_geodistance, m) {
66

77
m.def(
88
"function_name",

src/intersections.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
void function(const Eigen::MatrixXd& V, const Eigen::MatrixXi& F) {}
44

5-
NB_MODULE(intersections, m) {
5+
NB_MODULE(_intersections, m) {
66

77
m.def(
88
"function_name",

src/isolines.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
void function(const Eigen::MatrixXd& V, const Eigen::MatrixXi& F) {}
44

5-
NB_MODULE(isolines, m) {
5+
NB_MODULE(_isolines, m) {
66

77
m.def(
88
"function_name",

src/massmatrix.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
void function(const Eigen::MatrixXd& V, const Eigen::MatrixXi& F) {}
44

5-
NB_MODULE(massmatrix, m) {
5+
NB_MODULE(_massmatrix, m) {
66

77
m.def(
88
"function_name",

0 commit comments

Comments
 (0)