-
Notifications
You must be signed in to change notification settings - Fork 58
/
PTKViewer.m
138 lines (117 loc) · 4.68 KB
/
PTKViewer.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
classdef PTKViewer < GemFigure
% PTKViewer. A standalone image viewer for showing 3D images slice-by-slice
%
% PTKViewer uses MimViewerPanel to create a visualisation window for the
% supplied image, which can be a PTKImage or raw data. If a raw data
% matrix is supplied, the type argument can be supplied to ensure the
% image is displayed as expected.
%
% Syntax:
% obj = PTKViewer;
% obj = PTKViewer(image);
% obj = PTKViewer(image, image_type);
% obj = PTKViewer(image, image_type, reporting);
% obj = PTKViewer(image, overlay_image);
% obj = PTKViewer(image, overlay_image, reporting);
%
% Examples
% --------
%
% % Displays my_image, where my_image is a 3D image matrix or a PTKImage
% PTKViewer(my_image);
%
% % Displays my_image as a greyscale image, where my_image is a 3D image.
% % If my_Image is a PTKImage, the type will be ignored
% PTKViewer(my_image, PTKImageType.Grayscale);
%
% % Displays my_image in the background with overlay_image as an overlay
% viewer = PTKViewer(my_image, overlay_image);
%
% % Displays my_image as a greyscale image, and overlay_image as an indexed colour image
% viewer = PTKViewer(my_image, PTKImageType.Grayscale);
% viewer.ViewerPanelHandle.OverlayImage = overlay_image; % Must be a PTKImage
%
%
% Licence
% -------
% Part of the TD Pulmonary Toolkit. https://github.com/tomdoel/pulmonarytoolkit
% Author: Tom Doel, 2012. www.tomdoel.com
% Distributed under the GNU GPL v3 licence. Please see website for details.
%
properties
ViewerPanelHandle
end
properties (SetAccess = private)
Image
Overlay
end
methods
function obj = PTKViewer(image, overlay_or_type, reporting)
if nargin < 1
image = [];
end
% The second argument can be the type of the image, or an overlay image
if nargin < 2
overlay = [];
type = [];
else
if isa(overlay_or_type, 'PTKImageType')
overlay = [];
type = overlay_or_type;
elseif isa(overlay_or_type, 'PTKImage')
overlay = overlay_or_type;
type = [];
end
end
if nargin < 3
reporting = CoreReportingDefault;
end
title = 'PTK Viewer';
if isa(image, 'PTKImage')
image_handle = image;
if ~isempty(image.Title)
title = image.Title;
end
else
if isempty(type)
image_handle = PTKImage(image);
else
image_handle = PTKImage(image, type);
end
end
if isa(overlay, 'PTKImage')
overlay_handle = overlay;
if isempty(title) && ~isempty(image.Title)
title = image.Title;
end
else
overlay_handle = PTKImage(overlay);
end
if isempty(title)
title = 'PTK Viewer';
end
% Call the base class to initialise the hidden window
obj = obj@GemFigure(title, [], reporting);
obj.ViewerPanelHandle = MimViewerPanelWithControlPanel(obj);
obj.AddChild(obj.ViewerPanelHandle);
obj.Image = image_handle;
obj.Overlay = overlay_handle;
obj.Resize([100 50 700 600]);
% Create the figure
obj.Show;
end
function CreateGuiComponent(obj, position)
CreateGuiComponent@GemFigure(obj, position);
obj.ViewerPanelHandle.BackgroundImage = obj.Image;
obj.ViewerPanelHandle.OverlayImage = obj.Overlay;
obj.ViewerPanelHandle.SliceNumber = max(1, round(obj.Image.ImageSize/2));
end
function Resize(obj, position)
Resize@GemFigure(obj, position);
parent_width_pixels = max(1, position(3));
parent_height_pixels = max(1, position(4));
panel_position = [1 1 parent_width_pixels parent_height_pixels];
obj.ViewerPanelHandle.Resize(panel_position);
end
end
end