Medical Imaging Interaction Toolkit  2018.4.99-87d68d9f
Medical Imaging Interaction Toolkit
mitkDICOMGDCMTagCache.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "mitkDICOMGDCMTagCache.h"
14 #include "mitkDICOMEnums.h"
16 
18 {
19 }
20 
22 {
23 }
24 
26 {
27  assert( frame );
28 
29  for ( auto frameIter = m_ScanResult.cbegin(); frameIter != m_ScanResult.cend(); ++frameIter )
30  {
31  if ( **frameIter == *frame )
32  {
33  return (*frameIter)->GetTagValueAsString(tag);
34  }
35  }
36 
37  if ( m_ScannedTags.find( tag ) != m_ScannedTags.cend() )
38  {
39  if ( std::find( m_InputFilenames.cbegin(), m_InputFilenames.cend(), frame->Filename )
40  == m_InputFilenames.cend() )
41  {
42  // callers are required to tell us about the filenames they are interested in
43  // this is a helpful reminder for them to inform us
44  std::stringstream errorstring;
45  errorstring << "Invalid call to DICOMGDCMTagCache::GetTagValue( "
46  << "'" << frame->Filename << "', frame " << frame->FrameNo
47  << " ). Filename was never mentioned before!";
48  MITK_ERROR << errorstring.str();
49  throw std::invalid_argument( errorstring.str() );
50  }
51  }
52  else
53  {
54  // callers are required to tell us about the tags they are interested in
55  // this is a helpful reminder for them to inform us
56  std::stringstream errorstring;
57  errorstring << "Invalid call to DICOMGDCMTagCache::GetTagValue( ";
58  tag.Print( errorstring );
59  errorstring << " ). Tag was never mentioned before!";
60  MITK_ERROR << errorstring.str();
61  throw std::invalid_argument( errorstring.str() );
62  }
63 
64  return DICOMDatasetFinding();
65 }
66 
69 {
70  FindingsListType result;
71  if (path.Size() == 1 && path.IsExplicit())
72  {
73  result.push_back(this->GetTagValue(frame, path.GetFirstNode().tag));
74  }
75  return result;
76 }
77 
79 {
80  return m_ScanResult;
81 }
82 
83 void
84 mitk::DICOMGDCMTagCache::InitCache(const std::set<DICOMTag>& scannedTags, const std::shared_ptr<gdcm::Scanner>& scanner, const StringList& inputFiles)
85 {
86  m_ScannedTags = scannedTags;
87  m_InputFilenames = inputFiles;
88  m_Scanner = scanner;
89 
90  m_ScanResult.clear();
91  m_ScanResult.reserve(m_InputFilenames.size());
92 
93  for (auto inputIter = m_InputFilenames.cbegin(); inputIter != m_InputFilenames.cend(); ++inputIter)
94  {
96  m_Scanner->GetMapping(inputIter->c_str())).GetPointer());
97  }
98 }
99 
100 const gdcm::Scanner&
102 {
103  return *(this->m_Scanner);
104 }
static Pointer New()
Class is used to identify (nested) attributes in a DICOM dataset. In contrast to the class DICOMTag...
void Print(std::ostream &os) const
add "(group-id,element-id) name" to given stream
std::set< DICOMTag > m_ScannedTags
#define MITK_ERROR
Definition: mitkLogMacros.h:20
std::shared_ptr< gdcm::Scanner > m_Scanner
const unsigned int FrameNo
frame number, starting with 0
Representation of a DICOM tag.
Definition: mitkDICOMTag.h:32
DICOMDatasetFinding GetTagValue(DICOMImageFrameInfo *frame, const DICOMTag &tag) const override
Describes a frame within a DICOM file.
PathIndexType Size() const
std::list< DICOMDatasetFinding > FindingsListType
const std::string Filename
absolute filename
void InitCache(const std::set< DICOMTag > &scannedTags, const std::shared_ptr< gdcm::Scanner > &scanner, const StringList &inputFiles)
std::vector< std::string > StringList
DICOMDatasetAccessingImageFrameList m_ScanResult
DICOMDatasetAccessingImageFrameList GetFrameInfoList() const override
Retrieve a result list for file-by-file tag access.
std::vector< DICOMDatasetAccessingImageFrameInfo::Pointer > DICOMDatasetAccessingImageFrameList
const gdcm::Scanner & GetScanner() const
std::list< DICOMDatasetFinding > FindingsListType
NodeInfo & GetFirstNode()