Mercurial > hg > orthanc-stone
annotate Applications/Samples/SingleFrameApplication.h @ 96:f8bce1bebe01 wasm
removal of the NotifyLayerError callback
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 30 May 2017 10:30:57 +0200 |
parents | 7b14c12a3be5 |
children | d18dcc963930 |
rev | line source |
---|---|
0 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
40
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
5 * Copyright (C) 2017 Osimis, Belgium |
0 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
47 | 8 * modify it under the terms of the GNU Affero General Public License |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
0 | 11 * |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
47 | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
0 | 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 **/ | |
20 | |
21 | |
22 #pragma once | |
23 | |
24 #include "SampleApplicationBase.h" | |
85 | 25 #include "SampleInteractor.h" |
0 | 26 |
79 | 27 #include "../../Framework/Layers/OrthancFrameLayerSource.h" |
28 #include "../../Framework/Widgets/LayerWidget.h" | |
51 | 29 #include "../../Resources/Orthanc/Core/Logging.h" |
0 | 30 |
31 namespace OrthancStone | |
32 { | |
33 namespace Samples | |
34 { | |
66 | 35 class SingleFrameApplication : |
36 public SampleApplicationBase, | |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
37 private ILayerSource::IObserver |
0 | 38 { |
66 | 39 private: |
85 | 40 class Interactor : public IWorldSceneInteractor |
41 { | |
42 public: | |
43 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& widget, | |
44 const ViewportGeometry& view, | |
45 MouseButton button, | |
46 double x, | |
47 double y, | |
48 IStatusBar* statusBar) | |
49 { | |
50 return NULL; | |
51 } | |
52 | |
53 virtual void MouseOver(CairoContext& context, | |
54 WorldSceneWidget& widget, | |
55 const ViewportGeometry& view, | |
56 double x, | |
57 double y, | |
58 IStatusBar* statusBar) | |
59 { | |
60 if (statusBar != NULL) | |
61 { | |
62 Vector p = dynamic_cast<LayerWidget&>(widget).GetSlice().MapSliceToWorldCoordinates(x, y); | |
63 | |
64 char buf[64]; | |
65 sprintf(buf, "X = %.02f Y = %.02f Z = %.02f (in cm)", | |
66 p[0] / 10.0, p[1] / 10.0, p[2] / 10.0); | |
67 statusBar->SetMessage(buf); | |
68 } | |
69 } | |
70 | |
71 virtual void MouseWheel(WorldSceneWidget& widget, | |
72 MouseWheelDirection direction, | |
73 KeyboardModifiers modifiers, | |
74 IStatusBar* statusBar) | |
75 { | |
76 } | |
77 | |
78 virtual void KeyPressed(WorldSceneWidget& widget, | |
79 char key, | |
80 KeyboardModifiers modifiers, | |
81 IStatusBar* statusBar) | |
82 { | |
83 switch (key) | |
84 { | |
85 case 's': | |
86 widget.SetDefaultView(); | |
87 break; | |
88 | |
89 default: | |
90 break; | |
91 } | |
92 } | |
93 }; | |
94 | |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
95 virtual void NotifyGeometryReady(const ILayerSource& source) |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
96 { |
92 | 97 // Once the geometry of the series is downloaded from Orthanc, |
98 // display its first slice, and adapt the viewport to fit this | |
99 // slice | |
100 | |
90
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
101 const OrthancFrameLayerSource& frame = |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
102 dynamic_cast<const OrthancFrameLayerSource&>(source); |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
103 |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
104 if (frame.GetSliceCount() > 0) |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
105 { |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
106 widget_->SetSlice(frame.GetSlice(0).GetGeometry()); |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
107 widget_->SetDefaultView(); |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
108 } |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
109 } |
66 | 110 |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
111 virtual void NotifyGeometryError(const ILayerSource& source) |
66 | 112 { |
113 } | |
114 | |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
115 virtual void NotifyContentChange(const ILayerSource& source) |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
116 { |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
117 } |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
118 |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
119 virtual void NotifySliceChange(const ILayerSource& source, |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
120 const Slice& slice) |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
121 { |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
122 } |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
123 |
90
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
124 virtual void NotifyLayerReady(std::auto_ptr<ILayerRenderer>& layer, |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
125 const ILayerSource& source, |
96
f8bce1bebe01
removal of the NotifyLayerError callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
94
diff
changeset
|
126 const Slice& slice, |
f8bce1bebe01
removal of the NotifyLayerError callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
94
diff
changeset
|
127 bool isError) |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
128 { |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
129 } |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
130 |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
131 LayerWidget* widget_; |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
132 |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
133 public: |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
134 SingleFrameApplication() : |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
135 widget_(NULL) |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
136 { |
66 | 137 } |
138 | |
0 | 139 virtual void DeclareCommandLineOptions(boost::program_options::options_description& options) |
140 { | |
141 boost::program_options::options_description generic("Sample options"); | |
142 generic.add_options() | |
143 ("instance", boost::program_options::value<std::string>(), | |
144 "Orthanc ID of the instance") | |
145 ("frame", boost::program_options::value<unsigned int>()->default_value(0), | |
146 "Number of the frame, for multi-frame DICOM instances") | |
147 ("smooth", boost::program_options::value<bool>()->default_value(true), | |
148 "Enable linear interpolation to smooth the image") | |
149 ; | |
150 | |
151 options.add(generic); | |
152 } | |
153 | |
154 virtual void Initialize(BasicApplicationContext& context, | |
155 IStatusBar& statusBar, | |
156 const boost::program_options::variables_map& parameters) | |
157 { | |
158 using namespace OrthancStone; | |
159 | |
85 | 160 statusBar.SetMessage("Use the key \"s\" to reinitialize the layout"); |
161 | |
0 | 162 if (parameters.count("instance") != 1) |
163 { | |
164 LOG(ERROR) << "The instance ID is missing"; | |
165 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
166 } | |
167 | |
168 std::string instance = parameters["instance"].as<std::string>(); | |
169 int frame = parameters["frame"].as<unsigned int>(); | |
170 | |
66 | 171 std::auto_ptr<LayerWidget> widget(new LayerWidget); |
172 | |
94 | 173 #if 1 |
66 | 174 std::auto_ptr<OrthancFrameLayerSource> layer |
175 (new OrthancFrameLayerSource(context.GetWebService(), instance, frame)); | |
90
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
176 layer->Register(*this); |
66 | 177 widget->AddLayer(layer.release()); |
178 | |
179 if (parameters["smooth"].as<bool>()) | |
180 { | |
181 RenderStyle s; | |
182 s.interpolation_ = ImageInterpolation_Linear; | |
183 widget->SetLayerStyle(0, s); | |
184 } | |
185 #else | |
186 // 0178023P** | |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
187 std::auto_ptr<OrthancFrameLayerSource> ct; |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
188 ct.reset(new OrthancFrameLayerSource(context.GetWebService(), "c804a1a2-142545c9-33b32fe2-3df4cec0-a2bea6d6", 0)); |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
189 //ct.reset(new OrthancFrameLayerSource(context.GetWebService(), "4bd4304f-47478948-71b24af2-51f4f1bc-275b6c1b", 0)); // BAD SLICE |
90
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
190 ct->Register(*this); |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
191 widget->AddLayer(ct.release()); |
66 | 192 |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
193 std::auto_ptr<OrthancFrameLayerSource> pet; |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
194 pet.reset(new OrthancFrameLayerSource(context.GetWebService(), "a1c4dc6b-255d27f0-88069875-8daed730-2f5ee5c6", 0)); |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
195 widget->AddLayer(pet.release()); |
66 | 196 |
85 | 197 { |
198 RenderStyle s; | |
199 s.alpha_ = 1; | |
200 widget->SetLayerStyle(0, s); | |
201 } | |
202 | |
203 { | |
204 RenderStyle s; | |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
205 //s.drawGrid_ = true; |
85 | 206 s.SetColor(255, 0, 0); // Draw missing PET layer in red |
207 s.alpha_ = 0.5; | |
208 s.applyLut_ = true; | |
209 s.lut_ = Orthanc::EmbeddedResources::COLORMAP_JET; | |
210 widget->SetLayerStyle(1, s); | |
211 } | |
66 | 212 #endif |
85 | 213 |
66 | 214 widget_ = widget.get(); |
85 | 215 widget_->SetTransmitMouseOver(true); |
216 widget_->SetInteractor(context.AddInteractor(new Interactor)); | |
66 | 217 context.SetCentralWidget(widget.release()); |
0 | 218 } |
219 }; | |
220 } | |
221 } |