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