comparison Applications/Samples/SingleFrameApplication.h @ 98:a33abae66344 wasm

scrolling over series
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 30 May 2017 15:02:24 +0200
parents d18dcc963930
children 166a555becbf
comparison
equal deleted inserted replaced
97:d18dcc963930 98:a33abae66344
37 private ILayerSource::IObserver 37 private ILayerSource::IObserver
38 { 38 {
39 private: 39 private:
40 class Interactor : public IWorldSceneInteractor 40 class Interactor : public IWorldSceneInteractor
41 { 41 {
42 private:
43 SingleFrameApplication& application_;
44
42 public: 45 public:
46 Interactor(SingleFrameApplication& application) :
47 application_(application)
48 {
49 }
50
43 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& widget, 51 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& widget,
44 const ViewportGeometry& view, 52 const ViewportGeometry& view,
45 MouseButton button, 53 MouseButton button,
46 double x, 54 double x,
47 double y, 55 double y,
71 virtual void MouseWheel(WorldSceneWidget& widget, 79 virtual void MouseWheel(WorldSceneWidget& widget,
72 MouseWheelDirection direction, 80 MouseWheelDirection direction,
73 KeyboardModifiers modifiers, 81 KeyboardModifiers modifiers,
74 IStatusBar* statusBar) 82 IStatusBar* statusBar)
75 { 83 {
84 unsigned int scale = (modifiers & KeyboardModifiers_Control ? 10 : 1);
85
86 switch (direction)
87 {
88 case MouseWheelDirection_Up:
89 application_.OffsetSlice(-scale);
90 break;
91
92 case MouseWheelDirection_Down:
93 application_.OffsetSlice(scale);
94 break;
95
96 default:
97 break;
98 }
76 } 99 }
77 100
78 virtual void KeyPressed(WorldSceneWidget& widget, 101 virtual void KeyPressed(WorldSceneWidget& widget,
79 char key, 102 char key,
80 KeyboardModifiers modifiers, 103 KeyboardModifiers modifiers,
90 break; 113 break;
91 } 114 }
92 } 115 }
93 }; 116 };
94 117
95 virtual void NotifyGeometryReady(const ILayerSource& source) 118
96 { 119 void OffsetSlice(int offset)
97 // Once the geometry of the series is downloaded from Orthanc, 120 {
98 // display its first slice, and adapt the viewport to fit this 121 if (source_ != NULL)
99 // slice 122 {
100 123 int slice = static_cast<int>(slice_) + offset;
101 const OrthancFrameLayerSource& frame = 124
102 dynamic_cast<const OrthancFrameLayerSource&>(source); 125 if (slice < 0)
103 126 {
104 if (frame.GetSliceCount() > 0) 127 slice = 0;
105 { 128 }
129
130 if (slice >= static_cast<int>(source_->GetSliceCount()))
131 {
132 slice = source_->GetSliceCount() - 1;
133 }
134
135 if (slice != static_cast<int>(slice_))
136 {
137 SetSlice(slice);
138 }
139 }
140 }
141
142
143 void SetSlice(size_t index)
144 {
145 if (source_ != NULL &&
146 index < source_->GetSliceCount())
147 {
148 slice_ = index;
149
106 #if 1 150 #if 1
107 GeometryToolbox::Print(frame.GetSlice(0).GetGeometry().GetOrigin()); 151 widget_->SetSlice(source_->GetSlice(slice_).GetGeometry());
108 widget_->SetSlice(frame.GetSlice(0).GetGeometry());
109 #else 152 #else
110 // TEST for scene extents - Rotate the axes 153 // TEST for scene extents - Rotate the axes
111 double a = 15.0 / 180.0 * M_PI; 154 double a = 15.0 / 180.0 * M_PI;
112 155
113 Vector x; GeometryToolbox::AssignVector(x, cos(a), sin(a), 0); 156 Vector x; GeometryToolbox::AssignVector(x, cos(a), sin(a), 0);
114 Vector y; GeometryToolbox::AssignVector(y, -sin(a), cos(a), 0); 157 Vector y; GeometryToolbox::AssignVector(y, -sin(a), cos(a), 0);
115 GeometryToolbox::Print(frame.GetSlice(0).GetGeometry().GetOrigin()); 158 GeometryToolbox::Print(source_->GetSlice(slice_).GetGeometry().GetOrigin());
116 GeometryToolbox::Print(x); 159 GeometryToolbox::Print(x);
117 GeometryToolbox::Print(y); 160 GeometryToolbox::Print(y);
118 SliceGeometry s(frame.GetSlice(0).GetGeometry().GetOrigin(), x, y); 161 SliceGeometry s(source_->GetSlice(slice_).GetGeometry().GetOrigin(), x, y);
119 widget_->SetSlice(s); 162 widget_->SetSlice(s);
120 #endif 163 #endif
121 164 }
122 widget_->SetDefaultView(); 165 }
123 } 166
167
168 virtual void NotifyGeometryReady(const ILayerSource& source)
169 {
170 // Once the geometry of the series is downloaded from Orthanc,
171 // display its first slice, and adapt the viewport to fit this
172 // slice
173 if (source_ == &source)
174 {
175 SetSlice(source_->GetSliceCount() / 2);
176 }
177
178 widget_->SetDefaultView();
124 } 179 }
125 180
126 virtual void NotifyGeometryError(const ILayerSource& source) 181 virtual void NotifyGeometryError(const ILayerSource& source)
127 { 182 {
128 } 183 }
141 const Slice& slice, 196 const Slice& slice,
142 bool isError) 197 bool isError)
143 { 198 {
144 } 199 }
145 200
146 LayerWidget* widget_; 201 LayerWidget* widget_;
202 const OrthancFrameLayerSource* source_;
203 unsigned int slice_;
147 204
148 public: 205 public:
149 SingleFrameApplication() : 206 SingleFrameApplication() :
150 widget_(NULL) 207 widget_(NULL),
208 source_(NULL),
209 slice_(0)
151 { 210 {
152 } 211 }
153 212
154 virtual void DeclareCommandLineOptions(boost::program_options::options_description& options) 213 virtual void DeclareCommandLineOptions(boost::program_options::options_description& options)
155 { 214 {
185 244
186 std::auto_ptr<LayerWidget> widget(new LayerWidget); 245 std::auto_ptr<LayerWidget> widget(new LayerWidget);
187 246
188 #if 1 247 #if 1
189 std::auto_ptr<OrthancFrameLayerSource> layer 248 std::auto_ptr<OrthancFrameLayerSource> layer
190 (new OrthancFrameLayerSource(context.GetWebService(), instance, frame)); 249 (new OrthancFrameLayerSource(context.GetWebService()));
250 layer->LoadInstance(instance, frame);
251 //layer->LoadSeries("6f1b492a-e181e200-44e51840-ef8db55e-af529ab6");
191 layer->Register(*this); 252 layer->Register(*this);
253 source_ = layer.get();
192 widget->AddLayer(layer.release()); 254 widget->AddLayer(layer.release());
193 255
194 RenderStyle s; 256 RenderStyle s;
195 257
196 if (parameters["smooth"].as<bool>()) 258 if (parameters["smooth"].as<bool>())
202 widget->SetLayerStyle(0, s); 264 widget->SetLayerStyle(0, s);
203 #else 265 #else
204 // 0178023P** 266 // 0178023P**
205 // Extent of the CT layer: (-35.068 -20.368) => (34.932 49.632) 267 // Extent of the CT layer: (-35.068 -20.368) => (34.932 49.632)
206 std::auto_ptr<OrthancFrameLayerSource> ct; 268 std::auto_ptr<OrthancFrameLayerSource> ct;
207 ct.reset(new OrthancFrameLayerSource(context.GetWebService(), "c804a1a2-142545c9-33b32fe2-3df4cec0-a2bea6d6", 0)); 269 ct.reset(new OrthancFrameLayerSource(context.GetWebService()));
208 //ct.reset(new OrthancFrameLayerSource(context.GetWebService(), "4bd4304f-47478948-71b24af2-51f4f1bc-275b6c1b", 0)); // BAD SLICE 270 //ct->LoadInstance("c804a1a2-142545c9-33b32fe2-3df4cec0-a2bea6d6", 0);
271 //ct->LoadInstance("4bd4304f-47478948-71b24af2-51f4f1bc-275b6c1b", 0); // BAD SLICE
272 ct->LoadSeries("dd069910-4f090474-7d2bba07-e5c10783-f9e4fb1d");
273
209 ct->Register(*this); 274 ct->Register(*this);
210 widget->AddLayer(ct.release()); 275 widget->AddLayer(ct.release());
211 276
212 std::auto_ptr<OrthancFrameLayerSource> pet; 277 std::auto_ptr<OrthancFrameLayerSource> pet;
213 pet.reset(new OrthancFrameLayerSource(context.GetWebService(), "a1c4dc6b-255d27f0-88069875-8daed730-2f5ee5c6", 0)); 278 pet.reset(new OrthancFrameLayerSource(context.GetWebService()));
279 //pet->LoadInstance("a1c4dc6b-255d27f0-88069875-8daed730-2f5ee5c6", 0);
280 pet->LoadSeries("aabad2e7-80702b5d-e599d26c-4f13398e-38d58a9e");
281 pet->Register(*this);
282 source_ = pet.get();
214 widget->AddLayer(pet.release()); 283 widget->AddLayer(pet.release());
215 284
216 { 285 {
217 RenderStyle s; 286 RenderStyle s;
218 //s.drawGrid_ = true; 287 //s.drawGrid_ = true;
225 //s.drawGrid_ = true; 294 //s.drawGrid_ = true;
226 s.SetColor(255, 0, 0); // Draw missing PET layer in red 295 s.SetColor(255, 0, 0); // Draw missing PET layer in red
227 s.alpha_ = 0.5; 296 s.alpha_ = 0.5;
228 s.applyLut_ = true; 297 s.applyLut_ = true;
229 s.lut_ = Orthanc::EmbeddedResources::COLORMAP_JET; 298 s.lut_ = Orthanc::EmbeddedResources::COLORMAP_JET;
299 s.interpolation_ = ImageInterpolation_Linear;
230 widget->SetLayerStyle(1, s); 300 widget->SetLayerStyle(1, s);
231 } 301 }
232 #endif 302 #endif
233 303
234 widget_ = widget.get(); 304 widget_ = widget.get();
235 widget_->SetTransmitMouseOver(true); 305 widget_->SetTransmitMouseOver(true);
236 widget_->SetInteractor(context.AddInteractor(new Interactor)); 306 widget_->SetInteractor(context.AddInteractor(new Interactor(*this)));
237 context.SetCentralWidget(widget.release()); 307 context.SetCentralWidget(widget.release());
238 } 308 }
239 }; 309 };
240 } 310 }
241 } 311 }