Mercurial > hg > orthanc-stone
annotate Applications/Samples/WebAssembly/RtViewer/RtViewerWasm.cpp @ 1961:cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 27 Oct 2022 18:43:20 +0200 |
parents | 1cfd602de69d |
children | 07964689cb0b |
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 | 22 #include "../../Common/RtViewerApp.h" |
23 #include "../../Common/RtViewerView.h" | |
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 |
1902 | 27 #include "../../../../OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyLoadersContext.h" |
28 #include "../../../../OrthancStone/Sources/Platforms/WebAssembly/WebGLViewport.h" | |
1543 | 29 #include "../../../../OrthancStone/Sources/StoneException.h" |
30 #include "../../../../OrthancStone/Sources/StoneInitialization.h" | |
1393
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
31 |
1466 | 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) |
1897
144f8f82c15a
added ctrl key in RtViewerWasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
83 { |
1406
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
84 delta = -1; |
1897
144f8f82c15a
added ctrl key in RtViewerWasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
85 } |
144f8f82c15a
added ctrl key in RtViewerWasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
86 else if (wheelEvent->deltaY > 0) |
144f8f82c15a
added ctrl key in RtViewerWasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
87 { |
1406
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
88 delta = 1; |
1897
144f8f82c15a
added ctrl key in RtViewerWasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
89 } |
144f8f82c15a
added ctrl key in RtViewerWasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
90 |
144f8f82c15a
added ctrl key in RtViewerWasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
91 if (wheelEvent->mouse.ctrlKey) |
144f8f82c15a
added ctrl key in RtViewerWasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
92 { |
144f8f82c15a
added ctrl key in RtViewerWasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
93 delta *= 10; |
144f8f82c15a
added ctrl key in RtViewerWasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
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 |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
96 that->Scroll(delta); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
97 |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
98 return 1; |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
99 } |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
100 |
1404
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
101 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
|
102 const std::string& canvasId) |
1393
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
103 { |
1406
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
104 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
|
105 |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
106 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
|
107 |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
108 // 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
|
109 |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
110 std::string selector = "#" + canvasId; |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
111 |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
112 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
|
113 selector.c_str(), |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
114 userData, |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
115 false, |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
116 &RtViewerView_Scroll, |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
117 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
|
118 |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
119 return viewport; |
1393
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
120 } |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
121 |
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
|
122 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
|
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 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
|
125 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
|
126 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
|
127 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
|
128 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
|
129 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
|
130 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
|
131 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
|
132 } |
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
|
133 |
1404
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
134 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
|
135 unsigned int canvasWidth, |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
136 unsigned int canvasHeight) |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
137 { |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
138 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
139 } |
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 |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
142 void RtViewerApp::RunWasm() |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
143 { |
1640
52b8b96cb55f
cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1619
diff
changeset
|
144 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
|
145 |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
146 // 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
|
147 boost::shared_ptr<WebAssemblyLoadersContext> loadersContext = |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
148 boost::dynamic_pointer_cast<WebAssemblyLoadersContext>(loadersContext_); |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
149 |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
150 if (HasArgument("orthanc")) |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
151 loadersContext->SetLocalOrthanc(GetArgument("orthanc")); |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
152 else |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
153 loadersContext->SetLocalOrthanc(".."); |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
154 |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
155 loadersContext->SetDicomCacheSize(128 * 1024 * 1024); // 128MB |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
156 |
1404
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
157 CreateLoaders(); |
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 CreateView("RtViewer_Axial", VolumeProjection_Axial); |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
160 CreateView("RtViewer_Coronal", VolumeProjection_Coronal); |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
161 CreateView("RtViewer_Sagittal", VolumeProjection_Sagittal); |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
162 |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
163 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
|
164 { |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
165 views_[i]->PrepareViewport(); |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
166 } |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
167 |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
168 StartLoaders(); |
1393
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
169 } |
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 |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
172 extern "C" |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
173 { |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
174 boost::shared_ptr<OrthancStone::RtViewerApp> g_app; |
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 int main(int argc, char const *argv[]) |
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 try |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
179 { |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
180 OrthancStone::StoneInitialize(); |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
181 Orthanc::Logging::Initialize(); |
1594
74ed691f9c64
fix initial rendering of MPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1591
diff
changeset
|
182 //Orthanc::Logging::EnableTraceLevel(true); |
74ed691f9c64
fix initial rendering of MPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1591
diff
changeset
|
183 Orthanc::Logging::EnableInfoLevel(true); |
1393
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
184 |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
185 LOG(WARNING) << "Initializing native Stone"; |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
186 |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
187 LOG(WARNING) << "Compiled with Emscripten " << __EMSCRIPTEN_major__ |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
188 << "." << __EMSCRIPTEN_minor__ |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
189 << "." << __EMSCRIPTEN_tiny__; |
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 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
|
192 |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
193 g_app = OrthancStone::RtViewerApp::Create(); |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
194 |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
195 DISPATCH_JAVASCRIPT_EVENT("WasmModuleInitialized"); |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
196 } |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
197 EXTERN_CATCH_EXCEPTIONS; |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
198 } |
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 EMSCRIPTEN_KEEPALIVE |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
201 void Initialize(const char* canvasId) |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
202 { |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
203 try |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
204 { |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
205 g_app->RunWasm(); |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
206 } |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
207 EXTERN_CATCH_EXCEPTIONS; |
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 |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
210 EMSCRIPTEN_KEEPALIVE |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
211 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
|
212 { |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
213 // 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
|
214 LOG(INFO) << "Received GET argument: [" << key << "] = [" << value << "]"; |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
215 g_app->SetArgument(key, value); |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
216 } |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
217 |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
218 } |