-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotBrain.m
More file actions
163 lines (147 loc) · 5.34 KB
/
plotBrain.m
File metadata and controls
163 lines (147 loc) · 5.34 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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
function [p,boundary_plot,BOUNDARY] = ...
plotBrain(vertices, faces, rois, varargin)
%PLOTBRAIN Wrapper for plotSurfaceROIBoundary
% Syntax
% ---
% plotBrain(vertices, faces, rois, data)
% plotBrain(surface, rois, data)
% plotBrain(___, Name, Value)
% [p,boundary_plot,new_cmap,BOUNDARY,new_climits,orig_data_climits] = plotBrain(___)
%
%
% Description
% ---
% plotBrain(vertices, faces, rois, data) plots a surface patch object by
% creating a surface mesh using `vertices` and `faces`, allocating each vertex
% to a region using `rois`, and plotting each vertex or roi according to a
% colormap.
% plotBrain(surface, rois, data) uses the surface to generate the patch
% object.
% plotBrain(___, Name, Value) specifies additional parameters for plotting.
% [p,boundary_plot,new_cmap,BOUNDARY,new_climits,orig_data_climits] =
% plotBrain(___) returns the objects generated by plotSurfaceRoiBoundary.
%
%
% Examples
% ---
% figure; plotBrain(lh_verts, lh_faces, lh_aparc, 1:34);
% figure; plotBrain(struct('vertices', rh_inflated_verts, 'faces', rh_faces), rh_HCPMMP1, 1:180, 'view', "rm", 'plotSurfaceROIBoundaryOptions', {'midpoint', autumn(10)});
%
%
% Input Arguments
% ---
% vertices - vertex coordinates (matrix)
% V × 3 matrix of xyz coordinates of surface vertices (V is the number of
% vertices).
%
% faces - face allocations (matrix)
% F × 3 matrix, where each row is the vertex IDs that make up each face (F is
% the number of faces).
%
% rois - parcellation aka ROI allocation (vector)
% V × 1 matrix, where each element is the ROI that each vertex is allocated
% to.
%
% data - data to be plotted (vector)
% two options: data for each ROI: R × 1 matrix, where each element is the
% data for each ROI (where R is the number of ROIs); OR
% data for each vertex: V × 1 matrix, where each element is the
% data for each vertex.
%
% surface - surface object containing vertices and faces (struct)
% Struct with at least two fields, `vertices` and `faces`, as above.
%
% Name-Value Arguments
% ---
% plotSurfaceROIBoundaryOptions - plotting options (cell)
% Cell that contains arguments which are passed on to PLOTSURFACEROIBOUNDARY
% without modification. In order, this should contain boundary_method, cmap,
% colorUnknownGrey, linewidth, and climits.
%
% view - view perspective for current axis ("ll" (default)|"lm"|"rl"|"rm"|double)
% Specifies the camera position to view the surface patch plot. Can be either
% a two-letter string (specifying left/right hemisphere and medial/lateral
% view), or a two- or three-element array specifying the line of sight.
%
% camlights - position of camlights ([80,-10;-80,-10] (default)|matrix)
% If particularly desired, the position of the camlights can be specified
% using an nCamlights × 2 matrix, where the two columns represent the x and y
% coordinates of each camlight.
%
%
% Output Arguments
% ---
% p, boundary_plot, new_cmap, BOUNDARY, new_climits, orig_data_climits
% as described in PLOTSURFACEROIBOUNDARY
%
%
% See also
% ---
% plotSurfaceRoiBoundary, VIEW
%
%
% Authors
% ---
% Mehul Gajwani, Monash University, 2023
% TODO : add another wrapper for plotting 4 views in a line or grid (2 flags)
% TODO : add dependencies to MATLAB docstring
%% Prelims
ip = inputParser;
addRequired(ip, 'vertices');
addRequired(ip, 'faces');
addRequired(ip, 'rois');
addOptional(ip, 'data', false);
addParameter(ip, 'view', 'll'); % default view is left lateral
addParameter(ip, 'plotSurfaceROIBoundaryOptions', {'faces', parula(100), 0});
addParameter(ip, 'camlights', [[80, -10]; [-80, -10]]);
addParameter(ip, 'overrideAssertions', false);
parse(ip, vertices, faces, rois, varargin{:});
%% Re-allocate data if first argument is a struct
if ~ip.Results.data | isa(vertices, 'struct') %#ok<OR2>
data = reshape(ip.Results.rois, [], 1);
rois = reshape(ip.Results.faces, [], 1);
faces = ip.Results.vertices.faces;
vertices = ip.Results.vertices.vertices;
else
data = reshape(ip.Results.data, [], 1);
rois = reshape(ip.Results.rois, [], 1);
faces = ip.Results.faces;
vertices = ip.Results.vertices;
end
%% Assertions
if ~ip.Results.overrideAssertions
assert(size(vertices, 1) == size(rois, 1), ...
'vertices and rois are not the same length');
assert(size(vertices, 2) == 3, ...
'vertices needs x, y, z, coordinates');
assert(max(faces(:)) == size(vertices, 1), ...
'faces should use all the vertices');
assert(size(faces, 2) == 3, ...
'each face should have three vertices');
end
%% Do plotting
% use plotSurfaceROIBoundary
[p,boundary_plot,BOUNDARY] = ...
plotSurfaceROIBoundary(...
struct('vertices', vertices, 'faces', faces), rois, data, ...
ip.Results.plotSurfaceROIBoundaryOptions{:});
% beautify axes
axis off; axis tight; axis equal;
% set camlights
camlights = ip.Results.camlights;
for ii = 1:size(camlights, 1)
camlight(camlights(ii, 1), camlights(ii, 2));
end
%% Change view according to flag
if isa(ip.Results.view, 'double')
view(ip.Results.view);
else
switch ip.Results.view
case "lm", view([90 0]);
case "ll", view([-90 0]);
case "rm", view([-90 0]);
case "rl", view([90 0]);
otherwise, view([0 90]); % top view
end
end
end