Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkDICOMGDCMTagScanner.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 
18 #include "mitkDICOMGDCMTagCache.h"
20 
21 #include <gdcmScanner.h>
22 
24 {
25  m_GDCMScanner = std::make_shared<gdcm::Scanner>();
26 }
27 
29 {
30 }
31 
33 {
34  assert( frame );
35  assert(m_Cache.IsNotNull());
36 
37  if (m_Cache.IsNull())
38  {
39  mitkThrow() << "Wrong usage of DICOMGDCMScanner- Called GetTagValue() before scanned at least once. No scanner cache available.";
40  }
41 
42  return m_Cache->GetTagValue(frame, tag);
43 }
44 
46 {
47  m_ScannedTags.insert( tag );
48  m_GDCMScanner->AddTag(
49  gdcm::Tag( tag.GetGroup(), tag.GetElement() ) ); // also a set, duplicate calls to AddTag don't hurt
50 }
51 
53 {
54  for ( auto tagIter = tags.cbegin(); tagIter != tags.cend(); ++tagIter )
55  {
56  this->AddTag( *tagIter );
57  }
58 }
59 
61 {
62  if (path.Size() != 1 || !path.IsExplicit())
63  {
64  std::stringstream errorstring;
65  errorstring << "Invalid call to DICOMGDCMTagScanner::AddTagPath(). "
66  << "Scanner does only support pathes that are explicitly specify one tag. "
67  << "Invalid path: "<<path.ToStr();
68  MITK_ERROR << errorstring.str();
69  throw std::invalid_argument(errorstring.str());
70  }
71  this->AddTag(path.GetFirstNode().tag);
72 }
73 
75 {
76  for (const auto& path : paths)
77  {
78  if (path.Size() != 1 || !path.IsExplicit())
79  {
80  std::stringstream errorstring;
81  errorstring << "Invalid call to DICOMGDCMTagScanner::AddTagPaths(). "
82  << "Scanner does only support pathes that are explicitly specify one tag. "
83  << "Invalid path: " << path.ToStr();
84  MITK_ERROR << errorstring.str();
85  throw std::invalid_argument(errorstring.str());
86  }
87  this->AddTag(path.GetFirstNode().tag);
88  }
89 }
90 
92 {
93  m_InputFilenames = filenames;
94 }
95 
96 
98 {
99  // TODO integrate push/pop locale??
100  m_GDCMScanner->Scan( m_InputFilenames );
101 
103  newCache->InitCache(m_ScannedTags, m_GDCMScanner, m_InputFilenames);
104 
105  m_Cache = newCache;
106 }
107 
110 {
111  return m_Cache.GetPointer();
112 }
113 
115 {
117  if (m_Cache.IsNotNull())
118  {
119  result = m_Cache->GetFrameInfoList();
120  }
121  return result;
122 }
static Pointer New()
itk::SmartPointer< Self > Pointer
Class is used to identify (nested) attributes in a DICOM dataset. In contrast to the class DICOMTag...
std::shared_ptr< gdcm::Scanner > m_GDCMScanner
virtual DICOMTagCache::Pointer GetScanCache() const override
Retrieve Pointer to the complete cache of the scan.
#define MITK_ERROR
Definition: mitkLogMacros.h:24
std::vector< DICOMTag > DICOMTagList
Definition: mitkDICOMTag.h:64
Representation of a DICOM tag.
Definition: mitkDICOMTag.h:37
virtual void AddTagPaths(const DICOMTagPathList &tags) override
Add a list of tag pathes to the scanning process.
virtual DICOMDatasetFinding GetTagValue(DICOMImageFrameInfo *frame, const DICOMTag &tag) const
Directly retrieve the tag value for a given frame and tag.
std::string ToStr() const
virtual void Scan()
Start the scanning process. Calling Scan() will invalidate previous scans, forgetting all about files...
virtual void AddTagPath(const DICOMTagPath &tag) override
Add this tag path to the scanning process.
Describes a frame within a DICOM file.
unsigned int GetGroup() const
bool IsExplicit() const
PathIndexType Size() const
#define mitkThrow()
virtual void AddTag(const DICOMTag &tag) override
Add this tag to the scanning process.
virtual void AddTags(const DICOMTagList &tags) override
Add a list of tags to the scanning process.
std::vector< std::string > StringList
std::vector< DICOMTagPath > DICOMTagPathList
unsigned int GetElement() const
std::vector< DICOMDatasetAccessingImageFrameInfo::Pointer > DICOMDatasetAccessingImageFrameList
virtual DICOMDatasetAccessingImageFrameList GetFrameInfoList() const override
Retrieve a result list for file-by-file tag access.
NodeInfo & GetFirstNode()
virtual void SetInputFiles(const StringList &filenames) override
Define the list of files to scan. This does not ADD to an internal list, but it replaces the whole li...