annotate Framework/Viewport/WebGLViewportsRegistry.cpp @ 1344:00c8322bbe69 broker

Ability to force a re-slice of the structure set volume. This is a fix for the fact that the structure set does not increase the slice revision when new polygons are added. This should be fixed in the slicer but this is a temporary fix until this is done properly.
author Benjamin Golinvaux <bgo@osimis.io>
date Mon, 06 Apr 2020 08:44:10 +0200
parents ab81ee8fce1f
children 30deba7bc8e2
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
1271
0ca50d275b9a upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1242
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * 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
9 * as published by the Free Software Foundation, either version 3 of
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * 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
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * 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
18 * 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
19 **/
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 #include "WebGLViewportsRegistry.h"
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
1331
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
24 #include "../Toolbox/GenericToolbox.h"
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
25
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include <Core/OrthancException.h>
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
1242
b9b5d4378874 working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1235
diff changeset
28 #include <boost/make_shared.hpp>
b9b5d4378874 working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1235
diff changeset
29
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 namespace OrthancStone
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 void WebGLViewportsRegistry::LaunchTimer()
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 {
1331
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
34 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
35 OnTimeoutCallback,
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
36 timeoutMS_,
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
37 reinterpret_cast<void*>(this));
1232
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
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 void WebGLViewportsRegistry::OnTimeout()
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
1331
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
42 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
43 it != viewports_.end();
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
44 ++it)
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 if (it->second == NULL ||
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 it->second->IsContextLost())
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 LOG(INFO) << "WebGL context lost for canvas: " << it->first;
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 // Try and duplicate the HTML5 canvas in the DOM
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 EM_ASM({
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 var canvas = document.getElementById(UTF8ToString($0));
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 if (canvas) {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 var parent = canvas.parentElement;
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 if (parent) {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 var cloned = canvas.cloneNode(true /* deep copy */);
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 parent.insertBefore(cloned, canvas);
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 parent.removeChild(canvas);
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 },
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 it->first.c_str() // $0 = ID of the canvas
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 );
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 // 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
67 // replaced by a fresh one with the same ID: Recreate the
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 // WebGL context on the new canvas
1242
b9b5d4378874 working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1235
diff changeset
69 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
70
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
71 // 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
72 // and set them to the new viewport
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 {
1299
c38c89684d83 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1271
diff changeset
74 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
75
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
76 // TODO: remove ViewportController
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
77 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
78 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
79
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
80 {
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
81 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
82 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
83 }
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 // Replace the old WebGL viewport by the new one
1242
b9b5d4378874 working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1235
diff changeset
87 it->second = viewport;
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 // Tag the fresh canvas as needing a repaint
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 {
1299
c38c89684d83 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1271
diff changeset
91 std::unique_ptr<IViewport::ILock> lock(it->second->Lock());
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 lock->Invalidate();
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 }
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
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 LaunchTimer();
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 void WebGLViewportsRegistry::OnTimeoutCallback(void *userData)
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 {
1331
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
102 // 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
103 WebGLViewportsRegistry* that =
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
104 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
105 that->OnTimeout();
1232
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
1235
e71ee3e88448 WebGLViewportsRegistry in milliseconds, and Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1232
diff changeset
108 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
109 timeoutMS_(timeoutMS),
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
110 timeOutID_(0)
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 {
1235
e71ee3e88448 WebGLViewportsRegistry in milliseconds, and Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1232
diff changeset
112 if (timeoutMS <= 0)
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 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 }
1235
e71ee3e88448 WebGLViewportsRegistry in milliseconds, and Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1232
diff changeset
116
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 LaunchTimer();
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
1331
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
120 WebGLViewportsRegistry::~WebGLViewportsRegistry()
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
121 {
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
122 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
123 Clear();
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
124 }
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125
1331
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
126 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
127 const std::string& canvasId)
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 if (viewports_.find(canvasId) != viewports_.end())
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 LOG(ERROR) << "Canvas was already registered: " << canvasId;
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 else
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 {
1331
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
136 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
137 WebGLViewport::Create(canvasId);
1242
b9b5d4378874 working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1235
diff changeset
138 viewports_[canvasId] = viewport;
b9b5d4378874 working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1235
diff changeset
139 return viewport;
1232
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 }
1331
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
142
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 void WebGLViewportsRegistry::Remove(const std::string& canvasId)
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 Viewports::iterator found = viewports_.find(canvasId);
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 if (found == viewports_.end())
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 LOG(ERROR) << "Cannot remove unregistered canvas: " << canvasId;
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 else
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 viewports_.erase(found);
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 }
1331
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
156
1235
e71ee3e88448 WebGLViewportsRegistry in milliseconds, and Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1232
diff changeset
157 void WebGLViewportsRegistry::Clear()
e71ee3e88448 WebGLViewportsRegistry in milliseconds, and Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1232
diff changeset
158 {
e71ee3e88448 WebGLViewportsRegistry in milliseconds, and Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1232
diff changeset
159 viewports_.clear();
e71ee3e88448 WebGLViewportsRegistry in milliseconds, and Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1232
diff changeset
160 }
e71ee3e88448 WebGLViewportsRegistry in milliseconds, and Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1232
diff changeset
161
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 WebGLViewportsRegistry::Accessor::Accessor(WebGLViewportsRegistry& that,
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 const std::string& canvasId) :
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 that_(that)
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 Viewports::iterator viewport = that.viewports_.find(canvasId);
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 if (viewport != that.viewports_.end() &&
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 viewport->second != NULL)
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 lock_.reset(viewport->second->Lock());
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 }
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
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 IViewport::ILock& WebGLViewportsRegistry::Accessor::GetViewport() const
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 if (IsValid())
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 return *lock_;
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 else
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 }
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 }