-
Notifications
You must be signed in to change notification settings - Fork 71
/
meshresample.m
51 lines (46 loc) · 1.7 KB
/
meshresample.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function [node,elem]=meshresample(v,f,keepratio)
%
% [node,elem]=meshresample(v,f,keepratio)
%
% resample mesh using CGAL mesh simplification utility
%
% author: Qianqian Fang, <q.fang at neu.edu>
% date: 2007/11/12
%
% input:
% v: list of nodes
% f: list of surface elements (each row for each triangle)
% keepratio: decimation rate, a number less than 1, as the percentage
% of the elements after the sampling
%
% output:
% node: the node coordinates of the sampled surface mesh
% elem: the element list of the sampled surface mesh
%
% -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
%
[node,elem]=domeshsimplify(v,f,keepratio);
if(length(node)==0)
warning(['Your input mesh contains topological defects, and the ',...
'mesh resampling utility aborted during processing. Now iso2mesh ',...
'is trying to repair your mesh with meshcheckrepair. ',...
'You can also call this manually before passing your mesh to meshresample.'] );
[vnew,fnew]=meshcheckrepair(v,f);
[node,elem]=domeshsimplify(vnew,fnew,keepratio);
end
[node,I,J]=unique(node,'rows');
elem=J(elem);
saveoff(node,elem,mwpath('post_remesh.off'));
end
% function to perform the actual resampling
function [node,elem]=domeshsimplify(v,f,keepratio)
exesuff=getexeext;
exesuff=fallbackexeext(exesuff,'cgalsimp2');
saveoff(v,f,mwpath('pre_remesh.off'));
deletemeshfile(mwpath('post_remesh.off'));
[status, cmdout]=system([' "' mcpath('cgalsimp2') exesuff '" "' mwpath('pre_remesh.off') '" ' num2str(keepratio) ' "' mwpath('post_remesh.off') '"']);
if(status~=0)
error(sprintf('cgalsimp2 command failed'));
end
[node,elem]=readoff(mwpath('post_remesh.off'));
end