annotate OrthancFramework/Sources/DicomParsing/ParsedDicomCache.cpp @ 5649:4a2bfda999c6

todo
author Alain Mazy <am@orthanc.team>
date Mon, 03 Jun 2024 14:30:30 +0200
parents f7adfb22e20e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
5640
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
5485
48b8dae6dc77 upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
4456
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 *
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * This program is free software: you can redistribute it and/or
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * 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
11 * as published by the Free Software Foundation, either version 3 of
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * the License, or (at your option) any later version.
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 *
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * 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
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * Lesser General Public License for more details.
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 *
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * 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
20 * License along with this program. If not, see
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * <http://www.gnu.org/licenses/>.
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
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "../PrecompiledHeaders.h"
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "ParsedDicomCache.h"
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include "../OrthancException.h"
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 namespace Orthanc
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 class ParsedDicomCache::Item : public ICacheable
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 private:
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 std::unique_ptr<ParsedDicomFile> dicom_;
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 size_t fileSize_;
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 public:
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 Item(ParsedDicomFile* dicom,
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 size_t fileSize) :
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 dicom_(dicom),
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 fileSize_(fileSize)
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 if (dicom == NULL)
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 throw OrthancException(ErrorCode_NullPointer);
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
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 virtual size_t GetMemoryUsage() const ORTHANC_OVERRIDE
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 return fileSize_;
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
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 ParsedDicomFile& GetDicom() const
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 assert(dicom_.get() != NULL);
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 return *dicom_;
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
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 ParsedDicomCache::ParsedDicomCache(size_t size) :
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 cacheSize_(size),
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 largeSize_(0)
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 if (size == 0)
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 throw OrthancException(ErrorCode_ParameterOutOfRange);
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
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
4457
789676a8c96a Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4456
diff changeset
74 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
75 {
4458
e4dae17035b9 fix ParsedDicomCache for emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
76 #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
77 boost::mutex::scoped_lock lock(mutex_);
4458
e4dae17035b9 fix ParsedDicomCache for emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
78 #endif
4457
789676a8c96a Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4456
diff changeset
79
789676a8c96a Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4456
diff changeset
80 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
81 {
789676a8c96a Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4456
diff changeset
82 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
83 }
789676a8c96a Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4456
diff changeset
84 else
789676a8c96a Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4456
diff changeset
85 {
789676a8c96a Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4456
diff changeset
86 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
87 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
88 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
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
789676a8c96a Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4456
diff changeset
93 size_t ParsedDicomCache::GetCurrentSize()
4456
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 {
4458
e4dae17035b9 fix ParsedDicomCache for emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
95 #if !defined(__EMSCRIPTEN__)
4456
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 boost::mutex::scoped_lock lock(mutex_);
4458
e4dae17035b9 fix ParsedDicomCache for emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
97 #endif
4456
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 if (cache_.get() == NULL)
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 return largeSize_;
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 }
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 else
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 {
4457
789676a8c96a Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4456
diff changeset
105 assert(largeDicom_.get() == NULL);
4456
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 assert(largeSize_ == 0);
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 return cache_->GetCurrentSize();
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
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 void ParsedDicomCache::Invalidate(const std::string& id)
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 {
4458
e4dae17035b9 fix ParsedDicomCache for emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
114 #if !defined(__EMSCRIPTEN__)
4456
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 boost::mutex::scoped_lock lock(mutex_);
4458
e4dae17035b9 fix ParsedDicomCache for emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
116 #endif
4456
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 if (cache_.get() != NULL)
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 cache_->Invalidate(id);
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
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 if (largeId_ == id)
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 largeDicom_.reset(NULL);
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 largeSize_ = 0;
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
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 void ParsedDicomCache::Acquire(const std::string& id,
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 ParsedDicomFile* dicom, // Takes ownership
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 size_t fileSize)
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 {
4458
e4dae17035b9 fix ParsedDicomCache for emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
135 #if !defined(__EMSCRIPTEN__)
4456
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 boost::mutex::scoped_lock lock(mutex_);
4458
e4dae17035b9 fix ParsedDicomCache for emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
137 #endif
4456
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 if (fileSize >= cacheSize_)
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 cache_.reset(NULL);
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 largeDicom_.reset(dicom);
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 largeId_ = id;
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 largeSize_ = fileSize;
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 }
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 else
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 largeDicom_.reset(NULL);
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 largeSize_ = 0;
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 if (cache_.get() == NULL)
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 cache_.reset(new MemoryObjectCache);
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 cache_->SetMaximumSize(cacheSize_);
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
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 cache_->Acquire(id, new Item(dicom, fileSize));
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
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 ParsedDicomCache::Accessor::Accessor(ParsedDicomCache& that,
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 const std::string& id) :
4458
e4dae17035b9 fix ParsedDicomCache for emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
164 #if !defined(__EMSCRIPTEN__)
4456
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 lock_(that.mutex_),
4458
e4dae17035b9 fix ParsedDicomCache for emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
166 #endif
4456
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 id_(id),
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 file_(NULL),
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 fileSize_(0)
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 if (that.largeDicom_.get() != NULL &&
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 that.largeId_ == id)
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 file_ = that.largeDicom_.get();
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 fileSize_ = that.largeSize_;
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 }
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 else if (that.cache_.get() != NULL)
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 accessor_.reset(new MemoryObjectCache::Accessor(
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 *that.cache_, id, true /* unique */));
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 if (accessor_->IsValid())
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 const Item& item = dynamic_cast<const Item&>(accessor_->GetValue());
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 file_ = &item.GetDicom();
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 fileSize_ = item.GetMemoryUsage();
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
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190
4495
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4458
diff changeset
191 bool ParsedDicomCache::Accessor::IsValid() const
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4458
diff changeset
192 {
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4458
diff changeset
193 return file_ != NULL;
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
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4458
diff changeset
196
4456
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 ParsedDicomFile& ParsedDicomCache::Accessor::GetDicom() const
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 if (IsValid())
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 assert(file_ != NULL);
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 return *file_;
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 }
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 else
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 throw OrthancException(ErrorCode_BadSequenceOfCalls);
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
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 size_t ParsedDicomCache::Accessor::GetFileSize() const
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 if (IsValid())
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 return fileSize_;
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 }
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 else
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 throw OrthancException(ErrorCode_BadSequenceOfCalls);
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 }
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 }