21 #include "gdcmScanner.h"
22 #include "gdcmReader.h"
24 #include <vnl/vnl_math.h>
26 static bool GetTagFromHierarchy( std::vector< gdcm::Tag > hierarchy,
const gdcm::Tag& t_tag,
const gdcm::DataSet& dataset, gdcm::DataSet& target)
28 if( hierarchy.empty() )
31 const gdcm::DataElement& de = dataset.GetDataElement( hierarchy.at(0) );
32 const auto seq = de.GetValueAsSQ();
35 if( hierarchy.size() == 1 )
37 gdcm::Item& item2 = seq->GetItem(1);
38 gdcm::DataSet& nestedds2 = item2.GetNestedDataSet();
40 const gdcm::DataElement& nde2 = nestedds2.GetDataElement( t_tag );
54 if( seq->FindDataElement( hierarchy.at(1) ) )
56 for( gdcm::SequenceOfItems::SizeType i=1; i< seq->GetNumberOfItems(); i++ )
58 gdcm::Item& item = seq->GetItem(i);
59 gdcm::DataSet &nestedds = item.GetNestedDataSet();
62 return GetTagFromHierarchy( std::vector< gdcm::Tag >( hierarchy.begin() + 1, hierarchy.end() ), t_tag, nestedds, target);
83 std::string::size_type tag_position =
84 tag_value.find(
"B_value", 0 );
86 if( tag_position == std::string::npos )
88 MITK_ERROR <<
"No b value information found. ";
92 std::string value_string = tag_value.substr( tag_position, tag_value.size() - tag_position + 1 );
94 std::vector<double> value_array;
97 values.
b_value = value_array.at(0);
101 MITK_INFO(
"diffusion.dicomreader.siemens") <<
"No b-value tag found. ";
108 std::string::size_type tag_position = tag_value.find(
"DiffusionGradientDirection", 0 );
111 if( tag_position == std::string::npos )
113 MITK_WARN <<
"No gradient direction information, but non-zero b-value. Possibly an IVIM dataset. " <<
"\n"
114 <<
"Setting gradient to (1,1,1).";
122 std::string gradient_direction_str = tag_value.substr( tag_position, tag_value.size() - tag_position + 1 );
126 if( value_array.size() != 3 )
128 MITK_ERROR <<
" Retrieved gradient information of length " << value_array.size();
132 for(
unsigned int i=0; i<value_array.size(); i++)
134 values.
g_vector[i] = value_array.at(i);
157 Siemens_Header_Format Siemens_CSA1_Format( 64,
sizeof(int32_t), 4,
sizeof(int32_t),
sizeof(int32_t) );
158 Siemens_Header_Format Siemens_CSA2_Format( 64,
sizeof(int32_t), 4,
sizeof(int32_t),
sizeof(int32_t) );
160 m_SiemensFormatsCollection.push_back( Siemens_CSA1_Format );
161 m_SiemensFormatsCollection.push_back( Siemens_CSA2_Format );
173 gdcm::Reader gdcmReader;
174 gdcmReader.SetFileName( filename.c_str() );
182 const gdcm::DataSet& dataset = gdcmReader.GetFile().GetDataSet();
184 const gdcm::Tag t_sie_diffusion( 0x0029,0x1010 );
188 std::string siemens_diffusionheader_str;
189 if(
RevealBinaryTag( t_sie_diffusion, dataset, siemens_diffusionheader_str ) )
192 this->ExtractSiemensDiffusionTagInformation( siemens_diffusionheader_str, values );
194 m_HeaderInformationList.push_back( values );
199 const gdcm::Tag t_sie_bvalue( 0x0018, 0x9087);
200 const gdcm::Tag t_sie_gradient( 0x0021, 0x1146);
202 std::vector< gdcm::Tag > bv_hierarchy;
203 bv_hierarchy.push_back( gdcm::Tag(0x5200,0x9230) );
204 bv_hierarchy.push_back( gdcm::Tag(0x0018,0x9117) );
206 gdcm::DataSet bvalueset;
213 MITK_INFO(
"siemens.dicom.diffusion.bvalue") << dbvalue;
214 values.
b_value = std::ceil( dbvalue );
222 std::vector< gdcm::Tag > g_hierarchy;
223 g_hierarchy.push_back( gdcm::Tag(0x5200,0x9230) );
224 g_hierarchy.push_back( gdcm::Tag(0x0021,0x11fe) );
228 double gr_dir_arr[3] = {1,0,-1};
231 MITK_INFO(
"siemens.dicom.diffusion.gradient") <<
"(" << gr_dir_arr[0] <<
"," << gr_dir_arr[1] <<
"," <<gr_dir_arr[2] <<
")";
234 values.
g_vector.copy_in( &gr_dir_arr[0] );
239 m_HeaderInformationList.push_back( values );
bool ParseInputString(std::string input, std::vector< double > &values, Siemens_Header_Format format_specs)
bool RevealBinaryTag(const gdcm::Tag tag, const gdcm::DataSet &dataset, std::string &target)
Retrieve the value of a gdcm tag to the given string.
SiemensDiffusionHeaderType
static const std::string filename
MITKCORE_EXPORT const ScalarType eps
bool RevealBinaryTagC(const gdcm::Tag tag, const gdcm::DataSet &dataset, char *target_array)
SiemensDiffusionHeaderType GetHeaderType(std::string header)