Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/StoneInitialization.cpp @ 1512:244ad1e4e76a
reorganization of folders
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Jul 2020 16:21:02 +0200 |
parents | Framework/StoneInitialization.cpp@30deba7bc8e2 |
children | 5887a4f8594b |
comparison
equal
deleted
inserted
replaced
1511:9dfeee74c1e6 | 1512:244ad1e4e76a |
---|---|
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 | |
22 #include "StoneInitialization.h" | |
23 | |
24 #if !defined(ORTHANC_ENABLE_SDL) | |
25 # error Macro ORTHANC_ENABLE_SDL must be defined | |
26 #endif | |
27 | |
28 #if !defined(ORTHANC_ENABLE_SSL) | |
29 # error Macro ORTHANC_ENABLE_SSL must be defined | |
30 #endif | |
31 | |
32 #if !defined(ORTHANC_ENABLE_CURL) | |
33 # error Macro ORTHANC_ENABLE_CURL must be defined | |
34 #endif | |
35 | |
36 #if !defined(ORTHANC_ENABLE_DCMTK) | |
37 # error Macro ORTHANC_ENABLE_DCMTK must be defined | |
38 # if !defined(DCMTK_VERSION_NUMBER) | |
39 # error Macro DCMTK_VERSION_NUMBER must be defined | |
40 # endif | |
41 #endif | |
42 | |
43 #if ORTHANC_ENABLE_SDL == 1 | |
44 # include "Viewport/SdlWindow.h" | |
45 #endif | |
46 | |
47 #if ORTHANC_ENABLE_CURL == 1 | |
48 # include <HttpClient.h> | |
49 #endif | |
50 | |
51 #if ORTHANC_ENABLE_DCMTK == 1 | |
52 # include <DicomParsing/FromDcmtkBridge.h> | |
53 #endif | |
54 | |
55 #if ORTHANC_ENABLE_WASM == 1 | |
56 static double viewportsTimeout_ = 1000; | |
57 static std::unique_ptr<OrthancStone::WebGLViewportsRegistry> viewportsRegistry_; | |
58 #endif | |
59 | |
60 #include "Toolbox/LinearAlgebra.h" | |
61 | |
62 #include <Logging.h> | |
63 #include <OrthancException.h> | |
64 #include <Toolbox.h> | |
65 | |
66 #include <locale> | |
67 | |
68 | |
69 namespace OrthancStone | |
70 { | |
71 void StoneInitialize(void* pluginContext) | |
72 { | |
73 if (pluginContext != NULL) | |
74 { | |
75 Orthanc::Logging::InitializePluginContext(pluginContext); | |
76 } | |
77 else | |
78 { | |
79 Orthanc::Logging::Initialize(); | |
80 } | |
81 | |
82 #if ORTHANC_ENABLE_SSL == 1 | |
83 // Must be before curl | |
84 Orthanc::Toolbox::InitializeOpenSsl(); | |
85 #endif | |
86 | |
87 #if ORTHANC_ENABLE_CURL == 1 | |
88 Orthanc::HttpClient::GlobalInitialize(); | |
89 # if ORTHANC_ENABLE_SSL == 1 | |
90 Orthanc::HttpClient::ConfigureSsl(false, ""); | |
91 # endif | |
92 #endif | |
93 | |
94 #if ORTHANC_ENABLE_DCMTK == 1 | |
95 Orthanc::FromDcmtkBridge::InitializeDictionary(true); | |
96 Orthanc::FromDcmtkBridge::InitializeCodecs(); | |
97 # if DCMTK_VERSION_NUMBER <= 360 | |
98 OFLog::configure(OFLogger::FATAL_LOG_LEVEL); | |
99 # else | |
100 OFLog::configure(OFLogger::OFF_LOG_LEVEL); | |
101 # endif | |
102 #endif | |
103 | |
104 /** | |
105 * This call is necessary to make "boost::lexical_cast<>" work in | |
106 * a consistent way in the presence of "double" or "float", and of | |
107 * a numeric locale that replaces dot (".") by comma (",") as the | |
108 * decimal separator. | |
109 * https://stackoverflow.com/a/18981514/881731 | |
110 **/ | |
111 std::locale::global(std::locale::classic()); | |
112 | |
113 { | |
114 // Run-time checks of locale settings, to be run after Qt has | |
115 // been initialized, as Qt changes locale settings | |
116 | |
117 { | |
118 OrthancStone::Vector v; | |
119 if (!OrthancStone::LinearAlgebra::ParseVector(v, "1.3671875\\-1.3671875") || | |
120 v.size() != 2 || | |
121 !OrthancStone::LinearAlgebra::IsNear(1.3671875f, v[0]) || | |
122 !OrthancStone::LinearAlgebra::IsNear(-1.3671875f, v[1])) | |
123 { | |
124 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, | |
125 "Error in the locale settings, giving up"); | |
126 } | |
127 } | |
128 | |
129 { | |
130 Json::Value dicomweb = Json::objectValue; | |
131 dicomweb["00280030"] = Json::objectValue; | |
132 dicomweb["00280030"]["vr"] = "DS"; | |
133 dicomweb["00280030"]["Value"] = Json::arrayValue; | |
134 dicomweb["00280030"]["Value"].append(1.2f); | |
135 dicomweb["00280030"]["Value"].append(-1.5f); | |
136 | |
137 Orthanc::DicomMap source; | |
138 source.FromDicomWeb(dicomweb); | |
139 | |
140 std::string s; | |
141 OrthancStone::Vector v; | |
142 if (!source.LookupStringValue(s, Orthanc::DICOM_TAG_PIXEL_SPACING, false) || | |
143 !OrthancStone::LinearAlgebra::ParseVector(v, s) || | |
144 v.size() != 2 || | |
145 !OrthancStone::LinearAlgebra::IsNear(1.2f, v[0]) || | |
146 !OrthancStone::LinearAlgebra::IsNear(-1.5f, v[1])) | |
147 { | |
148 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, | |
149 "Error in the locale settings, giving up"); | |
150 } | |
151 } | |
152 } | |
153 | |
154 #if ORTHANC_ENABLE_SDL == 1 | |
155 OrthancStone::SdlWindow::GlobalInitialize(); | |
156 #endif | |
157 } | |
158 | |
159 | |
160 void StoneFinalize() | |
161 { | |
162 #if ORTHANC_ENABLE_WASM == 1 | |
163 viewportsRegistry_.reset(); | |
164 #endif | |
165 | |
166 #if ORTHANC_ENABLE_SDL == 1 | |
167 OrthancStone::SdlWindow::GlobalFinalize(); | |
168 #endif | |
169 | |
170 #if ORTHANC_ENABLE_DCMTK == 1 | |
171 Orthanc::FromDcmtkBridge::FinalizeCodecs(); | |
172 #endif | |
173 | |
174 #if ORTHANC_ENABLE_CURL == 1 | |
175 Orthanc::HttpClient::GlobalFinalize(); | |
176 #endif | |
177 | |
178 #if ORTHANC_ENABLE_SSL == 1 | |
179 Orthanc::Toolbox::FinalizeOpenSsl(); | |
180 #endif | |
181 | |
182 Orthanc::Logging::Finalize(); | |
183 } | |
184 | |
185 | |
186 #if ORTHANC_ENABLE_WASM == 1 | |
187 void SetWebGLViewportsRegistryTimeout(double timeout) | |
188 { | |
189 if (viewportsRegistry_.get()) | |
190 { | |
191 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
192 } | |
193 else | |
194 { | |
195 viewportsTimeout_ = timeout; | |
196 } | |
197 } | |
198 #endif | |
199 | |
200 | |
201 #if ORTHANC_ENABLE_WASM == 1 | |
202 WebGLViewportsRegistry& GetWebGLViewportsRegistry() | |
203 { | |
204 if (viewportsRegistry_.get() == NULL) | |
205 { | |
206 viewportsRegistry_.reset(new WebGLViewportsRegistry(viewportsTimeout_)); | |
207 } | |
208 | |
209 return *viewportsRegistry_; | |
210 } | |
211 #endif | |
212 } |