added conversion helpers for matlab
added examples for using the python wrappers in matlab
This commit is contained in:
@@ -1,59 +0,0 @@
|
||||
V = py.igl.eigen.MatrixXd();
|
||||
F = py.igl.eigen.MatrixXi();
|
||||
py.igl.read_triangle_mesh('../tutorial/shared/fertility.off', V, F);
|
||||
|
||||
% Alternative discrete mean curvature
|
||||
HN = py.igl.eigen.MatrixXd();
|
||||
L = py.igl.eigen.SparseMatrixd();
|
||||
M = py.igl.eigen.SparseMatrixd();
|
||||
Minv = py.igl.eigen.SparseMatrixd();
|
||||
|
||||
|
||||
py.igl.cotmatrix(V,F,L)
|
||||
py.igl.massmatrix(V,F,py.igl.MASSMATRIX_TYPE_VORONOI,M)
|
||||
|
||||
py.igl.invert_diag(M,Minv)
|
||||
|
||||
% Laplace-Beltrami of position
|
||||
HN = -Minv*(L*V)
|
||||
|
||||
% Extract magnitude as mean curvature
|
||||
H = HN.rowwiseNorm()
|
||||
|
||||
% Compute curvature directions via quadric fitting
|
||||
PD1 = py.igl.eigen.MatrixXd()
|
||||
PD2 = py.igl.eigen.MatrixXd()
|
||||
|
||||
PV1 = py.igl.eigen.MatrixXd()
|
||||
PV2 = py.igl.eigen.MatrixXd()
|
||||
|
||||
py.igl.principal_curvature(V,F,PD1,PD2,PV1,PV2)
|
||||
|
||||
% Mean curvature
|
||||
H = 0.5*(PV1+PV2)
|
||||
|
||||
viewer = py.igl.viewer.Viewer()
|
||||
viewer.data.set_mesh(V, F)
|
||||
|
||||
% Compute pseudocolor
|
||||
C = py.igl.eigen.MatrixXd()
|
||||
py.igl.parula(H,true,C)
|
||||
|
||||
viewer.data.set_colors(C)
|
||||
|
||||
% Average edge length for sizing
|
||||
avg = py.igl.avg_edge_length(V,F)
|
||||
|
||||
% Draw a blue segment parallel to the minimal curvature direction
|
||||
red = py.iglhelpers.p2e(py.numpy.array([[0.8,0.2,0.2]]))
|
||||
blue = py.iglhelpers.p2e(py.numpy.array([[0.2,0.2,0.8]]))
|
||||
|
||||
viewer.data.add_edges(V + PD1*avg, V - PD1*avg, blue)
|
||||
|
||||
% Draw a red segment parallel to the maximal curvature direction
|
||||
viewer.data.add_edges(V + PD2*avg, V - PD2*avg, red)
|
||||
|
||||
% Hide wireframe
|
||||
viewer.core.show_lines = false
|
||||
|
||||
viewer.launch()
|
||||
@@ -0,0 +1,18 @@
|
||||
%% Launch the external viewer
|
||||
launch_viewer;
|
||||
|
||||
%% Load a mesh in OFF format
|
||||
V = py.igl.eigen.MatrixXd();
|
||||
F = py.igl.eigen.MatrixXi();
|
||||
py.igl.readOFF('../tutorial/shared/beetle.off', V, F);
|
||||
|
||||
%% Scale the x coordinate in matlab
|
||||
V = p2m(V);
|
||||
V(:,1) = V(:,1) * 2;
|
||||
V = m2p(V);
|
||||
|
||||
%% Plot the mesh
|
||||
viewer = py.tcpviewer_single.TCPViewer();
|
||||
viewer.data.set_mesh(V, F);
|
||||
viewer.launch();
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
% Launch the external viewer
|
||||
launch_viewer;
|
||||
|
||||
V = py.igl.eigen.MatrixXd();
|
||||
F = py.igl.eigen.MatrixXi();
|
||||
py.igl.read_triangle_mesh('../tutorial/shared/fertility.off', V, F);
|
||||
|
||||
% Alternative discrete mean curvature
|
||||
HN = py.igl.eigen.MatrixXd();
|
||||
L = py.igl.eigen.SparseMatrixd();
|
||||
M = py.igl.eigen.SparseMatrixd();
|
||||
Minv = py.igl.eigen.SparseMatrixd();
|
||||
|
||||
|
||||
py.igl.cotmatrix(V,F,L);
|
||||
py.igl.massmatrix(V,F,py.igl.MASSMATRIX_TYPE_VORONOI,M);
|
||||
|
||||
py.igl.invert_diag(M,Minv);
|
||||
|
||||
% Laplace-Beltrami of position
|
||||
HN = -Minv*(L*V);
|
||||
|
||||
% Extract magnitude as mean curvature
|
||||
H = HN.rowwiseNorm();
|
||||
|
||||
% Compute curvature directions via quadric fitting
|
||||
PD1 = py.igl.eigen.MatrixXd();
|
||||
PD2 = py.igl.eigen.MatrixXd();
|
||||
|
||||
PV1 = py.igl.eigen.MatrixXd();
|
||||
PV2 = py.igl.eigen.MatrixXd();
|
||||
|
||||
py.igl.principal_curvature(V,F,PD1,PD2,PV1,PV2);
|
||||
|
||||
% Mean curvature
|
||||
H = 0.5*(PV1+PV2);
|
||||
|
||||
viewer = py.tcpviewer_single.TCPViewer();
|
||||
viewer.data.set_mesh(V, F);
|
||||
|
||||
% Compute pseudocolor
|
||||
C = py.igl.eigen.MatrixXd();
|
||||
py.igl.parula(H,true,C);
|
||||
|
||||
viewer.data.set_colors(C);
|
||||
|
||||
% Average edge length for sizing
|
||||
avg = py.igl.avg_edge_length(V,F);
|
||||
|
||||
% Draw a blue segment parallel to the minimal curvature direction
|
||||
red = m2p([0.8,0.2,0.2]);
|
||||
blue = m2p([0.2,0.2,0.8]);
|
||||
|
||||
viewer.data.add_edges(V + PD1*avg, V - PD1*avg, blue);
|
||||
|
||||
% Draw a red segment parallel to the maximal curvature direction
|
||||
viewer.data.add_edges(V + PD2*avg, V - PD2*avg, red);
|
||||
|
||||
% Plot
|
||||
viewer.launch()
|
||||
@@ -0,0 +1,3 @@
|
||||
system('python tcpviewer_single.py&');
|
||||
|
||||
pause(0.1) % Wait a bit for the viewer to start
|
||||
@@ -0,0 +1,19 @@
|
||||
% Converts a Matlab matrix to a python-wrapped Eigen Matrix
|
||||
function [ P ] = m2p( M )
|
||||
if (isa(M, 'double'))
|
||||
% Convert the matrix to a python 1D array
|
||||
a = py.array.array('d',reshape(M,1,numel(M)));
|
||||
% Then convert it to a eigen type
|
||||
t = py.igl.eigen.MatrixXd(a.tolist());
|
||||
% Finally reshape it back
|
||||
P = t.MapMatrix(uint16(size(M,1)),uint16(size(M,2)));
|
||||
elseif (isa(M, 'integer'))
|
||||
% Convert the matrix to a python 1D array
|
||||
a = py.array.array('i',reshape(M,1,numel(M)));
|
||||
% Then convert it to a eigen type
|
||||
t = py.igl.eigen.MatrixXi(a.tolist());
|
||||
% Finally reshape it back
|
||||
P = t.MapMatrix(uint16(size(M,1)),uint16(size(M,2)));
|
||||
else
|
||||
error('Unsupported numerical type.');
|
||||
end
|
||||
@@ -0,0 +1,17 @@
|
||||
% Converts a python-wrapped Eigen Matrix to a Matlab matrix
|
||||
function [ M ] = p2m( P )
|
||||
if py.repr(py.type(P)) == '<class ''igl.eigen.MatrixXd''>'
|
||||
% Convert it to a python array first
|
||||
t = py.array.array('d',P);
|
||||
% Reshape it
|
||||
M = reshape(double(t),P.rows(),P.cols());
|
||||
elseif py.repr(py.type(P)) == '<class ''igl.eigen.MatrixXi''>'
|
||||
% Convert it to a python array first
|
||||
t = py.array.array('i',P);
|
||||
% Reshape it
|
||||
M = reshape(int32(t),P.rows(),P.cols());
|
||||
else
|
||||
error('Unsupported numerical type.');
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
% Load a mesh in OFF format
|
||||
V = py.igl.eigen.MatrixXd();
|
||||
F = py.igl.eigen.MatrixXi();
|
||||
py.igl.readOFF('../tutorial/shared/beetle.off', V, F);
|
||||
|
||||
V
|
||||
|
||||
% Plot the mesh
|
||||
viewer = py.tcpviewer.TCPViewer()
|
||||
viewer.data.set_mesh(V, F)
|
||||
viewer.launch()
|
||||
|
||||
Reference in New Issue
Block a user