annotate Applications/Samples/SimpleViewerApplication.h @ 250:5e642859267e am-2

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