annotate Samples/WebAssembly/BasicMPR.cpp @ 820:270c31978df1

BasicMPR sample
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 29 May 2019 13:40:07 +0200
parents
children 76e8224bc300
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
820
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include <emscripten.h>
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include <emscripten/fetch.h>
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include <emscripten/html5.h>
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include "../../Framework/Loaders/OrthancSeriesVolumeProgressiveLoader.h"
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include "../../Framework/OpenGL/WebAssemblyOpenGLContext.h"
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include "../../Framework/Scene2D/GrayscaleStyleConfigurator.h"
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include "../../Framework/Scene2D/OpenGLCompositor.h"
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include "../../Framework/Scene2D/PanSceneTracker.h"
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #include "../../Framework/Scene2D/RotateSceneTracker.h"
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include "../../Framework/Scene2D/ZoomSceneTracker.h"
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "../../Framework/Scene2DViewport/IFlexiblePointerTracker.h"
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "../../Framework/Scene2DViewport/ViewportController.h"
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include "../../Framework/StoneInitialization.h"
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include "../../Framework/Volumes/VolumeSceneLayerSource.h"
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 #include <Core/OrthancException.h>
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 #include <Core/Toolbox.h>
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 static const unsigned int FONT_SIZE = 32;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 namespace OrthancStone
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 class WebAssemblyViewport : public boost::noncopyable
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 private:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 // the construction order is important because compositor_
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 // will hold a reference to the scene that belong to the
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 // controller_ object
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 OpenGL::WebAssemblyOpenGLContext context_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 boost::shared_ptr<ViewportController> controller_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 OpenGLCompositor compositor_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 void SetupEvents(const std::string& canvas);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 public:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 WebAssemblyViewport(MessageBroker& broker,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 const std::string& canvas) :
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 context_(canvas),
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 controller_(new ViewportController(broker)),
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 compositor_(context_, *controller_->GetScene())
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 compositor_.SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 FONT_SIZE, Orthanc::Encoding_Latin1);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 SetupEvents(canvas);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 Scene2D& GetScene()
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 return *controller_->GetScene();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 const boost::shared_ptr<ViewportController>& GetController()
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 return controller_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 void UpdateSize()
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 context_.UpdateSize();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 compositor_.UpdateSize();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 Refresh();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 void Refresh()
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 compositor_.Refresh();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 const std::string& GetCanvasIdentifier() const
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 return context_.GetCanvasIdentifier();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 ScenePoint2D GetPixelCenterCoordinates(int x, int y) const
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 return compositor_.GetPixelCenterCoordinates(x, y);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 unsigned int GetCanvasWidth() const
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 return context_.GetCanvasWidth();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 unsigned int GetCanvasHeight() const
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 return context_.GetCanvasHeight();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 };
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 class ActiveTracker : public boost::noncopyable
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 private:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 boost::shared_ptr<IFlexiblePointerTracker> tracker_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 std::string canvasIdentifier_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 bool insideCanvas_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 public:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 ActiveTracker(const boost::shared_ptr<IFlexiblePointerTracker>& tracker,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 const WebAssemblyViewport& viewport) :
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 tracker_(tracker),
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 canvasIdentifier_(viewport.GetCanvasIdentifier()),
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 insideCanvas_(true)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 if (tracker_.get() == NULL)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 bool IsAlive() const
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 return tracker_->IsAlive();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 void PointerMove(const PointerEvent& event)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 tracker_->PointerMove(event);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 void PointerUp(const PointerEvent& event)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 tracker_->PointerUp(event);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 };
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 static OrthancStone::PointerEvent* ConvertMouseEvent(
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 const EmscriptenMouseEvent& source,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 OrthancStone::WebAssemblyViewport& viewport)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 std::auto_ptr<OrthancStone::PointerEvent> target(
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 new OrthancStone::PointerEvent);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 target->AddPosition(viewport.GetPixelCenterCoordinates(
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 source.targetX, source.targetY));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 target->SetAltModifier(source.altKey);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 target->SetControlModifier(source.ctrlKey);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 target->SetShiftModifier(source.shiftKey);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 return target.release();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 std::auto_ptr<OrthancStone::ActiveTracker> tracker_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 EM_BOOL OnMouseEvent(int eventType,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 const EmscriptenMouseEvent *mouseEvent,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 void *userData)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 if (mouseEvent != NULL &&
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 userData != NULL)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 OrthancStone::WebAssemblyViewport& viewport =
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 *reinterpret_cast<OrthancStone::WebAssemblyViewport*>(userData);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 switch (eventType)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 case EMSCRIPTEN_EVENT_CLICK:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 static unsigned int count = 0;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 char buf[64];
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 sprintf(buf, "click %d", count++);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 std::auto_ptr<OrthancStone::TextSceneLayer> layer(new OrthancStone::TextSceneLayer);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 layer->SetText(buf);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 viewport.GetScene().SetLayer(100, layer.release());
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 viewport.Refresh();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 break;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 case EMSCRIPTEN_EVENT_MOUSEDOWN:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 boost::shared_ptr<OrthancStone::IFlexiblePointerTracker> t;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 std::auto_ptr<OrthancStone::PointerEvent> event(
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 ConvertMouseEvent(*mouseEvent, viewport));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 switch (mouseEvent->button)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 case 0: // Left button
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 emscripten_console_log("Creating RotateSceneTracker");
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 t.reset(new OrthancStone::RotateSceneTracker(
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 viewport.GetController(), *event));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 break;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 case 1: // Middle button
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 emscripten_console_log("Creating PanSceneTracker");
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 LOG(INFO) << "Creating PanSceneTracker" ;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 t.reset(new OrthancStone::PanSceneTracker(
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 viewport.GetController(), *event));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 break;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 case 2: // Right button
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 emscripten_console_log("Creating ZoomSceneTracker");
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 t.reset(new OrthancStone::ZoomSceneTracker(
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 viewport.GetController(), *event, viewport.GetCanvasWidth()));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 break;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 default:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 break;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 if (t.get() != NULL)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 tracker_.reset(
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 new OrthancStone::ActiveTracker(t, viewport));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 viewport.Refresh();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 break;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 case EMSCRIPTEN_EVENT_MOUSEMOVE:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 if (tracker_.get() != NULL)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 std::auto_ptr<OrthancStone::PointerEvent> event(
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 ConvertMouseEvent(*mouseEvent, viewport));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 tracker_->PointerMove(*event);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 viewport.Refresh();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 break;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 case EMSCRIPTEN_EVENT_MOUSEUP:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 if (tracker_.get() != NULL)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 std::auto_ptr<OrthancStone::PointerEvent> event(
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 ConvertMouseEvent(*mouseEvent, viewport));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 tracker_->PointerUp(*event);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 viewport.Refresh();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 if (!tracker_->IsAlive())
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 tracker_.reset();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 break;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 default:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 break;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 return true;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 void OrthancStone::WebAssemblyViewport::SetupEvents(const std::string& canvas)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 emscripten_set_mousedown_callback(canvas.c_str(), this, false, OnMouseEvent);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 emscripten_set_mousemove_callback(canvas.c_str(), this, false, OnMouseEvent);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 emscripten_set_mouseup_callback(canvas.c_str(), this, false, OnMouseEvent);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 namespace OrthancStone
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 class VolumeSlicerViewport : public IObserver
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 private:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 OrthancStone::WebAssemblyViewport viewport_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 std::auto_ptr<VolumeSceneLayerSource> source_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 VolumeProjection projection_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 std::vector<CoordinateSystem3D> planes_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 size_t currentPlane_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 void Handle(const DicomVolumeImage::GeometryReadyMessage& message)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 LOG(INFO) << "Geometry is available";
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 const VolumeImageGeometry& geometry = message.GetOrigin().GetGeometry();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 const unsigned int depth = geometry.GetProjectionDepth(projection_);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 currentPlane_ = depth / 2;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 planes_.resize(depth);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 for (unsigned int z = 0; z < depth; z++)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 planes_[z] = geometry.GetProjectionSlice(projection_, z);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 public:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 VolumeSlicerViewport(MessageBroker& broker,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 const std::string& canvas,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 VolumeProjection projection) :
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 IObserver(broker),
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 viewport_(broker, canvas),
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 projection_(projection),
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 currentPlane_(0)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 void UpdateSize()
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 viewport_.UpdateSize();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 void SetSlicer(int layerDepth,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 const boost::shared_ptr<IVolumeSlicer>& slicer,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 IObservable& loader,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 ILayerStyleConfigurator* configurator)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 if (source_.get() != NULL)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 "Only one slicer can be registered");
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 loader.RegisterObserverCallback(
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 new Callable<VolumeSlicerViewport, DicomVolumeImage::GeometryReadyMessage>
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 (*this, &VolumeSlicerViewport::Handle));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 source_.reset(new VolumeSceneLayerSource(viewport_.GetScene(), layerDepth, slicer));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 if (configurator != NULL)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 source_->SetConfigurator(configurator);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 void Refresh()
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 if (source_.get() != NULL &&
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 currentPlane_ < planes_.size())
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 source_->Update(planes_[currentPlane_]);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 };
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 class WebAssemblyOracle :
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 public IOracle,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 public IObservable
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 private:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 typedef std::map<std::string, std::string> HttpHeaders;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 class FetchContext : public boost::noncopyable
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 private:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 class Emitter : public IMessageEmitter
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 private:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 WebAssemblyOracle& oracle_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 public:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 Emitter(WebAssemblyOracle& oracle) :
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 oracle_(oracle)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 virtual void EmitMessage(const IObserver& receiver,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 const IMessage& message)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 oracle_.EmitMessage(receiver, message);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 };
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 Emitter emitter_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 const IObserver& receiver_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 std::auto_ptr<IOracleCommand> command_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 std::string expectedContentType_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 public:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 FetchContext(WebAssemblyOracle& oracle,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 const IObserver& receiver,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 IOracleCommand* command,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 const std::string& expectedContentType) :
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 emitter_(oracle),
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 receiver_(receiver),
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 command_(command),
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 expectedContentType_(expectedContentType)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 if (command == NULL)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 const std::string& GetExpectedContentType() const
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 return expectedContentType_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 void EmitMessage(const IMessage& message)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 emitter_.EmitMessage(receiver_, message);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 IMessageEmitter& GetEmitter()
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 return emitter_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 const IObserver& GetReceiver() const
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426 return receiver_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 IOracleCommand& GetCommand() const
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 return *command_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 template <typename T>
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435 const T& GetTypedCommand() const
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 return dynamic_cast<T&>(*command_);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 };
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 static void FetchSucceeded(emscripten_fetch_t *fetch)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 /**
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 * Firstly, make a local copy of the fetched information, and
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 * free data associated with the fetch.
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 **/
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448 std::auto_ptr<FetchContext> context(reinterpret_cast<FetchContext*>(fetch->userData));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 std::string answer;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 if (fetch->numBytes > 0)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 answer.assign(fetch->data, fetch->numBytes);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 /**
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 * TODO - HACK - As of emscripten-1.38.31, the fetch API does
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 * not contain a way to retrieve the HTTP headers of the
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 * answer. We make the assumption that the "Content-Type" header
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460 * of the response is the same as the "Accept" header of the
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 * query. This should be fixed in future versions of emscripten.
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 * https://github.com/emscripten-core/emscripten/pull/8486
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 **/
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 HttpHeaders headers;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 if (!context->GetExpectedContentType().empty())
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468 headers["Content-Type"] = context->GetExpectedContentType();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472 emscripten_fetch_close(fetch);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
475 /**
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476 * Secondly, use the retrieved data.
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477 **/
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 try
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481 if (context.get() == NULL)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485 else
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 switch (context->GetCommand().GetType())
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 case IOracleCommand::Type_OrthancRestApi:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 OrthancRestApiCommand::SuccessMessage message
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492 (context->GetTypedCommand<OrthancRestApiCommand>(), headers, answer);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 context->EmitMessage(message);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494 break;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
496
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497 case IOracleCommand::Type_GetOrthancImage:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499 context->GetTypedCommand<GetOrthancImageCommand>().ProcessHttpAnswer
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500 (context->GetEmitter(), context->GetReceiver(), answer, headers);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501 break;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504 case IOracleCommand::Type_GetOrthancWebViewerJpeg:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506 context->GetTypedCommand<GetOrthancWebViewerJpegCommand>().ProcessHttpAnswer
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 (context->GetEmitter(), context->GetReceiver(), answer);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508 break;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511 default:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512 LOG(ERROR) << "Command type not implemented by the WebAssembly Oracle: "
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513 << context->GetCommand().GetType();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517 catch (Orthanc::OrthancException& e)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519 LOG(ERROR) << "Error while processing a fetch answer in the oracle: " << e.What();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 static void FetchFailed(emscripten_fetch_t *fetch)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525 std::auto_ptr<FetchContext> context(reinterpret_cast<FetchContext*>(fetch->userData));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527 LOG(ERROR) << "Fetching " << fetch->url << " failed, HTTP failure status code: " << fetch->status;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
529 /**
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
530 * TODO - The following code leads to an infinite recursion, at
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
531 * least with Firefox running on incognito mode => WHY?
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
532 **/
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
533 //emscripten_fetch_close(fetch); // Also free data on failure.
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
534 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537 class FetchCommand : public boost::noncopyable
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
538 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539 private:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540 WebAssemblyOracle& oracle_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
541 const IObserver& receiver_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542 std::auto_ptr<IOracleCommand> command_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 Orthanc::HttpMethod method_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 std::string uri_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545 std::string body_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546 HttpHeaders headers_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
547 unsigned int timeout_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
548 std::string expectedContentType_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
549
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
550 public:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551 FetchCommand(WebAssemblyOracle& oracle,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
552 const IObserver& receiver,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
553 IOracleCommand* command) :
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
554 oracle_(oracle),
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
555 receiver_(receiver),
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556 command_(command),
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557 method_(Orthanc::HttpMethod_Get),
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558 timeout_(0)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
559 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560 if (command == NULL)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
561 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
562 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
563 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
564 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
566 void SetMethod(Orthanc::HttpMethod method)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568 method_ = method;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
569 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
571 void SetUri(const std::string& uri)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573 uri_ = uri;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
574 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
576 void SetBody(std::string& body /* will be swapped */)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
577 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
578 body_.swap(body);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
579 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
580
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
581 void SetHttpHeaders(const HttpHeaders& headers)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
582 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
583 headers_ = headers;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
584 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
585
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
586 void SetTimeout(unsigned int timeout)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
587 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
588 timeout_ = timeout;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
589 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
590
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
591 void Execute()
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
592 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
593 if (command_.get() == NULL)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
594 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
595 // Cannot call Execute() twice
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
596 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
597 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
598
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
599 emscripten_fetch_attr_t attr;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
600 emscripten_fetch_attr_init(&attr);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
601
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
602 const char* method;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
603
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
604 switch (method_)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
605 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
606 case Orthanc::HttpMethod_Get:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
607 method = "GET";
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
608 break;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
609
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
610 case Orthanc::HttpMethod_Post:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
611 method = "POST";
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
612 break;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
613
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
614 case Orthanc::HttpMethod_Delete:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
615 method = "DELETE";
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
616 break;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
617
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
618 case Orthanc::HttpMethod_Put:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
619 method = "PUT";
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
620 break;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
621
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
622 default:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
623 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
624 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
625
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
626 strcpy(attr.requestMethod, method);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
627
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
628 attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
629 attr.onsuccess = FetchSucceeded;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
630 attr.onerror = FetchFailed;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
631 attr.timeoutMSecs = timeout_ * 1000;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
632
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
633 std::vector<const char*> headers;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
634 headers.reserve(2 * headers_.size() + 1);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
635
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
636 std::string expectedContentType;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
637
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
638 for (HttpHeaders::const_iterator it = headers_.begin(); it != headers_.end(); ++it)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
639 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
640 std::string key;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
641 Orthanc::Toolbox::ToLowerCase(key, it->first);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
642
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
643 if (key == "accept")
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
644 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
645 expectedContentType = it->second;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
646 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
647
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
648 if (key != "accept-encoding") // Web browsers forbid the modification of this HTTP header
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
649 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
650 headers.push_back(it->first.c_str());
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
651 headers.push_back(it->second.c_str());
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
652 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
653 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
654
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
655 headers.push_back(NULL); // Termination of the array of HTTP headers
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
656
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
657 attr.requestHeaders = &headers[0];
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
658
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
659 if (!body_.empty())
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
660 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
661 attr.requestDataSize = body_.size();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
662 attr.requestData = body_.c_str();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
663 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
664
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
665 // Must be the last call to prevent memory leak on error
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
666 attr.userData = new FetchContext(oracle_, receiver_, command_.release(), expectedContentType);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
667 emscripten_fetch(&attr, uri_.c_str());
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
668 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
669 };
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
670
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
671
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
672 void Execute(const IObserver& receiver,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
673 OrthancRestApiCommand* command)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
674 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
675 FetchCommand fetch(*this, receiver, command);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
676
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
677 fetch.SetMethod(command->GetMethod());
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
678 fetch.SetUri(command->GetUri());
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
679 fetch.SetHttpHeaders(command->GetHttpHeaders());
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
680 fetch.SetTimeout(command->GetTimeout());
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
681
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
682 if (command->GetMethod() == Orthanc::HttpMethod_Put ||
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
683 command->GetMethod() == Orthanc::HttpMethod_Put)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
684 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
685 std::string body;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
686 command->SwapBody(body);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
687 fetch.SetBody(body);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
688 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
689
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
690 fetch.Execute();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
691 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
692
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
693
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
694 void Execute(const IObserver& receiver,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
695 GetOrthancImageCommand* command)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
696 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
697 FetchCommand fetch(*this, receiver, command);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
698
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
699 fetch.SetUri(command->GetUri());
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
700 fetch.SetHttpHeaders(command->GetHttpHeaders());
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
701 fetch.SetTimeout(command->GetTimeout());
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
702
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
703 fetch.Execute();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
704 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
705
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
706
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
707 void Execute(const IObserver& receiver,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
708 GetOrthancWebViewerJpegCommand* command)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
709 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
710 FetchCommand fetch(*this, receiver, command);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
711
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
712 fetch.SetUri(command->GetUri());
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
713 fetch.SetHttpHeaders(command->GetHttpHeaders());
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
714 fetch.SetTimeout(command->GetTimeout());
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
715
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
716 fetch.Execute();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
717 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
718
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
719
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
720 public:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
721 WebAssemblyOracle(MessageBroker& broker) :
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
722 IObservable(broker)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
723 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
724 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
725
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
726 virtual void Schedule(const IObserver& receiver,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
727 IOracleCommand* command)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
728 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
729 std::auto_ptr<IOracleCommand> protection(command);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
730
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
731 if (command == NULL)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
732 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
733 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
734 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
735
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
736 switch (command->GetType())
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
737 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
738 case IOracleCommand::Type_OrthancRestApi:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
739 Execute(receiver, dynamic_cast<OrthancRestApiCommand*>(protection.release()));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
740 break;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
741
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
742 case IOracleCommand::Type_GetOrthancImage:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
743 Execute(receiver, dynamic_cast<GetOrthancImageCommand*>(protection.release()));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
744 break;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
745
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
746 case IOracleCommand::Type_GetOrthancWebViewerJpeg:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
747 Execute(receiver, dynamic_cast<GetOrthancWebViewerJpegCommand*>(protection.release()));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
748 break;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
749
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
750 default:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
751 LOG(ERROR) << "Command type not implemented by the WebAssembly Oracle: " << command->GetType();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
752 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
753 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
754
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
755 virtual void Start()
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
756 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
757 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
758
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
759 virtual void Stop()
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
760 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
761 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
762 };
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
763 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
764
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
765
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
766
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
767
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
768 boost::shared_ptr<OrthancStone::DicomVolumeImage> ct_(new OrthancStone::DicomVolumeImage);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
769
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
770 boost::shared_ptr<OrthancStone::OrthancSeriesVolumeProgressiveLoader> loader_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
771
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
772 std::auto_ptr<OrthancStone::VolumeSlicerViewport> viewport1_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
773 std::auto_ptr<OrthancStone::VolumeSlicerViewport> viewport2_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
774 std::auto_ptr<OrthancStone::VolumeSlicerViewport> viewport3_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
775
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
776 OrthancStone::MessageBroker broker_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
777 OrthancStone::WebAssemblyOracle oracle_(broker_);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
778
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
779
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
780 EM_BOOL OnWindowResize(int eventType, const EmscriptenUiEvent *uiEvent, void *userData)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
781 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
782 try
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
783 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
784 if (viewport1_.get() != NULL)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
785 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
786 viewport1_->UpdateSize();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
787 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
788
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
789 if (viewport2_.get() != NULL)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
790 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
791 viewport2_->UpdateSize();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
792 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
793
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
794 if (viewport3_.get() != NULL)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
795 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
796 viewport3_->UpdateSize();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
797 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
798 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
799 catch (Orthanc::OrthancException& e)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
800 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
801 LOG(ERROR) << "Exception while updating canvas size: " << e.What();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
802 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
803
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
804 return true;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
805 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
806
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
807
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
808
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
809
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
810 EM_BOOL OnAnimationFrame(double time, void *userData)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
811 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
812 try
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
813 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
814 if (viewport1_.get() != NULL)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
815 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
816 viewport1_->Refresh();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
817 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
818
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
819 if (viewport2_.get() != NULL)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
820 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
821 viewport2_->Refresh();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
822 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
823
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
824 if (viewport3_.get() != NULL)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
825 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
826 viewport3_->Refresh();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
827 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
828
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
829 return true;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
830 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
831 catch (Orthanc::OrthancException& e)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
832 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
833 LOG(ERROR) << "Exception in the animation loop, stopping now: " << e.What();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
834 return false;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
835 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
836 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
837
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
838
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
839 extern "C"
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
840 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
841 int main(int argc, char const *argv[])
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
842 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
843 OrthancStone::StoneInitialize();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
844 Orthanc::Logging::EnableInfoLevel(true);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
845 // Orthanc::Logging::EnableTraceLevel(true);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
846 EM_ASM(window.dispatchEvent(new CustomEvent("WebAssemblyLoaded")););
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
847 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
848
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
849 EMSCRIPTEN_KEEPALIVE
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
850 void Initialize()
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
851 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
852 try
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
853 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
854 loader_.reset(new OrthancStone::OrthancSeriesVolumeProgressiveLoader(ct_, oracle_, oracle_));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
855
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
856 viewport1_.reset(new OrthancStone::VolumeSlicerViewport(broker_, "mycanvas1", OrthancStone::VolumeProjection_Axial));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
857 viewport1_->SetSlicer(0, loader_, *loader_, new OrthancStone::GrayscaleStyleConfigurator);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
858 viewport1_->UpdateSize();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
859
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
860 viewport2_.reset(new OrthancStone::VolumeSlicerViewport(broker_, "mycanvas2", OrthancStone::VolumeProjection_Coronal));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
861 viewport2_->SetSlicer(0, loader_, *loader_, new OrthancStone::GrayscaleStyleConfigurator);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
862 viewport2_->UpdateSize();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
863
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
864 viewport3_.reset(new OrthancStone::VolumeSlicerViewport(broker_, "mycanvas3", OrthancStone::VolumeProjection_Sagittal));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
865 viewport3_->SetSlicer(0, loader_, *loader_, new OrthancStone::GrayscaleStyleConfigurator);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
866 viewport3_->UpdateSize();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
867
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
868 emscripten_set_resize_callback("#window", NULL, false, OnWindowResize);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
869
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
870 emscripten_request_animation_frame_loop(OnAnimationFrame, NULL);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
871
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
872 oracle_.Start();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
873 loader_->LoadSeries("a04ecf01-79b2fc33-58239f7e-ad9db983-28e81afa");
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
874 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
875 catch (Orthanc::OrthancException& e)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
876 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
877 LOG(ERROR) << "Exception during Initialize(): " << e.What();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
878 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
879 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
880 }