22 #include "gdcmGlobal.h"
26 #include "gdcmImageReader.h"
27 #include "gdcmDictEntry.h"
28 #include "gdcmDicts.h"
41 std::string::size_type atPosition = tagString.find( nameString, startPos );
42 if ( atPosition == std::string::npos)
48 std::string infoAsString = tagString.substr( atPosition, tagString.size()-atPosition+1 );
49 const char * infoAsCharPtr = infoAsString.c_str();
51 int vm = *(infoAsCharPtr+64);
54 for (
int k = 0; k < vm; k++)
56 int itemLength = *(infoAsCharPtr+offset+4);
57 int strideSize =
static_cast<int> (ceil(static_cast<double>(itemLength)/4) * 4);
58 std::string valueString = infoAsString.substr( offset+16, itemLength );
59 valueArray.push_back( atof(valueString.c_str()) );
60 offset += 16+strideSize;
69 std::string::size_type pos = -1;
72 nItems = ExtractSiemensDiffusionInformation( tagString, nameString, valueArray, pos+1 );
73 pos = tagString.find( nameString, pos+1 );
74 if ( pos == std::string::npos )
87 if(m_DicomFilenames.size())
94 VolumeReaderType::DictionaryArrayRawPointer
95 inputDict = m_VolumeReader->GetMetaDataDictionaryArray();
103 itk::ExposeMetaData<std::string> ( *(*inputDict)[0],
"0020|0032", tag );
104 sscanf( tag.c_str(),
"%f\\%f\\%f", &x0, &y0, &z0 );
110 if((*inputDict).size() > 1)
112 itk::ExposeMetaData<std::string> ( *(*inputDict)[1],
"0020|0032", tag );
113 sscanf( tag.c_str(),
"%f\\%f\\%f", &x1, &y1, &z1 );
115 x1 -= x0; y1 -= y0; z1 -= z0;
116 x0 = x1*this->m_Output->xSlice + y1*this->m_Output->ySlice + z1*this->m_Output->zSlice;
119 m_SliceOrderIS =
false;
126 this->m_Output->nSliceInVolume = m_sliceLocations.size();
128 nStride = this->m_Output->nSliceInVolume;
130 MITK_INFO << m_DicomFilenames[0] << std::endl;
131 MITK_INFO <<
"Dims " << this->m_Output->nRows <<
"x"
132 << this->m_Output->nCols <<
"x" << this->m_Output->nSliceInVolume <<
" " << std::endl;
134 for (
int k = 0; k < m_nSlice; k += nStride )
137 gdcm::ImageReader reader;
138 reader.SetFileName( m_DicomFilenames[k].c_str() );
141 itkExceptionMacro(<<
"Cannot read requested file");
144 const gdcm::DataSet &ds = f.GetDataSet();
147 auto it = ds.Begin();
151 for(; it != ds.End(); ++it)
153 const gdcm::DataElement &ref = *it;
154 if (ref.GetTag() == gdcm::Tag(0x0029,0x1010)) {
155 tag = std::string(ref.GetByteValue()->GetPointer(),ref.GetByteValue()->GetLength());
160 std::vector<double> valueArray(0);
161 vnl_vector_fixed<double, 3> vect3d;
162 int nItems = ExtractSiemensDiffusionInformation(tag,
"B_value", valueArray);
163 if (nItems != 1 || valueArray[0] == 0)
166 MITK_INFO <<
"Reading diffusion info from 0019|100c and 0019|100e tags" << std::endl;
167 bool success =
false;
169 for(it = ds.Begin(); it != ds.End(); ++it)
171 const gdcm::DataElement &ref = *it;
172 if (ref.GetTag() == gdcm::Tag(0x0019,0x100c)) {
173 tag = std::string(ref.GetByteValue()->GetPointer(),ref.GetByteValue()->GetLength());
174 this->m_Output->bValue = atof( tag.c_str() );
182 if(this->m_Output->bValue == 0)
189 for(it = ds.Begin(); it != ds.End(); ++it)
191 const gdcm::DataElement &ref = *it;
192 if (ref.GetTag() == gdcm::Tag(0x0019,0x100e)) {
193 tag = std::string(ref.GetByteValue()->GetPointer(),ref.GetByteValue()->GetLength());
200 memcpy( &vect3d[0], tag.c_str()+0, 8 );
201 memcpy( &vect3d[1], tag.c_str()+8, 8 );
202 memcpy( &vect3d[2], tag.c_str()+16, 8 );
204 this->m_Output->DiffusionVector = vect3d;
205 TransformGradients();
206 MITK_INFO <<
"BV: " << this->m_Output->bValue;
207 MITK_INFO <<
" GD: " << this->m_Output->DiffusionVector;
214 MITK_INFO <<
"Reading diffusion info from 0029,1010 tag" << std::endl;
215 this->m_Output->bValue = valueArray[0];
217 if(this->m_Output->bValue == 0)
223 valueArray.resize(0);
224 nItems = ExtractSiemensDiffusionGradientInformation(tag,
"DiffusionGradientDirection", valueArray);
227 vect3d[0] = valueArray[0];
228 vect3d[1] = valueArray[1];
229 vect3d[2] = valueArray[2];
231 this->m_Output->DiffusionVector = vect3d;
232 TransformGradients();
233 MITK_INFO <<
"BV: " << this->m_Output->bValue;
234 MITK_INFO <<
" GD: " << this->m_Output->DiffusionVector;
239 MITK_ERROR <<
"No diffusion info found, forcing to BASELINE image." << std::endl;
240 this->m_Output->bValue = 0.0;
242 this->m_Output->DiffusionVector = vect3d;
Convenience class to temporarily change the current locale.