Mercurial > hg > orthanc-stone
comparison Framework/Loaders/LoaderCache.cpp @ 1019:29f5f2031310
Added a way to specificy which structures are to be initially displayed (the
default being ALL structures displayed) + the loader maintains a list of
structure display state, that can be modified continuously + the cache now takes
the initial list of structure into account for computing the entry + added methods
to change the loaded structure visibility + disabled the alternate loaders
(DicomStructureSetLoader2 and friends) + disabled corresponding tests
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Fri, 27 Sep 2019 13:32:05 +0200 |
parents | e704a53c9d0a |
children | f6be9412e42a |
comparison
equal
deleted
inserted
replaced
1018:58eed6bbcabb | 1019:29f5f2031310 |
---|---|
21 #include "LoaderCache.h" | 21 #include "LoaderCache.h" |
22 | 22 |
23 #include "OrthancSeriesVolumeProgressiveLoader.h" | 23 #include "OrthancSeriesVolumeProgressiveLoader.h" |
24 #include "OrthancMultiframeVolumeLoader.h" | 24 #include "OrthancMultiframeVolumeLoader.h" |
25 #include "DicomStructureSetLoader.h" | 25 #include "DicomStructureSetLoader.h" |
26 | |
27 #ifdef BGO_ENABLE_DICOMSTRUCTURESETLOADER2 | |
26 #include "DicomStructureSetLoader2.h" | 28 #include "DicomStructureSetLoader2.h" |
29 #endif | |
30 //BGO_ENABLE_DICOMSTRUCTURESETLOADER2 | |
31 | |
27 | 32 |
28 #if ORTHANC_ENABLE_WASM == 1 | 33 #if ORTHANC_ENABLE_WASM == 1 |
29 # include <unistd.h> | 34 # include <unistd.h> |
30 # include "../Oracle/WebAssemblyOracle.h" | 35 # include "../Oracle/WebAssemblyOracle.h" |
31 #else | 36 #else |
32 # include "../Oracle/ThreadedOracle.h" | 37 # include "../Oracle/ThreadedOracle.h" |
33 #endif | 38 #endif |
34 | 39 |
35 #include "../Messages/LockingEmitter.h" | 40 #include "../Messages/LockingEmitter.h" |
41 | |
42 #ifdef BGO_ENABLE_DICOMSTRUCTURESETLOADER2 | |
36 #include "../Toolbox/DicomStructureSet2.h" | 43 #include "../Toolbox/DicomStructureSet2.h" |
44 #endif | |
45 //BGO_ENABLE_DICOMSTRUCTURESETLOADER2 | |
46 | |
37 #include "../Volumes/DicomVolumeImage.h" | 47 #include "../Volumes/DicomVolumeImage.h" |
38 #include "../Volumes/DicomVolumeImageMPRSlicer.h" | 48 #include "../Volumes/DicomVolumeImageMPRSlicer.h" |
49 | |
50 #ifdef BGO_ENABLE_DICOMSTRUCTURESETLOADER2 | |
39 #include "../Volumes/DicomStructureSetSlicer2.h" | 51 #include "../Volumes/DicomStructureSetSlicer2.h" |
52 #endif | |
53 //BGO_ENABLE_DICOMSTRUCTURESETLOADER2 | |
40 | 54 |
41 #include <Core/OrthancException.h> | 55 #include <Core/OrthancException.h> |
42 #include <Core/Toolbox.h> | 56 #include <Core/Toolbox.h> |
43 | 57 |
44 namespace OrthancStone | 58 namespace OrthancStone |
185 LOG(ERROR) << "Unknown exception in LoaderCache"; | 199 LOG(ERROR) << "Unknown exception in LoaderCache"; |
186 throw; | 200 throw; |
187 } | 201 } |
188 } | 202 } |
189 | 203 |
204 #ifdef BGO_ENABLE_DICOMSTRUCTURESETLOADER2 | |
205 | |
190 boost::shared_ptr<DicomStructureSetSlicer2> LoaderCache::GetDicomStructureSetSlicer2(std::string instanceUuid) | 206 boost::shared_ptr<DicomStructureSetSlicer2> LoaderCache::GetDicomStructureSetSlicer2(std::string instanceUuid) |
191 { | 207 { |
192 // if the loader is not available, let's trigger its creation | 208 // if the loader is not available, let's trigger its creation |
193 if (dicomStructureSetSlicers2_.find(instanceUuid) == dicomStructureSetSlicers2_.end()) | 209 if (dicomStructureSetSlicers2_.find(instanceUuid) == dicomStructureSetSlicers2_.end()) |
194 { | 210 { |
196 } | 212 } |
197 ORTHANC_ASSERT(dicomStructureSetSlicers2_.find(instanceUuid) != dicomStructureSetSlicers2_.end()); | 213 ORTHANC_ASSERT(dicomStructureSetSlicers2_.find(instanceUuid) != dicomStructureSetSlicers2_.end()); |
198 | 214 |
199 return dicomStructureSetSlicers2_[instanceUuid]; | 215 return dicomStructureSetSlicers2_[instanceUuid]; |
200 } | 216 } |
201 | 217 #endif |
202 boost::shared_ptr<DicomStructureSetLoader> LoaderCache::GetDicomStructureSetLoader(std::string instanceUuid) | 218 //BGO_ENABLE_DICOMSTRUCTURESETLOADER2 |
219 | |
220 | |
221 /** | |
222 This method allows to convert a list of string into a string by | |
223 sorting the strings then joining them | |
224 */ | |
225 static std::string SortAndJoin(const std::vector<std::string>& stringList) | |
226 { | |
227 if (stringList.size() == 0) | |
228 { | |
229 return ""; | |
230 } | |
231 else | |
232 { | |
233 std::vector<std::string> sortedStringList = stringList; | |
234 std::sort(sortedStringList.begin(), sortedStringList.end()); | |
235 std::stringstream s; | |
236 s << sortedStringList[0]; | |
237 for (size_t i = 1; i < sortedStringList.size(); ++i) | |
238 { | |
239 s << "-" << sortedStringList[i]; | |
240 } | |
241 return s.str(); | |
242 } | |
243 } | |
244 | |
245 boost::shared_ptr<DicomStructureSetLoader> | |
246 LoaderCache::GetDicomStructureSetLoader( | |
247 std::string inInstanceUuid, | |
248 const std::vector<std::string>& initiallyVisibleStructures) | |
203 { | 249 { |
204 try | 250 try |
205 { | 251 { |
206 // normalize keys a little | 252 // normalize keys a little |
207 instanceUuid = Orthanc::Toolbox::StripSpaces(instanceUuid); | 253 inInstanceUuid = Orthanc::Toolbox::StripSpaces(inInstanceUuid); |
208 Orthanc::Toolbox::ToLowerCase(instanceUuid); | 254 Orthanc::Toolbox::ToLowerCase(inInstanceUuid); |
255 | |
256 std::string initiallyVisibleStructuresKey = | |
257 SortAndJoin(initiallyVisibleStructures); | |
258 | |
259 std::string entryKey = inInstanceUuid + "_" + initiallyVisibleStructuresKey; | |
209 | 260 |
210 // find in cache | 261 // find in cache |
211 if (dicomStructureSetLoaders_.find(instanceUuid) == dicomStructureSetLoaders_.end()) | 262 if (dicomStructureSetLoaders_.find(entryKey) == dicomStructureSetLoaders_.end()) |
212 { | 263 { |
213 boost::shared_ptr<DicomStructureSetLoader> loader; | 264 boost::shared_ptr<DicomStructureSetLoader> loader; |
214 | 265 |
215 { | 266 { |
216 #if ORTHANC_ENABLE_WASM == 1 | 267 #if ORTHANC_ENABLE_WASM == 1 |
217 loader.reset(new DicomStructureSetLoader(oracle_, oracle_)); | 268 loader.reset(new DicomStructureSetLoader(oracle_, oracle_)); |
218 #else | 269 #else |
219 LockingEmitter::WriterLock lock(lockingEmitter_); | 270 LockingEmitter::WriterLock lock(lockingEmitter_); |
220 loader.reset(new DicomStructureSetLoader(oracle_, lock.GetOracleObservable())); | 271 loader.reset(new DicomStructureSetLoader(oracle_, lock.GetOracleObservable())); |
221 #endif | 272 #endif |
222 loader->LoadInstance(instanceUuid); | 273 loader->LoadInstance(inInstanceUuid, initiallyVisibleStructures); |
223 } | 274 } |
224 dicomStructureSetLoaders_[instanceUuid] = loader; | 275 dicomStructureSetLoaders_[entryKey] = loader; |
225 } | 276 } |
226 return dicomStructureSetLoaders_[instanceUuid]; | 277 return dicomStructureSetLoaders_[entryKey]; |
227 } | 278 } |
228 catch (const Orthanc::OrthancException& e) | 279 catch (const Orthanc::OrthancException& e) |
229 { | 280 { |
230 if (e.HasDetails()) | 281 if (e.HasDetails()) |
231 { | 282 { |
247 LOG(ERROR) << "Unknown exception in LoaderCache"; | 298 LOG(ERROR) << "Unknown exception in LoaderCache"; |
248 throw; | 299 throw; |
249 } | 300 } |
250 } | 301 } |
251 | 302 |
303 #ifdef BGO_ENABLE_DICOMSTRUCTURESETLOADER2 | |
252 | 304 |
253 boost::shared_ptr<DicomStructureSetLoader2> LoaderCache::GetDicomStructureSetLoader2(std::string instanceUuid) | 305 boost::shared_ptr<DicomStructureSetLoader2> LoaderCache::GetDicomStructureSetLoader2(std::string instanceUuid) |
254 { | 306 { |
255 try | 307 try |
256 { | 308 { |
301 { | 353 { |
302 LOG(ERROR) << "Unknown exception in GetDicomStructureSetLoader2"; | 354 LOG(ERROR) << "Unknown exception in GetDicomStructureSetLoader2"; |
303 throw; | 355 throw; |
304 } | 356 } |
305 } | 357 } |
358 | |
359 #endif | |
360 // BGO_ENABLE_DICOMSTRUCTURESETLOADER2 | |
361 | |
306 | 362 |
307 void LoaderCache::ClearCache() | 363 void LoaderCache::ClearCache() |
308 { | 364 { |
309 #if ORTHANC_ENABLE_WASM != 1 | 365 #if ORTHANC_ENABLE_WASM != 1 |
310 LockingEmitter::WriterLock lock(lockingEmitter_); | 366 LockingEmitter::WriterLock lock(lockingEmitter_); |
317 seriesVolumeProgressiveLoaders_.clear(); | 373 seriesVolumeProgressiveLoaders_.clear(); |
318 multiframeVolumeLoaders_.clear(); | 374 multiframeVolumeLoaders_.clear(); |
319 dicomVolumeImageMPRSlicers_.clear(); | 375 dicomVolumeImageMPRSlicers_.clear(); |
320 dicomStructureSetLoaders_.clear(); | 376 dicomStructureSetLoaders_.clear(); |
321 | 377 |
378 #ifdef BGO_ENABLE_DICOMSTRUCTURESETLOADER2 | |
322 // order is important! | 379 // order is important! |
323 dicomStructureSetLoaders2_.clear(); | 380 dicomStructureSetLoaders2_.clear(); |
324 dicomStructureSetSlicers2_.clear(); | 381 dicomStructureSetSlicers2_.clear(); |
325 dicomStructureSets2_.clear(); | 382 dicomStructureSets2_.clear(); |
383 #endif | |
384 // BGO_ENABLE_DICOMSTRUCTURESETLOADER2 | |
326 } | 385 } |
327 | 386 |
328 template<typename T> void DebugDisplayObjRefCountsInMap( | 387 template<typename T> void DebugDisplayObjRefCountsInMap( |
329 const std::string& name, const std::map<std::string, boost::shared_ptr<T> >& myMap) | 388 const std::string& name, const std::map<std::string, boost::shared_ptr<T> >& myMap) |
330 { | 389 { |
342 { | 401 { |
343 DebugDisplayObjRefCountsInMap("seriesVolumeProgressiveLoaders_", seriesVolumeProgressiveLoaders_); | 402 DebugDisplayObjRefCountsInMap("seriesVolumeProgressiveLoaders_", seriesVolumeProgressiveLoaders_); |
344 DebugDisplayObjRefCountsInMap("multiframeVolumeLoaders_", multiframeVolumeLoaders_); | 403 DebugDisplayObjRefCountsInMap("multiframeVolumeLoaders_", multiframeVolumeLoaders_); |
345 DebugDisplayObjRefCountsInMap("dicomVolumeImageMPRSlicers_", dicomVolumeImageMPRSlicers_); | 404 DebugDisplayObjRefCountsInMap("dicomVolumeImageMPRSlicers_", dicomVolumeImageMPRSlicers_); |
346 DebugDisplayObjRefCountsInMap("dicomStructureSetLoaders_", dicomStructureSetLoaders_); | 405 DebugDisplayObjRefCountsInMap("dicomStructureSetLoaders_", dicomStructureSetLoaders_); |
406 #ifdef BGO_ENABLE_DICOMSTRUCTURESETLOADER2 | |
347 DebugDisplayObjRefCountsInMap("dicomStructureSetLoaders2_", dicomStructureSetLoaders2_); | 407 DebugDisplayObjRefCountsInMap("dicomStructureSetLoaders2_", dicomStructureSetLoaders2_); |
348 DebugDisplayObjRefCountsInMap("dicomStructureSetSlicers2_", dicomStructureSetSlicers2_); | 408 DebugDisplayObjRefCountsInMap("dicomStructureSetSlicers2_", dicomStructureSetSlicers2_); |
409 #endif | |
410 //BGO_ENABLE_DICOMSTRUCTURESETLOADER2 | |
349 } | 411 } |
350 } | 412 } |