20 #include "gdcmGlobal.h"
24 #include "gdcmImageReader.h"
26 #include "gdcmDicts.h"
27 #include "gdcmDictEntry.h"
28 #include "gdcmDictEntry.h"
31 #include "gdcmSerieHelper.h"
44 std::string::size_type atPosition = tagString.find( nameString );
45 if ( atPosition == std::string::npos)
51 std::string infoAsString = tagString.substr( atPosition, tagString.size()-atPosition+1 );
52 const char * infoAsCharPtr = infoAsString.c_str();
54 int vm = *(infoAsCharPtr+64);
55 std::string vr = infoAsString.substr( 68, 4 );
61 for (
int k = 0; k < vm; k++)
63 int itemLength = *(infoAsCharPtr+offset+4);
64 int strideSize =
static_cast<int> (ceil(static_cast<double>(itemLength)/4) * 4);
65 std::string valueString = infoAsString.substr( offset+16, itemLength );
66 valueArray.push_back( atof(valueString.c_str()) );
67 offset += 16+strideSize;
78 if(m_DicomFilenames.size())
83 VolumeReaderType::DictionaryArrayRawPointer inputDict
84 = m_VolumeReader->GetMetaDataDictionaryArray();
91 std::cout <<
"Siemens SliceMosaic......" << std::endl;
93 m_SliceOrderIS =
false;
99 gdcm::ImageReader reader;
100 reader.SetFileName( m_DicomFilenames[0].c_str() );
103 itkExceptionMacro(<<
"Cannot read requested file");
106 const gdcm::DataSet &ds = f.GetDataSet();
109 auto it = ds.Begin();
113 for(; it != ds.End(); ++it)
115 const gdcm::DataElement &ref = *it;
116 if (ref.GetTag() == gdcm::Tag(0x0029,0x1010)) {
117 tag = std::string(ref.GetByteValue()->GetPointer(),ref.GetByteValue()->GetLength());
122 std::vector<double> valueArray(0);
123 int nItems = ExtractSiemensDiffusionInformation(tag,
"SliceNormalVector", valueArray);
126 std::cout <<
"Warning: Cannot find complete information on SliceNormalVector in 0029|1010\n";
127 std::cout <<
" Slice order may be wrong.\n";
129 else if (valueArray[2] > 0)
131 m_SliceOrderIS =
true;
135 valueArray.resize(0);
136 nItems = ExtractSiemensDiffusionInformation(tag,
"NumberOfImagesInMosaic", valueArray);
139 if (valueArray.size() < 1)
141 MITK_ERROR <<
"MOSAIC Image has no valid tag (0029,1010). ABORTING" << std::endl;
142 mitkThrow() <<
"MOSAIC Image has no valid tag (0029,1010). ABORTING";
147 std::cout <<
"Warning: Cannot find complete information on NumberOfImagesInMosaic in 0029|1010\n";
148 std::cout <<
" Resulting image may contain empty slices.\n";
152 this->m_Output->nSliceInVolume =
static_cast<int>(valueArray[0]);
153 mMosaic =
static_cast<int> (ceil(sqrt(valueArray[0])));
156 std::cout <<
"Mosaic in " << mMosaic <<
" X " << nMosaic <<
" blocks (total number of blocks = " << valueArray[0] <<
").\n";
163 std::cout <<
"Data in Siemens Mosaic Format\n";
166 std::cout <<
"Number of Slices in each volume: " << this->m_Output->nSliceInVolume << std::endl;
169 for (
int k = 0; k < m_nSlice; k += nStride )
171 gdcm::ImageReader reader;
172 reader.SetFileName( m_DicomFilenames[0].c_str() );
175 itkExceptionMacro(<<
"Cannot read requested file");
178 const gdcm::DataSet &ds = f.GetDataSet();
181 auto it = ds.Begin();
185 for(; it != ds.End(); ++it)
187 const gdcm::DataElement &ref = *it;
188 if (ref.GetTag() == gdcm::Tag(0x0029,0x1010)) {
189 tag = std::string(ref.GetByteValue()->GetPointer(),ref.GetByteValue()->GetLength());
194 std::vector<double> valueArray(0);
195 vnl_vector_fixed<double, 3> vect3d;
196 int nItems = ExtractSiemensDiffusionInformation(tag,
"B_value", valueArray);
197 if (nItems != 1 || valueArray[0] == 0)
199 MITK_INFO <<
"Reading diffusion info from 0019|100c and 0019|100e tags";
201 bool success = itk::ExposeMetaData<std::string> ( *(*inputDict)[0],
"0019|100c", tag );
204 this->m_Output->bValue = atof( tag.c_str() );
206 success = itk::ExposeMetaData<std::string> ( *(*inputDict)[k],
"0019|100e", tag);
209 memcpy( &vect3d[0], tag.c_str()+0, 8 );
210 memcpy( &vect3d[1], tag.c_str()+8, 8 );
211 memcpy( &vect3d[2], tag.c_str()+16, 8 );
213 this->m_Output->DiffusionVector = vect3d;
214 TransformGradients();
215 MITK_INFO <<
"BV: " << this->m_Output->bValue;
216 MITK_INFO <<
" GD: " << this->m_Output->DiffusionVector << std::endl;
223 MITK_INFO <<
"Reading diffusion info from 0029|1010 tags";
224 this->m_Output->bValue = valueArray[0];
227 valueArray.resize(0);
228 nItems = ExtractSiemensDiffusionInformation(tag,
"DiffusionGradientDirection", valueArray);
231 vect3d[0] = valueArray[0];
232 vect3d[1] = valueArray[1];
233 vect3d[2] = valueArray[2];
235 this->m_Output->DiffusionVector = vect3d;
236 TransformGradients();
237 MITK_INFO <<
"BV: " << this->m_Output->bValue;
238 MITK_INFO <<
" GD: " << this->m_Output->DiffusionVector;
243 MITK_ERROR <<
"No diffusion info found, assuming BASELINE" << std::endl;
244 this->m_Output->bValue = 0.0;
246 this->m_Output->DiffusionVector = vect3d;