Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkDiffusionHeaderSiemensMosaicDICOMFileReader.cpp
Go to the documentation of this file.
3 
4 #include <sstream>
5 
8 {
9 
10 }
11 
14 {
15 
16 }
17 
20 {
21  // retrieve also mosaic information
22  if( !this->ReadDiffusionHeader( filename ) )
23  {
24  MITK_ERROR << "Using MOSAIC Reader for non-mosaic files ";
25  }
26 
27  gdcm::Reader gdcmReader;
28  gdcmReader.SetFileName( filename.c_str() );
29 
30  gdcmReader.Read();
31  const gdcm::DataSet& dataset = gdcmReader.GetFile().GetDataSet();
32 
33  // (0018,0088) DS [2.5] # 4, 1 SpacingBetweenSlices
34  // important for mosaic data
35  std::string spacing_between_slices;
36  if( RevealBinaryTag( gdcm::Tag(0x0018, 0x0088 ), dataset, spacing_between_slices ) )
37  {
38  std::istringstream ifs_spacing(spacing_between_slices );
39  ifs_spacing >> this->m_MosaicDescriptor.spacing[2];
40  }
41 
42  //(0028,0030) DS [2.5\2.5] # 8, 2 PixelSpacing
43  std::string inplace_spacing;
44  if( RevealBinaryTag( gdcm::Tag(0x0028, 0x0030 ), dataset, inplace_spacing ) )
45  {
46  std::stringstream iplss( inplace_spacing );
47  std::string buffer;
48  unsigned int idx=0;
49  while( std::getline( iplss, buffer, '\\' ) )
50  {
51  std::istringstream substream(buffer);
52  substream >> this->m_MosaicDescriptor.spacing[idx++];
53  }
54  }
55 
56  // (0020,0032) DS [-802.51815986633\-801.18644070625\-30.680992126465] # 50, 3 ImagePositionPatient
57  std::string position_patient;
58  if( RevealBinaryTag( gdcm::Tag( 0x0028, 0x0032), dataset, position_patient) )
59  {
60  std::stringstream ppass( inplace_spacing );
61  std::string buffer;
62  unsigned int idx=0;
63  while( std::getline( ppass, buffer, '\\' ) )
64  {
65  std::istringstream substream(buffer);
66  substream >> this->m_MosaicDescriptor.origin[idx++];
67  }
68  }
69 
70 }
71 
74 {
75  gdcm::Reader gdcmReader;
76  gdcmReader.SetFileName( filename.c_str() );
77 
78  gdcmReader.Read();
79 
80  MITK_INFO << " -- Analyzing: " << filename;
81 
82  const gdcm::DataSet& dataset = gdcmReader.GetFile().GetDataSet();
83 
84  const gdcm::Tag t_sie_diffusion( 0x0029,0x1010 );
85  const gdcm::Tag t_sie_diffusion_alt( 0x0029,0x1110 );
86  std::string siemens_diffusionheader_str;
87 
88  if( RevealBinaryTag( t_sie_diffusion, dataset, siemens_diffusionheader_str )
89  || RevealBinaryTag( t_sie_diffusion_alt, dataset, siemens_diffusionheader_str) )
90  {
92  // wait for success
93  if( !this->ExtractSiemensDiffusionTagInformation( siemens_diffusionheader_str, header_values ))
94  return false;
95 
96  mitk::SiemensDiffusionHeaderType hformat = GetHeaderType( siemens_diffusionheader_str );
97  Siemens_Header_Format specs = this->m_SiemensFormatsCollection.at( hformat );
98 
99  std::string::size_type tag_position = siemens_diffusionheader_str.find( "NumberOfImagesInMosaic", 0 );
100  if( tag_position != std::string::npos )
101  {
102  std::vector<double> value_array;
103  ParseInputString( siemens_diffusionheader_str.substr( tag_position, siemens_diffusionheader_str.size() - tag_position + 1 ),
104  value_array,
105  specs
106  );
107 
108  header_values.n_images = value_array[0];
109  this->m_MosaicDescriptor.nimages = value_array[0];
110  }
111 
112  tag_position = siemens_diffusionheader_str.find("SliceNormalVector", 0);
113  if( tag_position != std::string::npos )
114  {
115  std::vector<double> value_array;
116  ParseInputString( siemens_diffusionheader_str.substr( tag_position, siemens_diffusionheader_str.size() - tag_position + 1 ),
117  value_array,
118  specs
119  );
120 
121  MITK_DEBUG << "SliceNormal";
122  for( unsigned int i=0; i<value_array.size(); i++)
123  {
124  MITK_DEBUG << value_array.at(i);
125  }
126 
127  if( value_array.size() > 2 )
128  {
129  header_values.slicenormalup = (value_array[2] > 0);
130  this->m_MosaicDescriptor.slicenormalup = ( value_array[2] > 0);
131  }
132 
133  }
134 
135 
136 
137  m_HeaderInformationList.push_back( header_values );
138 
139  }
140 
141  return (m_HeaderInformationList.size() > 0);
142 
143 }
bool ParseInputString(std::string input, std::vector< double > &values, Siemens_Header_Format format_specs)
#define MITK_INFO
Definition: mitkLogMacros.h:22
bool RevealBinaryTag(const gdcm::Tag tag, const gdcm::DataSet &dataset, std::string &target)
Retrieve the value of a gdcm tag to the given string.
#define MITK_ERROR
Definition: mitkLogMacros.h:24
#define MITK_DEBUG
Definition: mitkLogMacros.h:26
static const std::string filename
SiemensDiffusionHeaderType GetHeaderType(std::string header)