Skip to content

Commit e2ea10d

Browse files
ADD massmatrix.
1 parent f1efd89 commit e2ea10d

File tree

5 files changed

+60
-14
lines changed

5 files changed

+60
-14
lines changed

environment.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
name: compas_libigl-dev
12
channels:
23
- conda-forge
4+
- defaults
35
dependencies:
4-
- python>=3.9
5-
- pip>=19.0
6-
- git
7-
- cmake>=3.14
6+
- python <=3.12
7+
- pip
8+
- cmake
89
- compas
9-
- invoke
1010
- pip:
11-
- -e .[dev]
11+
- -r requirements-dev.txt
12+
- .

src/compas.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040

4141
#include <igl/isolines.h>
4242

43+
#include <igl/massmatrix.h>
44+
4345
#include <igl/map_vertices_to_circle.h>
4446
#include <igl/harmonic.h>
4547
#include <igl/doublearea.h>

src/compas_libigl/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
from .geodistance import trimesh_geodistance
77
from .intersections import intersection_ray_mesh, intersection_rays_mesh
88
from .isolines import trimesh_isolines, groupsort_isolines
9+
from .massmatrix import trimesh_massmatrix
910

10-
11-
# from .massmatrix import trimesh_massmatrix
1211
# from .meshing import trimesh_remesh_along_isoline
1312
# from .parametrisation import trimesh_harmonic, trimesh_lscm
1413
# from .planarize import quadmesh_planarize
@@ -89,7 +88,7 @@ def get_armadillo():
8988
"compas_libigl.geodistance",
9089
"compas_libigl.intersections",
9190
"compas_libigl.isolines",
92-
# "compas_libigl.massmatrix",
91+
"compas_libigl.massmatrix",
9392
# "compas_libigl.meshing",
9493
# "compas_libigl.parametrisation",
9594
# "compas_libigl.planarize",
@@ -113,7 +112,7 @@ def get_armadillo():
113112
"intersection_rays_mesh",
114113
"trimesh_isolines",
115114
"groupsort_isolines",
116-
# "trimesh_massmatrix",
115+
"trimesh_massmatrix",
117116
# "trimesh_remesh_along_isoline",
118117
# "trimesh_harmonic",
119118
# "trimesh_lscm",

src/compas_libigl/massmatrix.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import numpy as np
2+
from compas.plugins import plugin
3+
4+
from compas_libigl import _massmatrix
5+
6+
7+
@plugin(category="trimesh")
8+
def trimesh_massmatrix(M):
9+
"""Compute massmatrix on a triangle mesh using a scalarfield of data points
10+
assigned to its vertices.
11+
12+
Parameters
13+
----------
14+
M : tuple or :class:`compas.datastructures.Mesh`
15+
A mesh represented by a list of vertices and a list of faces
16+
or by a COMPAS mesh object.
17+
18+
Returns
19+
-------
20+
array
21+
The mass per vertex.
22+
23+
Examples
24+
--------
25+
>>> import compas
26+
>>> import compas_libigl
27+
>>> from compas.datastructures import Mesh
28+
>>> mesh = Mesh.from_off(compas.get("tubemesh.off"))
29+
>>> mesh.quads_to_triangles()
30+
>>> M = mesh.to_vertices_and_faces()
31+
>>> mass = compas_libigl.trimesh_massmatrix(M)
32+
33+
"""
34+
V, F = M
35+
V = np.asarray(V, dtype=np.float64)
36+
F = np.asarray(F, dtype=np.int32)
37+
return _massmatrix.trimesh_massmatrix(V, F)

src/massmatrix.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
#include "massmatrix.hpp"
22

3-
void function(const compas::RowMatrixXd& V, const compas::RowMatrixXi& F) {}
3+
Eigen::VectorXd trimesh_massmatrix(compas::RowMatrixXd V, compas::RowMatrixXi F) {
4+
Eigen::SparseMatrix<double> M;
5+
igl::massmatrix(V, F, igl::MASSMATRIX_TYPE_VORONOI, M);
6+
7+
Eigen::VectorXd mass = M.diagonal();
8+
9+
return mass;
10+
}
411

512
NB_MODULE(_massmatrix, m) {
613

714
m.def(
8-
"function_name",
9-
&function,
10-
"Description.",
15+
"trimesh_massmatrix",
16+
&trimesh_massmatrix,
17+
"Compute the mass matrix of a triangle mesh.",
1118
"V"_a,
1219
"F"_a);
1320
}

0 commit comments

Comments
 (0)