Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkDiffusionHeaderGEDICOMFileReader.cpp
Go to the documentation of this file.
2 #include <vnl/vnl_math.h>
3 
6 {
7 
8 }
9 
12 {
13 
14 }
15 
18 {
19 
20  gdcm::Reader gdcmReader;
21  gdcmReader.SetFileName( filename.c_str() );
22 
23  gdcmReader.Read();
24 
25  gdcm::Tag ge_bvalue_tag( 0x0043, 0x1039 );
26  gdcm::Tag ge_gradient_x( 0x0019, 0x10bb );
27  gdcm::Tag ge_gradient_y( 0x0019, 0x10bc );
28  gdcm::Tag ge_gradient_z( 0x0019, 0x10bd );
29 
30  bool success = true;
32 
33  std::string ge_tagvalue_string;
34  char* pEnd;
35 
36  // start with b-value
37  success = RevealBinaryTag( ge_bvalue_tag, gdcmReader.GetFile().GetDataSet(), ge_tagvalue_string );
38  // b value stored in the first bytes
39  // typical example: "1000\8\0\0" for bvalue=1000
40  // "40\8\0\0" for bvalue=40
41  // so we need to cut off the last 6 elements
42  const char* bval_string = ge_tagvalue_string.substr(0,ge_tagvalue_string.length()-6).c_str();
43  header_info.b_value = static_cast<unsigned int>(strtod( bval_string, &pEnd ));
44 
45  // now retrieve the gradient direction
46  if(success &&
47  RevealBinaryTag( ge_gradient_x, gdcmReader.GetFile().GetDataSet(), ge_tagvalue_string ) )
48  {
49  header_info.g_vector[0] = strtod( ge_tagvalue_string.c_str(), &pEnd );
50  }
51  else
52  {
53  success = false;
54  }
55 
56  if( success &&
57  RevealBinaryTag( ge_gradient_y, gdcmReader.GetFile().GetDataSet(), ge_tagvalue_string ) )
58  {
59  header_info.g_vector[1] = strtod( ge_tagvalue_string.c_str(), &pEnd );
60  }
61  else
62  {
63  success = false;
64  }
65 
66  if( success &&
67  RevealBinaryTag( ge_gradient_z, gdcmReader.GetFile().GetDataSet(), ge_tagvalue_string ) )
68  {
69  header_info.g_vector[2] = strtod( ge_tagvalue_string.c_str(), &pEnd );
70  }
71  else
72  {
73  success = false;
74  }
75 
76  if( success )
77  {
78  // Fix for (0,0,0) direction in IVIM datasets
79  if( header_info.b_value > 0 &&
80  header_info.g_vector.two_norm() < vnl_math::eps )
81  {
82  header_info.g_vector.fill(1);
83  header_info.g_vector.normalize();
84  header_info.isotropic = true;
85  }
86 
87  // mark baseline
88  if( header_info.b_value == 0 )
89  header_info.baseline = true;
90 
91  this->m_HeaderInformationList.push_back( header_info );
92 
93  header_info.Print();
94  }
95 
96  return success;
97 
98 
99 
100 }
101 
102 
bool RevealBinaryTag(const gdcm::Tag tag, const gdcm::DataSet &dataset, std::string &target)
Retrieve the value of a gdcm tag to the given string.
The DiffusionImageHeaderInformation struct.
static const std::string filename
virtual bool ReadDiffusionHeader(std::string filename) override
MITKCORE_EXPORT const ScalarType eps