-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathLVrotation.m
295 lines (242 loc) · 8.33 KB
/
LVrotation.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
function [varargout] = LVrotation(varargin)
%function to define the LV rotation
macro_helper(varargin{:});
if nargin == 0 || isempty(varargin{1})
varargin{1} = 'init';
end
[varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard
%------------
function init %#ok<DEFNU>
%------------
%open the gui to define LV rotation
global DATA NO SET
gui = mygui('LVrotation.fig');
DATA.GUI.LVrotation = gui;
gui.no = NO;
gui.slice = round(0.5*(SET(gui.no).StartSlice+SET(gui.no).EndSlice));
%set rotation and slice
set(gui.handles.rotationslider,'value',SET(gui.no).SectorRotation);
set(gui.handles.slicetext,'String',dprintf('Slice %d',gui.slice));
if SET(NO).ZSize > 1
set(gui.handles.sliceslider,'Min',1,'Max',...
SET(NO).ZSize,'Value',SET(NO).ZSize-gui.slice+1,'SliderStep',...
[1 3]/(SET(NO).ZSize));
else
set(gui.handles.sliceslider,'Visible','off');
set(gui.handles.slicetext,'Visible','off');
end
segment('recursekeypressfcn',gui.fig,@(hObject,eventdata)LVrotation('keypressed',eventdata))
%plot image
plotimage;
if ~DATA.Testing
%block any further analysis until this interface is closed
uiwait(gui.fig);
else
ok_Callback;
end
%--------------------------
function requestfocus
%--------------------------
global DATA
gui = DATA.GUI.LVrotation;
warning off
jFig = get(gui.fig,'JavaFrame');
jFig.requestFocus;
warning on;
%-------------------------
function keypressed(evt) %#ok<DEFNU>
%-------------------------
%%Keypress function
global DATA
gui = DATA.GUI.LVrotation;
% take away focus from sliders
requestfocus;
switch evt.Key
case {'downarrow','uparrow'}
%move slice
oldvalue = mygetslider(gui.handles.sliceslider);
h = gui.handles.sliceslider;
stepvalue = (h.Max - h.Min)*h.SliderStep(1);
if contains(evt.Key,'up')
newvalue = oldvalue + stepvalue;
else
newvalue = oldvalue - stepvalue;
end
if newvalue > h.Min && newvalue < h.Max
gui.handles.sliceslider.Value = newvalue;
elseif newvalue > h.Max
gui.handles.sliceslider.Value = h.Max;
elseif newvalue < h.Min
gui.handles.sliceslider.Value = h.Min;
end
sliceslider_Callback
case {'rightarrow','leftarrow'}
oldvalue = mygetslider(gui.handles.rotationslider);
h = gui.handles.rotationslider;
stepvalue = (h.Max - h.Min)*h.SliderStep(1);
if contains(evt.Key,'right')
newvalue = oldvalue + stepvalue;
else
newvalue = oldvalue - stepvalue;
end
if newvalue > h.Min && newvalue < h.Max
gui.handles.rotationslider.Value = newvalue;
elseif newvalue > h.Max
gui.handles.rotationslider.Value = h.Max;
elseif newvalue < h.Min
gui.handles.rotationslider.Value = h.Min;
end
rotationslider_Callback
otherwise
return
end
%-----------------
function plotimage
%-----------------
%plot the image
global DATA SET
gui = DATA.GUI.LVrotation;
tf = SET(gui.no).CurrentTimeFrame;
SET(gui.no).SectorRotation = mygetvalue(gui.handles.rotationslider);
%Plot image
temp = SET(gui.no).IM(:,:,tf,gui.slice);
temp = min(max(temp,0),1);
imsize = size(temp);
%force true color
image(calcfunctions('remapuint8',temp,gui.no,calcfunctions('returnmapping',gui.no,true)),...
'parent',gui.handles.imageaxes);
axis(gui.handles.imageaxes,'image','off');
%Upsample model
if not(DATA.Pref.RadialProfiles == DATA.NumPoints)
[endox,endoy] = calcfunctions('resamplemodel',SET(gui.no).EndoX(:,tf,gui.slice),SET(gui.no).EndoY(:,tf,gui.slice),DATA.Pref.RadialProfiles);
if ~isempty(SET(gui.no).EpiX)
[epix,epiy] = calcfunctions('resamplemodel',SET(gui.no).EpiX(:,tf,gui.slice), SET(gui.no).EpiY(:,tf,gui.slice),DATA.Pref.RadialProfiles);
end
else
endox = SET(gui.no).EndoX(:,tf,gui.slice);
endoy = SET(gui.no).EndoY(:,tf,gui.slice);
if ~isempty(SET(gui.no).EpiX)
epix = SET(gui.no).EpiX(:,tf,gui.slice);
epiy = SET(gui.no).EpiY(:,tf,gui.slice);
end
end
if isempty(SET(gui.no).EpiX)
epix = NaN;
epiy = NaN;
end
%Plot contours
hold(gui.handles.imageaxes,'on');
gui.handles.endocontour = plot(gui.handles.imageaxes,endoy,endox,'r-');
set(gui.handles.endocontour,'linewidth',DATA.Pref.LineWidth);
if ~isempty(SET(gui.no).EpiX)
gui.handles.epicontour = plot(gui.handles.imageaxes,epiy,epix,'g-');
set(gui.handles.epicontour,'linewidth',DATA.Pref.LineWidth);
end
%Plot sectors
hold(gui.handles.imageaxes,'on');
if isnan(epix(1))
%--- Only endo exist => draw only endo
%get positions.
[gui.meanx,gui.meany,gui.sectors] = calcfunctions('findmeaninsectorslice','endo',DATA.Pref.RadialProfiles,...
tf,gui.slice,1,gui.no);
xpos = endoy(gui.sectors(1));
ypos = endox(gui.sectors(1));
%Draw an extra long line
h = plot(gui.handles.imageaxes,[min(imsize(2),max(1,gui.meany)) min(imsize(2),max(1,1.5*xpos-0.5*gui.meany))], ...
[min(imsize(1),max(1,gui.meanx)) min(imsize(1),max(1,1.5*ypos-0.5*gui.meany))],'y-');
set(h,'linewidth',DATA.Pref.LineWidth);
else
%--- Epi exists => draw both
%get positions.
[gui.meanx,gui.meany,gui.sectors] = calcfunctions('findmeaninsectorslice','epi',DATA.Pref.RadialProfiles,...
tf,gui.slice,1,gui.no);
xpos = epiy(gui.sectors(1));
ypos = epix(gui.sectors(1));
%Draw an extra long line
gui.handles.line = plot(gui.handles.imageaxes,[min(imsize(2),max(1,gui.meany)) min(imsize(2),max(1,1.5*xpos-0.5*gui.meany))], ...
[min(imsize(1),max(1,gui.meanx)) min(imsize(1),max(1,1.5*ypos-0.5*gui.meanx))],'y-');
set(gui.handles.line,'linewidth',DATA.Pref.LineWidth);
end
hold off
%-------------------------------
function rotationslider_Callback %#ok<DEFNU>
%-------------------------------
%Callback for rotation slider. Update slice image.
plotimage;
%----------------------------
function sliceslider_Callback
%----------------------------
%Callback for slider to toggle slice
global DATA SET
gui = DATA.GUI.LVrotation;
requestfocus;
gui.slice = SET(gui.no).ZSize-round(mygetvalue(gui.handles.sliceslider))+1;
set(gui.handles.sliceslider,'Value',round(mygetvalue(gui.handles.sliceslider)));
set(gui.handles.slicetext,'String',dprintf('Slice %d',gui.slice));
plotimage;
%---------------------------------------
function rotationfromannotation_Callback %#ok<DEFNU>
%---------------------------------------
%Finds rotation by looking at RV insertion points.
global DATA SET
gui = DATA.GUI.LVrotation;
requestfocus;
v = get(gui.handles.rotationfromannotationcheckbox,'value');
if v
pos = rotationfromannotationhelper(gui.no);
if isempty(pos)
set(gui.handles.rotationfromannotationcheckbox,'value',0);
end
end
%update slider
set(gui.handles.rotationslider,'value',SET(gui.no).SectorRotation);
%call to graphically update rotation & bullseye
plotimage;
%--------------------------------------
function pos = rotationfromannotationhelper(no)
%--------------------------------------
%Find suitable sector rotation based on RV insertion points
global SET
%Find slices with RV insertion points
slices = false(1,SET(no).ZSize);
for loop = 1:length(SET(no).Point.Z)
if isequal(SET(no).Point.Label{loop},'RV insertion') || isequal(SET(no).Point.Label{loop},'P1')|| isequal(SET(no).Point.Label{loop},'P2')
slices(SET(no).Point.Z(loop)) = true;
end
end
%Find slices
pos = find(slices);
if isempty(pos)
mywarning(dprintf('No RV points found. Define two RV annotation points.'));
return
end
pos = reportbullseye('sectorrotationhelper',no);
%-------------------
function ok_Callback
%-------------------
%start the bullseye analsysia and close the LV rotation interface
global DATA SET
gui = DATA.GUI.LVrotation;
%if user click ok for 0 in LV rotation, define it as 0.1 degrees in order
%to remember that the user have checked the LV rotation
if SET(gui.no).SectorRotation == 0
SET(gui.no).SectorRotation = 0.1;
end
close_Callback;
reportbullseye('startbullseye');
%------------------------
function cancel_Callback %#ok<DEFNU>
%-----------------------
%cancel the analysis and close the LV rotation interface
close_Callback;
%----------------------
function close_Callback
%----------------------
%Properly close the GUI.
global DATA
try
DATA.GUI.LVrotation = close(DATA.GUI.LVrotation); %close the gui
catch %#ok<CTCH>
delete(gcbf)
end
DATA.GUI.LVrotation= [];