-
Notifications
You must be signed in to change notification settings - Fork 5
/
my_tess_extract_struct.m
70 lines (53 loc) · 2.09 KB
/
my_tess_extract_struct.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
function [sSurf, iSurface] = my_tess_extract_struct( sSurf, StructNames, NewComment )
% TESS_EXTRACT_STRUCT: Extract a few structures from a surface file (based on the "Structures" atlas).
%
% USAGE: [NewSurfaceFile, iSurface] = tess_concatenate(SurfaceFile, StructNames, NewComment='')
%
% INPUT:
% - SurfaceFile : File name of the surface file to process
% - StructNames : Cell-array of structure names to extract from the selected file
% - NewComment : Name of the output surface
% OUTPUT:
% - NewSurfaceFile : Filename of the newly created file
% - iSurface : Index of the new surface file
% Parse inputs
if (nargin < 3) || isempty(NewComment)
NewComment = [];
end
if ischar(StructNames)
StructNames = {StructNames};
end
% ===== LOAD FILE =====
% Progress bar
% Load file
if isempty(sSurf)
return;
end
% Find atlas "Structures"
iAtlas = find(strcmpi({sSurf.Atlas.Name}, 'Structures'));
if isempty(iAtlas)
error('Atlas "Structures" not found in this file.');
end
% Find all the scout names listed in input
[tmp,iScouts] = intersect(lower({sSurf.Atlas(iAtlas).Scouts.Label}), lower(StructNames));
if isempty(iScouts)
error('Requested regions were not found.');
end
% ===== REMOVE VERTICES =====
% Get all the vertices in the selected scouts
iKeepVert = [sSurf.Atlas(iAtlas).Scouts(iScouts).Vertices];
% Get all the vertices to remove
iRemoveVert = setdiff(1:size(sSurf.Vertices,1), iKeepVert);
% Remove vertices
[sSurf.Vertices, sSurf.Faces, sSurf.Atlas] = tess_remove_vert(sSurf.Vertices, sSurf.Faces, iRemoveVert, sSurf.Atlas);
% ===== CREATE NEW STRUCTURE =====
% Comment
if ~isempty(NewComment)
sSurf.Comment = NewComment;
elseif (length(StructNames) == 1)
sSurf.Comment = [sSurf.Comment ' | ' StructNames{1}];
elseif (length(StructNames) == 2) && (length(StructNames{1}) > 2) && (length(StructNames{2}) > 2) && strcmpi(StructNames{1}(1:end-2), StructNames{2}(1:end-2))
sSurf.Comment = [sSurf.Comment ' | ' StructNames{1}(1:end-2)];
else
sSurf.Comment = [sSurf.Comment ' | keep'];
end