-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathpresetview.m
145 lines (123 loc) · 4.39 KB
/
presetview.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
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
classdef presetview
properties
name
hotkey
nbrofims = [];
matrix = [];
panelstype = [];
ImageOrientation %(this will only be used if it contains ones and zeros)
ImageType
ImageViewPlane
SequenceName
SeriesDescription
DICOMImageType
IsEmpty %to handle empty frames
IsTimeResolved %(this is not stored, but calculated as TSize>1)
IsSingleSlice %(this not stored but calculated as ZSize==1)
IsCine %(true if returned as cine in findno call)
IsScar %(true if returned as scar in findno call)
IsFlow %(true if returned as flow in findno call)
IsMar %(true if returned as MaR in findno call)
IsPerfusion %(true if returned as Perfusion in findno call) Reserved for future use
IsT2Star %(true if...) Reserved for future use
%Maybe some more deduced image type
end
methods
%-----------------------------------
function v = presetview(nmin,hkeyin)
%-----------------------------------
% Constructor
global DATA SET
if nargin < 2
hkeyin = '';
end
v.name = nmin;
v.hotkey = hkeyin;
v.matrix = DATA.ViewMatrix;
v.panelstype = DATA.ViewPanelsType;
nbrofims = prod(v.matrix); %#ok<*PROP>
v.nbrofims = nbrofims;
prp = setdiff(properties(v),{'name','hotkey','nbrofims','matrix','panelstype'});
isprp = prp(strncmp('Is',prp,2));
fdprp = setdiff(prp,isprp); %properties directly taken from fields of SET struct
[cineno,scarno,flowno,~,marno] = findfunctions('findno');
for i = 1:numel(isprp)
v.(isprp{i}) = zeros(1,nbrofims);
end
for i = 1:numel(fdprp)
v.(fdprp{i}) = cell(1,nbrofims);
end
for i = 1:nbrofims
no = DATA.ViewPanels(i);
if no == 0
v.IsEmpty(i) = 1;
else
setstr = SET(no);
for fi = 1:numel(fdprp)
field = fdprp{fi};
v.(field){i} = setstr.(field);
end
v.IsTimeResolved(i) = setstr.TSize > 1;
v.IsSingleSlice(i) = setstr.ZSize == 1;
v.IsCine(i) = ismember(no,cineno);
v.IsScar(i) = ismember(no,scarno);
v.IsFlow(i) = ismember(no,flowno);
v.IsMar(i) = ismember(no,marno);
v.IsPerfusion(i) = 0; %future use
v.IsT2Star(i) = 0; %future use
end
end
end
%----------------------
function nos = match(v)
%----------------------
% Find nos that best match stored view
global SET
nos = zeros(1,v.nbrofims);
prp = setdiff(properties(v),{'name';'hotkey';'nbrofims';'matrix';'panelstype'});
isprp = prp(strncmp('Is',prp,2));
fdprp = setdiff(prp,isprp); %properties directly taken from fields of SET struct
w3prp = {'ImageType',...
'ImageViewPlane',...
'IsTimeResolved',...
'IsSingleSlice'};
w1prp = setdiff(prp,w3prp); %Properties that are weighted at one point
[cineno,scarno,flowno,~,marno] = findfunctions('findno');
for i = 1:v.nbrofims
if v.IsEmpty(i)
nos(i) = 0;
else
points = zeros(1,numel(SET));
for no = 1:numel(SET)
setstr = SET(no);
%Go through field properties to look for matchings
for j = 1:numel(fdprp)
field = fdprp{j};
if isequal(setstr.(field),v.(field){i})
if ismember(field,w3prp)
points(no) = points(no)+3;
else
points(no) = points(no)+1;
end
end
end
%Now for the 'Is' properties
isvec = zeros(numel(isprp),1);
isvec(1) = v.IsTimeResolved(i) == (setstr.TSize > 1);
isvec(2) = v.IsSingleSlice(i) == (setstr.ZSize == 1);
isvec(3) = v.IsCine(i) == ismember(no,cineno);
isvec(4) = v.IsScar(i) == ismember(no,scarno);
isvec(5) = v.IsFlow(i) == ismember(no,flowno);
isvec(6) = v.IsMar(i) == ismember(no,marno);
isvec(isvec == 0) = -1;
isvec(7) = 0; %future use
isvec(8) = 0; %future use
weights = ones(numel(isprp),1)+2*ismember(isprp,w3prp);
points(no) = points(no) + weights'*isvec; %scalar product
end
[~,nos(i)] = max(points);
end
end
end
end
end