Mercurial > hg > orthanc
comparison OrthancServer/Sources/DicomInstanceToStore.cpp @ 4505:97d103b57cd1
removed cached dicom summary from DicomInstanceToStore
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 10 Feb 2021 12:07:03 +0100 |
parents | 7d1eabfac6e0 |
children | ac69c9f76c71 |
comparison
equal
deleted
inserted
replaced
4504:7d1eabfac6e0 | 4505:97d103b57cd1 |
---|---|
155 bool hasBuffer_; | 155 bool hasBuffer_; |
156 std::unique_ptr<std::string> ownBuffer_; | 156 std::unique_ptr<std::string> ownBuffer_; |
157 const void* bufferData_; | 157 const void* bufferData_; |
158 size_t bufferSize_; | 158 size_t bufferSize_; |
159 SmartContainer<ParsedDicomFile> parsed_; | 159 SmartContainer<ParsedDicomFile> parsed_; |
160 SmartContainer<DicomMap> summary_; | |
161 MetadataMap metadata_; | 160 MetadataMap metadata_; |
162 | 161 |
163 PImpl() : | 162 PImpl() : |
164 hasBuffer_(false), | 163 hasBuffer_(false), |
165 bufferData_(NULL), | 164 bufferData_(NULL), |
166 bufferSize_(0) | 165 bufferSize_(0) |
167 { | 166 { |
168 } | 167 } |
169 | 168 |
170 private: | 169 private: |
171 std::unique_ptr<DicomInstanceHasher> hasher_; | 170 void ComputeParsedDicomFileIfMissing() |
172 | |
173 void ParseDicomFile() | |
174 { | 171 { |
175 if (!parsed_.HasContent()) | 172 if (!parsed_.HasContent()) |
176 { | 173 { |
177 if (!hasBuffer_) | 174 if (!hasBuffer_) |
178 { | 175 { |
188 parsed_.TakeOwnership(new ParsedDicomFile(bufferData_, bufferSize_)); | 185 parsed_.TakeOwnership(new ParsedDicomFile(bufferData_, bufferSize_)); |
189 } | 186 } |
190 } | 187 } |
191 } | 188 } |
192 | 189 |
193 void ComputeMissingInformation() | 190 void ComputeDicomBufferIfMissing() |
194 { | 191 { |
195 if (hasBuffer_ && | |
196 summary_.HasContent()) | |
197 { | |
198 // Fine, everything is available | |
199 return; | |
200 } | |
201 | |
202 if (!hasBuffer_) | 192 if (!hasBuffer_) |
203 { | 193 { |
204 if (!parsed_.HasContent()) | 194 if (!parsed_.HasContent()) |
205 { | 195 { |
206 if (!summary_.HasContent()) | 196 throw OrthancException(ErrorCode_NotImplemented); |
207 { | |
208 throw OrthancException(ErrorCode_NotImplemented); | |
209 } | |
210 else | |
211 { | |
212 parsed_.TakeOwnership(new ParsedDicomFile(summary_.GetConstContent(), | |
213 GetDefaultDicomEncoding(), | |
214 false /* be strict */)); | |
215 } | |
216 } | 197 } |
217 | 198 |
218 // Serialize the parsed DICOM file | 199 // Serialize the parsed DICOM file |
219 ownBuffer_.reset(new std::string); | 200 ownBuffer_.reset(new std::string); |
220 if (!FromDcmtkBridge::SaveToMemoryBuffer(*ownBuffer_, | 201 if (!FromDcmtkBridge::SaveToMemoryBuffer(*ownBuffer_, |
224 "Unable to serialize a DICOM file to a memory buffer"); | 205 "Unable to serialize a DICOM file to a memory buffer"); |
225 } | 206 } |
226 | 207 |
227 hasBuffer_ = true; | 208 hasBuffer_ = true; |
228 } | 209 } |
229 | |
230 if (!summary_.HasContent()) | |
231 { | |
232 // At this point, we know that the DICOM file is available as a | |
233 // memory buffer, but that its summary or its JSON version is | |
234 // missing | |
235 | |
236 ParseDicomFile(); | |
237 assert(parsed_.HasContent()); | |
238 | |
239 // At this point, we have parsed the DICOM file | |
240 | |
241 summary_.Allocate(); | |
242 OrthancConfiguration::DefaultExtractDicomSummary(summary_.GetContent(), parsed_.GetContent()); | |
243 } | |
244 } | 210 } |
245 | 211 |
246 | 212 |
247 public: | 213 public: |
248 void SetBuffer(const void* data, | 214 void SetBuffer(const void* data, |
254 hasBuffer_ = true; | 220 hasBuffer_ = true; |
255 } | 221 } |
256 | 222 |
257 const void* GetBufferData() | 223 const void* GetBufferData() |
258 { | 224 { |
259 ComputeMissingInformation(); | 225 ComputeDicomBufferIfMissing(); |
260 | 226 |
261 if (!hasBuffer_) | 227 if (!hasBuffer_) |
262 { | 228 { |
263 throw OrthancException(ErrorCode_InternalError); | 229 throw OrthancException(ErrorCode_InternalError); |
264 } | 230 } |
281 } | 247 } |
282 | 248 |
283 | 249 |
284 size_t GetBufferSize() | 250 size_t GetBufferSize() |
285 { | 251 { |
286 ComputeMissingInformation(); | 252 ComputeDicomBufferIfMissing(); |
287 | 253 |
288 if (!hasBuffer_) | 254 if (!hasBuffer_) |
289 { | 255 { |
290 throw OrthancException(ErrorCode_InternalError); | 256 throw OrthancException(ErrorCode_InternalError); |
291 } | 257 } |
299 return bufferSize_; | 265 return bufferSize_; |
300 } | 266 } |
301 } | 267 } |
302 | 268 |
303 | 269 |
304 const DicomMap& GetSummary() | |
305 { | |
306 ComputeMissingInformation(); | |
307 | |
308 if (!summary_.HasContent()) | |
309 { | |
310 throw OrthancException(ErrorCode_InternalError); | |
311 } | |
312 | |
313 return summary_.GetConstContent(); | |
314 } | |
315 | |
316 | |
317 DicomInstanceHasher& GetHasher() | |
318 { | |
319 if (hasher_.get() == NULL) | |
320 { | |
321 hasher_.reset(new DicomInstanceHasher(GetSummary())); | |
322 } | |
323 | |
324 if (hasher_.get() == NULL) | |
325 { | |
326 throw OrthancException(ErrorCode_InternalError); | |
327 } | |
328 | |
329 return *hasher_; | |
330 } | |
331 | |
332 | |
333 bool LookupTransferSyntax(std::string& result) | 270 bool LookupTransferSyntax(std::string& result) |
334 { | 271 { |
335 ComputeMissingInformation(); | |
336 | |
337 DicomMap header; | 272 DicomMap header; |
338 if (DicomMap::ParseDicomMetaInformation(header, GetBufferData(), GetBufferSize())) | 273 if (DicomMap::ParseDicomMetaInformation(header, GetBufferData(), GetBufferSize())) |
339 { | 274 { |
340 const DicomValue* value = header.TestAndGetValue(DICOM_TAG_TRANSFER_SYNTAX_UID); | 275 const DicomValue* value = header.TestAndGetValue(DICOM_TAG_TRANSFER_SYNTAX_UID); |
341 if (value != NULL && | 276 if (value != NULL && |
363 } | 298 } |
364 | 299 |
365 | 300 |
366 ParsedDicomFile& GetParsedDicomFile() | 301 ParsedDicomFile& GetParsedDicomFile() |
367 { | 302 { |
368 ComputeMissingInformation(); | 303 ComputeParsedDicomFileIfMissing(); |
369 ParseDicomFile(); | |
370 | 304 |
371 if (parsed_.HasContent()) | 305 if (parsed_.HasContent()) |
372 { | 306 { |
373 return parsed_.GetContent(); | 307 return parsed_.GetContent(); |
374 } | 308 } |
409 { | 343 { |
410 pimpl_->parsed_.SetReference(parsed); | 344 pimpl_->parsed_.SetReference(parsed); |
411 } | 345 } |
412 | 346 |
413 | 347 |
414 void DicomInstanceToStore::SetSummary(const DicomMap& summary) | |
415 { | |
416 pimpl_->summary_.SetConstReference(summary); | |
417 } | |
418 | |
419 | |
420 const DicomInstanceToStore::MetadataMap& DicomInstanceToStore::GetMetadata() const | 348 const DicomInstanceToStore::MetadataMap& DicomInstanceToStore::GetMetadata() const |
421 { | 349 { |
422 return pimpl_->metadata_; | 350 return pimpl_->metadata_; |
423 } | 351 } |
424 | 352 |
447 { | 375 { |
448 return const_cast<PImpl&>(*pimpl_).GetBufferSize(); | 376 return const_cast<PImpl&>(*pimpl_).GetBufferSize(); |
449 } | 377 } |
450 | 378 |
451 | 379 |
452 const DicomMap& DicomInstanceToStore::GetSummary() | |
453 { | |
454 return pimpl_->GetSummary(); | |
455 } | |
456 | |
457 | |
458 bool DicomInstanceToStore::LookupTransferSyntax(std::string& result) const | 380 bool DicomInstanceToStore::LookupTransferSyntax(std::string& result) const |
459 { | 381 { |
460 return const_cast<PImpl&>(*pimpl_).LookupTransferSyntax(result); | 382 return const_cast<PImpl&>(*pimpl_).LookupTransferSyntax(result); |
461 } | 383 } |
462 | 384 |
463 | 385 |
464 DicomInstanceHasher& DicomInstanceToStore::GetHasher() | |
465 { | |
466 return pimpl_->GetHasher(); | |
467 } | |
468 | |
469 bool DicomInstanceToStore::HasPixelData() const | 386 bool DicomInstanceToStore::HasPixelData() const |
470 { | 387 { |
471 return const_cast<PImpl&>(*pimpl_).GetParsedDicomFile().HasTag(DICOM_TAG_PIXEL_DATA); | 388 return const_cast<PImpl&>(*pimpl_).GetParsedDicomFile().HasTag(DICOM_TAG_PIXEL_DATA); |
472 } | 389 } |
473 | 390 |