annotate ViewerPlugin/DicomPyramidCache.cpp @ 237:c2863f5204a8

fix build because of update in Orthanc framework
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 05 May 2021 14:34:07 +0200
parents 1e864138f0da
children 49f647ed1b4c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
73
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
214
1e864138f0da upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium
73
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "../Framework/PrecompiledHeadersWSI.h"
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "DicomPyramidCache.h"
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
199
a1c265cb2174 replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 196
diff changeset
25 #include <Compatibility.h> // For std::unique_ptr
a1c265cb2174 replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 196
diff changeset
26
73
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include <cassert>
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 namespace OrthancWSI
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 DicomPyramid* DicomPyramidCache::GetCachedPyramid(const std::string& seriesId)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 // Mutex is assumed to be locked
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 DicomPyramid* pyramid = NULL;
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 // Is the series of interest already cached as a pyramid?
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 if (cache_.Contains(seriesId, pyramid))
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 if (pyramid == NULL)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 // Tag the series as the most recently used
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 cache_.MakeMostRecent(seriesId);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 return pyramid;
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 DicomPyramid& DicomPyramidCache::GetPyramid(const std::string& seriesId,
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 boost::mutex::scoped_lock& lock)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 // Mutex is assumed to be locked
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 DicomPyramid* pyramid = GetCachedPyramid(seriesId);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 if (pyramid != NULL)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 return *pyramid;
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 // Unlock the mutex to construct the pyramid (this is a
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 // time-consuming operation, we don't want it to block other clients)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 lock.unlock();
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
199
a1c265cb2174 replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 196
diff changeset
69 std::unique_ptr<DicomPyramid> pyramid
73
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 (new DicomPyramid(orthanc_, seriesId, true /* use metadata cache */));
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 // The pyramid is constructed: Store it into the cache
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 lock.lock();
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 DicomPyramid* cached = GetCachedPyramid(seriesId);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 if (cached != NULL)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 // The pyramid was already constructed by another request in
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 // between, reuse the cached value (the auto_ptr destroys
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 // the just-constructed pyramid)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 return *cached;
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 if (cache_.GetSize() == maxSize_)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 // The cache has grown too large: First delete the least
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 // recently used entry
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 DicomPyramid* oldest = NULL;
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 cache_.RemoveOldest(oldest);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 if (oldest == NULL)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 else
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 delete oldest;
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 // Now we have at least one free entry in the cache
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 assert(cache_.GetSize() < maxSize_);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 // Add a new element to the cache and make it the most
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 // recently used entry
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 DicomPyramid* payload = pyramid.release();
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 cache_.Add(seriesId, payload);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 return *payload;
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
196
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
114 DicomPyramidCache::DicomPyramidCache(OrthancStone::IOrthancConnection& orthanc,
73
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 size_t maxSize) :
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 orthanc_(orthanc),
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 maxSize_(maxSize)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 DicomPyramidCache::~DicomPyramidCache()
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 while (!cache_.IsEmpty())
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 DicomPyramid* pyramid = NULL;
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 std::string seriesId = cache_.RemoveOldest(pyramid);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 if (pyramid != NULL)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 delete pyramid;
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 void DicomPyramidCache::Invalidate(const std::string& seriesId)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 boost::mutex::scoped_lock lock(mutex_);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 if (cache_.Contains(seriesId))
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 {
199
a1c265cb2174 replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 196
diff changeset
143 std::unique_ptr<DicomPyramid> pyramid(cache_.Invalidate(seriesId));
73
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 if (pyramid.get() == NULL)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 DicomPyramidCache::Locker::Locker(DicomPyramidCache& cache,
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 const std::string& seriesId) :
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 lock_(cache.mutex_),
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 pyramid_(cache.GetPyramid(seriesId, lock_))
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 }