Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkDICOMGDCMTagCache.h"
18 #include "mitkDICOMEnums.h"
20 
22 {
23 }
24 
26 {
27 }
28 
30 {
31  assert( frame );
32 
33  for ( auto frameIter = m_ScanResult.cbegin(); frameIter != m_ScanResult.cend(); ++frameIter )
34  {
35  if ( **frameIter == *frame )
36  {
37  return (*frameIter)->GetTagValueAsString(tag);
38  }
39  }
40 
41  if ( m_ScannedTags.find( tag ) != m_ScannedTags.cend() )
42  {
43  if ( std::find( m_InputFilenames.cbegin(), m_InputFilenames.cend(), frame->Filename )
44  == m_InputFilenames.cend() )
45  {
46  // callers are required to tell us about the filenames they are interested in
47  // this is a helpful reminder for them to inform us
48  std::stringstream errorstring;
49  errorstring << "Invalid call to DICOMGDCMTagCache::GetTagValue( "
50  << "'" << frame->Filename << "', frame " << frame->FrameNo
51  << " ). Filename was never mentioned before!";
52  MITK_ERROR << errorstring.str();
53  throw std::invalid_argument( errorstring.str() );
54  }
55  }
56  else
57  {
58  // callers are required to tell us about the tags they are interested in
59  // this is a helpful reminder for them to inform us
60  std::stringstream errorstring;
61  errorstring << "Invalid call to DICOMGDCMTagCache::GetTagValue( ";
62  tag.Print( errorstring );
63  errorstring << " ). Tag was never mentioned before!";
64  MITK_ERROR << errorstring.str();
65  throw std::invalid_argument( errorstring.str() );
66  }
67 
68  return DICOMDatasetFinding();
69 }
70 
73 {
74  FindingsListType result;
75  if (path.Size() == 1 && path.IsExplicit())
76  {
77  result.push_back(this->GetTagValue(frame, path.GetFirstNode().tag));
78  }
79  return result;
80 }
81 
83 {
84  return m_ScanResult;
85 }
86 
87 void
88 mitk::DICOMGDCMTagCache::InitCache(const std::set<DICOMTag>& scannedTags, const std::shared_ptr<gdcm::Scanner>& scanner, const StringList& inputFiles)
89 {
90  m_ScannedTags = scannedTags;
91  m_InputFilenames = inputFiles;
92  m_Scanner = scanner;
93 
94  m_ScanResult.clear();
95  m_ScanResult.reserve(m_InputFilenames.size());
96 
97  for (auto inputIter = m_InputFilenames.cbegin(); inputIter != m_InputFilenames.cend(); ++inputIter)
98  {
99  m_ScanResult.push_back(DICOMGDCMImageFrameInfo::New(DICOMImageFrameInfo::New(*inputIter, 0),
100  m_Scanner->GetMapping(inputIter->c_str())).GetPointer());
101  }
102 }
103 
104 const gdcm::Scanner&
106 {
107  return *(this->m_Scanner);
108 }
Class is used to identify (nested) attributes in a DICOM dataset. In contrast to the class DICOMTag...
#define MITK_ERROR
Definition: mitkLogMacros.h:24
const unsigned int FrameNo
frame number, starting with 0
Representation of a DICOM tag.
Definition: mitkDICOMTag.h:37
const gdcm::Scanner & GetScanner() const
virtual DICOMDatasetFinding GetTagValue(DICOMImageFrameInfo *frame, const DICOMTag &tag) const override
Describes a frame within a DICOM file.
bool IsExplicit() const
std::list< DICOMDatasetFinding > FindingsListType
const std::string Filename
absolute filename
PathIndexType Size() const
void InitCache(const std::set< DICOMTag > &scannedTags, const std::shared_ptr< gdcm::Scanner > &scanner, const StringList &inputFiles)
std::vector< std::string > StringList
virtual DICOMDatasetAccessingImageFrameList GetFrameInfoList() const override
Retrieve a result list for file-by-file tag access.
std::vector< DICOMDatasetAccessingImageFrameInfo::Pointer > DICOMDatasetAccessingImageFrameList
std::list< DICOMDatasetFinding > FindingsListType
void Print(std::ostream &os) const
add "(group-id,element-id) name" to given stream
NodeInfo & GetFirstNode()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.