comparison Framework/Loaders/LoaderCache.cpp @ 1343:e92c516adcbd broker

Dead code removal
author Benjamin Golinvaux <bgo@osimis.io>
date Mon, 06 Apr 2020 08:43:03 +0200
parents 556b4bc19118
children f4a06ad1580b
comparison
equal deleted inserted replaced
1342:13573ff63eb6 1343:e92c516adcbd
25 #include "OrthancMultiframeVolumeLoader.h" 25 #include "OrthancMultiframeVolumeLoader.h"
26 #include "DicomStructureSetLoader.h" 26 #include "DicomStructureSetLoader.h"
27 27
28 #include "../Loaders/ILoadersContext.h" 28 #include "../Loaders/ILoadersContext.h"
29 29
30
31 #ifdef BGO_ENABLE_DICOMSTRUCTURESETLOADER2
32 #include "DicomStructureSetLoader2.h"
33 #endif
34 //BGO_ENABLE_DICOMSTRUCTURESETLOADER2
35
36
37 #if ORTHANC_ENABLE_WASM == 1 30 #if ORTHANC_ENABLE_WASM == 1
38 # include <unistd.h> 31 # include <unistd.h>
39 # include "../Oracle/WebAssemblyOracle.h" 32 # include "../Oracle/WebAssemblyOracle.h"
40 #else 33 #else
41 # include "../Oracle/ThreadedOracle.h" 34 # include "../Oracle/ThreadedOracle.h"
42 #endif 35 #endif
43 36
44 #ifdef BGO_ENABLE_DICOMSTRUCTURESETLOADER2
45 #include "../../Toolbox/DicomStructureSet2.h"
46 #endif
47 //BGO_ENABLE_DICOMSTRUCTURESETLOADER2
48
49 #include "../Volumes/DicomVolumeImage.h" 37 #include "../Volumes/DicomVolumeImage.h"
50 #include "../Volumes/DicomVolumeImageMPRSlicer.h" 38 #include "../Volumes/DicomVolumeImageMPRSlicer.h"
51
52 #ifdef BGO_ENABLE_DICOMSTRUCTURESETLOADER2
53 #include "../../Volumes/DicomStructureSetSlicer2.h"
54 #endif
55 //BGO_ENABLE_DICOMSTRUCTURESETLOADER2
56 39
57 #include <Core/OrthancException.h> 40 #include <Core/OrthancException.h>
58 #include <Core/Toolbox.h> 41 #include <Core/Toolbox.h>
59 42
60 namespace OrthancStone 43 namespace OrthancStone
177 LOG(ERROR) << "Unknown exception in LoaderCache"; 160 LOG(ERROR) << "Unknown exception in LoaderCache";
178 throw; 161 throw;
179 } 162 }
180 } 163 }
181 164
182 #ifdef BGO_ENABLE_DICOMSTRUCTURESETLOADER2
183
184 boost::shared_ptr<DicomStructureSetSlicer2> LoaderCache::GetDicomStructureSetSlicer2(std::string instanceUuid)
185 {
186 // if the loader is not available, let's trigger its creation
187 if (dicomStructureSetSlicers2_.find(instanceUuid) == dicomStructureSetSlicers2_.end())
188 {
189 GetDicomStructureSetLoader2(instanceUuid);
190 }
191 ORTHANC_ASSERT(dicomStructureSetSlicers2_.find(instanceUuid) != dicomStructureSetSlicers2_.end());
192
193 return dicomStructureSetSlicers2_[instanceUuid];
194 }
195 #endif
196 //BGO_ENABLE_DICOMSTRUCTURESETLOADER2
197
198
199 /** 165 /**
200 This method allows to convert a list of string into a string by 166 This method allows to convert a list of string into a string by
201 sorting the strings then joining them 167 sorting the strings then joining them
202 */ 168 */
203 static std::string SortAndJoin(const std::vector<std::string>& stringList) 169 static std::string SortAndJoin(const std::vector<std::string>& stringList)
271 { 237 {
272 LOG(ERROR) << "Unknown exception in LoaderCache"; 238 LOG(ERROR) << "Unknown exception in LoaderCache";
273 throw; 239 throw;
274 } 240 }
275 } 241 }
276
277 #ifdef BGO_ENABLE_DICOMSTRUCTURESETLOADER2
278
279 boost::shared_ptr<DicomStructureSetLoader2> LoaderCache::GetDicomStructureSetLoader2(std::string instanceUuid)
280 {
281 try
282 {
283 // normalize keys a little
284 instanceUuid = Orthanc::Toolbox::StripSpaces(instanceUuid);
285 Orthanc::Toolbox::ToLowerCase(instanceUuid);
286
287 // find in cache
288 if (dicomStructureSetLoaders2_.find(instanceUuid) == dicomStructureSetLoaders2_.end())
289 {
290 boost::shared_ptr<DicomStructureSetLoader2> loader;
291 boost::shared_ptr<DicomStructureSet2> structureSet(new DicomStructureSet2());
292 boost::shared_ptr<DicomStructureSetSlicer2> rtSlicer(new DicomStructureSetSlicer2(structureSet));
293 dicomStructureSetSlicers2_[instanceUuid] = rtSlicer;
294 dicomStructureSets2_[instanceUuid] = structureSet; // to prevent it from being deleted
295 {
296 #if ORTHANC_ENABLE_WASM == 1
297 loader.reset(new DicomStructureSetLoader2(*(structureSet.get()), oracle_, oracle_));
298 #else
299 LockingEmitter::WriterLock lock(lockingEmitter_);
300 // TODO: clarify lifetimes... this is DANGEROUS!
301 loader.reset(new DicomStructureSetLoader2(*(structureSet.get()), oracle_, lock.GetOracleObservable()));
302 #endif
303 loader->LoadInstance(instanceUuid);
304 }
305 dicomStructureSetLoaders2_[instanceUuid] = loader;
306 }
307 return dicomStructureSetLoaders2_[instanceUuid];
308 }
309 catch (const Orthanc::OrthancException& e)
310 {
311 if (e.HasDetails())
312 {
313 LOG(ERROR) << "OrthancException in GetDicomStructureSetLoader2: " << e.What() << " Details: " << e.GetDetails();
314 }
315 else
316 {
317 LOG(ERROR) << "OrthancException in GetDicomStructureSetLoader2: " << e.What();
318 }
319 throw;
320 }
321 catch (const std::exception& e)
322 {
323 LOG(ERROR) << "std::exception in GetDicomStructureSetLoader2: " << e.what();
324 throw;
325 }
326 catch (...)
327 {
328 LOG(ERROR) << "Unknown exception in GetDicomStructureSetLoader2";
329 throw;
330 }
331 }
332
333 #endif
334 // BGO_ENABLE_DICOMSTRUCTURESETLOADER2
335
336 242
337 void LoaderCache::ClearCache() 243 void LoaderCache::ClearCache()
338 { 244 {
339 std::unique_ptr<OrthancStone::ILoadersContext::ILock> lock(loadersContext_.Lock()); 245 std::unique_ptr<OrthancStone::ILoadersContext::ILock> lock(loadersContext_.Lock());
340 246
345 seriesVolumeProgressiveLoaders_.clear(); 251 seriesVolumeProgressiveLoaders_.clear();
346 multiframeVolumeLoaders_.clear(); 252 multiframeVolumeLoaders_.clear();
347 dicomVolumeImageMPRSlicers_.clear(); 253 dicomVolumeImageMPRSlicers_.clear();
348 dicomStructureSetLoaders_.clear(); 254 dicomStructureSetLoaders_.clear();
349 255
350 #ifdef BGO_ENABLE_DICOMSTRUCTURESETLOADER2
351 // order is important!
352 dicomStructureSetLoaders2_.clear();
353 dicomStructureSetSlicers2_.clear();
354 dicomStructureSets2_.clear();
355 #endif
356 // BGO_ENABLE_DICOMSTRUCTURESETLOADER2
357 } 256 }
358 257
359 template<typename T> void DebugDisplayObjRefCountsInMap( 258 template<typename T> void DebugDisplayObjRefCountsInMap(
360 const std::string& name, const std::map<std::string, boost::shared_ptr<T> >& myMap) 259 const std::string& name, const std::map<std::string, boost::shared_ptr<T> >& myMap)
361 { 260 {
373 { 272 {
374 DebugDisplayObjRefCountsInMap("seriesVolumeProgressiveLoaders_", seriesVolumeProgressiveLoaders_); 273 DebugDisplayObjRefCountsInMap("seriesVolumeProgressiveLoaders_", seriesVolumeProgressiveLoaders_);
375 DebugDisplayObjRefCountsInMap("multiframeVolumeLoaders_", multiframeVolumeLoaders_); 274 DebugDisplayObjRefCountsInMap("multiframeVolumeLoaders_", multiframeVolumeLoaders_);
376 DebugDisplayObjRefCountsInMap("dicomVolumeImageMPRSlicers_", dicomVolumeImageMPRSlicers_); 275 DebugDisplayObjRefCountsInMap("dicomVolumeImageMPRSlicers_", dicomVolumeImageMPRSlicers_);
377 DebugDisplayObjRefCountsInMap("dicomStructureSetLoaders_", dicomStructureSetLoaders_); 276 DebugDisplayObjRefCountsInMap("dicomStructureSetLoaders_", dicomStructureSetLoaders_);
378 #ifdef BGO_ENABLE_DICOMSTRUCTURESETLOADER2
379 DebugDisplayObjRefCountsInMap("dicomStructureSetLoaders2_", dicomStructureSetLoaders2_);
380 DebugDisplayObjRefCountsInMap("dicomStructureSetSlicers2_", dicomStructureSetSlicers2_);
381 #endif
382 //BGO_ENABLE_DICOMSTRUCTURESETLOADER2
383 } 277 }
384 } 278 }