Skip to content

Commit 54af4fa

Browse files
author
Steffen Schuler
committed
Small improvements to...
remeshTriangleMesh, tetrahedralizeTriangleMesh, vtkStreamTracer
1 parent 265fa59 commit 54af4fa

4 files changed

+33
-19
lines changed

MATLAB/remeshTriangleMesh.m

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1-
function vtk = remeshTriangleMesh(vtk, numPoints, creaseAngle)
1+
function vtk = remeshTriangleMesh(vtk, numPoints, extraFlags)
22

3-
if nargin < 3
4-
creaseAngle = [];
3+
if nargin < 3 || isempty(extraFlags)
4+
extraFlags = '';
5+
end
6+
if ~isempty(numPoints)
7+
extraFlags = sprintf('%s -v %i', extraFlags, round(numPoints));
58
end
69

710
% make sure the source mesh contains at least 4 times as many triangles as
811
% the target mesh (needed for good results with Instant Meshes)
912
numPointsSource = size(vtk.cells,1);
1013
numSubdiv = max(1-floor(log(numPointsSource/numPoints)/log(4)),0);
1114
if numSubdiv
12-
vtk = vtkLinearSubdivisionFilter(vtk, numSubdiv);
15+
try
16+
vtk = vtkLinearSubdivisionFilter(vtk, numSubdiv);
17+
catch
18+
warning('Skipping subdivision before remeshing.');
19+
end
1320
end
1421

1522
tmpfile = [tempname '.ply'];
@@ -21,17 +28,14 @@
2128
instantmeshes = '/Applications/Instant Meshes.app/Contents/MacOS/Instant Meshes';
2229
end
2330
if ~exist(instantmeshes, 'file')
24-
instantmeshes = '/Volumes/ServerApps/Instant Meshes.app/Contents/MacOS/Instant Meshes';
31+
instantmeshes = '/Users/ss029/Applications/Instant Meshes.app/Contents/MacOS/Instant Meshes';
32+
% instantmeshes = '/Volumes/ServerApps/Instant Meshes.app/Contents/MacOS/Instant Meshes';
2533
end
2634
if ~exist(instantmeshes, 'file')
2735
error('Instant Meshes could not be found.');
2836
end
2937

30-
if isempty(creaseAngle)
31-
system(sprintf('''%s'' %s -v %i -o %s -r 6 -p 6 -S 0 -d', instantmeshes, tmpfile, round(numPoints), tmpfile));
32-
else
33-
system(sprintf('''%s'' %s -v %i -o %s -r 6 -p 6 -S 0 -d -c %.1f', instantmeshes, tmpfile, round(numPoints), tmpfile, creaseAngle));
34-
end
38+
system(sprintf('''%s'' %s -o %s -r 6 -p 6 -S 0 -d %s', instantmeshes, tmpfile, tmpfile, extraFlags));
3539

3640
vtk = vtkRead(tmpfile);
3741
delete(tmpfile);

MATLAB/tetrahedralizeTriangleMesh.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
optimizeNetgen = false;
55
end
66
if nargin < 3 || isempty(optimizeThreshold)
7-
optimizeThreshold = 0.3;
7+
optimizeThreshold = 1;
88
end
99
if nargin < 2 || isempty(relativeEdgeLength)
1010
relativeEdgeLength = 1;

MATLAB/tetrahedralizeTriangleMesh_twoSurfaces.m

+18-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
function vtk_vol = tetrahedralizeTriangleMesh_twoSurfaces(vtk_inner_sur, vtk_outer_sur, relativeEdgeLength, optimizeThreshold)
1+
function vtk_vol = tetrahedralizeTriangleMesh_twoSurfaces(vtk_inner_sur, vtk_outer_sur, relativeEdgeLength, optimizeThreshold, optimizeNetgen)
22

3-
if nargin < 4
4-
optimizeThreshold = 0.3;
3+
if nargin < 5
4+
optimizeNetgen = false;
55
end
6-
if nargin < 3
6+
if nargin < 4 || isempty(optimizeThreshold)
7+
optimizeThreshold = 1;
8+
end
9+
if nargin < 3 || isempty(relativeEdgeLength)
710
relativeEdgeLength = 1;
811
end
912

@@ -25,11 +28,20 @@
2528
gmsh = 'gmsh';
2629
[noAliasFound,~] = system(sprintf('which %s', gmsh));
2730
if noAliasFound
31+
gmsh = '/Applications/Gmsh.app/Contents/MacOS/gmsh';
32+
end
33+
if ~exist(gmsh, 'file')
2834
gmsh = '/Volumes/ServerApps/Gmsh.app/Contents/MacOS/gmsh';
2935
end
36+
if ~exist(gmsh, 'file')
37+
error('Gmsh could not be found.');
38+
end
3039

31-
system(sprintf('%s %s -3 -order 1 -format vtk -v 4 -clmax %.3f -optimize_threshold %.3f', gmsh, geofile, clmax, optimizeThreshold));
32-
% system(sprintf('%s %s -3 -order 1 -format vtk -v 4 -clmax %.3f -optimize_netgen -optimize_threshold %.3f', gmsh, geofile, clmax, optimizeThreshold));
40+
if optimizeNetgen
41+
system(sprintf('%s %s -3 -order 1 -format vtk -v 4 -clmax %.3f -optimize_netgen -optimize_threshold %.3f', gmsh, geofile, clmax, optimizeThreshold));
42+
else
43+
system(sprintf('%s %s -3 -order 1 -format vtk -v 4 -clmax %.3f -optimize_threshold %.3f', gmsh, geofile, clmax, optimizeThreshold));
44+
end
3345

3446
vtkfile = [tmpdir '/' geoname '.vtk'];
3547
vtk_vol = vtkRead(vtkfile);

vtkStreamTracer/vtkStreamTracer.cxx

-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
4949

5050
///// Apply vtkGradientFilter and vtkStreamTracer /////
5151

52-
if(pointSet1->GetDataObjectType() == VTK_POLY_DATA)
53-
mexErrMsgTxt("vtkStreamTracer requires an unstructured grid as first input.");
5452
if(pointSet2->GetDataObjectType() != VTK_POLY_DATA)
5553
mexErrMsgTxt("vtkStreamTracer requires poly data as second input. Incompatible cell(s) found.");
5654

0 commit comments

Comments
 (0)