Mercurial > hg > orthanc-stone
comparison Framework/Loaders/LoaderCache.cpp @ 929:408bcc6c1505
Added Loader cache. Not activated yet.
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Wed, 24 Jul 2019 14:27:06 +0200 |
parents | |
children | bf03cb879eb4 |
comparison
equal
deleted
inserted
replaced
927:39d2a3661665 | 929:408bcc6c1505 |
---|---|
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-2019 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 "LoaderCache.h" | |
22 | |
23 #include "OrthancSeriesVolumeProgressiveLoader.h" | |
24 #include "OrthancMultiframeVolumeLoader.h" | |
25 #include "DicomStructureSetLoader.h" | |
26 | |
27 #include "../Messages/LockingEmitter.h" | |
28 #include "../Volumes/DicomVolumeImage.h" | |
29 #include "../Volumes/DicomVolumeImageMPRSlicer.h" | |
30 | |
31 #include <Core/OrthancException.h> | |
32 #include <Core/Toolbox.h> | |
33 | |
34 namespace OrthancStone | |
35 { | |
36 #if ORTHANC_ENABLE_WASM == 1 | |
37 LoaderCache::LoaderCache(IOracle& oracle) | |
38 : oracle_(oracle) | |
39 { | |
40 | |
41 } | |
42 #else | |
43 LoaderCache::LoaderCache(IOracle& oracle, LockingEmitter& lockingEmitter) | |
44 : oracle_(oracle) | |
45 , lockingEmitter_(lockingEmitter) | |
46 { | |
47 } | |
48 #endif | |
49 | |
50 boost::shared_ptr<OrthancStone::OrthancSeriesVolumeProgressiveLoader> | |
51 LoaderCache::GetSeriesVolumeProgressiveLoader(std::string seriesUuid) | |
52 { | |
53 try | |
54 { | |
55 // normalize keys a little | |
56 seriesUuid = Orthanc::Toolbox::StripSpaces(seriesUuid); | |
57 Orthanc::Toolbox::ToLowerCase(seriesUuid); | |
58 | |
59 // find in cache | |
60 if (seriesVolumeProgressiveLoaders_.find(seriesUuid) == seriesVolumeProgressiveLoaders_.end()) | |
61 { | |
62 boost::shared_ptr<DicomVolumeImage> volumeImage(new DicomVolumeImage); | |
63 boost::shared_ptr<OrthancSeriesVolumeProgressiveLoader> loader; | |
64 | |
65 { | |
66 #if ORTHANC_ENABLE_WASM == 1 | |
67 loader.reset(new OrthancSeriesVolumeProgressiveLoader(volumeImage, GetParent()->GetOracleRef(), GetParent()->GetOracleRef())); | |
68 #else | |
69 LockingEmitter::WriterLock lock(lockingEmitter_); | |
70 loader.reset(new OrthancSeriesVolumeProgressiveLoader(volumeImage, oracle_, lock.GetOracleObservable())); | |
71 #endif | |
72 loader->LoadSeries(seriesUuid); | |
73 } | |
74 seriesVolumeProgressiveLoaders_[seriesUuid] = loader; | |
75 } | |
76 return seriesVolumeProgressiveLoaders_[seriesUuid]; | |
77 } | |
78 catch (const Orthanc::OrthancException& e) | |
79 { | |
80 if (e.HasDetails()) | |
81 { | |
82 LOG(ERROR) << "OrthancException in LoaderCache: " << e.What() << " Details: " << e.GetDetails(); | |
83 } | |
84 else | |
85 { | |
86 LOG(ERROR) << "OrthancException in LoaderCache: " << e.What(); | |
87 } | |
88 throw; | |
89 } | |
90 catch (const std::exception& e) | |
91 { | |
92 LOG(ERROR) << "std::exception in LoaderCache: " << e.what(); | |
93 throw; | |
94 } | |
95 catch (...) | |
96 { | |
97 LOG(ERROR) << "Unknown exception in LoaderCache"; | |
98 throw; | |
99 } | |
100 } | |
101 | |
102 boost::shared_ptr<DicomVolumeImageMPRSlicer> LoaderCache::GetMultiframeDicomVolumeImageMPRSlicer(std::string instanceUuid) | |
103 { | |
104 try | |
105 { | |
106 // normalize keys a little | |
107 instanceUuid = Orthanc::Toolbox::StripSpaces(instanceUuid); | |
108 Orthanc::Toolbox::ToLowerCase(instanceUuid); | |
109 | |
110 // find in cache | |
111 if (dicomVolumeImageMPRSlicers_.find(instanceUuid) == dicomVolumeImageMPRSlicers_.end()) | |
112 { | |
113 boost::shared_ptr<DicomVolumeImage> volumeImage(new DicomVolumeImage); | |
114 boost::shared_ptr<OrthancMultiframeVolumeLoader> loader; | |
115 | |
116 { | |
117 #if ORTHANC_ENABLE_WASM == 1 | |
118 loader.reset(new OrthancMultiframeVolumeLoader(volumeImage, GetParent()->GetOracleRef(), GetParent()->GetOracleRef())); | |
119 #else | |
120 LockingEmitter::WriterLock lock(lockingEmitter_); | |
121 loader.reset(new OrthancMultiframeVolumeLoader(volumeImage, oracle_, lock.GetOracleObservable())); | |
122 #endif | |
123 loader->LoadInstance(instanceUuid); | |
124 } | |
125 multiframeVolumeLoaders_[instanceUuid] = loader; | |
126 boost::shared_ptr<DicomVolumeImageMPRSlicer> mprSlicer(new DicomVolumeImageMPRSlicer(volumeImage)); | |
127 dicomVolumeImageMPRSlicers_[instanceUuid] = mprSlicer; | |
128 } | |
129 return dicomVolumeImageMPRSlicers_[instanceUuid]; | |
130 } | |
131 catch (const Orthanc::OrthancException& e) | |
132 { | |
133 if (e.HasDetails()) | |
134 { | |
135 LOG(ERROR) << "OrthancException in LoaderCache: " << e.What() << " Details: " << e.GetDetails(); | |
136 } | |
137 else | |
138 { | |
139 LOG(ERROR) << "OrthancException in LoaderCache: " << e.What(); | |
140 } | |
141 throw; | |
142 } | |
143 catch (const std::exception& e) | |
144 { | |
145 LOG(ERROR) << "std::exception in LoaderCache: " << e.what(); | |
146 throw; | |
147 } | |
148 catch (...) | |
149 { | |
150 LOG(ERROR) << "Unknown exception in LoaderCache"; | |
151 throw; | |
152 } | |
153 } | |
154 | |
155 boost::shared_ptr<DicomStructureSetLoader> LoaderCache::GetDicomStructureSetLoader(std::string instanceUuid) | |
156 { | |
157 try | |
158 { | |
159 // normalize keys a little | |
160 instanceUuid = Orthanc::Toolbox::StripSpaces(instanceUuid); | |
161 Orthanc::Toolbox::ToLowerCase(instanceUuid); | |
162 | |
163 // find in cache | |
164 if (dicomStructureSetLoaders_.find(instanceUuid) == dicomStructureSetLoaders_.end()) | |
165 { | |
166 boost::shared_ptr<DicomStructureSetLoader> loader; | |
167 | |
168 { | |
169 #if ORTHANC_ENABLE_WASM == 1 | |
170 loader.reset(new DicomStructureSetLoader(volumeImage, GetParent()->GetOracleRef(), GetParent()->GetOracleRef())); | |
171 #else | |
172 LockingEmitter::WriterLock lock(lockingEmitter_); | |
173 loader.reset(new DicomStructureSetLoader(oracle_, lock.GetOracleObservable())); | |
174 #endif | |
175 loader->LoadInstance(instanceUuid); | |
176 } | |
177 dicomStructureSetLoaders_[instanceUuid] = loader; | |
178 } | |
179 return dicomStructureSetLoaders_[instanceUuid]; | |
180 } | |
181 catch (const Orthanc::OrthancException& e) | |
182 { | |
183 if (e.HasDetails()) | |
184 { | |
185 LOG(ERROR) << "OrthancException in LoaderCache: " << e.What() << " Details: " << e.GetDetails(); | |
186 } | |
187 else | |
188 { | |
189 LOG(ERROR) << "OrthancException in LoaderCache: " << e.What(); | |
190 } | |
191 throw; | |
192 } | |
193 catch (const std::exception& e) | |
194 { | |
195 LOG(ERROR) << "std::exception in LoaderCache: " << e.what(); | |
196 throw; | |
197 } | |
198 catch (...) | |
199 { | |
200 LOG(ERROR) << "Unknown exception in LoaderCache"; | |
201 throw; | |
202 } | |
203 } | |
204 | |
205 | |
206 void LoaderCache::ClearCache() | |
207 { | |
208 #if ORTHANC_ENABLE_WASM != 1 | |
209 LockingEmitter::WriterLock lock(lockingEmitter_); | |
210 #endif | |
211 seriesVolumeProgressiveLoaders_.clear(); | |
212 multiframeVolumeLoaders_.clear(); | |
213 dicomVolumeImageMPRSlicers_.clear(); | |
214 dicomStructureSetLoaders_.clear(); | |
215 } | |
216 | |
217 } |