Mercurial > hg > orthanc-stone
comparison Samples/Sdl/RtViewer/RtViewerSdl.cpp @ 1386:dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Mon, 27 Apr 2020 16:48:19 +0200 |
parents | 24bcff8ea58f |
children | 5c83be3a6be5 |
comparison
equal
deleted
inserted
replaced
1385:ffe9beb7c5d3 | 1386:dfb48f0794b1 |
---|---|
1 /** | |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 #include "RtViewer.h" | |
22 #include "SampleHelpers.h" | |
23 | |
24 #include <Framework/StoneException.h> | |
25 | |
26 #include <boost/program_options.hpp> | |
27 #include <SDL.h> | |
28 | |
29 #include <string> | |
30 | |
31 static void GLAPIENTRY | |
32 OpenGLMessageCallback(GLenum source, | |
33 GLenum type, | |
34 GLuint id, | |
35 GLenum severity, | |
36 GLsizei length, | |
37 const GLchar* message, | |
38 const void* userParam) | |
39 { | |
40 if (severity != GL_DEBUG_SEVERITY_NOTIFICATION) | |
41 { | |
42 fprintf(stderr, "GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s\n", | |
43 (type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : ""), | |
44 type, severity, message); | |
45 } | |
46 } | |
47 | |
48 namespace OrthancStone | |
49 { | |
50 void RtViewerApp::ProcessOptions(int argc, char* argv[]) | |
51 { | |
52 namespace po = boost::program_options; | |
53 po::options_description desc("Usage:"); | |
54 | |
55 //ctLoader->LoadSeries("a04ecf01-79b2fc33-58239f7e-ad9db983-28e81afa"); // CT | |
56 //doseLoader->LoadInstance("830a69ff-8e4b5ee3-b7f966c8-bccc20fb-d322dceb"); // RT-DOSE | |
57 //rtstructLoader->LoadInstance("54460695-ba3885ee-ddf61ac0-f028e31d-a6e474d9"); // RT-STRUCT | |
58 | |
59 | |
60 desc.add_options() | |
61 ("loglevel", po::value<std::string>()->default_value("WARNING"), | |
62 "You can choose WARNING, INFO or TRACE for the logging level: Errors and warnings will always be displayed. (default: WARNING)") | |
63 | |
64 ("orthanc", po::value<std::string>()->default_value("http://localhost:8042"), | |
65 "Base URL of the Orthanc instance") | |
66 | |
67 ("ctseries", po::value<std::string>()->default_value("a04ecf01-79b2fc33-58239f7e-ad9db983-28e81afa"), | |
68 "Orthanc ID of the CT series to load") | |
69 | |
70 ("rtdose", po::value<std::string>()->default_value("830a69ff-8e4b5ee3-b7f966c8-bccc20fb-d322dceb"), | |
71 "Orthanc ID of the RTDOSE instance to load") | |
72 | |
73 ("rtstruct", po::value<std::string>()->default_value("54460695-ba3885ee-ddf61ac0-f028e31d-a6e474d9"), | |
74 "Orthanc ID of the RTSTRUCT instance to load") | |
75 ; | |
76 | |
77 po::variables_map vm; | |
78 try | |
79 { | |
80 po::store(po::parse_command_line(argc, argv, desc), vm); | |
81 po::notify(vm); | |
82 } | |
83 catch (std::exception& e) | |
84 { | |
85 std::cerr << "Please check your command line options! (\"" << e.what() << "\")" << std::endl; | |
86 } | |
87 | |
88 if (vm.count("loglevel") > 0) | |
89 { | |
90 std::string logLevel = vm["loglevel"].as<std::string>(); | |
91 OrthancStoneHelpers::SetLogLevel(logLevel); | |
92 } | |
93 | |
94 if (vm.count("orthanc") > 0) | |
95 { | |
96 // maybe check URL validity here | |
97 orthancUrl_ = vm["orthanc"].as<std::string>(); | |
98 } | |
99 | |
100 if (vm.count("ctseries") > 0) | |
101 { | |
102 ctSeriesId_ = vm["ctseries"].as<std::string>(); | |
103 } | |
104 | |
105 if (vm.count("rtdose") > 0) | |
106 { | |
107 doseInstanceId_ = vm["rtdose"].as<std::string>(); | |
108 } | |
109 | |
110 if (vm.count("rtstruct") > 0) | |
111 { | |
112 rtStructInstanceId_ = vm["rtstruct"].as<std::string>(); | |
113 } | |
114 } | |
115 | |
116 void RtViewerApp::RunSdl(int argc, char* argv[]) | |
117 { | |
118 ProcessOptions(argc, argv); | |
119 | |
120 { | |
121 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock()); | |
122 ViewportController& controller = lock->GetController(); | |
123 Scene2D& scene = controller.GetScene(); | |
124 ICompositor& compositor = lock->GetCompositor(); | |
125 | |
126 // False means we do NOT let Windows treat this as a legacy application | |
127 // that needs to be scaled | |
128 controller.FitContent(compositor.GetCanvasWidth(), compositor.GetCanvasHeight()); | |
129 | |
130 glEnable(GL_DEBUG_OUTPUT); | |
131 glDebugMessageCallback(OpenGLMessageCallback, 0); | |
132 | |
133 compositor.SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT, | |
134 FONT_SIZE_0, Orthanc::Encoding_Latin1); | |
135 compositor.SetFont(1, Orthanc::EmbeddedResources::UBUNTU_FONT, | |
136 FONT_SIZE_1, Orthanc::Encoding_Latin1); | |
137 } | |
138 //////// from loader | |
139 | |
140 loadersContext_.reset(new GenericLoadersContext(1, 4, 1)); | |
141 loadersContext_->StartOracle(); | |
142 | |
143 /** | |
144 It is very important that the Oracle (responsible for network I/O be started before creating and firing the | |
145 loaders, for any command scheduled by the loader before the oracle is started will be lost. | |
146 */ | |
147 PrepareLoadersAndSlicers(); | |
148 | |
149 bool stopApplication = false; | |
150 | |
151 while (!stopApplication) | |
152 { | |
153 //compositor.Refresh(scene); | |
154 | |
155 SDL_Event event; | |
156 while (!stopApplication && SDL_PollEvent(&event)) | |
157 { | |
158 if (event.type == SDL_QUIT) | |
159 { | |
160 stopApplication = true; | |
161 break; | |
162 } | |
163 else if (event.type == SDL_WINDOWEVENT && | |
164 event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) | |
165 { | |
166 DisableTracker(); // was: tracker.reset(NULL); | |
167 } | |
168 else if (event.type == SDL_KEYDOWN && | |
169 event.key.repeat == 0 /* Ignore key bounce */) | |
170 { | |
171 switch (event.key.keysym.sym) | |
172 { | |
173 case SDLK_f: | |
174 // TODO: implement GetWindow!!! | |
175 // viewport_->GetContext()->GetWindow().ToggleMaximize(); | |
176 ORTHANC_ASSERT(false, "Please implement GetWindow()"); | |
177 break; | |
178 case SDLK_q: | |
179 stopApplication = true; | |
180 break; | |
181 default: | |
182 break; | |
183 } | |
184 } | |
185 HandleApplicationEvent(event); | |
186 } | |
187 SDL_Delay(1); | |
188 } | |
189 loadersContext_->StopOracle(); | |
190 } | |
191 } |