Mercurial > hg > orthanc-stone
comparison Applications/Samples/SimpleViewerApplicationSingleFile.h @ 726:4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 21 May 2019 11:43:25 +0200 |
parents | 79bb0a02d1cc |
children | c35e98d22764 |
comparison
equal
deleted
inserted
replaced
714:d2c0e347ddc2 | 726:4f2416d519b4 |
---|---|
45 class SimpleViewerApplication : | 45 class SimpleViewerApplication : |
46 public SampleSingleCanvasWithButtonsApplicationBase, | 46 public SampleSingleCanvasWithButtonsApplicationBase, |
47 public IObserver | 47 public IObserver |
48 { | 48 { |
49 private: | 49 private: |
50 class ThumbnailInteractor : public IWorldSceneInteractor | 50 class ThumbnailInteractor : public Deprecated::IWorldSceneInteractor |
51 { | 51 { |
52 private: | 52 private: |
53 SimpleViewerApplication& application_; | 53 SimpleViewerApplication& application_; |
54 | 54 |
55 public: | 55 public: |
56 ThumbnailInteractor(SimpleViewerApplication& application) : | 56 ThumbnailInteractor(SimpleViewerApplication& application) : |
57 application_(application) | 57 application_(application) |
58 { | 58 { |
59 } | 59 } |
60 | 60 |
61 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& widget, | 61 virtual Deprecated::IWorldSceneMouseTracker* CreateMouseTracker(Deprecated::WorldSceneWidget& widget, |
62 const ViewportGeometry& view, | 62 const Deprecated::ViewportGeometry& view, |
63 MouseButton button, | 63 MouseButton button, |
64 KeyboardModifiers modifiers, | 64 KeyboardModifiers modifiers, |
65 int viewportX, | 65 int viewportX, |
66 int viewportY, | 66 int viewportY, |
67 double x, | 67 double x, |
68 double y, | 68 double y, |
69 IStatusBar* statusBar, | 69 Deprecated::IStatusBar* statusBar, |
70 const std::vector<Touch>& displayTouches) | 70 const std::vector<Deprecated::Touch>& displayTouches) |
71 { | 71 { |
72 if (button == MouseButton_Left) | 72 if (button == MouseButton_Left) |
73 { | 73 { |
74 statusBar->SetMessage("selected thumbnail " + widget.GetName()); | 74 statusBar->SetMessage("selected thumbnail " + widget.GetName()); |
75 std::string seriesId = widget.GetName().substr(strlen("thumbnail-series-")); | 75 std::string seriesId = widget.GetName().substr(strlen("thumbnail-series-")); |
77 } | 77 } |
78 return NULL; | 78 return NULL; |
79 } | 79 } |
80 | 80 |
81 virtual void MouseOver(CairoContext& context, | 81 virtual void MouseOver(CairoContext& context, |
82 WorldSceneWidget& widget, | 82 Deprecated::WorldSceneWidget& widget, |
83 const ViewportGeometry& view, | 83 const Deprecated::ViewportGeometry& view, |
84 double x, | 84 double x, |
85 double y, | 85 double y, |
86 IStatusBar* statusBar) | 86 Deprecated::IStatusBar* statusBar) |
87 { | 87 { |
88 } | 88 } |
89 | 89 |
90 virtual void MouseWheel(WorldSceneWidget& widget, | 90 virtual void MouseWheel(Deprecated::WorldSceneWidget& widget, |
91 MouseWheelDirection direction, | 91 MouseWheelDirection direction, |
92 KeyboardModifiers modifiers, | 92 KeyboardModifiers modifiers, |
93 IStatusBar* statusBar) | 93 Deprecated::IStatusBar* statusBar) |
94 { | 94 { |
95 } | 95 } |
96 | 96 |
97 virtual void KeyPressed(WorldSceneWidget& widget, | 97 virtual void KeyPressed(Deprecated::WorldSceneWidget& widget, |
98 KeyboardKeys key, | 98 KeyboardKeys key, |
99 char keyChar, | 99 char keyChar, |
100 KeyboardModifiers modifiers, | 100 KeyboardModifiers modifiers, |
101 IStatusBar* statusBar) | 101 Deprecated::IStatusBar* statusBar) |
102 { | 102 { |
103 } | 103 } |
104 }; | 104 }; |
105 | 105 |
106 class MainWidgetInteractor : public IWorldSceneInteractor | 106 class MainWidgetInteractor : public Deprecated::IWorldSceneInteractor |
107 { | 107 { |
108 private: | 108 private: |
109 SimpleViewerApplication& application_; | 109 SimpleViewerApplication& application_; |
110 | 110 |
111 public: | 111 public: |
112 MainWidgetInteractor(SimpleViewerApplication& application) : | 112 MainWidgetInteractor(SimpleViewerApplication& application) : |
113 application_(application) | 113 application_(application) |
114 { | 114 { |
115 } | 115 } |
116 | 116 |
117 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& widget, | 117 virtual Deprecated::IWorldSceneMouseTracker* CreateMouseTracker(Deprecated::WorldSceneWidget& widget, |
118 const ViewportGeometry& view, | 118 const Deprecated::ViewportGeometry& view, |
119 MouseButton button, | 119 MouseButton button, |
120 KeyboardModifiers modifiers, | 120 KeyboardModifiers modifiers, |
121 int viewportX, | 121 int viewportX, |
122 int viewportY, | 122 int viewportY, |
123 double x, | 123 double x, |
124 double y, | 124 double y, |
125 IStatusBar* statusBar, | 125 Deprecated::IStatusBar* statusBar, |
126 const std::vector<Touch>& displayTouches) | 126 const std::vector<Deprecated::Touch>& displayTouches) |
127 { | 127 { |
128 if (button == MouseButton_Left) | 128 if (button == MouseButton_Left) |
129 { | 129 { |
130 if (application_.currentTool_ == Tool_LineMeasure) | 130 if (application_.currentTool_ == Tool_LineMeasure) |
131 { | 131 { |
132 return new LineMeasureTracker(statusBar, dynamic_cast<SliceViewerWidget&>(widget).GetSlice(), | 132 return new Deprecated::LineMeasureTracker(statusBar, dynamic_cast<Deprecated::SliceViewerWidget&>(widget).GetSlice(), |
133 x, y, 255, 0, 0, application_.GetFont()); | 133 x, y, 255, 0, 0, application_.GetFont()); |
134 } | 134 } |
135 else if (application_.currentTool_ == Tool_CircleMeasure) | 135 else if (application_.currentTool_ == Tool_CircleMeasure) |
136 { | 136 { |
137 return new CircleMeasureTracker(statusBar, dynamic_cast<SliceViewerWidget&>(widget).GetSlice(), | 137 return new Deprecated::CircleMeasureTracker(statusBar, dynamic_cast<Deprecated::SliceViewerWidget&>(widget).GetSlice(), |
138 x, y, 255, 0, 0, application_.GetFont()); | 138 x, y, 255, 0, 0, application_.GetFont()); |
139 } | 139 } |
140 } | 140 } |
141 return NULL; | 141 return NULL; |
142 } | 142 } |
143 | 143 |
144 virtual void MouseOver(CairoContext& context, | 144 virtual void MouseOver(CairoContext& context, |
145 WorldSceneWidget& widget, | 145 Deprecated::WorldSceneWidget& widget, |
146 const ViewportGeometry& view, | 146 const Deprecated::ViewportGeometry& view, |
147 double x, | 147 double x, |
148 double y, | 148 double y, |
149 IStatusBar* statusBar) | 149 Deprecated::IStatusBar* statusBar) |
150 { | 150 { |
151 if (statusBar != NULL) | 151 if (statusBar != NULL) |
152 { | 152 { |
153 Vector p = dynamic_cast<SliceViewerWidget&>(widget).GetSlice().MapSliceToWorldCoordinates(x, y); | 153 Vector p = dynamic_cast<Deprecated::SliceViewerWidget&>(widget).GetSlice().MapSliceToWorldCoordinates(x, y); |
154 | 154 |
155 char buf[64]; | 155 char buf[64]; |
156 sprintf(buf, "X = %.02f Y = %.02f Z = %.02f (in cm)", | 156 sprintf(buf, "X = %.02f Y = %.02f Z = %.02f (in cm)", |
157 p[0] / 10.0, p[1] / 10.0, p[2] / 10.0); | 157 p[0] / 10.0, p[1] / 10.0, p[2] / 10.0); |
158 statusBar->SetMessage(buf); | 158 statusBar->SetMessage(buf); |
159 } | 159 } |
160 } | 160 } |
161 | 161 |
162 virtual void MouseWheel(WorldSceneWidget& widget, | 162 virtual void MouseWheel(Deprecated::WorldSceneWidget& widget, |
163 MouseWheelDirection direction, | 163 MouseWheelDirection direction, |
164 KeyboardModifiers modifiers, | 164 KeyboardModifiers modifiers, |
165 IStatusBar* statusBar) | 165 Deprecated::IStatusBar* statusBar) |
166 { | 166 { |
167 } | 167 } |
168 | 168 |
169 virtual void KeyPressed(WorldSceneWidget& widget, | 169 virtual void KeyPressed(Deprecated::WorldSceneWidget& widget, |
170 KeyboardKeys key, | 170 KeyboardKeys key, |
171 char keyChar, | 171 char keyChar, |
172 KeyboardModifiers modifiers, | 172 KeyboardModifiers modifiers, |
173 IStatusBar* statusBar) | 173 Deprecated::IStatusBar* statusBar) |
174 { | 174 { |
175 switch (keyChar) | 175 switch (keyChar) |
176 { | 176 { |
177 case 's': | 177 case 's': |
178 widget.FitContent(); | 178 widget.FitContent(); |
239 }; | 239 }; |
240 | 240 |
241 Tool currentTool_; | 241 Tool currentTool_; |
242 std::auto_ptr<MainWidgetInteractor> mainWidgetInteractor_; | 242 std::auto_ptr<MainWidgetInteractor> mainWidgetInteractor_; |
243 std::auto_ptr<ThumbnailInteractor> thumbnailInteractor_; | 243 std::auto_ptr<ThumbnailInteractor> thumbnailInteractor_; |
244 LayoutWidget* mainLayout_; | 244 Deprecated::LayoutWidget* mainLayout_; |
245 LayoutWidget* thumbnailsLayout_; | 245 Deprecated::LayoutWidget* thumbnailsLayout_; |
246 std::vector<SliceViewerWidget*> thumbnails_; | 246 std::vector<Deprecated::SliceViewerWidget*> thumbnails_; |
247 | 247 |
248 std::map<std::string, std::vector<std::string> > instancesIdsPerSeriesId_; | 248 std::map<std::string, std::vector<std::string> > instancesIdsPerSeriesId_; |
249 std::map<std::string, Json::Value> seriesTags_; | 249 std::map<std::string, Json::Value> seriesTags_; |
250 | 250 |
251 unsigned int currentInstanceIndex_; | 251 unsigned int currentInstanceIndex_; |
252 OrthancStone::WidgetViewport* wasmViewport1_; | 252 Deprecated::WidgetViewport* wasmViewport1_; |
253 OrthancStone::WidgetViewport* wasmViewport2_; | 253 Deprecated::WidgetViewport* wasmViewport2_; |
254 | 254 |
255 IStatusBar* statusBar_; | 255 Deprecated::IStatusBar* statusBar_; |
256 std::auto_ptr<SmartLoader> smartLoader_; | 256 std::auto_ptr<Deprecated::SmartLoader> smartLoader_; |
257 | 257 |
258 Orthanc::Font font_; | 258 Orthanc::Font font_; |
259 | 259 |
260 public: | 260 public: |
261 SimpleViewerApplication(MessageBroker& broker) : | 261 SimpleViewerApplication(MessageBroker& broker) : |
280 | 280 |
281 options.add(generic); | 281 options.add(generic); |
282 } | 282 } |
283 | 283 |
284 virtual void Initialize(StoneApplicationContext* context, | 284 virtual void Initialize(StoneApplicationContext* context, |
285 IStatusBar& statusBar, | 285 Deprecated::IStatusBar& statusBar, |
286 const boost::program_options::variables_map& parameters) | 286 const boost::program_options::variables_map& parameters) |
287 { | 287 { |
288 using namespace OrthancStone; | 288 using namespace OrthancStone; |
289 | 289 |
290 context_ = context; | 290 context_ = context; |
291 statusBar_ = &statusBar; | 291 statusBar_ = &statusBar; |
292 | 292 |
293 {// initialize viewports and layout | 293 {// initialize viewports and layout |
294 mainLayout_ = new LayoutWidget("main-layout"); | 294 mainLayout_ = new Deprecated::LayoutWidget("main-layout"); |
295 mainLayout_->SetPadding(10); | 295 mainLayout_->SetPadding(10); |
296 mainLayout_->SetBackgroundCleared(true); | 296 mainLayout_->SetBackgroundCleared(true); |
297 mainLayout_->SetBackgroundColor(0, 0, 0); | 297 mainLayout_->SetBackgroundColor(0, 0, 0); |
298 mainLayout_->SetHorizontal(); | 298 mainLayout_->SetHorizontal(); |
299 | 299 |
300 thumbnailsLayout_ = new LayoutWidget("thumbnail-layout"); | 300 thumbnailsLayout_ = new Deprecated::LayoutWidget("thumbnail-layout"); |
301 thumbnailsLayout_->SetPadding(10); | 301 thumbnailsLayout_->SetPadding(10); |
302 thumbnailsLayout_->SetBackgroundCleared(true); | 302 thumbnailsLayout_->SetBackgroundCleared(true); |
303 thumbnailsLayout_->SetBackgroundColor(50, 50, 50); | 303 thumbnailsLayout_->SetBackgroundColor(50, 50, 50); |
304 thumbnailsLayout_->SetVertical(); | 304 thumbnailsLayout_->SetVertical(); |
305 | 305 |
306 mainWidget_ = new SliceViewerWidget(GetBroker(), "main-viewport"); | 306 mainWidget_ = new Deprecated::SliceViewerWidget(GetBroker(), "main-viewport"); |
307 //mainWidget_->RegisterObserver(*this); | 307 //mainWidget_->RegisterObserver(*this); |
308 | 308 |
309 // hierarchy | 309 // hierarchy |
310 mainLayout_->AddWidget(thumbnailsLayout_); | 310 mainLayout_->AddWidget(thumbnailsLayout_); |
311 mainLayout_->AddWidget(mainWidget_); | 311 mainLayout_->AddWidget(mainWidget_); |
312 | 312 |
313 // sources | 313 // sources |
314 smartLoader_.reset(new SmartLoader(GetBroker(), context->GetOrthancApiClient())); | 314 smartLoader_.reset(new Deprecated::SmartLoader(GetBroker(), context->GetOrthancApiClient())); |
315 smartLoader_->SetImageQuality(SliceImageQuality_FullPam); | 315 smartLoader_->SetImageQuality(SliceImageQuality_FullPam); |
316 | 316 |
317 mainLayout_->SetTransmitMouseOver(true); | 317 mainLayout_->SetTransmitMouseOver(true); |
318 mainWidgetInteractor_.reset(new MainWidgetInteractor(*this)); | 318 mainWidgetInteractor_.reset(new MainWidgetInteractor(*this)); |
319 mainWidget_->SetInteractor(*mainWidgetInteractor_); | 319 mainWidget_->SetInteractor(*mainWidgetInteractor_); |
327 if (parameters.count("studyId") < 1) | 327 if (parameters.count("studyId") < 1) |
328 { | 328 { |
329 LOG(WARNING) << "The study ID is missing, will take the first studyId found in Orthanc"; | 329 LOG(WARNING) << "The study ID is missing, will take the first studyId found in Orthanc"; |
330 context->GetOrthancApiClient().GetJsonAsync( | 330 context->GetOrthancApiClient().GetJsonAsync( |
331 "/studies", | 331 "/studies", |
332 new Callable<SimpleViewerApplication, OrthancApiClient::JsonResponseReadyMessage> | 332 new Callable<SimpleViewerApplication, Deprecated::OrthancApiClient::JsonResponseReadyMessage> |
333 (*this, &SimpleViewerApplication::OnStudyListReceived)); | 333 (*this, &SimpleViewerApplication::OnStudyListReceived)); |
334 } | 334 } |
335 else | 335 else |
336 { | 336 { |
337 SelectStudy(parameters["studyId"].as<std::string>()); | 337 SelectStudy(parameters["studyId"].as<std::string>()); |
338 } | 338 } |
339 } | 339 } |
340 | 340 |
341 void OnStudyListReceived(const OrthancApiClient::JsonResponseReadyMessage& message) | 341 void OnStudyListReceived(const Deprecated::OrthancApiClient::JsonResponseReadyMessage& message) |
342 { | 342 { |
343 const Json::Value& response = message.GetJson(); | 343 const Json::Value& response = message.GetJson(); |
344 | 344 |
345 if (response.isArray() && | 345 if (response.isArray() && |
346 response.size() >= 1) | 346 response.size() >= 1) |
347 { | 347 { |
348 SelectStudy(response[0].asString()); | 348 SelectStudy(response[0].asString()); |
349 } | 349 } |
350 } | 350 } |
351 | 351 |
352 void OnStudyReceived(const OrthancApiClient::JsonResponseReadyMessage& message) | 352 void OnStudyReceived(const Deprecated::OrthancApiClient::JsonResponseReadyMessage& message) |
353 { | 353 { |
354 const Json::Value& response = message.GetJson(); | 354 const Json::Value& response = message.GetJson(); |
355 | 355 |
356 if (response.isObject() && response["Series"].isArray()) | 356 if (response.isObject() && response["Series"].isArray()) |
357 { | 357 { |
358 for (size_t i=0; i < response["Series"].size(); i++) | 358 for (size_t i=0; i < response["Series"].size(); i++) |
359 { | 359 { |
360 context_->GetOrthancApiClient().GetJsonAsync( | 360 context_->GetOrthancApiClient().GetJsonAsync( |
361 "/series/" + response["Series"][(int)i].asString(), | 361 "/series/" + response["Series"][(int)i].asString(), |
362 new Callable<SimpleViewerApplication, OrthancApiClient::JsonResponseReadyMessage> | 362 new Callable<SimpleViewerApplication, Deprecated::OrthancApiClient::JsonResponseReadyMessage> |
363 (*this, &SimpleViewerApplication::OnSeriesReceived)); | 363 (*this, &SimpleViewerApplication::OnSeriesReceived)); |
364 } | 364 } |
365 } | 365 } |
366 } | 366 } |
367 | 367 |
368 void OnSeriesReceived(const OrthancApiClient::JsonResponseReadyMessage& message) | 368 void OnSeriesReceived(const Deprecated::OrthancApiClient::JsonResponseReadyMessage& message) |
369 { | 369 { |
370 const Json::Value& response = message.GetJson(); | 370 const Json::Value& response = message.GetJson(); |
371 | 371 |
372 if (response.isObject() && | 372 if (response.isObject() && |
373 response["Instances"].isArray() && | 373 response["Instances"].isArray() && |
385 | 385 |
386 // load the first instance in the thumbnail | 386 // load the first instance in the thumbnail |
387 LoadThumbnailForSeries(seriesId, instancesIdsPerSeriesId_[seriesId][0]); | 387 LoadThumbnailForSeries(seriesId, instancesIdsPerSeriesId_[seriesId][0]); |
388 | 388 |
389 // if this is the first thumbnail loaded, load the first instance in the mainWidget | 389 // if this is the first thumbnail loaded, load the first instance in the mainWidget |
390 SliceViewerWidget& widget = *dynamic_cast<SliceViewerWidget*>(mainWidget_); | 390 Deprecated::SliceViewerWidget& widget = *dynamic_cast<Deprecated::SliceViewerWidget*>(mainWidget_); |
391 if (widget.GetLayerCount() == 0) | 391 if (widget.GetLayerCount() == 0) |
392 { | 392 { |
393 smartLoader_->SetFrameInWidget(widget, 0, instancesIdsPerSeriesId_[seriesId][0], 0); | 393 smartLoader_->SetFrameInWidget(widget, 0, instancesIdsPerSeriesId_[seriesId][0], 0); |
394 } | 394 } |
395 } | 395 } |
396 } | 396 } |
397 | 397 |
398 void LoadThumbnailForSeries(const std::string& seriesId, const std::string& instanceId) | 398 void LoadThumbnailForSeries(const std::string& seriesId, const std::string& instanceId) |
399 { | 399 { |
400 LOG(INFO) << "Loading thumbnail for series " << seriesId; | 400 LOG(INFO) << "Loading thumbnail for series " << seriesId; |
401 SliceViewerWidget* thumbnailWidget = new SliceViewerWidget(GetBroker(), "thumbnail-series-" + seriesId); | 401 Deprecated::SliceViewerWidget* thumbnailWidget = new Deprecated::SliceViewerWidget(GetBroker(), "thumbnail-series-" + seriesId); |
402 thumbnails_.push_back(thumbnailWidget); | 402 thumbnails_.push_back(thumbnailWidget); |
403 thumbnailsLayout_->AddWidget(thumbnailWidget); | 403 thumbnailsLayout_->AddWidget(thumbnailWidget); |
404 thumbnailWidget->RegisterObserverCallback(new Callable<SimpleViewerApplication, SliceViewerWidget::GeometryChangedMessage>(*this, &SimpleViewerApplication::OnWidgetGeometryChanged)); | 404 thumbnailWidget->RegisterObserverCallback(new Callable<SimpleViewerApplication, Deprecated::SliceViewerWidget::GeometryChangedMessage>(*this, &SimpleViewerApplication::OnWidgetGeometryChanged)); |
405 smartLoader_->SetFrameInWidget(*thumbnailWidget, 0, instanceId, 0); | 405 smartLoader_->SetFrameInWidget(*thumbnailWidget, 0, instanceId, 0); |
406 thumbnailWidget->SetInteractor(*thumbnailInteractor_); | 406 thumbnailWidget->SetInteractor(*thumbnailInteractor_); |
407 } | 407 } |
408 | 408 |
409 void SelectStudy(const std::string& studyId) | 409 void SelectStudy(const std::string& studyId) |
410 { | 410 { |
411 LOG(INFO) << "Selecting study: " << studyId; | 411 LOG(INFO) << "Selecting study: " << studyId; |
412 context_->GetOrthancApiClient().GetJsonAsync( | 412 context_->GetOrthancApiClient().GetJsonAsync( |
413 "/studies/" + studyId, new Callable<SimpleViewerApplication, OrthancApiClient::JsonResponseReadyMessage> | 413 "/studies/" + studyId, new Callable<SimpleViewerApplication, Deprecated::OrthancApiClient::JsonResponseReadyMessage> |
414 (*this, &SimpleViewerApplication::OnStudyReceived)); | 414 (*this, &SimpleViewerApplication::OnStudyReceived)); |
415 } | 415 } |
416 | 416 |
417 void OnWidgetGeometryChanged(const SliceViewerWidget::GeometryChangedMessage& message) | 417 void OnWidgetGeometryChanged(const Deprecated::SliceViewerWidget::GeometryChangedMessage& message) |
418 { | 418 { |
419 // TODO: The "const_cast" could probably be replaced by "mainWidget" | 419 // TODO: The "const_cast" could probably be replaced by "mainWidget" |
420 const_cast<SliceViewerWidget&>(message.GetOrigin()).FitContent(); | 420 const_cast<Deprecated::SliceViewerWidget&>(message.GetOrigin()).FitContent(); |
421 } | 421 } |
422 | 422 |
423 void SelectSeriesInMainViewport(const std::string& seriesId) | 423 void SelectSeriesInMainViewport(const std::string& seriesId) |
424 { | 424 { |
425 SliceViewerWidget& widget = *dynamic_cast<SliceViewerWidget*>(mainWidget_); | 425 Deprecated::SliceViewerWidget& widget = *dynamic_cast<Deprecated::SliceViewerWidget*>(mainWidget_); |
426 smartLoader_->SetFrameInWidget(widget, 0, instancesIdsPerSeriesId_[seriesId][0], 0); | 426 smartLoader_->SetFrameInWidget(widget, 0, instancesIdsPerSeriesId_[seriesId][0], 0); |
427 } | 427 } |
428 | 428 |
429 const Orthanc::Font& GetFont() const | 429 const Orthanc::Font& GetFont() const |
430 { | 430 { |