Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
mitkGEDicomDiffusionImageHeaderReader.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 
19 #include <mitkLocaleSwitch.h>
20 
21 
22 #include "gdcmGlobal.h"
23 #include "gdcmDict.h"
24 #include "gdcmDicts.h"
25 #include "gdcmDictEntry.h"
26 #include "gdcmDictEntry.h"
27 #include "gdcmDict.h"
28 #include "gdcmFile.h"
29 #include "gdcmSerieHelper.h"
30 
31 
33 {
34 }
35 
37 {
38 }
39 
40 // do the work
42 {
43 
44  // check if there are filenames
45  if(m_DicomFilenames.size())
46  {
47  mitk::LocaleSwitch localeSwitch("C");
48 
49  // adapted from namic-sandbox
50  // DicomToNrrdConverter.cxx
51 
52  VolumeReaderType::DictionaryArrayRawPointer inputDict
53  = m_VolumeReader->GetMetaDataDictionaryArray();
54 
55  ReadPublicTags();
56 
57  float x0, y0, z0;
58  float x1, y1, z1;
59  std::string tag;
60  tag.clear();
61  itk::ExposeMetaData<std::string> ( *(*inputDict)[0], "0020|0032", tag );
62  sscanf( tag.c_str(), "%f\\%f\\%f", &x0, &y0, &z0 );
63  std::cout << "Slice 0: " << tag << std::endl;
64  tag.clear();
65 
66  // assume volume interleaving, i.e. the second dicom file stores
67  // the second slice in the same volume as the first dicom file
68  itk::ExposeMetaData<std::string> ( *(*inputDict)[1], "0020|0032", tag );
69  sscanf( tag.c_str(), "%f\\%f\\%f", &x1, &y1, &z1 );
70  std::cout << "Slice 1: " << tag << std::endl;
71  x1 -= x0; y1 -= y0; z1 -= z0;
72  x0 = x1*this->m_Output->xSlice + y1*this->m_Output->ySlice + z1*this->m_Output->zSlice;
73  if (x0 < 0)
74  {
75  m_SliceOrderIS = false;
76  }
77 
78  ReadPublicTags2();
79 
80  int nSliceInVolume;
81  int nVolume;
82 
83  nSliceInVolume = m_sliceLocations.size();
84  nVolume = m_nSlice/nSliceInVolume;
85 
86  // assume volume interleaving
87  std::cout << "Number of Slices: " << m_nSlice << std::endl;
88  std::cout << "Number of Volume: " << nVolume << std::endl;
89  std::cout << "Number of Slices in each volume: " << nSliceInVolume << std::endl;
90 
91  for (int k = 0; k < m_nSlice; k += nSliceInVolume)
92  {
93  tag.clear();
94  bool exist = itk::ExposeMetaData<std::string> ( *(*inputDict)[k], "0043|1039", tag);
95  float b = atof( tag.c_str() );
96  this->m_Output->bValue = b;
97 
98  vnl_vector_fixed<double, 3> vect3d;
99  if (!exist || b == 0)
100  {
101  vect3d.fill( 0 );
102  this->m_Output->DiffusionVector = vect3d;
103  continue;
104  }
105 
106  vect3d.fill( 0 );
107  tag.clear();
108  itk::ExposeMetaData<std::string> ( *(*inputDict)[k], "0019|10bb", tag);
109  vect3d[0] = atof( tag.c_str() );
110 
111  tag.clear();
112  itk::ExposeMetaData<std::string> ( *(*inputDict)[k], "0019|10bc", tag);
113  vect3d[1] = atof( tag.c_str() );
114 
115  tag.clear();
116  itk::ExposeMetaData<std::string> ( *(*inputDict)[k], "0019|10bd", tag);
117  vect3d[2] = atof( tag.c_str() );
118 
119  vect3d.normalize();
120  this->m_Output->DiffusionVector = vect3d;
121  }
122 
123  TransformGradients();
124  }
125 }
126 
127 
Convenience class to temporarily change the current locale.