comparison Samples/SingleVolumeApplication.h @ 0:351ab0da0150

initial commit
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 14 Oct 2016 15:34:11 +0200
parents
children ff1e935768e7
comparison
equal deleted inserted replaced
-1:000000000000 0:351ab0da0150
1 /**
2 * Stone of Orthanc
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 *
6 * This program is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * In addition, as a special exception, the copyright holders of this
12 * program give permission to link the code of its release with the
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
14 * that use the same license as the "OpenSSL" library), and distribute
15 * the linked executables. You must obey the GNU General Public License
16 * in all respects for all of the code used other than "OpenSSL". If you
17 * modify file(s) with this exception, you may extend this exception to
18 * your version of the file(s), but you are not obligated to do so. If
19 * you do not wish to do so, delete this exception statement from your
20 * version. If you delete this exception statement from all source files
21 * in the program, then also delete it here.
22 *
23 * This program is distributed in the hope that it will be useful, but
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 * General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 **/
31
32
33 #pragma once
34
35 #include "SampleInteractor.h"
36
37 #include "../Framework/Orthanc/Core/Toolbox.h"
38 #include "../Framework/Layers/LineMeasureTracker.h"
39 #include "../Framework/Layers/CircleMeasureTracker.h"
40 #include "../Framework/Orthanc/Core/Logging.h"
41
42 namespace OrthancStone
43 {
44 namespace Samples
45 {
46 class SingleVolumeApplication : public SampleApplicationBase
47 {
48 private:
49 class Interactor : public SampleInteractor
50 {
51 private:
52 enum MouseMode
53 {
54 MouseMode_None,
55 MouseMode_TrackCoordinates,
56 MouseMode_LineMeasure,
57 MouseMode_CircleMeasure
58 };
59
60 MouseMode mouseMode_;
61
62 void SetMouseMode(MouseMode mode,
63 IStatusBar* statusBar)
64 {
65 if (mouseMode_ == mode)
66 {
67 mouseMode_ = MouseMode_None;
68 }
69 else
70 {
71 mouseMode_ = mode;
72 }
73
74 if (statusBar)
75 {
76 switch (mouseMode_)
77 {
78 case MouseMode_None:
79 statusBar->SetMessage("Disabling the mouse tools");
80 break;
81
82 case MouseMode_TrackCoordinates:
83 statusBar->SetMessage("Tracking the mouse coordinates");
84 break;
85
86 case MouseMode_LineMeasure:
87 statusBar->SetMessage("Mouse clicks will now measure the distances");
88 break;
89
90 case MouseMode_CircleMeasure:
91 statusBar->SetMessage("Mouse clicks will now draw circles");
92 break;
93
94 default:
95 break;
96 }
97 }
98 }
99
100 public:
101 Interactor(VolumeImage& volume,
102 VolumeProjection projection,
103 bool reverse) :
104 SampleInteractor(volume, projection, reverse),
105 mouseMode_(MouseMode_None)
106 {
107 }
108
109 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& widget,
110 const SliceGeometry& slice,
111 const ViewportGeometry& view,
112 MouseButton button,
113 double x,
114 double y,
115 IStatusBar* statusBar)
116 {
117 if (button == MouseButton_Left)
118 {
119 switch (mouseMode_)
120 {
121 case MouseMode_LineMeasure:
122 return new LineMeasureTracker(NULL, slice, x, y, 255, 0, 0, 14 /* font size */);
123
124 case MouseMode_CircleMeasure:
125 return new CircleMeasureTracker(NULL, slice, x, y, 255, 0, 0, 14 /* font size */);
126
127 default:
128 break;
129 }
130 }
131
132 return NULL;
133 }
134
135 virtual void MouseOver(CairoContext& context,
136 WorldSceneWidget& widget,
137 const SliceGeometry& slice,
138 const ViewportGeometry& view,
139 double x,
140 double y,
141 IStatusBar* statusBar)
142 {
143 if (mouseMode_ == MouseMode_TrackCoordinates &&
144 statusBar != NULL)
145 {
146 Vector p = slice.MapSliceToWorldCoordinates(x, y);
147
148 char buf[64];
149 sprintf(buf, "X = %.02f Y = %.02f Z = %.02f (in cm)", p[0] / 10.0, p[1] / 10.0, p[2] / 10.0);
150 statusBar->SetMessage(buf);
151 }
152 }
153
154
155 virtual void KeyPressed(WorldSceneWidget& widget,
156 char key,
157 KeyboardModifiers modifiers,
158 IStatusBar* statusBar)
159 {
160 switch (key)
161 {
162 case 't':
163 SetMouseMode(MouseMode_TrackCoordinates, statusBar);
164 break;
165
166 case 'm':
167 SetMouseMode(MouseMode_LineMeasure, statusBar);
168 break;
169
170 case 'c':
171 SetMouseMode(MouseMode_CircleMeasure, statusBar);
172 break;
173
174 case 'b':
175 {
176 if (statusBar)
177 {
178 statusBar->SetMessage("Setting Hounsfield window to bones");
179 }
180
181 RenderStyle style;
182 style.windowing_ = ImageWindowing_Bone;
183 dynamic_cast<LayeredSceneWidget&>(widget).SetLayerStyle(0, style);
184 break;
185 }
186
187 case 'l':
188 {
189 if (statusBar)
190 {
191 statusBar->SetMessage("Setting Hounsfield window to lung");
192 }
193
194 RenderStyle style;
195 style.windowing_ = ImageWindowing_Lung;
196 dynamic_cast<LayeredSceneWidget&>(widget).SetLayerStyle(0, style);
197 break;
198 }
199
200 case 'd':
201 {
202 if (statusBar)
203 {
204 statusBar->SetMessage("Setting Hounsfield window to what is written in the DICOM file");
205 }
206
207 RenderStyle style;
208 style.windowing_ = ImageWindowing_Default;
209 dynamic_cast<LayeredSceneWidget&>(widget).SetLayerStyle(0, style);
210 break;
211 }
212
213 default:
214 break;
215 }
216 }
217 };
218
219
220 public:
221 virtual void DeclareCommandLineOptions(boost::program_options::options_description& options)
222 {
223 boost::program_options::options_description generic("Sample options");
224 generic.add_options()
225 ("series", boost::program_options::value<std::string>(),
226 "Orthanc ID of the series")
227 ("threads", boost::program_options::value<unsigned int>()->default_value(3),
228 "Number of download threads")
229 ("projection", boost::program_options::value<std::string>()->default_value("axial"),
230 "Projection of interest (can be axial, sagittal or coronal)")
231 ("reverse", boost::program_options::value<bool>()->default_value(false),
232 "Reverse the normal direction of the volume")
233 ;
234
235 options.add(generic);
236 }
237
238 virtual void Initialize(BasicApplicationContext& context,
239 IStatusBar& statusBar,
240 const boost::program_options::variables_map& parameters)
241 {
242 using namespace OrthancStone;
243
244 if (parameters.count("series") != 1)
245 {
246 LOG(ERROR) << "The series ID is missing";
247 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
248 }
249
250 std::string series = parameters["series"].as<std::string>();
251 unsigned int threads = parameters["threads"].as<unsigned int>();
252 bool reverse = parameters["reverse"].as<bool>();
253
254 std::string tmp = parameters["projection"].as<std::string>();
255 Orthanc::Toolbox::ToLowerCase(tmp);
256
257 VolumeProjection projection;
258 if (tmp == "axial")
259 {
260 projection = VolumeProjection_Axial;
261 }
262 else if (tmp == "sagittal")
263 {
264 projection = VolumeProjection_Sagittal;
265 }
266 else if (tmp == "coronal")
267 {
268 projection = VolumeProjection_Coronal;
269 }
270 else
271 {
272 LOG(ERROR) << "Unknown projection: " << tmp;
273 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
274 }
275
276 VolumeImage& volume = context.AddSeriesVolume(series, true /* progressive download */, threads);
277
278 std::auto_ptr<Interactor> interactor(new Interactor(volume, projection, reverse));
279
280 std::auto_ptr<LayeredSceneWidget> widget(new LayeredSceneWidget);
281 widget->AddLayer(new VolumeImage::LayerFactory(volume));
282 widget->SetSlice(interactor->GetCursor().GetCurrentSlice());
283 widget->SetInteractor(*interactor);
284
285 context.AddInteractor(interactor.release());
286 context.SetCentralWidget(widget.release());
287
288 statusBar.SetMessage("Use the keys \"b\", \"l\" and \"d\" to change Hounsfield windowing");
289 statusBar.SetMessage("Use the keys \"t\" to track the (X,Y,Z) mouse coordinates");
290 statusBar.SetMessage("Use the keys \"m\" to measure distances");
291 statusBar.SetMessage("Use the keys \"c\" to draw circles");
292 }
293 };
294 }
295 }