annotate Applications/Samples/SimpleViewerApplication.h @ 266:c9cf95b49a86 am-2

removed OrthancSlicesLoader::ISliceLoaderObserver; now using standard messages instead
author am@osimis.io
date Tue, 21 Aug 2018 18:14:22 +0200
parents e5a9b3d03478
children 89d02de83c03
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
1 /**
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
2 * Stone of Orthanc
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
6 *
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
10 * the License, or (at your option) any later version.
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
11 *
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
15 * Affero General Public License for more details.
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
16 *
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
19 **/
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
20
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
21
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
22 #pragma once
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
23
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
24 #include "SampleApplicationBase.h"
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
25
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
26 #include "../../Framework/Layers/OrthancFrameLayerSource.h"
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
27 #include "../../Framework/Widgets/LayerWidget.h"
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
28 #include "../../Framework/Widgets/LayoutWidget.h"
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
29 #include "../../Framework/Messages/IObserver.h"
258
e5a9b3d03478 first very basic version of SmartLoader
am@osimis.io
parents: 257
diff changeset
30 #include "../../Framework/SmartLoader.h"
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
31
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
32 #include <Core/Logging.h>
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
33
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
34 namespace OrthancStone
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
35 {
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
36 namespace Samples
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
37 {
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
38 class SimpleViewerApplication :
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
39 public SampleApplicationBase,
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
40 public IObserver
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
41 {
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
42 private:
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
43 class Interactor : public IWorldSceneInteractor
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
44 {
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
45 private:
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
46 SimpleViewerApplication& application_;
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
47
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
48 public:
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
49 Interactor(SimpleViewerApplication& application) :
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
50 application_(application)
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
51 {
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
52 }
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
53
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
54 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& widget,
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
55 const ViewportGeometry& view,
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
56 MouseButton button,
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
57 double x,
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
58 double y,
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
59 IStatusBar* statusBar)
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
60 {
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
61 return NULL;
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
62 }
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
63
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
64 virtual void MouseOver(CairoContext& context,
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
65 WorldSceneWidget& widget,
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
66 const ViewportGeometry& view,
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
67 double x,
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
68 double y,
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
69 IStatusBar* statusBar)
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
70 {
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
71 if (statusBar != NULL)
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
72 {
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
73 Vector p = dynamic_cast<LayerWidget&>(widget).GetSlice().MapSliceToWorldCoordinates(x, y);
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
74
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
75 char buf[64];
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
76 sprintf(buf, "X = %.02f Y = %.02f Z = %.02f (in cm)",
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
77 p[0] / 10.0, p[1] / 10.0, p[2] / 10.0);
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
78 statusBar->SetMessage(buf);
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
79 }
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
80 }
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
81
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
82 virtual void MouseWheel(WorldSceneWidget& widget,
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
83 MouseWheelDirection direction,
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
84 KeyboardModifiers modifiers,
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
85 IStatusBar* statusBar)
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
86 {
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
87 // int scale = (modifiers & KeyboardModifiers_Control ? 10 : 1);
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
88
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
89 // switch (direction)
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
90 // {
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
91 // case MouseWheelDirection_Up:
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
92 // application_.OffsetSlice(-scale);
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
93 // break;
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
94
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
95 // case MouseWheelDirection_Down:
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
96 // application_.OffsetSlice(scale);
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
97 // break;
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
98
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
99 // default:
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
100 // break;
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
101 // }
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
102 }
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
103
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
104 virtual void KeyPressed(WorldSceneWidget& widget,
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
105 char key,
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
106 KeyboardModifiers modifiers,
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
107 IStatusBar* statusBar)
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
108 {
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
109 switch (key)
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
110 {
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
111 case 's':
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
112 widget.SetDefaultView();
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
113 break;
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
114 case 'n':
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
115 application_.NextImage(widget);
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
116 break;
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
117
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
118 default:
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
119 break;
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
120 }
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
121 }
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
122 };
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
123
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
124
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
125 // void OffsetSlice(int offset)
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
126 // {
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
127 // if (source_ != NULL)
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
128 // {
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
129 // int slice = static_cast<int>(slice_) + offset;
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
130
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
131 // if (slice < 0)
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
132 // {
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
133 // slice = 0;
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
134 // }
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
135
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
136 // if (slice >= static_cast<int>(source_->GetSliceCount()))
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
137 // {
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
138 // slice = source_->GetSliceCount() - 1;
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
139 // }
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
140
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
141 // if (slice != static_cast<int>(slice_))
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
142 // {
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
143 // SetSlice(slice);
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
144 // }
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
145 // }
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
146 // }
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
147
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
148
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
149 // void SetSlice(size_t index)
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
150 // {
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
151 // if (source_ != NULL &&
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
152 // index < source_->GetSliceCount())
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
153 // {
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
154 // slice_ = index;
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
155
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
156 //#if 1
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
157 // widget_->SetSlice(source_->GetSlice(slice_).GetGeometry());
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
158 //#else
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
159 // // TEST for scene extents - Rotate the axes
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
160 // double a = 15.0 / 180.0 * M_PI;
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
161
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
162 //#if 1
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
163 // Vector x; GeometryToolbox::AssignVector(x, cos(a), sin(a), 0);
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
164 // Vector y; GeometryToolbox::AssignVector(y, -sin(a), cos(a), 0);
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
165 //#else
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
166 // // Flip the normal
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
167 // Vector x; GeometryToolbox::AssignVector(x, cos(a), sin(a), 0);
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
168 // Vector y; GeometryToolbox::AssignVector(y, sin(a), -cos(a), 0);
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
169 //#endif
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
170
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
171 // SliceGeometry s(source_->GetSlice(slice_).GetGeometry().GetOrigin(), x, y);
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
172 // widget_->SetSlice(s);
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
173 //#endif
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
174 // }
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
175 // }
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
176
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
177
266
c9cf95b49a86 removed OrthancSlicesLoader::ISliceLoaderObserver; now using standard messages instead
am@osimis.io
parents: 258
diff changeset
178 virtual void HandleMessage(const IObservable& from, const IMessage& message) {
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
179 switch (message.GetType()) {
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
180 case MessageType_GeometryReady:
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
181 mainLayout_->SetDefaultView();
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
182 break;
253
8ff70c04c6df IObservable/IObserver now working in WASM too
am@osimis.io
parents: 251
diff changeset
183 default:
8ff70c04c6df IObservable/IObserver now working in WASM too
am@osimis.io
parents: 251
diff changeset
184 VLOG("unhandled message type" << message.GetType());
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
185 }
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
186 }
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
187
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 237
diff changeset
188 std::unique_ptr<Interactor> interactor_;
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
189 LayoutWidget* mainLayout_;
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
190 LayoutWidget* thumbnailsLayout_;
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
191 LayerWidget* mainViewport_;
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
192 std::vector<LayerWidget*> thumbnails_;
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
193 std::vector<std::string> instances_;
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
194 unsigned int currentInstanceIndex_;
237
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 235
diff changeset
195 OrthancStone::WidgetViewport* wasmViewport1_;
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 235
diff changeset
196 OrthancStone::WidgetViewport* wasmViewport2_;
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
197
254
abc1c6231947 cleanup
am@osimis.io
parents: 253
diff changeset
198 IStatusBar* statusBar_;
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
199 unsigned int slice_;
258
e5a9b3d03478 first very basic version of SmartLoader
am@osimis.io
parents: 257
diff changeset
200 std::unique_ptr<SmartLoader> smartLoader_;
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
201
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
202 public:
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
203 SimpleViewerApplication(MessageBroker& broker) :
258
e5a9b3d03478 first very basic version of SmartLoader
am@osimis.io
parents: 257
diff changeset
204 IObserver(broker),
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
205 mainLayout_(NULL),
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
206 currentInstanceIndex_(0),
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 237
diff changeset
207 wasmViewport1_(NULL),
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
208 wasmViewport2_(NULL),
258
e5a9b3d03478 first very basic version of SmartLoader
am@osimis.io
parents: 257
diff changeset
209 slice_(0)
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
210 {
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
211 }
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
212
237
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 235
diff changeset
213 virtual void Finalize() {}
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 235
diff changeset
214 virtual IWidget* GetCentralWidget() {return mainLayout_;}
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 235
diff changeset
215
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
216 virtual void DeclareStartupOptions(boost::program_options::options_description& options)
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
217 {
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
218 boost::program_options::options_description generic("Sample options");
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
219 generic.add_options()
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
220 // ("study", boost::program_options::value<std::string>(),
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
221 // "Orthanc ID of the study")
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
222 ("instance1", boost::program_options::value<std::string>(),
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
223 "Orthanc ID of the instances")
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
224 ("instance2", boost::program_options::value<std::string>(),
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
225 "Orthanc ID of the instances")
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
226 ;
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
227
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
228 options.add(generic);
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
229 }
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
230
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 237
diff changeset
231 virtual void Initialize(BasicApplicationContext* context,
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 237
diff changeset
232 IStatusBar& statusBar,
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
233 const boost::program_options::variables_map& parameters)
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
234 {
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
235 using namespace OrthancStone;
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
236
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 237
diff changeset
237 context_ = context;
254
abc1c6231947 cleanup
am@osimis.io
parents: 253
diff changeset
238 statusBar_ = &statusBar;
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
239 statusBar.SetMessage("Use the key \"s\" to reinitialize the layout");
254
abc1c6231947 cleanup
am@osimis.io
parents: 253
diff changeset
240 statusBar.SetMessage("Use the key \"n\" to go to next image in the main viewport");
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
241
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
242 if (parameters.count("instance1") < 1)
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
243 {
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
244 LOG(ERROR) << "The instance ID is missing";
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
245 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
246 }
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
247 if (parameters.count("instance2") < 1)
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
248 {
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
249 LOG(ERROR) << "The instance ID is missing";
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
250 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
251 }
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
252 instances_.push_back(parameters["instance1"].as<std::string>());
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
253 instances_.push_back(parameters["instance2"].as<std::string>());
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
254
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
255 mainLayout_ = new LayoutWidget();
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
256 mainLayout_->SetPadding(10);
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
257 mainLayout_->SetBackgroundCleared(true);
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
258 mainLayout_->SetBackgroundColor(0, 0, 0);
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
259 mainLayout_->SetHorizontal();
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
260
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
261 thumbnailsLayout_ = new LayoutWidget();
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
262 thumbnailsLayout_->SetPadding(10);
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
263 thumbnailsLayout_->SetBackgroundCleared(true);
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
264 thumbnailsLayout_->SetBackgroundColor(50, 50, 50);
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
265 thumbnailsLayout_->SetVertical();
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
266
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
267 mainViewport_ = new LayerWidget(broker_);
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
268 thumbnails_.push_back(new LayerWidget(broker_));
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
269 thumbnails_.push_back(new LayerWidget(broker_));
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
270
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
271 // hierarchy
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
272 mainLayout_->AddWidget(thumbnailsLayout_);
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
273 mainLayout_->AddWidget(mainViewport_);
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
274 thumbnailsLayout_->AddWidget(thumbnails_[0]);
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
275 thumbnailsLayout_->AddWidget(thumbnails_[1]);
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
276
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
277 // sources
258
e5a9b3d03478 first very basic version of SmartLoader
am@osimis.io
parents: 257
diff changeset
278 smartLoader_.reset(new SmartLoader(broker_, context_->GetWebService()));
e5a9b3d03478 first very basic version of SmartLoader
am@osimis.io
parents: 257
diff changeset
279 smartLoader_->SetImageQuality(SliceImageQuality_FullPam);
e5a9b3d03478 first very basic version of SmartLoader
am@osimis.io
parents: 257
diff changeset
280 smartLoader_->RegisterObserver(*this);
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
281
258
e5a9b3d03478 first very basic version of SmartLoader
am@osimis.io
parents: 257
diff changeset
282 mainViewport_->AddLayer(smartLoader_->GetFrame(instances_[currentInstanceIndex_], 0));
e5a9b3d03478 first very basic version of SmartLoader
am@osimis.io
parents: 257
diff changeset
283 thumbnails_[0]->AddLayer(smartLoader_->GetFrame(instances_[0], 0));
e5a9b3d03478 first very basic version of SmartLoader
am@osimis.io
parents: 257
diff changeset
284 thumbnails_[1]->AddLayer(smartLoader_->GetFrame(instances_[1], 0));
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
285
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
286 mainLayout_->SetTransmitMouseOver(true);
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 237
diff changeset
287 interactor_.reset(new Interactor(*this));
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 237
diff changeset
288 mainViewport_->SetInteractor(*interactor_);
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 237
diff changeset
289 }
237
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 235
diff changeset
290
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 237
diff changeset
291 #if ORTHANC_ENABLE_SDL==0
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 237
diff changeset
292 virtual void InitializeWasm() {
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 237
diff changeset
293
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 237
diff changeset
294 AttachWidgetToWasmViewport("canvas", thumbnailsLayout_);
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 237
diff changeset
295 AttachWidgetToWasmViewport("canvas2", mainViewport_);
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 237
diff changeset
296 }
237
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 235
diff changeset
297 #endif
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
298
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
299 void NextImage(WorldSceneWidget& widget) {
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
300 assert(context_);
254
abc1c6231947 cleanup
am@osimis.io
parents: 253
diff changeset
301 statusBar_->SetMessage("displaying next image");
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
302
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
303 currentInstanceIndex_ = (currentInstanceIndex_ + 1) % instances_.size();
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
304
258
e5a9b3d03478 first very basic version of SmartLoader
am@osimis.io
parents: 257
diff changeset
305 mainViewport_->ReplaceLayer(0, smartLoader_->GetFrame(instances_[currentInstanceIndex_], 0));
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
306
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
307 }
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
308 };
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
309
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
310
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
311 }
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
312 }