Mercurial > hg > orthanc
comparison Core/DicomParsing/IDicomTranscoder.cpp @ 3944:aae045f802f4 transcoding
preparing simplified interface for IDicomTranscoder
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 19 May 2020 10:17:06 +0200 |
parents | 7610af1532c3 |
children | 0b3256c3ee14 |
comparison
equal
deleted
inserted
replaced
3943:b26d25d3c1c7 | 3944:aae045f802f4 |
---|---|
33 | 33 |
34 #include "../PrecompiledHeaders.h" | 34 #include "../PrecompiledHeaders.h" |
35 #include "IDicomTranscoder.h" | 35 #include "IDicomTranscoder.h" |
36 | 36 |
37 #include "../OrthancException.h" | 37 #include "../OrthancException.h" |
38 #include "FromDcmtkBridge.h" | |
39 #include "ParsedDicomFile.h" | |
38 | 40 |
39 #include <dcmtk/dcmdata/dcfilefo.h> | 41 #include <dcmtk/dcmdata/dcfilefo.h> |
40 | 42 |
41 namespace Orthanc | 43 namespace Orthanc |
42 { | 44 { |
45 void IDicomTranscoder::DicomImage::Parse() | |
46 { | |
47 if (parsed_.get() != NULL || | |
48 buffer_.get() == NULL) | |
49 { | |
50 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
51 } | |
52 else | |
53 { | |
54 parsed_.reset(FromDcmtkBridge::LoadFromMemoryBuffer( | |
55 buffer_->empty() ? NULL : buffer_->c_str(), buffer_->size())); | |
56 | |
57 if (parsed_.get() == NULL) | |
58 { | |
59 throw OrthancException(ErrorCode_BadFileFormat); | |
60 } | |
61 } | |
62 } | |
63 | |
64 | |
65 void IDicomTranscoder::DicomImage::Serialize() | |
66 { | |
67 if (parsed_.get() == NULL || | |
68 buffer_.get() != NULL) | |
69 { | |
70 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
71 } | |
72 else if (parsed_->getDataset() == NULL) | |
73 { | |
74 throw OrthancException(ErrorCode_InternalError); | |
75 } | |
76 else | |
77 { | |
78 buffer_.reset(new std::string); | |
79 FromDcmtkBridge::SaveToMemoryBuffer(*buffer_, *parsed_->getDataset()); | |
80 } | |
81 } | |
82 | |
83 | |
84 void IDicomTranscoder::DicomImage::Clear() | |
85 { | |
86 parsed_.reset(NULL); | |
87 buffer_.reset(NULL); | |
88 } | |
89 | |
90 | |
91 void IDicomTranscoder::DicomImage::AcquireParsed(ParsedDicomFile& parsed) | |
92 { | |
93 AcquireParsed(parsed.ReleaseDcmtkObject()); | |
94 } | |
95 | |
96 | |
97 void IDicomTranscoder::DicomImage::AcquireParsed(DcmFileFormat* parsed) | |
98 { | |
99 if (parsed == NULL) | |
100 { | |
101 throw OrthancException(ErrorCode_NullPointer); | |
102 } | |
103 else if (parsed_.get() != NULL) | |
104 { | |
105 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
106 } | |
107 else if (parsed->getDataset() == NULL) | |
108 { | |
109 throw OrthancException(ErrorCode_InternalError); | |
110 } | |
111 else | |
112 { | |
113 parsed_.reset(parsed); | |
114 } | |
115 } | |
116 | |
117 | |
118 void IDicomTranscoder::DicomImage::AcquireParsed(DicomImage& other) | |
119 { | |
120 AcquireParsed(other.ReleaseParsed()); | |
121 } | |
122 | |
123 | |
124 void IDicomTranscoder::DicomImage::AcquireBuffer(std::string& buffer /* will be swapped */) | |
125 { | |
126 if (buffer_.get() != NULL) | |
127 { | |
128 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
129 } | |
130 else | |
131 { | |
132 buffer_.reset(new std::string); | |
133 buffer_->swap(buffer); | |
134 } | |
135 } | |
136 | |
137 | |
138 void IDicomTranscoder::DicomImage::AcquireBuffer(DicomImage& other) | |
139 { | |
140 if (buffer_.get() != NULL) | |
141 { | |
142 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
143 } | |
144 else if (other.buffer_.get() == NULL) | |
145 { | |
146 buffer_.reset(NULL); | |
147 } | |
148 else | |
149 { | |
150 buffer_.reset(other.buffer_.release()); | |
151 } | |
152 } | |
153 | |
154 | |
155 DcmFileFormat& IDicomTranscoder::DicomImage::GetParsed() | |
156 { | |
157 if (parsed_.get() != NULL) | |
158 { | |
159 return *parsed_; | |
160 } | |
161 else if (buffer_.get() != NULL) | |
162 { | |
163 Parse(); | |
164 return *parsed_; | |
165 } | |
166 else | |
167 { | |
168 throw OrthancException(ErrorCode_BadSequenceOfCalls, | |
169 "AcquireParsed() or AcquireBuffer() should have been called"); | |
170 } | |
171 } | |
172 | |
173 | |
174 DcmFileFormat* IDicomTranscoder::DicomImage::ReleaseParsed() | |
175 { | |
176 if (parsed_.get() != NULL) | |
177 { | |
178 buffer_.reset(NULL); | |
179 return parsed_.release(); | |
180 } | |
181 else if (buffer_.get() != NULL) | |
182 { | |
183 Parse(); | |
184 buffer_.reset(NULL); | |
185 return parsed_.release(); | |
186 } | |
187 else | |
188 { | |
189 throw OrthancException(ErrorCode_BadSequenceOfCalls, | |
190 "AcquireParsed() or AcquireBuffer() should have been called"); | |
191 } | |
192 } | |
193 | |
194 | |
195 const void* IDicomTranscoder::DicomImage::GetBufferData() | |
196 { | |
197 if (buffer_.get() == NULL) | |
198 { | |
199 Serialize(); | |
200 } | |
201 | |
202 assert(buffer_.get() != NULL); | |
203 return buffer_->empty() ? NULL : buffer_->c_str(); | |
204 } | |
205 | |
206 | |
207 size_t IDicomTranscoder::DicomImage::GetBufferSize() | |
208 { | |
209 if (buffer_.get() == NULL) | |
210 { | |
211 Serialize(); | |
212 } | |
213 | |
214 assert(buffer_.get() != NULL); | |
215 return buffer_->size(); | |
216 } | |
217 | |
218 | |
43 IDicomTranscoder::TranscodedDicom::TranscodedDicom(bool hasSopInstanceUidChanged) : | 219 IDicomTranscoder::TranscodedDicom::TranscodedDicom(bool hasSopInstanceUidChanged) : |
44 external_(NULL), | 220 external_(NULL), |
45 hasSopInstanceUidChanged_(hasSopInstanceUidChanged) | 221 hasSopInstanceUidChanged_(hasSopInstanceUidChanged) |
46 { | 222 { |
47 } | 223 } |