annotate Applications/Samples/SimpleViewerApplication.h @ 251:192e6e349e69 am-2

first usage of new message system (in SDL only)
author am@osimis.io
date Mon, 02 Jul 2018 18:13:46 +0200
parents 54c7284b0eff
children 8ff70c04c6df
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"
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
30
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
31 #include <Core/Logging.h>
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
32
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
33 namespace OrthancStone
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
34 {
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
35 namespace Samples
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
36 {
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
37 class SimpleViewerApplication :
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
38 public SampleApplicationBase,
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
39 public IObserver
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
40 {
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
41 private:
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
42 class Interactor : public IWorldSceneInteractor
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
43 {
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
44 private:
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
45 SimpleViewerApplication& application_;
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
46
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
47 public:
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
48 Interactor(SimpleViewerApplication& application) :
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
49 application_(application)
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
50 {
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 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& widget,
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
54 const ViewportGeometry& view,
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
55 MouseButton button,
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
56 double x,
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
57 double y,
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
58 IStatusBar* statusBar)
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
59 {
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
60 return NULL;
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
61 }
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 virtual void MouseOver(CairoContext& context,
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
64 WorldSceneWidget& widget,
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
65 const ViewportGeometry& view,
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
66 double x,
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
67 double y,
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
68 IStatusBar* statusBar)
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
69 {
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
70 if (statusBar != NULL)
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
71 {
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
72 Vector p = dynamic_cast<LayerWidget&>(widget).GetSlice().MapSliceToWorldCoordinates(x, y);
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
73
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
74 char buf[64];
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
75 sprintf(buf, "X = %.02f Y = %.02f Z = %.02f (in cm)",
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
76 p[0] / 10.0, p[1] / 10.0, p[2] / 10.0);
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
77 statusBar->SetMessage(buf);
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
78 }
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 virtual void MouseWheel(WorldSceneWidget& widget,
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
82 MouseWheelDirection direction,
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
83 KeyboardModifiers modifiers,
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
84 IStatusBar* statusBar)
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
85 {
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
86 // int scale = (modifiers & KeyboardModifiers_Control ? 10 : 1);
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
87
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
88 // switch (direction)
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
89 // {
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
90 // case MouseWheelDirection_Up:
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
91 // application_.OffsetSlice(-scale);
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
92 // break;
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
93
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
94 // case MouseWheelDirection_Down:
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
95 // application_.OffsetSlice(scale);
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
96 // break;
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
97
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
98 // default:
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
99 // break;
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
100 // }
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
101 }
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 virtual void KeyPressed(WorldSceneWidget& widget,
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
104 char key,
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
105 KeyboardModifiers modifiers,
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
106 IStatusBar* statusBar)
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
107 {
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
108 switch (key)
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
109 {
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
110 case 's':
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
111 widget.SetDefaultView();
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
112 break;
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
113 case 'n':
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
114 application_.NextImage(widget);
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
115 break;
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
116
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
117 default:
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
118 break;
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
119 }
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
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
124 // void OffsetSlice(int offset)
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
125 // {
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
126 // if (source_ != NULL)
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
127 // {
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
128 // int slice = static_cast<int>(slice_) + offset;
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
129
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
130 // if (slice < 0)
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
131 // {
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
132 // slice = 0;
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
133 // }
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
134
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
135 // if (slice >= static_cast<int>(source_->GetSliceCount()))
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
136 // {
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
137 // slice = source_->GetSliceCount() - 1;
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
138 // }
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
139
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
140 // if (slice != static_cast<int>(slice_))
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
141 // {
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
142 // SetSlice(slice);
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
143 // }
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 // }
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
146
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
147
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
148 // void SetSlice(size_t index)
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
149 // {
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
150 // if (source_ != NULL &&
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
151 // index < source_->GetSliceCount())
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
152 // {
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
153 // slice_ = index;
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
154
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
155 //#if 1
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
156 // widget_->SetSlice(source_->GetSlice(slice_).GetGeometry());
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
157 //#else
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
158 // // TEST for scene extents - Rotate the axes
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
159 // double a = 15.0 / 180.0 * M_PI;
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
160
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
161 //#if 1
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
162 // Vector x; GeometryToolbox::AssignVector(x, cos(a), sin(a), 0);
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
163 // Vector y; GeometryToolbox::AssignVector(y, -sin(a), cos(a), 0);
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
164 //#else
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
165 // // Flip the normal
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
166 // Vector x; GeometryToolbox::AssignVector(x, cos(a), sin(a), 0);
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
167 // Vector y; GeometryToolbox::AssignVector(y, sin(a), -cos(a), 0);
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
168 //#endif
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
169
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
170 // SliceGeometry s(source_->GetSlice(slice_).GetGeometry().GetOrigin(), x, y);
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
171 // widget_->SetSlice(s);
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
172 //#endif
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
173 // }
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
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
176
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
177 virtual void HandleMessage(IObservable& from, const IMessage& message) {
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
178 switch (message.GetType()) {
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
179 case MessageType_GeometryReady:
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
180 mainLayout_->SetDefaultView();
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
181 break;
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
182 }
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
183 }
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
184
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 237
diff changeset
185 std::unique_ptr<Interactor> interactor_;
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
186 LayoutWidget* mainLayout_;
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
187 LayoutWidget* thumbnailsLayout_;
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
188 LayerWidget* mainViewport_;
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
189 std::vector<LayerWidget*> thumbnails_;
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
190 std::vector<std::string> instances_;
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
191 unsigned int currentInstanceIndex_;
237
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 235
diff changeset
192 OrthancStone::WidgetViewport* wasmViewport1_;
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 235
diff changeset
193 OrthancStone::WidgetViewport* wasmViewport2_;
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
194
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
195 OrthancFrameLayerSource* source_;
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
196 unsigned int slice_;
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
197
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
198 public:
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
199 SimpleViewerApplication(MessageBroker& broker) :
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
200 mainLayout_(NULL),
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
201 currentInstanceIndex_(0),
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
202 source_(NULL),
237
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 235
diff changeset
203 slice_(0),
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 237
diff changeset
204 wasmViewport1_(NULL),
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
205 wasmViewport2_(NULL),
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
206 IObserver(broker)
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
207 {
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
208 }
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
209
237
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 235
diff changeset
210 virtual void Finalize() {}
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 235
diff changeset
211 virtual IWidget* GetCentralWidget() {return mainLayout_;}
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 235
diff changeset
212
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
213 virtual void DeclareStartupOptions(boost::program_options::options_description& options)
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
214 {
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
215 boost::program_options::options_description generic("Sample options");
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
216 generic.add_options()
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
217 // ("study", boost::program_options::value<std::string>(),
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
218 // "Orthanc ID of the study")
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
219 ("instance1", boost::program_options::value<std::string>(),
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
220 "Orthanc ID of the instances")
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
221 ("instance2", boost::program_options::value<std::string>(),
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
222 "Orthanc ID of the instances")
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
223 ;
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
224
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
225 options.add(generic);
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
226 }
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
227
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 237
diff changeset
228 virtual void Initialize(BasicApplicationContext* context,
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 237
diff changeset
229 IStatusBar& statusBar,
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
230 const boost::program_options::variables_map& parameters)
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
231 {
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
232 using namespace OrthancStone;
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
233
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 237
diff changeset
234 context_ = context;
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
235 statusBar.SetMessage("Use the key \"s\" to reinitialize the layout");
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
236
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
237 if (parameters.count("instance1") < 1)
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
238 {
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
239 LOG(ERROR) << "The instance ID is missing";
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
240 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
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("instance2") < 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 instances_.push_back(parameters["instance1"].as<std::string>());
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
248 instances_.push_back(parameters["instance2"].as<std::string>());
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
249
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
250 mainLayout_ = new LayoutWidget();
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
251 mainLayout_->SetPadding(10);
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
252 mainLayout_->SetBackgroundCleared(true);
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
253 mainLayout_->SetBackgroundColor(0, 0, 0);
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
254 mainLayout_->SetHorizontal();
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
255
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
256 thumbnailsLayout_ = new LayoutWidget();
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
257 thumbnailsLayout_->SetPadding(10);
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
258 thumbnailsLayout_->SetBackgroundCleared(true);
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
259 thumbnailsLayout_->SetBackgroundColor(50, 50, 50);
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
260 thumbnailsLayout_->SetVertical();
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
261
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
262 mainViewport_ = new LayerWidget(broker_);
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
263 thumbnails_.push_back(new LayerWidget(broker_));
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
264 thumbnails_.push_back(new LayerWidget(broker_));
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
265
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
266 // hierarchy
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
267 mainLayout_->AddWidget(thumbnailsLayout_);
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
268 mainLayout_->AddWidget(mainViewport_);
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
269 thumbnailsLayout_->AddWidget(thumbnails_[0]);
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
270 thumbnailsLayout_->AddWidget(thumbnails_[1]);
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
271
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
272 // sources
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
273 source_ = new OrthancFrameLayerSource(broker_, context_->GetWebService());
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
274 source_->LoadFrame(instances_[currentInstanceIndex_], 0);
245
e802578e1554 register observer
am@osimis.io
parents: 242
diff changeset
275 source_->Register(*this);
235
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 mainViewport_->AddLayer(source_);
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
278
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
279 OrthancFrameLayerSource* thumb0 = new OrthancFrameLayerSource(broker_, context_->GetWebService());
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
280 thumb0->LoadFrame(instances_[0], 0);
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
281 OrthancFrameLayerSource* thumb1 = new OrthancFrameLayerSource(broker_, context_->GetWebService());
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
282 thumb1->LoadFrame(instances_[1], 0);
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
283
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
284 thumbnails_[0]->AddLayer(thumb0);
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
285 thumbnails_[1]->AddLayer(thumb1);
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
286
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
287 mainLayout_->SetTransmitMouseOver(true);
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 237
diff changeset
288 interactor_.reset(new Interactor(*this));
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 237
diff changeset
289 mainViewport_->SetInteractor(*interactor_);
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 237
diff changeset
290 }
237
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 235
diff changeset
291
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 237
diff changeset
292 #if ORTHANC_ENABLE_SDL==0
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 237
diff changeset
293 virtual void InitializeWasm() {
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 237
diff changeset
294
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 237
diff changeset
295 AttachWidgetToWasmViewport("canvas", thumbnailsLayout_);
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 237
diff changeset
296 AttachWidgetToWasmViewport("canvas2", mainViewport_);
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 237
diff changeset
297 }
237
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 235
diff changeset
298 #endif
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
299
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
300 void NextImage(WorldSceneWidget& widget) {
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
301 assert(context_);
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
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
305 std::auto_ptr<OrthancFrameLayerSource> layer
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 249
diff changeset
306 (new OrthancFrameLayerSource(broker_, context_->GetWebService()));
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
307 layer->LoadFrame(instances_[currentInstanceIndex_], 0);
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
308
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
309 mainViewport_->ReplaceLayer(0, layer.release());
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
310 // source_->LoadFrame("45b7e6bc-168e8ed1-063dc08d-cffd6431-133a276a", 0);
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
311 }
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
312 };
249
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
313
54c7284b0eff merged useful changes from branch am
am@osimis.io
parents: 245
diff changeset
314
235
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
315 }
ce4405d98b92 Added SimpleViewerApplication (working in SDL)
am@osimis.io
parents:
diff changeset
316 }