annotate Applications/Platforms/WebAssembly/WebGLViewportsRegistry.cpp @ 1895:14c8f339d480

removed redundant definitions Point2D, Point3D and Vector3D from DicomStructureSetUtils.h
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 19 Jan 2022 14:51:55 +0100
parents 7053b8a0aaec
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
1871
7053b8a0aaec upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1870
diff changeset
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium
7053b8a0aaec upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1870
diff changeset
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * modify it under the terms of the GNU Affero General Public License
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * the License, or (at your option) any later version.
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * Affero General Public License for more details.
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * You should have received a copy of the GNU Affero General Public License
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "WebGLViewportsRegistry.h"
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
1591
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
25 #include "../../../OrthancStone/Sources/Scene2DViewport/ViewportController.h"
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
26 #include "../../../OrthancStone/Sources/Toolbox/GenericToolbox.h"
1331
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
27
1455
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1331
diff changeset
28 #include <OrthancException.h>
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
1242
b9b5d4378874 working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1235
diff changeset
30 #include <boost/make_shared.hpp>
b9b5d4378874 working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1235
diff changeset
31
1591
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
32
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
33 static double viewportsTimeout_ = 1000;
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
34 static std::unique_ptr<OrthancStone::WebGLViewportsRegistry> globalRegistry_;
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
35
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
36
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 namespace OrthancStone
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 void WebGLViewportsRegistry::LaunchTimer()
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
1331
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
41 timeOutID_ = emscripten_set_timeout(
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
42 OnTimeoutCallback,
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
43 timeoutMS_,
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
44 reinterpret_cast<void*>(this));
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 void WebGLViewportsRegistry::OnTimeout()
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 {
1331
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
49 for (Viewports::iterator it = viewports_.begin();
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
50 it != viewports_.end();
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
51 ++it)
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 if (it->second == NULL ||
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 it->second->IsContextLost())
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 LOG(INFO) << "WebGL context lost for canvas: " << it->first;
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 // Try and duplicate the HTML5 canvas in the DOM
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 EM_ASM({
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 var canvas = document.getElementById(UTF8ToString($0));
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 if (canvas) {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 var parent = canvas.parentElement;
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 if (parent) {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 var cloned = canvas.cloneNode(true /* deep copy */);
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 parent.insertBefore(cloned, canvas);
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 parent.removeChild(canvas);
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 },
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 it->first.c_str() // $0 = ID of the canvas
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 );
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 // At this point, the old canvas is removed from the DOM and
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 // replaced by a fresh one with the same ID: Recreate the
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 // WebGL context on the new canvas
1242
b9b5d4378874 working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1235
diff changeset
76 boost::shared_ptr<WebGLViewport> viewport;
1331
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
77
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
78 // we need to steal the properties from the old viewport
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
79 // and set them to the new viewport
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 {
1299
c38c89684d83 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1271
diff changeset
81 std::unique_ptr<IViewport::ILock> lock(it->second->Lock());
1331
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
82
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
83 // TODO: remove ViewportController
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
84 Scene2D* scene = lock->GetController().ReleaseScene();
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
85 viewport = WebGLViewport::Create(it->first);
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
86
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
87 {
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
88 std::unique_ptr<IViewport::ILock> newLock(viewport->Lock());
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
89 newLock->GetController().AcquireScene(scene);
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
90 }
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 // Replace the old WebGL viewport by the new one
1242
b9b5d4378874 working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1235
diff changeset
94 it->second = viewport;
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 // Tag the fresh canvas as needing a repaint
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 {
1299
c38c89684d83 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1271
diff changeset
98 std::unique_ptr<IViewport::ILock> lock(it->second->Lock());
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 lock->Invalidate();
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 LaunchTimer();
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 void WebGLViewportsRegistry::OnTimeoutCallback(void *userData)
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 {
1331
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
109 // This object dies with the process or tab.
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
110 WebGLViewportsRegistry* that =
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
111 reinterpret_cast<WebGLViewportsRegistry*>(userData);
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
112 that->OnTimeout();
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
1235
e71ee3e88448 WebGLViewportsRegistry in milliseconds, and Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1232
diff changeset
115 WebGLViewportsRegistry::WebGLViewportsRegistry(double timeoutMS) :
1331
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
116 timeoutMS_(timeoutMS),
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
117 timeOutID_(0)
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 {
1235
e71ee3e88448 WebGLViewportsRegistry in milliseconds, and Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1232
diff changeset
119 if (timeoutMS <= 0)
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 }
1235
e71ee3e88448 WebGLViewportsRegistry in milliseconds, and Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1232
diff changeset
123
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 LaunchTimer();
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126
1331
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
127 WebGLViewportsRegistry::~WebGLViewportsRegistry()
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
128 {
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
129 emscripten_clear_timeout(timeOutID_);
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
130 Clear();
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
131 }
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132
1331
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
133 boost::shared_ptr<WebGLViewport> WebGLViewportsRegistry::Add(
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
134 const std::string& canvasId)
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 if (viewports_.find(canvasId) != viewports_.end())
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 LOG(ERROR) << "Canvas was already registered: " << canvasId;
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 else
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 {
1331
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
143 boost::shared_ptr<WebGLViewport> viewport =
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
144 WebGLViewport::Create(canvasId);
1242
b9b5d4378874 working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1235
diff changeset
145 viewports_[canvasId] = viewport;
b9b5d4378874 working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1235
diff changeset
146 return viewport;
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 }
1331
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
149
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 void WebGLViewportsRegistry::Remove(const std::string& canvasId)
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 Viewports::iterator found = viewports_.find(canvasId);
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 if (found == viewports_.end())
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 LOG(ERROR) << "Cannot remove unregistered canvas: " << canvasId;
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 else
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 viewports_.erase(found);
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 }
1331
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
163
1235
e71ee3e88448 WebGLViewportsRegistry in milliseconds, and Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1232
diff changeset
164 void WebGLViewportsRegistry::Clear()
e71ee3e88448 WebGLViewportsRegistry in milliseconds, and Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1232
diff changeset
165 {
e71ee3e88448 WebGLViewportsRegistry in milliseconds, and Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1232
diff changeset
166 viewports_.clear();
e71ee3e88448 WebGLViewportsRegistry in milliseconds, and Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1232
diff changeset
167 }
e71ee3e88448 WebGLViewportsRegistry in milliseconds, and Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1232
diff changeset
168
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 WebGLViewportsRegistry::Accessor::Accessor(WebGLViewportsRegistry& that,
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 const std::string& canvasId) :
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 that_(that)
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 Viewports::iterator viewport = that.viewports_.find(canvasId);
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 if (viewport != that.viewports_.end() &&
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 viewport->second != NULL)
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 lock_.reset(viewport->second->Lock());
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 IViewport::ILock& WebGLViewportsRegistry::Accessor::GetViewport() const
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 if (IsValid())
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 return *lock_;
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 else
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 }
1591
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
192
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
193
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
194 void WebGLViewportsRegistry::FinalizeGlobalRegistry()
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
195 {
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
196 globalRegistry_.reset();
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
197 }
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
198
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
199
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
200 void WebGLViewportsRegistry::SetGlobalRegistryTimeout(double timeout)
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
201 {
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
202 if (globalRegistry_.get())
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
203 {
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
204 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
205 }
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
206 else
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
207 {
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
208 viewportsTimeout_ = timeout;
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
209 }
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
210 }
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
211
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
212
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
213 WebGLViewportsRegistry& WebGLViewportsRegistry::GetGlobalRegistry()
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
214 {
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
215 if (globalRegistry_.get() == NULL)
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
216 {
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
217 globalRegistry_.reset(new WebGLViewportsRegistry(viewportsTimeout_));
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
218 }
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
219
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
220 return *globalRegistry_;
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
221 }
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 }