Mercurial > hg > orthanc-stone
comparison Samples/BasicPetCtFusionApplication.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/Logging.h" | |
38 | |
39 namespace OrthancStone | |
40 { | |
41 namespace Samples | |
42 { | |
43 class BasicPetCtFusionApplication : public SampleApplicationBase | |
44 { | |
45 private: | |
46 class Interactor : public SampleInteractor | |
47 { | |
48 public: | |
49 static void SetStyle(LayeredSceneWidget& widget, | |
50 bool ct, | |
51 bool pet) | |
52 { | |
53 if (ct) | |
54 { | |
55 RenderStyle style; | |
56 style.windowing_ = ImageWindowing_Bone; | |
57 widget.SetLayerStyle(0, style); | |
58 } | |
59 else | |
60 { | |
61 RenderStyle style; | |
62 style.visible_ = false; | |
63 widget.SetLayerStyle(0, style); | |
64 } | |
65 | |
66 if (ct && pet) | |
67 { | |
68 RenderStyle style; | |
69 style.applyLut_ = true; | |
70 style.alpha_ = 0.5; | |
71 widget.SetLayerStyle(1, style); | |
72 } | |
73 else if (pet) | |
74 { | |
75 RenderStyle style; | |
76 style.applyLut_ = true; | |
77 widget.SetLayerStyle(1, style); | |
78 } | |
79 else | |
80 { | |
81 RenderStyle style; | |
82 style.visible_ = false; | |
83 widget.SetLayerStyle(1, style); | |
84 } | |
85 } | |
86 | |
87 | |
88 static bool IsVisible(LayeredSceneWidget& widget, | |
89 size_t layer) | |
90 { | |
91 RenderStyle style = widget.GetLayerStyle(layer); | |
92 return style.visible_; | |
93 } | |
94 | |
95 | |
96 static void ToggleInterpolation(LayeredSceneWidget& widget, | |
97 size_t layer) | |
98 { | |
99 RenderStyle style = widget.GetLayerStyle(layer); | |
100 | |
101 if (style.interpolation_ == ImageInterpolation_Linear) | |
102 { | |
103 style.interpolation_ = ImageInterpolation_Nearest; | |
104 } | |
105 else | |
106 { | |
107 style.interpolation_ = ImageInterpolation_Linear; | |
108 } | |
109 | |
110 widget.SetLayerStyle(layer, style); | |
111 } | |
112 | |
113 | |
114 Interactor(VolumeImage& volume, | |
115 VolumeProjection projection, | |
116 bool reverse) : | |
117 SampleInteractor(volume, projection, reverse) | |
118 { | |
119 } | |
120 | |
121 | |
122 virtual void KeyPressed(WorldSceneWidget& widget, | |
123 char key, | |
124 KeyboardModifiers modifiers, | |
125 IStatusBar* statusBar) | |
126 { | |
127 LayeredSceneWidget& layered = dynamic_cast<LayeredSceneWidget&>(widget); | |
128 | |
129 switch (key) | |
130 { | |
131 case 'c': | |
132 // Toggle the visibility of the CT layer | |
133 SetStyle(layered, !IsVisible(layered, 0), IsVisible(layered, 1)); | |
134 break; | |
135 | |
136 case 'p': | |
137 // Toggle the visibility of the PET layer | |
138 SetStyle(layered, IsVisible(layered, 0), !IsVisible(layered, 1)); | |
139 break; | |
140 | |
141 case 'i': | |
142 { | |
143 // Toggle on/off the interpolation | |
144 ToggleInterpolation(layered, 0); | |
145 ToggleInterpolation(layered, 1); | |
146 break; | |
147 } | |
148 | |
149 default: | |
150 break; | |
151 } | |
152 } | |
153 }; | |
154 | |
155 | |
156 public: | |
157 virtual void DeclareCommandLineOptions(boost::program_options::options_description& options) | |
158 { | |
159 boost::program_options::options_description generic("Sample options"); | |
160 generic.add_options() | |
161 ("ct", boost::program_options::value<std::string>(), | |
162 "Orthanc ID of the CT series") | |
163 ("pet", boost::program_options::value<std::string>(), | |
164 "Orthanc ID of the PET series") | |
165 ("threads", boost::program_options::value<unsigned int>()->default_value(3), | |
166 "Number of download threads for the CT series") | |
167 ; | |
168 | |
169 options.add(generic); | |
170 } | |
171 | |
172 virtual void Initialize(BasicApplicationContext& context, | |
173 IStatusBar& statusBar, | |
174 const boost::program_options::variables_map& parameters) | |
175 { | |
176 using namespace OrthancStone; | |
177 | |
178 if (parameters.count("ct") != 1 || | |
179 parameters.count("pet") != 1) | |
180 { | |
181 LOG(ERROR) << "The series ID is missing"; | |
182 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
183 } | |
184 | |
185 std::string ct = parameters["ct"].as<std::string>(); | |
186 std::string pet = parameters["pet"].as<std::string>(); | |
187 unsigned int threads = parameters["threads"].as<unsigned int>(); | |
188 | |
189 VolumeImage& ctVolume = context.AddSeriesVolume(ct, true /* progressive download */, threads); | |
190 VolumeImage& petVolume = context.AddSeriesVolume(pet, true /* progressive download */, 1); | |
191 | |
192 // Take the PET volume as the reference for the slices | |
193 std::auto_ptr<Interactor> interactor(new Interactor(petVolume, VolumeProjection_Axial, false /* don't reverse normal */)); | |
194 | |
195 std::auto_ptr<LayeredSceneWidget> widget(new LayeredSceneWidget); | |
196 widget->AddLayer(new VolumeImage::LayerFactory(ctVolume)); | |
197 widget->AddLayer(new VolumeImage::LayerFactory(petVolume)); | |
198 widget->SetSlice(interactor->GetCursor().GetCurrentSlice()); | |
199 widget->SetInteractor(*interactor); | |
200 | |
201 Interactor::SetStyle(*widget, true, true); // Initially, show both CT and PET layers | |
202 | |
203 context.AddInteractor(interactor.release()); | |
204 context.SetCentralWidget(widget.release()); | |
205 | |
206 statusBar.SetMessage("Use the key \"t\" to toggle the fullscreen mode"); | |
207 statusBar.SetMessage("Use the key \"c\" to show/hide the CT layer"); | |
208 statusBar.SetMessage("Use the key \"p\" to show/hide the PET layer"); | |
209 statusBar.SetMessage("Use the key \"i\" to toggle the smoothing of the images"); | |
210 } | |
211 }; | |
212 } | |
213 } |