annotate Applications/Samples/WebAssembly/RtViewer/RtViewerWasm.cpp @ 1896:b3c08e607d9f

simplified signature of DicomStructureSet::ProjectStructure()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 26 Jan 2022 17:19:37 +0100
parents 7053b8a0aaec
children 144f8f82c15a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1393
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
1 /**
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
2 * Stone of Orthanc
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
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
1393
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
7 *
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
8 * This program is free software: you can redistribute it and/or
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
9 * modify it under the terms of the GNU Affero General Public License
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
11 * the License, or (at your option) any later version.
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
12 *
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
13 * This program is distributed in the hope that it will be useful, but
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
16 * Affero General Public License for more details.
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
17 *
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
18 * You should have received a copy of the GNU Affero General Public License
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
20 **/
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
21
1466
339cd78ff1a2 fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
22 #include "../../Common/RtViewerApp.h"
339cd78ff1a2 fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
23 #include "../../Common/RtViewerView.h"
339cd78ff1a2 fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
24 #include "../../Common/SampleHelpers.h"
1393
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
25
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
26 // Stone of Orthanc includes
1543
4cfdaf4ef3fe fixing paths
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
27 #include "../../../../OrthancStone/Sources/StoneException.h"
4cfdaf4ef3fe fixing paths
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
28 #include "../../../../OrthancStone/Sources/StoneInitialization.h"
1591
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1543
diff changeset
29 #include "../../../Platforms/WebAssembly/WebAssemblyLoadersContext.h"
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1543
diff changeset
30 #include "../../../Platforms/WebAssembly/WebGLViewport.h"
1393
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
31
1466
339cd78ff1a2 fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
32 #include <Toolbox.h>
1393
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
33
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
34 #include <boost/program_options.hpp>
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
35 #include <boost/shared_ptr.hpp>
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
36 // #include <boost/pointer_cast.hpp> this include might be necessary in more recent boost versions
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
37
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
38 #include <emscripten.h>
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
39 #include <emscripten/html5.h>
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
40
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
41
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
42 #define DISPATCH_JAVASCRIPT_EVENT(name) \
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
43 EM_ASM( \
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
44 const customEvent = document.createEvent("CustomEvent"); \
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
45 customEvent.initCustomEvent(name, false, false, undefined); \
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
46 window.dispatchEvent(customEvent); \
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
47 );
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
48
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
49 #define EXTERN_CATCH_EXCEPTIONS \
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
50 catch (Orthanc::OrthancException& e) \
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
51 { \
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
52 LOG(ERROR) << "OrthancException: " << e.What(); \
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
53 DISPATCH_JAVASCRIPT_EVENT("StoneException"); \
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
54 } \
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
55 catch (OrthancStone::StoneException& e) \
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
56 { \
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
57 LOG(ERROR) << "StoneException: " << e.What(); \
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
58 DISPATCH_JAVASCRIPT_EVENT("StoneException"); \
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
59 } \
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
60 catch (std::exception& e) \
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
61 { \
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
62 LOG(ERROR) << "Runtime error: " << e.what(); \
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
63 DISPATCH_JAVASCRIPT_EVENT("StoneException"); \
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
64 } \
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
65 catch (...) \
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
66 { \
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
67 LOG(ERROR) << "Native exception"; \
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
68 DISPATCH_JAVASCRIPT_EVENT("StoneException"); \
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
69 }
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
70
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
71 namespace OrthancStone
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
72 {
1406
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
73 // typedef EM_BOOL (*OnMouseWheelFunc)(int eventType, const EmscriptenWheelEvent* wheelEvent, void* userData);
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
74
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
75 EM_BOOL RtViewerView_Scroll(int eventType,
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
76 const EmscriptenWheelEvent* wheelEvent,
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
77 void* userData)
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
78 {
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
79 RtViewerView* that = reinterpret_cast<RtViewerView*>(userData);
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
80
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
81 int delta = 0;
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
82 if (wheelEvent->deltaY < 0)
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
83 delta = -1;
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
84 if (wheelEvent->deltaY > 0)
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
85 delta = 1;
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
86
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
87 that->Scroll(delta);
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
88
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
89 return 1;
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
90 }
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
91
1404
3e644f6fadd4 Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1393
diff changeset
92 boost::shared_ptr<IViewport> RtViewerView::CreateViewport(
3e644f6fadd4 Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1393
diff changeset
93 const std::string& canvasId)
1393
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
94 {
1406
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
95 boost::shared_ptr<IViewport> viewport = WebGLViewport::Create(canvasId);
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
96
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
97 void* userData = reinterpret_cast<void*>(this);
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
98
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
99 // manually add the mouse wheel handler
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
100
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
101 std::string selector = "#" + canvasId;
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
102
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
103 emscripten_set_wheel_callback_on_thread(
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
104 selector.c_str(),
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
105 userData,
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
106 false,
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
107 &RtViewerView_Scroll,
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
108 EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD);
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
109
5d7ee14dc1eb Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1404
diff changeset
110 return viewport;
1393
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
111 }
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
112
1619
4c9e68291467 Added code to remove the wheel callback in dtor, to prevent access to dead object
Benjamin Golinvaux <bgo@osimis.io>
parents: 1594
diff changeset
113 void RtViewerView::CleanupViewportEvents()
4c9e68291467 Added code to remove the wheel callback in dtor, to prevent access to dead object
Benjamin Golinvaux <bgo@osimis.io>
parents: 1594
diff changeset
114 {
4c9e68291467 Added code to remove the wheel callback in dtor, to prevent access to dead object
Benjamin Golinvaux <bgo@osimis.io>
parents: 1594
diff changeset
115 void* userData = reinterpret_cast<void*>(this);
4c9e68291467 Added code to remove the wheel callback in dtor, to prevent access to dead object
Benjamin Golinvaux <bgo@osimis.io>
parents: 1594
diff changeset
116 std::string selector = "#" + canvasId_;
4c9e68291467 Added code to remove the wheel callback in dtor, to prevent access to dead object
Benjamin Golinvaux <bgo@osimis.io>
parents: 1594
diff changeset
117 emscripten_set_wheel_callback_on_thread(
4c9e68291467 Added code to remove the wheel callback in dtor, to prevent access to dead object
Benjamin Golinvaux <bgo@osimis.io>
parents: 1594
diff changeset
118 selector.c_str(),
4c9e68291467 Added code to remove the wheel callback in dtor, to prevent access to dead object
Benjamin Golinvaux <bgo@osimis.io>
parents: 1594
diff changeset
119 userData,
4c9e68291467 Added code to remove the wheel callback in dtor, to prevent access to dead object
Benjamin Golinvaux <bgo@osimis.io>
parents: 1594
diff changeset
120 false,
4c9e68291467 Added code to remove the wheel callback in dtor, to prevent access to dead object
Benjamin Golinvaux <bgo@osimis.io>
parents: 1594
diff changeset
121 NULL,
4c9e68291467 Added code to remove the wheel callback in dtor, to prevent access to dead object
Benjamin Golinvaux <bgo@osimis.io>
parents: 1594
diff changeset
122 EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD);
4c9e68291467 Added code to remove the wheel callback in dtor, to prevent access to dead object
Benjamin Golinvaux <bgo@osimis.io>
parents: 1594
diff changeset
123 }
4c9e68291467 Added code to remove the wheel callback in dtor, to prevent access to dead object
Benjamin Golinvaux <bgo@osimis.io>
parents: 1594
diff changeset
124
1404
3e644f6fadd4 Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1393
diff changeset
125 void RtViewerView::TakeScreenshot(const std::string& target,
1393
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
126 unsigned int canvasWidth,
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
127 unsigned int canvasHeight)
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
128 {
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
129 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
130 }
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
131
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
132
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
133 void RtViewerApp::RunWasm()
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
134 {
1640
52b8b96cb55f cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1619
diff changeset
135 loadersContext_.reset(new WebAssemblyLoadersContext(1, 4, 1));
1393
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
136
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
137 // we are in WASM --> downcast to concrete type
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
138 boost::shared_ptr<WebAssemblyLoadersContext> loadersContext =
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
139 boost::dynamic_pointer_cast<WebAssemblyLoadersContext>(loadersContext_);
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
140
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
141 if (HasArgument("orthanc"))
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
142 loadersContext->SetLocalOrthanc(GetArgument("orthanc"));
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
143 else
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
144 loadersContext->SetLocalOrthanc("..");
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
145
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
146 loadersContext->SetDicomCacheSize(128 * 1024 * 1024); // 128MB
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
147
1404
3e644f6fadd4 Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1393
diff changeset
148 CreateLoaders();
3e644f6fadd4 Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1393
diff changeset
149
3e644f6fadd4 Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1393
diff changeset
150 CreateView("RtViewer_Axial", VolumeProjection_Axial);
3e644f6fadd4 Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1393
diff changeset
151 CreateView("RtViewer_Coronal", VolumeProjection_Coronal);
3e644f6fadd4 Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1393
diff changeset
152 CreateView("RtViewer_Sagittal", VolumeProjection_Sagittal);
3e644f6fadd4 Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1393
diff changeset
153
3e644f6fadd4 Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1393
diff changeset
154 for (size_t i = 0; i < views_.size(); ++i)
3e644f6fadd4 Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1393
diff changeset
155 {
3e644f6fadd4 Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1393
diff changeset
156 views_[i]->PrepareViewport();
3e644f6fadd4 Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1393
diff changeset
157 }
3e644f6fadd4 Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1393
diff changeset
158
3e644f6fadd4 Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents: 1393
diff changeset
159 StartLoaders();
1393
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
160 }
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
161 }
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
162
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
163 extern "C"
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
164 {
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
165 boost::shared_ptr<OrthancStone::RtViewerApp> g_app;
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
166
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
167 int main(int argc, char const *argv[])
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
168 {
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
169 try
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
170 {
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
171 OrthancStone::StoneInitialize();
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
172 Orthanc::Logging::Initialize();
1594
74ed691f9c64 fix initial rendering of MPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1591
diff changeset
173 //Orthanc::Logging::EnableTraceLevel(true);
74ed691f9c64 fix initial rendering of MPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1591
diff changeset
174 Orthanc::Logging::EnableInfoLevel(true);
1393
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
175
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
176 LOG(WARNING) << "Initializing native Stone";
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
177
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
178 LOG(WARNING) << "Compiled with Emscripten " << __EMSCRIPTEN_major__
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
179 << "." << __EMSCRIPTEN_minor__
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
180 << "." << __EMSCRIPTEN_tiny__;
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
181
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
182 LOG(INFO) << "Endianness: " << Orthanc::EnumerationToString(Orthanc::Toolbox::DetectEndianness());
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
183
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
184 g_app = OrthancStone::RtViewerApp::Create();
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
185
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
186 DISPATCH_JAVASCRIPT_EVENT("WasmModuleInitialized");
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
187 }
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
188 EXTERN_CATCH_EXCEPTIONS;
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
189 }
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
190
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
191 EMSCRIPTEN_KEEPALIVE
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
192 void Initialize(const char* canvasId)
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
193 {
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
194 try
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
195 {
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
196 g_app->RunWasm();
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
197 }
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
198 EXTERN_CATCH_EXCEPTIONS;
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
199 }
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
200
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
201 EMSCRIPTEN_KEEPALIVE
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
202 void SetArgument(const char* key, const char* value)
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
203 {
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
204 // This is called for each GET argument (cf. "app.js")
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
205 LOG(INFO) << "Received GET argument: [" << key << "] = [" << value << "]";
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
206 g_app->SetArgument(key, value);
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
207 }
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
208
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1384
diff changeset
209 }