forked from openep/openep-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetClosedSurface.m
More file actions
58 lines (51 loc) · 1.68 KB
/
getClosedSurface.m
File metadata and controls
58 lines (51 loc) · 1.68 KB
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
function tr = getClosedSurface( userdata )
% GETCLOSEDSURFACE Fills all the holes in the userdata surface
%
% Usage:
% tr = getClosedSurface( userdata )
% Where:
% userdata - see importcarto_mem
% tr - a triRep object
%
% GETCLOSEDSURFACE Returns a new surface representation of the anatomical
% model with all the holes in the mesh filed. Closes the surface by the
% following algorithm. First, every complete free boundary is identified.
% Second, the barycentre of the free boundary is identified. Third, a
% triangulation is created covering this hole. Finally, the additional
% triangles are added to the TriRep.
%
% Author: Steven Williams (2020) (Copyright)
% SPDX-License-Identifier: Apache-2.0
%
% Modifications -
%
% Info on Code Testing:
% ---------------------------------------------------------------
% tr = getClosedSurface( userdata )
% ---------------------------------------------------------------
%
% ---------------------------------------------------------------
% code
% ---------------------------------------------------------------
% get the trirep
tr = userdata.surface.triRep;
% get all the free boundaries
[ FF, ~ ] = freeBoundaries( tr );
% step through each free boundary
for i = 1:numel(FF)
% get the points of this boundary
coords = freeBoundaryPoints(FF{i}, tr);
% find the centre of these points
centre = nanmean(coords, 1);
% create a triRep of the hole
X = [centre; coords];
numpts = size(X, 1);
A = ones(numpts-1,1);
B = [2:numpts]';
C = [[3:numpts]' ; 2];
TRI = [A B C];
newtr = TriRep(TRI, X(:,1), X(:,2), X(:,3));
% add this new triRep to the origianl triRep
tr = addtrirep(tr, newtr);
end
end