-
Notifications
You must be signed in to change notification settings - Fork 10
/
imtool3DROI.m
170 lines (143 loc) · 5.84 KB
/
imtool3DROI.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
classdef imtool3DROI < handle
%This is an abstract class for the ROI tools used in imtool3D
properties (SetObservable = true)
imageHandle
axesHandle
figureHandle
graphicsHandles
menuHandles
textHandle
tool
listenerHandle
lineColor = 'y';
markerColor = 'r';
visible = true;
textVisible = true; %this property is a slave to visible (i.e., if visible is false, the text will not be visible even if textVisible is true)
end
events
ROIdeleted
newROIPosition
newROIPositionUp
end
methods
%Constructor
function ROI = imtool3DROI(imageHandle,graphicsHandles,menuLabels,menuFunction,varargin)
%Set the properties
ROI.imageHandle = imageHandle;
ROI.graphicsHandles = graphicsHandles;
%Get the parent axes of the image
ROI.axesHandle = get(imageHandle(1),'Parent');
%Find the parent figure of the object
ROI.figureHandle = getParentFigure(imageHandle(1));
%create the context menu
c = uicontextmenu;
%set the graphics handles to use the context menu and set their
%color
if ROI.visible
str = 'on';
else
str = 'off';
end
for i=1:length(graphicsHandles)
set(graphicsHandles(i),'UIContextMenu',c)
switch class(graphicsHandles(i))
case 'matlab.graphics.chart.primitive.Line'
set(graphicsHandles(i),'Color',ROI.lineColor,'MarkerFaceColor',ROI.markerColor,'MarkerEdgeColor',ROI.markerColor,'Visible',str)
case 'matlab.graphics.primitive.Rectangle'
set(graphicsHandles(i),'EdgeColor',ROI.lineColor,'Visible',str)
otherwise
disp(class(graphicsHandles(i)))
end
end
%create each of the menu items and set their callback
%functions
menuFunction = @(source,callbackdata) menuFunction(source,callbackdata,ROI,varargin{:});
for i=1:length(menuLabels)
ROI.menuHandles(i) = uimenu('Parent',c,'Label',menuLabels{i},'Callback',menuFunction);
end
end
function set.lineColor(ROI,lineColor)
ROI.lineColor = lineColor;
graphicsHandles = ROI.graphicsHandles;
for i=1:length(graphicsHandles)
switch class(graphicsHandles(i))
case 'matlab.graphics.chart.primitive.Line'
set(graphicsHandles(i),'Color',ROI.lineColor)
case 'matlab.graphics.primitive.Rectangle'
set(graphicsHandles(i),'EdgeColor',ROI.lineColor)
otherwise
disp(class(graphicsHandles(i)))
end
end
end
function set.markerColor(ROI,markerColor)
ROI.markerColor = markerColor;
graphicsHandles = ROI.graphicsHandles;
for i=1:length(graphicsHandles)
switch class(graphicsHandles(i))
case 'matlab.graphics.chart.primitive.Line'
set(graphicsHandles(i),'MarkerFaceColor',ROI.markerColor,'MarkerEdgeColor',ROI.markerColor)
otherwise
disp(class(graphicsHandles(i)))
end
end
end
function set.visible(ROI,visible)
ROI.visible=visible;
if visible
str = 'on';
else
str = 'off';
end
%turn on or off the visibility of the ROI graphics
for i=1:length(ROI.graphicsHandles)
set(ROI.graphicsHandles(i),'Visible',str);
end
%Turn on or off the visibility of the text box
if visible
if ROI.textVisible
set(ROI.textHandle,'Visible','on');
else
set(ROI.textHandle,'Visible','off');
end
else
set(ROI.textHandle,'Visible','off');
end
end
function set.textVisible(ROI,textVisible)
ROI.textVisible=textVisible;
if textVisible
if ROI.visible
set(ROI.textHandle,'Visible','on');
else
set(ROI.textHandle,'Visible','off');
end
else
set(ROI.textHandle,'Visible','off');
%make sure the context menu is in sync with this
for i=1:length(ROI.menuHandles)
switch get(ROI.menuHandles(i),'Label')
case 'Hide Text'
set(ROI.menuHandles(i),'Checked','on');
end
end
end
end
%Destructor
function delete(ROI)
try
delete(ROI.graphicsHandles);
delete(ROI.textHandle);
delete(ROI.listenerHandle);
notify(ROI,'ROIdeleted');
end
end
end
end
function fig = getParentFigure(fig)
% if the object is a figure or figure descendent, return the
% figure. Otherwise return [].
while ~isempty(fig) & ~strcmp('figure', get(fig,'type'))
fig = get(fig,'parent');
end
end