comparison Applications/Samples/SingleFrameApplication.h @ 325:37ab9d83dc9b am-2

reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
author am@osimis.io
date Tue, 16 Oct 2018 11:30:00 +0200
parents ce4405d98b92
children 612238b3f3e8
comparison
equal deleted inserted replaced
324:29a79b8c3d39 325:37ab9d83dc9b
32 { 32 {
33 namespace Samples 33 namespace Samples
34 { 34 {
35 class SingleFrameApplication : 35 class SingleFrameApplication :
36 public SampleApplicationBase, 36 public SampleApplicationBase,
37 private ILayerSource::IObserver 37 public IObserver
38 { 38 {
39 private: 39 private:
40 class Interactor : public IWorldSceneInteractor 40 class Interactor : public IWorldSceneInteractor
41 { 41 {
42 private: 42 private:
49 } 49 }
50 50
51 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& widget, 51 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& widget,
52 const ViewportGeometry& view, 52 const ViewportGeometry& view,
53 MouseButton button, 53 MouseButton button,
54 KeyboardModifiers modifiers,
54 double x, 55 double x,
55 double y, 56 double y,
56 IStatusBar* statusBar) 57 IStatusBar* statusBar)
57 { 58 {
58 return NULL; 59 return NULL;
146 index < source_->GetSliceCount()) 147 index < source_->GetSliceCount())
147 { 148 {
148 slice_ = index; 149 slice_ = index;
149 150
150 #if 1 151 #if 1
151 widget_->SetSlice(source_->GetSlice(slice_).GetGeometry()); 152 mainWidget_->SetSlice(source_->GetSlice(slice_).GetGeometry());
152 #else 153 #else
153 // TEST for scene extents - Rotate the axes 154 // TEST for scene extents - Rotate the axes
154 double a = 15.0 / 180.0 * M_PI; 155 double a = 15.0 / 180.0 * M_PI;
155 156
156 #if 1 157 #if 1
167 #endif 168 #endif
168 } 169 }
169 } 170 }
170 171
171 172
172 virtual void NotifyGeometryReady(const ILayerSource& source) 173 void OnMainWidgetGeometryReady(const ILayerSource::GeometryReadyMessage& message)
173 { 174 {
174 // Once the geometry of the series is downloaded from Orthanc, 175 // Once the geometry of the series is downloaded from Orthanc,
175 // display its first slice, and adapt the viewport to fit this 176 // display its middle slice, and adapt the viewport to fit this
176 // slice 177 // slice
177 if (source_ == &source) 178 if (source_ == &message.origin_)
178 { 179 {
179 SetSlice(source_->GetSliceCount() / 2); 180 SetSlice(source_->GetSliceCount() / 2);
180 } 181 }
181 182
182 widget_->SetDefaultView(); 183 mainWidget_->SetDefaultView();
183 } 184 }
184 185
185 virtual void NotifyGeometryError(const ILayerSource& source) 186 LayerWidget* mainWidget_; // ownership is transfered to the application context
186 { 187 std::unique_ptr<Interactor> mainWidgetInteractor_;
187 } 188 std::unique_ptr<OrthancApiClient> orthancApiClient_;
188 189
189 virtual void NotifyContentChange(const ILayerSource& source) 190 const OrthancFrameLayerSource* source_;
190 { 191 unsigned int slice_;
191 } 192
192
193 virtual void NotifySliceChange(const ILayerSource& source,
194 const Slice& slice)
195 {
196 }
197
198 virtual void NotifyLayerReady(std::auto_ptr<ILayerRenderer>& layer,
199 const ILayerSource& source,
200 const CoordinateSystem3D& slice,
201 bool isError)
202 {
203 }
204
205 LayerWidget* widget_;
206 const OrthancFrameLayerSource* source_;
207 unsigned int slice_;
208
209 public: 193 public:
210 SingleFrameApplication() : 194 SingleFrameApplication(MessageBroker& broker) :
211 widget_(NULL), 195 IObserver(broker),
212 source_(NULL), 196 source_(NULL),
213 slice_(0) 197 slice_(0)
214 { 198 {
215 } 199 }
216 200
227 ; 211 ;
228 212
229 options.add(generic); 213 options.add(generic);
230 } 214 }
231 215
232 virtual void Initialize(IStatusBar& statusBar, 216 virtual void Initialize(StoneApplicationContext* context,
217 IStatusBar& statusBar,
233 const boost::program_options::variables_map& parameters) 218 const boost::program_options::variables_map& parameters)
234 { 219 {
235 using namespace OrthancStone; 220 using namespace OrthancStone;
221
222 context_ = context;
236 223
237 statusBar.SetMessage("Use the key \"s\" to reinitialize the layout"); 224 statusBar.SetMessage("Use the key \"s\" to reinitialize the layout");
238 225
239 if (parameters.count("instance") != 1) 226 if (parameters.count("instance") != 1)
240 { 227 {
243 } 230 }
244 231
245 std::string instance = parameters["instance"].as<std::string>(); 232 std::string instance = parameters["instance"].as<std::string>();
246 int frame = parameters["frame"].as<unsigned int>(); 233 int frame = parameters["frame"].as<unsigned int>();
247 234
248 std::auto_ptr<LayerWidget> widget(new LayerWidget); 235 orthancApiClient_.reset(new OrthancApiClient(IObserver::broker_, context_->GetWebService()));
249 236 mainWidget_ = new LayerWidget(broker_, "main-widget");
250 #if 1 237
251 std::auto_ptr<OrthancFrameLayerSource> layer 238 std::auto_ptr<OrthancFrameLayerSource> layer(new OrthancFrameLayerSource(broker_, *orthancApiClient_));
252 (new OrthancFrameLayerSource(context_->GetWebService())); 239 source_ = layer.get();
253 //layer->SetImageQuality(SliceImageQuality_Jpeg50);
254 layer->LoadFrame(instance, frame); 240 layer->LoadFrame(instance, frame);
255 //layer->LoadSeries("6f1b492a-e181e200-44e51840-ef8db55e-af529ab6"); 241 layer->RegisterObserverCallback(new Callable<SingleFrameApplication, ILayerSource::GeometryReadyMessage>(*this, &SingleFrameApplication::OnMainWidgetGeometryReady));
256 layer->Register(*this); 242 mainWidget_->AddLayer(layer.release());
257 source_ = layer.get();
258 widget->AddLayer(layer.release());
259 243
260 RenderStyle s; 244 RenderStyle s;
261 245
262 if (parameters["smooth"].as<bool>()) 246 if (parameters["smooth"].as<bool>())
263 { 247 {
264 s.interpolation_ = ImageInterpolation_Bilinear; 248 s.interpolation_ = ImageInterpolation_Bilinear;
265 } 249 }
266 250
267 //s.drawGrid_ = true; 251 mainWidget_->SetLayerStyle(0, s);
268 widget->SetLayerStyle(0, s); 252 mainWidget_->SetTransmitMouseOver(true);
269 #else 253
270 // 0178023P** 254 mainWidgetInteractor_.reset(new Interactor(*this));
271 // Extent of the CT layer: (-35.068 -20.368) => (34.932 49.632) 255 mainWidget_->SetInteractor(*mainWidgetInteractor_);
272 std::auto_ptr<OrthancFrameLayerSource> ct; 256 }
273 ct.reset(new OrthancFrameLayerSource(context_->GetWebService())); 257
274 //ct->LoadInstance("c804a1a2-142545c9-33b32fe2-3df4cec0-a2bea6d6", 0); 258 virtual void Finalize() {}
275 //ct->LoadInstance("4bd4304f-47478948-71b24af2-51f4f1bc-275b6c1b", 0); // BAD SLICE 259 virtual IWidget* GetCentralWidget() {return mainWidget_;}
276 //ct->SetImageQuality(SliceImageQuality_Jpeg50);
277 ct->LoadSeries("dd069910-4f090474-7d2bba07-e5c10783-f9e4fb1d");
278
279 ct->Register(*this);
280 widget->AddLayer(ct.release());
281
282 std::auto_ptr<OrthancFrameLayerSource> pet;
283 pet.reset(new OrthancFrameLayerSource(context_->GetWebService()));
284 //pet->LoadInstance("a1c4dc6b-255d27f0-88069875-8daed730-2f5ee5c6", 0);
285 pet->LoadSeries("aabad2e7-80702b5d-e599d26c-4f13398e-38d58a9e");
286 pet->Register(*this);
287 source_ = pet.get();
288 widget->AddLayer(pet.release());
289
290 {
291 RenderStyle s;
292 //s.drawGrid_ = true;
293 s.alpha_ = 1;
294 widget->SetLayerStyle(0, s);
295 }
296
297 {
298 RenderStyle s;
299 //s.drawGrid_ = true;
300 s.SetColor(255, 0, 0); // Draw missing PET layer in red
301 s.alpha_ = 0.5;
302 s.applyLut_ = true;
303 s.lut_ = Orthanc::EmbeddedResources::COLORMAP_JET;
304 s.interpolation_ = ImageInterpolation_Bilinear;
305 widget->SetLayerStyle(1, s);
306 }
307 #endif
308
309 widget_ = widget.get();
310 widget_->SetTransmitMouseOver(true);
311 widget_->SetInteractor(context_->AddInteractor(new Interactor(*this)));
312 context_->SetCentralWidget(widget.release());
313 }
314 }; 260 };
261
262
315 } 263 }
316 } 264 }