Mercurial > hg > orthanc-stone
annotate Applications/Samples/SimpleViewerApplication.h @ 318:3a4ca166fafa am-2
ImageAccessor refactoring + implemented Image Cache in SmartLoader
author | am@osimis.io |
---|---|
date | Mon, 08 Oct 2018 17:10:08 +0200 |
parents | b66d13708f40 |
children |
rev | line source |
---|---|
235 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
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. | |
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 | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
249 | 16 * |
235 | 17 * You should have received a copy of the GNU Affero General Public License |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #pragma once | |
23 | |
24 #include "SampleApplicationBase.h" | |
25 | |
26 #include "../../Framework/Layers/OrthancFrameLayerSource.h" | |
285
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
27 #include "../../Framework/Layers/CircleMeasureTracker.h" |
281 | 28 #include "../../Framework/Layers/LineMeasureTracker.h" |
235 | 29 #include "../../Framework/Widgets/LayerWidget.h" |
30 #include "../../Framework/Widgets/LayoutWidget.h" | |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
249
diff
changeset
|
31 #include "../../Framework/Messages/IObserver.h" |
258 | 32 #include "../../Framework/SmartLoader.h" |
235 | 33 |
287 | 34 #if ORTHANC_ENABLE_WASM==1 |
307 | 35 #include "../../Platforms/Wasm/WasmPlatformApplicationAdapter.h" |
287 | 36 #include "../../Platforms/Wasm/Defaults.h" |
37 #endif | |
235 | 38 #include <Core/Logging.h> |
39 | |
40 namespace OrthancStone | |
41 { | |
42 namespace Samples | |
43 { | |
44 class SimpleViewerApplication : | |
249 | 45 public SampleApplicationBase, |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
249
diff
changeset
|
46 public IObserver |
235 | 47 { |
48 private: | |
273
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
49 class ThumbnailInteractor : public IWorldSceneInteractor |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
50 { |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
51 private: |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
52 SimpleViewerApplication& application_; |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
53 public: |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
54 ThumbnailInteractor(SimpleViewerApplication& application) : |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
55 application_(application) |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
56 { |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
57 } |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
58 |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
59 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& widget, |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
60 const ViewportGeometry& view, |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
61 MouseButton button, |
281 | 62 KeyboardModifiers modifiers, |
273
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
63 double x, |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
64 double y, |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
65 IStatusBar* statusBar) |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
66 { |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
67 if (button == MouseButton_Left) |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
68 { |
279
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
69 statusBar->SetMessage("selected thumbnail " + widget.GetName()); |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
70 std::string seriesId = widget.GetName().substr(strlen("thumbnail-series-")); |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
71 application_.SelectSeriesInMainViewport(seriesId); |
273
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
72 } |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
73 return NULL; |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
74 } |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
75 virtual void MouseOver(CairoContext& context, |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
76 WorldSceneWidget& widget, |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
77 const ViewportGeometry& view, |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
78 double x, |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
79 double y, |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
80 IStatusBar* statusBar) |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
81 {} |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
82 |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
83 virtual void MouseWheel(WorldSceneWidget& widget, |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
84 MouseWheelDirection direction, |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
85 KeyboardModifiers modifiers, |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
86 IStatusBar* statusBar) |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
87 {} |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
88 |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
89 virtual void KeyPressed(WorldSceneWidget& widget, |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
90 char key, |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
91 KeyboardModifiers modifiers, |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
92 IStatusBar* statusBar) |
281 | 93 {} |
273
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
94 |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
95 }; |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
96 |
281 | 97 class MainWidgetInteractor : public IWorldSceneInteractor |
235 | 98 { |
99 private: | |
100 SimpleViewerApplication& application_; | |
101 | |
102 public: | |
281 | 103 MainWidgetInteractor(SimpleViewerApplication& application) : |
235 | 104 application_(application) |
105 { | |
106 } | |
107 | |
108 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& widget, | |
109 const ViewportGeometry& view, | |
110 MouseButton button, | |
281 | 111 KeyboardModifiers modifiers, |
235 | 112 double x, |
113 double y, | |
114 IStatusBar* statusBar) | |
115 { | |
281 | 116 if (button == MouseButton_Left) |
117 { | |
285
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
118 if (application_.currentTool_ == Tools_LineMeasure) |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
119 { |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
120 return new LineMeasureTracker(statusBar, dynamic_cast<LayerWidget&>(widget).GetSlice(), x, y, 255, 0, 0, 10); |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
121 } |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
122 else if (application_.currentTool_ == Tools_CircleMeasure) |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
123 { |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
124 return new CircleMeasureTracker(statusBar, dynamic_cast<LayerWidget&>(widget).GetSlice(), x, y, 255, 0, 0, 10); |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
125 } |
281 | 126 } |
235 | 127 return NULL; |
128 } | |
129 | |
130 virtual void MouseOver(CairoContext& context, | |
131 WorldSceneWidget& widget, | |
132 const ViewportGeometry& view, | |
133 double x, | |
134 double y, | |
135 IStatusBar* statusBar) | |
136 { | |
137 if (statusBar != NULL) | |
138 { | |
139 Vector p = dynamic_cast<LayerWidget&>(widget).GetSlice().MapSliceToWorldCoordinates(x, y); | |
140 | |
141 char buf[64]; | |
249 | 142 sprintf(buf, "X = %.02f Y = %.02f Z = %.02f (in cm)", |
235 | 143 p[0] / 10.0, p[1] / 10.0, p[2] / 10.0); |
144 statusBar->SetMessage(buf); | |
145 } | |
146 } | |
147 | |
148 virtual void MouseWheel(WorldSceneWidget& widget, | |
149 MouseWheelDirection direction, | |
150 KeyboardModifiers modifiers, | |
151 IStatusBar* statusBar) | |
152 { | |
153 } | |
154 | |
155 virtual void KeyPressed(WorldSceneWidget& widget, | |
156 char key, | |
157 KeyboardModifiers modifiers, | |
158 IStatusBar* statusBar) | |
159 { | |
160 switch (key) | |
161 { | |
249 | 162 case 's': |
163 widget.SetDefaultView(); | |
164 break; | |
235 | 165 |
249 | 166 default: |
167 break; | |
235 | 168 } |
169 } | |
170 }; | |
171 | |
307 | 172 |
173 #if ORTHANC_ENABLE_WASM==1 | |
174 class SimpleViewerApplicationAdapter : public WasmPlatformApplicationAdapter | |
175 { | |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
176 SimpleViewerApplication& viewerApplication_; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
177 |
307 | 178 public: |
179 SimpleViewerApplicationAdapter(MessageBroker& broker, SimpleViewerApplication& application) | |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
180 : WasmPlatformApplicationAdapter(broker, application), |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
181 viewerApplication_(application) |
307 | 182 { |
183 | |
184 } | |
185 | |
186 virtual void HandleMessageFromWeb(std::string& output, const std::string& input) { | |
187 if (input == "select-tool:line-measure") | |
188 { | |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
189 viewerApplication_.currentTool_ = Tools_LineMeasure; |
307 | 190 NotifyStatusUpdateFromCppToWeb("currentTool=line-measure"); |
191 } | |
192 else if (input == "select-tool:circle-measure") | |
193 { | |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
194 viewerApplication_.currentTool_ = Tools_CircleMeasure; |
307 | 195 NotifyStatusUpdateFromCppToWeb("currentTool=circle-measure"); |
196 } | |
197 | |
198 output = "ok"; | |
199 } | |
200 | |
201 virtual void NotifyStatusUpdateFromCppToWeb(const std::string& statusUpdateMessage) { | |
202 UpdateStoneApplicationStatusFromCpp(statusUpdateMessage.c_str()); | |
203 } | |
204 | |
205 }; | |
206 #endif | |
285
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
207 enum Tools { |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
208 Tools_LineMeasure, |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
209 Tools_CircleMeasure |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
210 }; |
235 | 211 |
285
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
212 Tools currentTool_; |
281 | 213 std::unique_ptr<MainWidgetInteractor> mainWidgetInteractor_; |
273
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
214 std::unique_ptr<ThumbnailInteractor> thumbnailInteractor_; |
235 | 215 LayoutWidget* mainLayout_; |
216 LayoutWidget* thumbnailsLayout_; | |
273
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
217 LayerWidget* mainWidget_; |
235 | 218 std::vector<LayerWidget*> thumbnails_; |
279
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
219 std::map<std::string, std::vector<std::string>> instancesIdsPerSeriesId_; |
287 | 220 std::map<std::string, Json::Value> seriesTags_; |
270 | 221 |
235 | 222 unsigned int currentInstanceIndex_; |
270 | 223 OrthancStone::WidgetViewport* wasmViewport1_; |
224 OrthancStone::WidgetViewport* wasmViewport2_; | |
235 | 225 |
254 | 226 IStatusBar* statusBar_; |
258 | 227 std::unique_ptr<SmartLoader> smartLoader_; |
270 | 228 std::unique_ptr<OrthancApiClient> orthancApiClient_; |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
249
diff
changeset
|
229 |
235 | 230 public: |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
249
diff
changeset
|
231 SimpleViewerApplication(MessageBroker& broker) : |
258 | 232 IObserver(broker), |
285
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
233 currentTool_(Tools_LineMeasure), |
235 | 234 mainLayout_(NULL), |
235 currentInstanceIndex_(0), | |
242 | 236 wasmViewport1_(NULL), |
285
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
237 wasmViewport2_(NULL) |
235 | 238 { |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
239 // DeclareIgnoredMessage(MessageType_Widget_ContentChanged); |
235 | 240 } |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
249
diff
changeset
|
241 |
237
b4642964c355
SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents:
235
diff
changeset
|
242 virtual void Finalize() {} |
b4642964c355
SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents:
235
diff
changeset
|
243 virtual IWidget* GetCentralWidget() {return mainLayout_;} |
b4642964c355
SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents:
235
diff
changeset
|
244 |
235 | 245 virtual void DeclareStartupOptions(boost::program_options::options_description& options) |
246 { | |
247 boost::program_options::options_description generic("Sample options"); | |
248 generic.add_options() | |
270 | 249 ("studyId", boost::program_options::value<std::string>(), |
250 "Orthanc ID of the study") | |
249 | 251 ; |
235 | 252 |
249 | 253 options.add(generic); |
235 | 254 } |
255 | |
288 | 256 virtual void Initialize(StoneApplicationContext* context, |
242 | 257 IStatusBar& statusBar, |
235 | 258 const boost::program_options::variables_map& parameters) |
259 { | |
260 using namespace OrthancStone; | |
261 | |
242 | 262 context_ = context; |
254 | 263 statusBar_ = &statusBar; |
270 | 264 |
265 {// initialize viewports and layout | |
273
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
266 mainLayout_ = new LayoutWidget("main-layout"); |
270 | 267 mainLayout_->SetPadding(10); |
268 mainLayout_->SetBackgroundCleared(true); | |
269 mainLayout_->SetBackgroundColor(0, 0, 0); | |
270 mainLayout_->SetHorizontal(); | |
271 | |
273
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
272 thumbnailsLayout_ = new LayoutWidget("thumbnail-layout"); |
270 | 273 thumbnailsLayout_->SetPadding(10); |
274 thumbnailsLayout_->SetBackgroundCleared(true); | |
275 thumbnailsLayout_->SetBackgroundColor(50, 50, 50); | |
276 thumbnailsLayout_->SetVertical(); | |
277 | |
273
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
278 mainWidget_ = new LayerWidget(broker_, "main-viewport"); |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
279 //mainWidget_->RegisterObserver(*this); |
270 | 280 |
281 // hierarchy | |
282 mainLayout_->AddWidget(thumbnailsLayout_); | |
273
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
283 mainLayout_->AddWidget(mainWidget_); |
270 | 284 |
317 | 285 orthancApiClient_.reset(new OrthancApiClient(IObserver::broker_, context_->GetWebService())); |
286 | |
270 | 287 // sources |
317 | 288 smartLoader_.reset(new SmartLoader(IObserver::broker_, *orthancApiClient_)); |
270 | 289 smartLoader_->SetImageQuality(SliceImageQuality_FullPam); |
290 | |
291 mainLayout_->SetTransmitMouseOver(true); | |
281 | 292 mainWidgetInteractor_.reset(new MainWidgetInteractor(*this)); |
293 mainWidget_->SetInteractor(*mainWidgetInteractor_); | |
273
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
294 thumbnailInteractor_.reset(new ThumbnailInteractor(*this)); |
270 | 295 } |
296 | |
235 | 297 statusBar.SetMessage("Use the key \"s\" to reinitialize the layout"); |
254 | 298 statusBar.SetMessage("Use the key \"n\" to go to next image in the main viewport"); |
235 | 299 |
270 | 300 |
301 if (parameters.count("studyId") < 1) | |
235 | 302 { |
270 | 303 LOG(WARNING) << "The study ID is missing, will take the first studyId found in Orthanc"; |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
304 orthancApiClient_->GetJsonAsync("/studies", new Callable<SimpleViewerApplication, OrthancApiClient::JsonResponseReadyMessage>(*this, &SimpleViewerApplication::OnStudyListReceived)); |
235 | 305 } |
270 | 306 else |
235 | 307 { |
270 | 308 SelectStudy(parameters["studyId"].as<std::string>()); |
235 | 309 } |
270 | 310 } |
235 | 311 |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
312 void OnStudyListReceived(const OrthancApiClient::JsonResponseReadyMessage& message) |
270 | 313 { |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
314 const Json::Value& response = message.Response; |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
315 |
270 | 316 if (response.isArray() && response.size() > 1) |
317 { | |
318 SelectStudy(response[0].asString()); | |
319 } | |
320 } | |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
321 void OnStudyReceived(const OrthancApiClient::JsonResponseReadyMessage& message) |
270 | 322 { |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
323 const Json::Value& response = message.Response; |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
324 |
270 | 325 if (response.isObject() && response["Series"].isArray()) |
326 { | |
327 for (size_t i=0; i < response["Series"].size(); i++) | |
328 { | |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
329 orthancApiClient_->GetJsonAsync("/series/" + response["Series"][(int)i].asString(), new Callable<SimpleViewerApplication, OrthancApiClient::JsonResponseReadyMessage>(*this, &SimpleViewerApplication::OnSeriesReceived)); |
270 | 330 } |
331 } | |
332 } | |
235 | 333 |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
334 void OnSeriesReceived(const OrthancApiClient::JsonResponseReadyMessage& message) |
270 | 335 { |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
336 const Json::Value& response = message.Response; |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
337 |
270 | 338 if (response.isObject() && response["Instances"].isArray() && response["Instances"].size() > 0) |
339 { | |
279
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
340 // keep track of all instances IDs |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
341 const std::string& seriesId = response["ID"].asString(); |
287 | 342 seriesTags_[seriesId] = response; |
279
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
343 instancesIdsPerSeriesId_[seriesId] = std::vector<std::string>(); |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
344 for (size_t i = 0; i < response["Instances"].size(); i++) |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
345 { |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
346 const std::string& instanceId = response["Instances"][static_cast<int>(i)].asString(); |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
347 instancesIdsPerSeriesId_[seriesId].push_back(instanceId); |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
348 } |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
349 |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
350 // load the first instance in the thumbnail |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
351 LoadThumbnailForSeries(seriesId, instancesIdsPerSeriesId_[seriesId][0]); |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
352 |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
353 // if this is the first thumbnail loaded, load the first instance in the mainWidget |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
354 if (mainWidget_->GetLayerCount() == 0) |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
355 { |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
356 smartLoader_->SetFrameInWidget(*mainWidget_, 0, instancesIdsPerSeriesId_[seriesId][0], 0); |
279
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
357 } |
270 | 358 } |
359 } | |
360 | |
361 void LoadThumbnailForSeries(const std::string& seriesId, const std::string& instanceId) | |
362 { | |
271
46c5296d867e
OracleWebService and BasicSdlApplicationContext using the same global mutex
am@osimis.io
parents:
270
diff
changeset
|
363 LOG(INFO) << "Loading thumbnail for series " << seriesId; |
307 | 364 LayerWidget* thumbnailWidget = new LayerWidget(IObserver::broker_, "thumbnail-series-" + seriesId); |
271
46c5296d867e
OracleWebService and BasicSdlApplicationContext using the same global mutex
am@osimis.io
parents:
270
diff
changeset
|
365 thumbnails_.push_back(thumbnailWidget); |
46c5296d867e
OracleWebService and BasicSdlApplicationContext using the same global mutex
am@osimis.io
parents:
270
diff
changeset
|
366 thumbnailsLayout_->AddWidget(thumbnailWidget); |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
367 thumbnailWidget->RegisterObserverCallback(new Callable<SimpleViewerApplication, LayerWidget::GeometryChangedMessage>(*this, &SimpleViewerApplication::OnWidgetGeometryChanged)); |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
368 smartLoader_->SetFrameInWidget(*thumbnailWidget, 0, instanceId, 0); |
279
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
369 thumbnailWidget->SetInteractor(*thumbnailInteractor_); |
270 | 370 } |
235 | 371 |
270 | 372 void SelectStudy(const std::string& studyId) |
373 { | |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
374 orthancApiClient_->GetJsonAsync("/studies/" + studyId, new Callable<SimpleViewerApplication, OrthancApiClient::JsonResponseReadyMessage>(*this, &SimpleViewerApplication::OnStudyReceived)); |
270 | 375 } |
376 | |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
377 void OnWidgetGeometryChanged(const LayerWidget::GeometryChangedMessage& message) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
378 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
379 message.origin_.SetDefaultView(); |
242 | 380 } |
237
b4642964c355
SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents:
235
diff
changeset
|
381 |
279
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
382 void SelectSeriesInMainViewport(const std::string& seriesId) |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
383 { |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
384 smartLoader_->SetFrameInWidget(*mainWidget_, 0, instancesIdsPerSeriesId_[seriesId][0], 0); |
249 | 385 } |
285
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
386 |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
387 virtual void OnPushButton1Clicked() {} |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
388 virtual void OnPushButton2Clicked() {} |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
389 virtual void OnTool1Clicked() { currentTool_ = Tools_LineMeasure;} |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
390 virtual void OnTool2Clicked() { currentTool_ = Tools_CircleMeasure;} |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
391 |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
392 virtual void GetButtonNames(std::string& pushButton1, |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
393 std::string& pushButton2, |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
394 std::string& tool1, |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
395 std::string& tool2 |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
396 ) { |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
397 tool1 = "line"; |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
398 tool2 = "circle"; |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
399 pushButton1 = "action1"; |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
400 pushButton2 = "action2"; |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
401 } |
287 | 402 |
403 #if ORTHANC_ENABLE_WASM==1 | |
404 virtual void InitializeWasm() { | |
405 | |
406 AttachWidgetToWasmViewport("canvas", thumbnailsLayout_); | |
407 AttachWidgetToWasmViewport("canvas2", mainWidget_); | |
408 } | |
409 #endif | |
235 | 410 }; |
249 | 411 |
412 | |
235 | 413 } |
414 } |