annotate Samples/WebAssembly/BasicMPR.cpp @ 822:76e8224bc300

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 29 May 2019 14:19:06 +0200
parents 270c31978df1
children 467d58a59718
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
822
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 820
diff changeset
94 void FitContent()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 820
diff changeset
95 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 820
diff changeset
96 GetScene().FitContent(context_.GetCanvasWidth(), context_.GetCanvasHeight());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 820
diff changeset
97 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 820
diff changeset
98
820
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 const std::string& GetCanvasIdentifier() 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 context_.GetCanvasIdentifier();
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 ScenePoint2D GetPixelCenterCoordinates(int x, int y) 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 compositor_.GetPixelCenterCoordinates(x, y);
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 GetCanvasWidth() 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_.GetCanvasWidth();
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 unsigned int GetCanvasHeight() const
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 return context_.GetCanvasHeight();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 };
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 class ActiveTracker : public boost::noncopyable
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 private:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 boost::shared_ptr<IFlexiblePointerTracker> tracker_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 std::string canvasIdentifier_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 bool insideCanvas_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 public:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 ActiveTracker(const boost::shared_ptr<IFlexiblePointerTracker>& tracker,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 const WebAssemblyViewport& viewport) :
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 tracker_(tracker),
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 canvasIdentifier_(viewport.GetCanvasIdentifier()),
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 insideCanvas_(true)
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 if (tracker_.get() == NULL)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 }
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 bool IsAlive() const
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 return tracker_->IsAlive();
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 PointerMove(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_->PointerMove(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 void PointerUp(const PointerEvent& event)
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 tracker_->PointerUp(event);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 };
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
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 static OrthancStone::PointerEvent* ConvertMouseEvent(
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 const EmscriptenMouseEvent& source,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 OrthancStone::WebAssemblyViewport& viewport)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 std::auto_ptr<OrthancStone::PointerEvent> target(
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 new OrthancStone::PointerEvent);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 target->AddPosition(viewport.GetPixelCenterCoordinates(
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 source.targetX, source.targetY));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 target->SetAltModifier(source.altKey);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 target->SetControlModifier(source.ctrlKey);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 target->SetShiftModifier(source.shiftKey);
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 return target.release();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 std::auto_ptr<OrthancStone::ActiveTracker> tracker_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 EM_BOOL OnMouseEvent(int eventType,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 const EmscriptenMouseEvent *mouseEvent,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 void *userData)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 if (mouseEvent != NULL &&
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 userData != NULL)
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 OrthancStone::WebAssemblyViewport& viewport =
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 *reinterpret_cast<OrthancStone::WebAssemblyViewport*>(userData);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 switch (eventType)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 case EMSCRIPTEN_EVENT_CLICK:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 static unsigned int count = 0;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 char buf[64];
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 sprintf(buf, "click %d", count++);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 std::auto_ptr<OrthancStone::TextSceneLayer> layer(new OrthancStone::TextSceneLayer);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 layer->SetText(buf);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 viewport.GetScene().SetLayer(100, layer.release());
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 viewport.Refresh();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 break;
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 case EMSCRIPTEN_EVENT_MOUSEDOWN:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 boost::shared_ptr<OrthancStone::IFlexiblePointerTracker> t;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203
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 std::auto_ptr<OrthancStone::PointerEvent> event(
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 ConvertMouseEvent(*mouseEvent, viewport));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 switch (mouseEvent->button)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 case 0: // Left button
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 emscripten_console_log("Creating RotateSceneTracker");
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 t.reset(new OrthancStone::RotateSceneTracker(
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 viewport.GetController(), *event));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 break;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 case 1: // Middle button
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 emscripten_console_log("Creating PanSceneTracker");
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 LOG(INFO) << "Creating PanSceneTracker" ;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 t.reset(new OrthancStone::PanSceneTracker(
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 viewport.GetController(), *event));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 break;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 case 2: // Right button
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 emscripten_console_log("Creating ZoomSceneTracker");
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 t.reset(new OrthancStone::ZoomSceneTracker(
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 viewport.GetController(), *event, viewport.GetCanvasWidth()));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 break;
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 default:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 break;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 if (t.get() != NULL)
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 tracker_.reset(
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 new OrthancStone::ActiveTracker(t, viewport));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 viewport.Refresh();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 break;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 case EMSCRIPTEN_EVENT_MOUSEMOVE:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 if (tracker_.get() != NULL)
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 std::auto_ptr<OrthancStone::PointerEvent> event(
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 ConvertMouseEvent(*mouseEvent, viewport));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 tracker_->PointerMove(*event);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 viewport.Refresh();
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 break;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 case EMSCRIPTEN_EVENT_MOUSEUP:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 if (tracker_.get() != NULL)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 std::auto_ptr<OrthancStone::PointerEvent> event(
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 ConvertMouseEvent(*mouseEvent, viewport));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 tracker_->PointerUp(*event);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 viewport.Refresh();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 if (!tracker_->IsAlive())
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 tracker_.reset();
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 break;
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 default:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 break;
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
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 return true;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 void OrthancStone::WebAssemblyViewport::SetupEvents(const std::string& canvas)
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 emscripten_set_mousedown_callback(canvas.c_str(), this, false, OnMouseEvent);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 emscripten_set_mousemove_callback(canvas.c_str(), this, false, OnMouseEvent);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 emscripten_set_mouseup_callback(canvas.c_str(), this, false, OnMouseEvent);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 }
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
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
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 namespace OrthancStone
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 class VolumeSlicerViewport : public IObserver
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 private:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 OrthancStone::WebAssemblyViewport viewport_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 std::auto_ptr<VolumeSceneLayerSource> source_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 VolumeProjection projection_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 std::vector<CoordinateSystem3D> planes_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 size_t currentPlane_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 void Handle(const DicomVolumeImage::GeometryReadyMessage& message)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 LOG(INFO) << "Geometry is available";
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 const VolumeImageGeometry& geometry = message.GetOrigin().GetGeometry();
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 const unsigned int depth = geometry.GetProjectionDepth(projection_);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 currentPlane_ = depth / 2;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 planes_.resize(depth);
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 for (unsigned int z = 0; z < depth; z++)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 planes_[z] = geometry.GetProjectionSlice(projection_, z);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 }
822
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 820
diff changeset
311
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 820
diff changeset
312 Refresh();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 820
diff changeset
313
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 820
diff changeset
314 viewport_.FitContent();
820
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 }
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 public:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 VolumeSlicerViewport(MessageBroker& broker,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 const std::string& canvas,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 VolumeProjection projection) :
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 IObserver(broker),
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 viewport_(broker, canvas),
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 projection_(projection),
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 currentPlane_(0)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 void UpdateSize()
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 viewport_.UpdateSize();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 void SetSlicer(int layerDepth,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 const boost::shared_ptr<IVolumeSlicer>& slicer,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 IObservable& loader,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 ILayerStyleConfigurator* configurator)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 if (source_.get() != NULL)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 "Only one slicer can be registered");
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
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 loader.RegisterObserverCallback(
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 new Callable<VolumeSlicerViewport, DicomVolumeImage::GeometryReadyMessage>
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 (*this, &VolumeSlicerViewport::Handle));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 source_.reset(new VolumeSceneLayerSource(viewport_.GetScene(), layerDepth, slicer));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 if (configurator != NULL)
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_->SetConfigurator(configurator);
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 void Refresh()
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 if (source_.get() != NULL &&
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 currentPlane_ < planes_.size())
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 source_->Update(planes_[currentPlane_]);
822
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 820
diff changeset
362 viewport_.Refresh();
820
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 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 };
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
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
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 class WebAssemblyOracle :
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 public IOracle,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 public IObservable
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 private:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 typedef std::map<std::string, std::string> HttpHeaders;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 class FetchContext : public boost::noncopyable
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 private:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 class Emitter : public IMessageEmitter
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 private:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 WebAssemblyOracle& oracle_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 public:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 Emitter(WebAssemblyOracle& oracle) :
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 oracle_(oracle)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 virtual void EmitMessage(const IObserver& receiver,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 const IMessage& message)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 oracle_.EmitMessage(receiver, message);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 };
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 Emitter emitter_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 const IObserver& receiver_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 std::auto_ptr<IOracleCommand> command_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 std::string 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 public:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 FetchContext(WebAssemblyOracle& oracle,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 const IObserver& receiver,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 IOracleCommand* command,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 const std::string& expectedContentType) :
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 emitter_(oracle),
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 receiver_(receiver),
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 command_(command),
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 expectedContentType_(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 if (command == NULL)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 }
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 const std::string& GetExpectedContentType() const
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 expectedContentType_;
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 void EmitMessage(const IMessage& message)
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 emitter_.EmitMessage(receiver_, message);
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 IMessageEmitter& GetEmitter()
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 emitter_;
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 const IObserver& GetReceiver() const
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 return receiver_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 }
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 IOracleCommand& GetCommand() const
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 return *command_;
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 template <typename T>
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 const T& GetTypedCommand() const
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 return dynamic_cast<T&>(*command_);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448 }
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
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 static void FetchSucceeded(emscripten_fetch_t *fetch)
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 /**
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 * Firstly, make a local copy of the fetched information, and
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455 * free data associated with the fetch.
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
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 std::auto_ptr<FetchContext> context(reinterpret_cast<FetchContext*>(fetch->userData));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460 std::string answer;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 if (fetch->numBytes > 0)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 answer.assign(fetch->data, fetch->numBytes);
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
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 /**
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467 * TODO - HACK - As of emscripten-1.38.31, the fetch API does
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468 * not contain a way to retrieve the HTTP headers of the
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469 * answer. We make the assumption that the "Content-Type" header
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470 * of the response is the same as the "Accept" header of the
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471 * query. This should be fixed in future versions of emscripten.
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472 * https://github.com/emscripten-core/emscripten/pull/8486
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 HttpHeaders headers;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476 if (!context->GetExpectedContentType().empty())
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 headers["Content-Type"] = context->GetExpectedContentType();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 }
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
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482 emscripten_fetch_close(fetch);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483
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 /**
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 * Secondly, use the retrieved data.
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 **/
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 try
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 if (context.get() == NULL)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495 else
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 switch (context->GetCommand().GetType())
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 case IOracleCommand::Type_OrthancRestApi:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501 OrthancRestApiCommand::SuccessMessage message
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502 (context->GetTypedCommand<OrthancRestApiCommand>(), headers, answer);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503 context->EmitMessage(message);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504 break;
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
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 case IOracleCommand::Type_GetOrthancImage:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 context->GetTypedCommand<GetOrthancImageCommand>().ProcessHttpAnswer
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 (context->GetEmitter(), context->GetReceiver(), answer, headers);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511 break;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514 case IOracleCommand::Type_GetOrthancWebViewerJpeg:
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 context->GetTypedCommand<GetOrthancWebViewerJpegCommand>().ProcessHttpAnswer
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517 (context->GetEmitter(), context->GetReceiver(), answer);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518 break;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519 }
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 default:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522 LOG(ERROR) << "Command type not implemented by the WebAssembly Oracle: "
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 << context->GetCommand().GetType();
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 }
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 catch (Orthanc::OrthancException& e)
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 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
530 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
531 }
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 static void FetchFailed(emscripten_fetch_t *fetch)
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 std::auto_ptr<FetchContext> context(reinterpret_cast<FetchContext*>(fetch->userData));
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 LOG(ERROR) << "Fetching " << fetch->url << " failed, HTTP failure status code: " << fetch->status;
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 /**
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540 * TODO - The following code leads to an infinite recursion, at
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
541 * least with Firefox running on incognito mode => WHY?
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542 **/
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 //emscripten_fetch_close(fetch); // Also free data on failure.
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
547 class FetchCommand : public boost::noncopyable
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
548 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
549 private:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
550 WebAssemblyOracle& oracle_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551 const IObserver& receiver_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
552 std::auto_ptr<IOracleCommand> command_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
553 Orthanc::HttpMethod method_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
554 std::string uri_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
555 std::string body_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556 HttpHeaders headers_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557 unsigned int timeout_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558 std::string expectedContentType_;
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 public:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
561 FetchCommand(WebAssemblyOracle& oracle,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
562 const IObserver& receiver,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
563 IOracleCommand* command) :
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
564 oracle_(oracle),
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565 receiver_(receiver),
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
566 command_(command),
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567 method_(Orthanc::HttpMethod_Get),
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568 timeout_(0)
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 if (command == NULL)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
571 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573 }
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 SetMethod(Orthanc::HttpMethod method)
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 method_ = method;
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 SetUri(const std::string& uri)
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 uri_ = uri;
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 SetBody(std::string& body /* will be swapped */)
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 body_.swap(body);
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 SetHttpHeaders(const HttpHeaders& headers)
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 headers_ = headers;
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
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
596 void SetTimeout(unsigned int timeout)
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 timeout_ = timeout;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
599 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
600
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
601 void Execute()
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
602 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
603 if (command_.get() == NULL)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
604 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
605 // Cannot call Execute() twice
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
606 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
607 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
608
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
609 emscripten_fetch_attr_t attr;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
610 emscripten_fetch_attr_init(&attr);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
611
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
612 const char* method;
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 switch (method_)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
615 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
616 case Orthanc::HttpMethod_Get:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
617 method = "GET";
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
618 break;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
619
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
620 case Orthanc::HttpMethod_Post:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
621 method = "POST";
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
622 break;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
623
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
624 case Orthanc::HttpMethod_Delete:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
625 method = "DELETE";
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
626 break;
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 case Orthanc::HttpMethod_Put:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
629 method = "PUT";
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
630 break;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
631
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
632 default:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
633 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
634 }
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 strcpy(attr.requestMethod, method);
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 attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
639 attr.onsuccess = FetchSucceeded;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
640 attr.onerror = FetchFailed;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
641 attr.timeoutMSecs = timeout_ * 1000;
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 std::vector<const char*> headers;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
644 headers.reserve(2 * headers_.size() + 1);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
645
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
646 std::string expectedContentType;
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 for (HttpHeaders::const_iterator it = headers_.begin(); it != headers_.end(); ++it)
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 std::string key;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
651 Orthanc::Toolbox::ToLowerCase(key, it->first);
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 if (key == "accept")
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 expectedContentType = it->second;
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
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
658 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
659 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
660 headers.push_back(it->first.c_str());
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
661 headers.push_back(it->second.c_str());
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
662 }
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 headers.push_back(NULL); // Termination of the array of HTTP headers
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
666
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
667 attr.requestHeaders = &headers[0];
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 if (!body_.empty())
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 attr.requestDataSize = body_.size();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
672 attr.requestData = body_.c_str();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
673 }
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 // Must be the last call to prevent memory leak on error
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
676 attr.userData = new FetchContext(oracle_, receiver_, command_.release(), expectedContentType);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
677 emscripten_fetch(&attr, uri_.c_str());
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
678 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
679 };
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
680
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 void Execute(const IObserver& receiver,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
683 OrthancRestApiCommand* command)
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 FetchCommand fetch(*this, receiver, command);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
686
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
687 fetch.SetMethod(command->GetMethod());
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
688 fetch.SetUri(command->GetUri());
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
689 fetch.SetHttpHeaders(command->GetHttpHeaders());
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
690 fetch.SetTimeout(command->GetTimeout());
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 if (command->GetMethod() == Orthanc::HttpMethod_Put ||
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
693 command->GetMethod() == Orthanc::HttpMethod_Put)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
694 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
695 std::string body;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
696 command->SwapBody(body);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
697 fetch.SetBody(body);
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
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
700 fetch.Execute();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
701 }
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
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
704 void Execute(const IObserver& receiver,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
705 GetOrthancImageCommand* command)
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 FetchCommand fetch(*this, receiver, command);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
708
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
709 fetch.SetUri(command->GetUri());
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
710 fetch.SetHttpHeaders(command->GetHttpHeaders());
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
711 fetch.SetTimeout(command->GetTimeout());
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
712
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
713 fetch.Execute();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
714 }
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
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
717 void Execute(const IObserver& receiver,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
718 GetOrthancWebViewerJpegCommand* command)
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 FetchCommand fetch(*this, receiver, command);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
721
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
722 fetch.SetUri(command->GetUri());
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
723 fetch.SetHttpHeaders(command->GetHttpHeaders());
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
724 fetch.SetTimeout(command->GetTimeout());
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 fetch.Execute();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
727 }
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
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
730 public:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
731 WebAssemblyOracle(MessageBroker& broker) :
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
732 IObservable(broker)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
733 {
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 virtual void Schedule(const IObserver& receiver,
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
737 IOracleCommand* command)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
738 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
739 std::auto_ptr<IOracleCommand> protection(command);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
740
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
741 if (command == NULL)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
742 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
743 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
744 }
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 switch (command->GetType())
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
747 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
748 case IOracleCommand::Type_OrthancRestApi:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
749 Execute(receiver, dynamic_cast<OrthancRestApiCommand*>(protection.release()));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
750 break;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
751
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
752 case IOracleCommand::Type_GetOrthancImage:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
753 Execute(receiver, dynamic_cast<GetOrthancImageCommand*>(protection.release()));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
754 break;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
755
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
756 case IOracleCommand::Type_GetOrthancWebViewerJpeg:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
757 Execute(receiver, dynamic_cast<GetOrthancWebViewerJpegCommand*>(protection.release()));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
758 break;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
759
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
760 default:
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
761 LOG(ERROR) << "Command type not implemented by the WebAssembly Oracle: " << command->GetType();
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 virtual void Start()
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
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
769 virtual void Stop()
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
770 {
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 };
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
773 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
774
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
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
777
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
778 boost::shared_ptr<OrthancStone::DicomVolumeImage> ct_(new OrthancStone::DicomVolumeImage);
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 boost::shared_ptr<OrthancStone::OrthancSeriesVolumeProgressiveLoader> loader_;
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 std::auto_ptr<OrthancStone::VolumeSlicerViewport> viewport1_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
783 std::auto_ptr<OrthancStone::VolumeSlicerViewport> viewport2_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
784 std::auto_ptr<OrthancStone::VolumeSlicerViewport> viewport3_;
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 OrthancStone::MessageBroker broker_;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
787 OrthancStone::WebAssemblyOracle oracle_(broker_);
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
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
790 EM_BOOL OnWindowResize(int eventType, const EmscriptenUiEvent *uiEvent, void *userData)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
791 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
792 try
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 (viewport1_.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 viewport1_->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 if (viewport2_.get() != NULL)
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 viewport2_->UpdateSize();
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 if (viewport3_.get() != NULL)
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 viewport3_->UpdateSize();
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 catch (Orthanc::OrthancException& e)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
810 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
811 LOG(ERROR) << "Exception while updating canvas size: " << e.What();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
812 }
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 return true;
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
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
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
820 EM_BOOL OnAnimationFrame(double time, void *userData)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
821 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
822 try
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 (viewport1_.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 viewport1_->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 if (viewport2_.get() != NULL)
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 viewport2_->Refresh();
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
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
834 if (viewport3_.get() != NULL)
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 viewport3_->Refresh();
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 return true;
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 catch (Orthanc::OrthancException& e)
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 LOG(ERROR) << "Exception in the animation loop, stopping now: " << e.What();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
844 return false;
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
845 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
846 }
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 extern "C"
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
850 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
851 int main(int argc, char const *argv[])
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
852 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
853 OrthancStone::StoneInitialize();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
854 Orthanc::Logging::EnableInfoLevel(true);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
855 // Orthanc::Logging::EnableTraceLevel(true);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
856 EM_ASM(window.dispatchEvent(new CustomEvent("WebAssemblyLoaded")););
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
857 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
858
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
859 EMSCRIPTEN_KEEPALIVE
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
860 void Initialize()
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
861 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
862 try
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 loader_.reset(new OrthancStone::OrthancSeriesVolumeProgressiveLoader(ct_, oracle_, oracle_));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
865
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
866 viewport1_.reset(new OrthancStone::VolumeSlicerViewport(broker_, "mycanvas1", OrthancStone::VolumeProjection_Axial));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
867 viewport1_->SetSlicer(0, loader_, *loader_, new OrthancStone::GrayscaleStyleConfigurator);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
868 viewport1_->UpdateSize();
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 viewport2_.reset(new OrthancStone::VolumeSlicerViewport(broker_, "mycanvas2", OrthancStone::VolumeProjection_Coronal));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
871 viewport2_->SetSlicer(0, loader_, *loader_, new OrthancStone::GrayscaleStyleConfigurator);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
872 viewport2_->UpdateSize();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
873
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
874 viewport3_.reset(new OrthancStone::VolumeSlicerViewport(broker_, "mycanvas3", OrthancStone::VolumeProjection_Sagittal));
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
875 viewport3_->SetSlicer(0, loader_, *loader_, new OrthancStone::GrayscaleStyleConfigurator);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
876 viewport3_->UpdateSize();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
877
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
878 emscripten_set_resize_callback("#window", NULL, false, OnWindowResize);
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 emscripten_request_animation_frame_loop(OnAnimationFrame, NULL);
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
881
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
882 oracle_.Start();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
883 loader_->LoadSeries("a04ecf01-79b2fc33-58239f7e-ad9db983-28e81afa");
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
884 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
885 catch (Orthanc::OrthancException& e)
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
886 {
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
887 LOG(ERROR) << "Exception during Initialize(): " << e.What();
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
888 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
889 }
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
890 }