annotate Applications/Samples/Sdl/SingleFrameViewer/SdlSimpleViewer.cpp @ 1688:c14dd6e11ddd

merge
author Benjamin Golinvaux <bgo@osimis.io>
date Wed, 25 Nov 2020 17:03:08 +0100
parents 4fb8fdf03314
children 9ac2a65d4172
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1458
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
1 /**
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
2 * Stone of Orthanc
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
4 * Department, University Hospital of Liege, Belgium
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
6 *
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
7 * This program is free software: you can redistribute it and/or
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
10 * the License, or (at your option) any later version.
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
11 *
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
12 * This program is distributed in the hope that it will be useful, but
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
15 * Affero General Public License for more details.
1596
4fb8fdf03314 removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1591
diff changeset
16 *
1458
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
19 **/
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
20
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
21
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
22 #include "SdlSimpleViewerApplication.h"
1387
4ebf246f3919 Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents: 1383
diff changeset
23 #include "../SdlHelpers.h"
4ebf246f3919 Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents: 1383
diff changeset
24 #include "../../Common/SampleHelpers.h"
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
25
1542
6e0da8370270 fixing paths
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
26 #include "../../../../OrthancStone/Sources/Loaders/GenericLoadersContext.h"
1560
b4ccd4963d37 fix sdl and wasm samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1542
diff changeset
27 #include "../../../../OrthancStone/Sources/StoneEnumerations.h"
1542
6e0da8370270 fixing paths
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
28 #include "../../../../OrthancStone/Sources/StoneException.h"
6e0da8370270 fixing paths
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
29 #include "../../../../OrthancStone/Sources/StoneInitialization.h"
1560
b4ccd4963d37 fix sdl and wasm samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1542
diff changeset
30 #include "../../../../OrthancStone/Sources/Viewport/DefaultViewportInteractor.h"
1591
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
31 #include "../../../Platforms/Sdl/SdlViewport.h"
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
32
1507
169adf9090a6 replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1458
diff changeset
33 #include <Compatibility.h> // For std::unique_ptr<>
1457
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1426
diff changeset
34 #include <OrthancException.h>
1387
4ebf246f3919 Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents: 1383
diff changeset
35
4ebf246f3919 Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents: 1383
diff changeset
36 #include <boost/program_options.hpp>
4ebf246f3919 Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents: 1383
diff changeset
37 #include <SDL.h>
4ebf246f3919 Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents: 1383
diff changeset
38
4ebf246f3919 Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents: 1383
diff changeset
39 #include <string>
4ebf246f3919 Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents: 1383
diff changeset
40
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
41
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
42 std::string orthancUrl;
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
43 std::string instanceId;
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
44 int frameIndex = 0;
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
45
1387
4ebf246f3919 Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents: 1383
diff changeset
46
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
47 static void ProcessOptions(int argc, char* argv[])
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
48 {
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
49 namespace po = boost::program_options;
1532
c7a37c3a0b8e print help in sdl samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
50 po::options_description desc("Usage");
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
51
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
52 desc.add_options()
1387
4ebf246f3919 Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents: 1383
diff changeset
53 ("loglevel", po::value<std::string>()->default_value("WARNING"),
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
54 "You can choose WARNING, INFO or TRACE for the logging level: Errors and warnings will always be displayed. (default: WARNING)")
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
55
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
56 ("orthanc", po::value<std::string>()->default_value("http://localhost:8042"),
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
57 "Base URL of the Orthanc instance")
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
58
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
59 ("instance", po::value<std::string>()->default_value("285dece8-e1956b38-cdc7d084-6ce3371e-536a9ffc"),
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
60 "Orthanc ID of the instance to display")
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
61
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
62 ("frame_index", po::value<int>()->default_value(0),
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
63 "The zero-based index of the frame (for multi-frame instances)")
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
64 ;
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
65
1532
c7a37c3a0b8e print help in sdl samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
66 std::cout << desc << std::endl;
c7a37c3a0b8e print help in sdl samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
67
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
68 po::variables_map vm;
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
69 try
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
70 {
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
71 po::store(po::parse_command_line(argc, argv, desc), vm);
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
72 po::notify(vm);
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
73 }
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
74 catch (std::exception& e)
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
75 {
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
76 std::cerr << "Please check your command line options! (\"" << e.what() << "\")" << std::endl;
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
77 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
78
1387
4ebf246f3919 Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents: 1383
diff changeset
79 if (vm.count("loglevel") > 0)
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
80 {
1387
4ebf246f3919 Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents: 1383
diff changeset
81 std::string logLevel = vm["loglevel"].as<std::string>();
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
82 OrthancStoneHelpers::SetLogLevel(logLevel);
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
83 }
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
84
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
85 if (vm.count("orthanc") > 0)
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
86 {
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
87 // maybe check URL validity here
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
88 orthancUrl = vm["orthanc"].as<std::string>();
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
89 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
90
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
91 if (vm.count("instance") > 0)
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
92 {
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
93 instanceId = vm["instance"].as<std::string>();
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
94 }
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
95
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
96 if (vm.count("frame_index") > 0)
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
97 {
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
98 frameIndex = vm["frame_index"].as<int>();
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
99 }
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
100
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
101 }
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
102
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
103 /**
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
104 * IMPORTANT: The full arguments to "main()" are needed for SDL on
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
105 * Windows. Otherwise, one gets the linking error "undefined reference
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
106 * to `SDL_main'". https://wiki.libsdl.org/FAQWindows
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
107 **/
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
108 int main(int argc, char* argv[])
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
109 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
110 try
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
111 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
112 OrthancStone::StoneInitialize();
1591
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
113 OrthancStone::SdlWindow::GlobalInitialize();
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
114
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
115 ProcessOptions(argc, argv);
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
116
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
117 //Orthanc::Logging::EnableInfoLevel(true);
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
118 //Orthanc::Logging::EnableTraceLevel(true);
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
119
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
120 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
121
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
122 #if 1
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
123 boost::shared_ptr<OrthancStone::SdlViewport> viewport =
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
124 OrthancStone::SdlOpenGLViewport::Create("Stone of Orthanc", 800, 600);
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
125 #else
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
126 boost::shared_ptr<OrthancStone::SdlViewport> viewport =
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
127 OrthancStone::SdlCairoViewport::Create("Stone of Orthanc", 800, 600);
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
128 #endif
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
129
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
130 OrthancStone::GenericLoadersContext context(1, 4, 1);
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
131
1395
62dc0d737e7b build script for wasm sample + updated instructions + fixed Sdl sample for Orthanc listening on other ports that 8042
Alain Mazy <alain@mazy.be>
parents: 1392
diff changeset
132 Orthanc::WebServiceParameters orthancWebService;
62dc0d737e7b build script for wasm sample + updated instructions + fixed Sdl sample for Orthanc listening on other ports that 8042
Alain Mazy <alain@mazy.be>
parents: 1392
diff changeset
133 orthancWebService.SetUrl(orthancUrl);
62dc0d737e7b build script for wasm sample + updated instructions + fixed Sdl sample for Orthanc listening on other ports that 8042
Alain Mazy <alain@mazy.be>
parents: 1392
diff changeset
134 context.SetOrthancParameters(orthancWebService);
62dc0d737e7b build script for wasm sample + updated instructions + fixed Sdl sample for Orthanc listening on other ports that 8042
Alain Mazy <alain@mazy.be>
parents: 1392
diff changeset
135
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
136 context.StartOracle();
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
137
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
138 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
139
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
140 boost::shared_ptr<SdlSimpleViewerApplication> application(
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
141 SdlSimpleViewerApplication::Create(context, viewport));
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
142
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
143 OrthancStone::DicomSource source;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
144
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
145 application->LoadOrthancFrame(source, instanceId, frameIndex);
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
146
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
147 OrthancStone::DefaultViewportInteractor interactor;
1535
301571299212 DefaultViewportInteractor::SetWindowingLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1532
diff changeset
148 interactor.SetWindowingLayer(0);
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
149
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
150 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
151 int scancodeCount = 0;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
152 const uint8_t* keyboardState = SDL_GetKeyboardState(&scancodeCount);
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
153
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
154 bool stop = false;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
155 while (!stop)
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
156 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
157 bool paint = false;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
158 SDL_Event event;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
159 while (SDL_PollEvent(&event))
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
160 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
161 if (event.type == SDL_QUIT)
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
162 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
163 stop = true;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
164 break;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
165 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
166 else if (viewport->IsRefreshEvent(event))
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
167 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
168 paint = true;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
169 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
170 else if (event.type == SDL_WINDOWEVENT &&
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
171 (event.window.event == SDL_WINDOWEVENT_RESIZED ||
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
172 event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED))
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
173 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
174 viewport->UpdateSize(event.window.data1, event.window.data2);
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
175 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
176 else if (event.type == SDL_WINDOWEVENT &&
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
177 (event.window.event == SDL_WINDOWEVENT_SHOWN ||
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
178 event.window.event == SDL_WINDOWEVENT_EXPOSED))
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
179 {
1576
92fca2b3ba3d sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1560
diff changeset
180 std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport->Lock());
92fca2b3ba3d sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1560
diff changeset
181 lock->RefreshCanvasSize();
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
182 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
183 else if (event.type == SDL_KEYDOWN &&
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
184 event.key.repeat == 0 /* Ignore key bounce */)
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
185 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
186 switch (event.key.keysym.sym)
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
187 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
188 case SDLK_f:
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
189 viewport->ToggleMaximize();
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
190 break;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
191
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
192 case SDLK_s:
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
193 application->FitContent();
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
194 break;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
195
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
196 case SDLK_q:
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
197 stop = true;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
198 break;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
199
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
200 default:
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
201 break;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
202 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
203 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
204 else if (event.type == SDL_MOUSEBUTTONDOWN ||
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
205 event.type == SDL_MOUSEMOTION ||
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
206 event.type == SDL_MOUSEBUTTONUP)
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
207 {
1507
169adf9090a6 replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1458
diff changeset
208 std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport->Lock());
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
209 if (lock->HasCompositor())
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
210 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
211 OrthancStone::PointerEvent p;
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
212 OrthancStoneHelpers::GetPointerEvent(p, lock->GetCompositor(),
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
213 event, keyboardState, scancodeCount);
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
214
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
215 switch (event.type)
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
216 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
217 case SDL_MOUSEBUTTONDOWN:
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
218 lock->GetController().HandleMousePress(interactor, p,
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
219 lock->GetCompositor().GetCanvasWidth(),
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
220 lock->GetCompositor().GetCanvasHeight());
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
221 lock->Invalidate();
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
222 break;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
223
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
224 case SDL_MOUSEMOTION:
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
225 if (lock->GetController().HandleMouseMove(p))
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
226 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
227 lock->Invalidate();
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
228 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
229 break;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
230
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
231 case SDL_MOUSEBUTTONUP:
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
232 lock->GetController().HandleMouseRelease(p);
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
233 lock->Invalidate();
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
234 break;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
235
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
236 default:
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
237 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
238 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
239 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
240 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
241 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
242
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
243 if (paint)
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
244 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
245 viewport->Paint();
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
246 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
247
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
248 // Small delay to avoid using 100% of CPU
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
249 SDL_Delay(1);
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
250 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
251 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
252 context.StopOracle();
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
253 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
254 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
255
1591
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
256 OrthancStone::SdlWindow::GlobalFinalize();
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
257 OrthancStone::StoneFinalize();
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
258 return 0;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
259 }
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
260 catch (Orthanc::OrthancException& e)
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
261 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
262 LOG(ERROR) << "OrthancException: " << e.What();
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
263 return -1;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
264 }
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
265 catch (OrthancStone::StoneException& e)
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
266 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
267 LOG(ERROR) << "StoneException: " << e.What();
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
268 return -1;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
269 }
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
270 catch (std::runtime_error& e)
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
271 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
272 LOG(ERROR) << "Runtime error: " << e.what();
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
273 return -1;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
274 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
275 catch (...)
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
276 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
277 LOG(ERROR) << "Native exception";
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
278 return -1;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
279 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
280 }