-
Notifications
You must be signed in to change notification settings - Fork 98
/
ea_concatfv.m
90 lines (78 loc) · 2.44 KB
/
ea_concatfv.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
function afv=ea_concatfv(fv,usecork,reduce)
if ~exist('reduce','var')
reduce=0;
end
if ~exist('usecork','var')
usecork=0;
end
if isa(fv, 'matlab.graphics.primitive.Surface')
fv = arrayfun(@(x) surf2patch(x,'triangles'), fv);
end
dataTrimmed = 0;
for f=1:length(fv)
if size(fv(f).vertices, 1) < size(fv(f).facevertexcdata, 1)
dataTrimmed = 1;
fv(f).facevertexcdata = fv(f).facevertexcdata(1:size(fv(f).vertices, 1), :);
end
end
if dataTrimmed
ea_cprintf('CmdWinWarnings', '\nNum of vertices doesn''t match facevertexcdata!\n');
end
if reduce
ea_dispercent(0,'Reducing patch');
for f=1:length(fv)
kfv=reducepatch(fv(f),reduce,'fast');
[~,ic]=ismember(kfv.vertices,fv(f).vertices,'rows');
kfv.facevertexcdata=fv(f).facevertexcdata(ic,:);
fv(f)=kfv;
ea_dispercent(f/length(fv));
end
ea_dispercent(1,'end');
end
if ~usecork
vertlen=cellfun(@length,{fv.vertices});
facelen=cellfun(@length,{fv.faces});
if isfield(fv,'facevertexcdata')
facecollen=cellfun(@length,{fv.facevertexcdata});
end
afv.faces=zeros(sum(facelen),3);
afv.vertices=zeros(sum(vertlen),3);
foffset=1;
voffset=1;
fcoffset=1;
fprintf('\n\n');
ea_dispercent(0,'Concatenating patch');
for f=1:length(fv)
fsize=size(fv(f).faces,1);
vsize=size(fv(f).vertices,1);
afv.faces(foffset:foffset+fsize-1,:)=...
fv(f).faces(:,1:3)+voffset-1;
afv.vertices(voffset:voffset+vsize-1,:)=...
fv(f).vertices;
foffset=foffset+fsize;
voffset=voffset+vsize;
if isfield(fv(f),'facevertexcdata')
if size(fv(f).facevertexcdata,1)<size(fv(f).facevertexcdata,2)
fv(f).facevertexcdata=fv(f).facevertexcdata';
end
fcsize=size(fv(f).facevertexcdata,1);
fcdim=size(fv(f).facevertexcdata,2);
if ~isfield(afv,'facevertexcdata')
afv.facevertexcdata=zeros(sum(facecollen),fcdim);
end
afv.facevertexcdata(fcoffset:fcoffset+fcsize-1,:)=...
fv(f).facevertexcdata;
fcoffset=fcoffset+fcsize;
end
ea_dispercent(f/length(fv));
end
ea_dispercent(1,'end');
else
for f=1:length(fv)
if f==1
afv=fv(1);
else
[afv.vertices,afv.faces]=surfboolean(fv(f).vertices,fv(f).faces,'xor',afv.vertices,afv.faces);
end
end
end