Mercurial > hg > orthanc
annotate OrthancFramework/Sources/DicomParsing/ParsedDicomCache.cpp @ 4844:55e8fb8e8028
tagging a pre-release of the Orthanc framework for WSI 1.1
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Dec 2021 14:01:17 +0100 |
parents | 7053502fbf97 |
children | 43e613a7756b |
rev | line source |
---|---|
4456
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
4831
7053502fbf97
added copyright UCLouvain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4495
diff
changeset
|
6 * Copyright (C) 2021-2021 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
4456
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * This program is free software: you can redistribute it and/or |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * as published by the Free Software Foundation, either version 3 of |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * the License, or (at your option) any later version. |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, but |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * Lesser General Public License for more details. |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * License along with this program. If not, see |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 **/ |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 #include "../PrecompiledHeaders.h" |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 #include "ParsedDicomCache.h" |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 #include "../OrthancException.h" |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 namespace Orthanc |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 class ParsedDicomCache::Item : public ICacheable |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 private: |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 std::unique_ptr<ParsedDicomFile> dicom_; |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 size_t fileSize_; |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 public: |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 Item(ParsedDicomFile* dicom, |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 size_t fileSize) : |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 dicom_(dicom), |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 fileSize_(fileSize) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 if (dicom == NULL) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 throw OrthancException(ErrorCode_NullPointer); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 virtual size_t GetMemoryUsage() const ORTHANC_OVERRIDE |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 return fileSize_; |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 ParsedDicomFile& GetDicom() const |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 assert(dicom_.get() != NULL); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 return *dicom_; |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 }; |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 ParsedDicomCache::ParsedDicomCache(size_t size) : |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 cacheSize_(size), |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 largeSize_(0) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 if (size == 0) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 throw OrthancException(ErrorCode_ParameterOutOfRange); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 |
4457
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
73 size_t ParsedDicomCache::GetNumberOfItems() |
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
74 { |
4458
e4dae17035b9
fix ParsedDicomCache for emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4457
diff
changeset
|
75 #if !defined(__EMSCRIPTEN__) |
4457
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
76 boost::mutex::scoped_lock lock(mutex_); |
4458
e4dae17035b9
fix ParsedDicomCache for emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4457
diff
changeset
|
77 #endif |
4457
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
78 |
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
79 if (cache_.get() == NULL) |
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
80 { |
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
81 return (largeDicom_.get() == NULL ? 0 : 1); |
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
82 } |
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
83 else |
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
84 { |
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
85 assert(largeDicom_.get() == NULL); |
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
86 assert(largeSize_ == 0); |
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
87 return cache_->GetNumberOfItems(); |
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
88 } |
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
89 } |
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
90 |
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
91 |
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
92 size_t ParsedDicomCache::GetCurrentSize() |
4456
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 { |
4458
e4dae17035b9
fix ParsedDicomCache for emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4457
diff
changeset
|
94 #if !defined(__EMSCRIPTEN__) |
4456
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 boost::mutex::scoped_lock lock(mutex_); |
4458
e4dae17035b9
fix ParsedDicomCache for emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4457
diff
changeset
|
96 #endif |
4456
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 if (cache_.get() == NULL) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 return largeSize_; |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 else |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 { |
4457
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
104 assert(largeDicom_.get() == NULL); |
4456
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 assert(largeSize_ == 0); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 return cache_->GetCurrentSize(); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 void ParsedDicomCache::Invalidate(const std::string& id) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 { |
4458
e4dae17035b9
fix ParsedDicomCache for emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4457
diff
changeset
|
113 #if !defined(__EMSCRIPTEN__) |
4456
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 boost::mutex::scoped_lock lock(mutex_); |
4458
e4dae17035b9
fix ParsedDicomCache for emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4457
diff
changeset
|
115 #endif |
4456
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 if (cache_.get() != NULL) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 cache_->Invalidate(id); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 if (largeId_ == id) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
123 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 largeDicom_.reset(NULL); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 largeSize_ = 0; |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
128 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 void ParsedDicomCache::Acquire(const std::string& id, |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 ParsedDicomFile* dicom, // Takes ownership |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 size_t fileSize) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 { |
4458
e4dae17035b9
fix ParsedDicomCache for emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4457
diff
changeset
|
134 #if !defined(__EMSCRIPTEN__) |
4456
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 boost::mutex::scoped_lock lock(mutex_); |
4458
e4dae17035b9
fix ParsedDicomCache for emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4457
diff
changeset
|
136 #endif |
4456
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 if (fileSize >= cacheSize_) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
140 cache_.reset(NULL); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
141 largeDicom_.reset(dicom); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
142 largeId_ = id; |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
143 largeSize_ = fileSize; |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
144 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
145 else |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
146 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
147 largeDicom_.reset(NULL); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
148 largeSize_ = 0; |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
150 if (cache_.get() == NULL) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
151 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
152 cache_.reset(new MemoryObjectCache); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 cache_->SetMaximumSize(cacheSize_); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 cache_->Acquire(id, new Item(dicom, fileSize)); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
159 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
160 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
161 ParsedDicomCache::Accessor::Accessor(ParsedDicomCache& that, |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
162 const std::string& id) : |
4458
e4dae17035b9
fix ParsedDicomCache for emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4457
diff
changeset
|
163 #if !defined(__EMSCRIPTEN__) |
4456
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
164 lock_(that.mutex_), |
4458
e4dae17035b9
fix ParsedDicomCache for emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4457
diff
changeset
|
165 #endif |
4456
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
166 id_(id), |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
167 file_(NULL), |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
168 fileSize_(0) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
169 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
170 if (that.largeDicom_.get() != NULL && |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
171 that.largeId_ == id) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
172 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
173 file_ = that.largeDicom_.get(); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
174 fileSize_ = that.largeSize_; |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
175 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
176 else if (that.cache_.get() != NULL) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
177 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
178 accessor_.reset(new MemoryObjectCache::Accessor( |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
179 *that.cache_, id, true /* unique */)); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
180 if (accessor_->IsValid()) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
181 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
182 const Item& item = dynamic_cast<const Item&>(accessor_->GetValue()); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
183 file_ = &item.GetDicom(); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
184 fileSize_ = item.GetMemoryUsage(); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
185 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
186 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
187 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
188 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
189 |
4495
fa2311f94d9f
IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4458
diff
changeset
|
190 bool ParsedDicomCache::Accessor::IsValid() const |
fa2311f94d9f
IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4458
diff
changeset
|
191 { |
fa2311f94d9f
IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4458
diff
changeset
|
192 return file_ != NULL; |
fa2311f94d9f
IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4458
diff
changeset
|
193 } |
fa2311f94d9f
IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4458
diff
changeset
|
194 |
fa2311f94d9f
IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4458
diff
changeset
|
195 |
4456
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
196 ParsedDicomFile& ParsedDicomCache::Accessor::GetDicom() const |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
197 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
198 if (IsValid()) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
199 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
200 assert(file_ != NULL); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
201 return *file_; |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
202 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
203 else |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
204 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
205 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
206 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
207 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
208 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
209 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
210 size_t ParsedDicomCache::Accessor::GetFileSize() const |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
211 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
212 if (IsValid()) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
213 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
214 return fileSize_; |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
215 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
216 else |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
217 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
218 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
219 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
220 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
221 } |