Mercurial > hg > orthanc
annotate Plugins/Samples/GdcmDecoder/GdcmDecoderCache.cpp @ 1849:6394a2f8f1e1
test main dicom tags at series level
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 01 Dec 2015 13:41:48 +0100 |
parents | 859224214616 |
children | b1291df2f780 |
rev | line source |
---|---|
1834 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, but | |
12 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 **/ | |
19 | |
20 | |
21 #include "GdcmDecoderCache.h" | |
22 | |
23 #include "OrthancImageWrapper.h" | |
24 | |
25 namespace OrthancPlugins | |
26 { | |
27 std::string GdcmDecoderCache::ComputeMd5(OrthancPluginContext* context, | |
28 const void* dicom, | |
29 size_t size) | |
30 { | |
31 std::string result; | |
32 | |
33 char* md5 = OrthancPluginComputeMd5(context, dicom, size); | |
34 | |
35 if (md5 == NULL) | |
36 { | |
37 throw std::runtime_error("Cannot compute MD5 hash"); | |
38 } | |
39 | |
40 bool ok = false; | |
41 try | |
42 { | |
43 result.assign(md5); | |
44 ok = true; | |
45 } | |
46 catch (...) | |
47 { | |
48 } | |
49 | |
50 OrthancPluginFreeString(context, md5); | |
51 | |
52 if (!ok) | |
53 { | |
54 throw std::runtime_error("Not enough memory"); | |
55 } | |
56 else | |
57 { | |
58 return result; | |
59 } | |
60 } | |
61 | |
62 | |
1837 | 63 OrthancImageWrapper* GdcmDecoderCache::Decode(OrthancPluginContext* context, |
64 const void* dicom, | |
65 const uint32_t size, | |
66 uint32_t frameIndex) | |
1834 | 67 { |
68 std::string md5 = ComputeMd5(context, dicom, size); | |
69 | |
70 // First check whether the previously decoded image is the same | |
71 // as this one | |
72 { | |
73 boost::mutex::scoped_lock lock(mutex_); | |
74 | |
75 if (decoder_.get() != NULL && | |
76 size_ == size && | |
77 md5_ == md5) | |
78 { | |
79 // This is the same image: Reuse the previous decoding | |
1840
859224214616
simplification of the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1837
diff
changeset
|
80 return new OrthancImageWrapper(context, decoder_->Decode(context, frameIndex)); |
1834 | 81 } |
82 } | |
83 | |
84 // This is not the same image | |
85 std::auto_ptr<GdcmImageDecoder> decoder(new GdcmImageDecoder(dicom, size)); | |
1840
859224214616
simplification of the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1837
diff
changeset
|
86 std::auto_ptr<OrthancImageWrapper> image(new OrthancImageWrapper(context, decoder->Decode(context, frameIndex))); |
1834 | 87 |
88 { | |
89 // Cache the newly created decoder for further use | |
90 boost::mutex::scoped_lock lock(mutex_); | |
91 decoder_ = decoder; | |
92 size_ = size; | |
93 md5_ = md5; | |
94 } | |
95 | |
1837 | 96 return image.release(); |
1834 | 97 } |
98 } |