X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=inline;f=src%2FcreaImageIODicomImageReader2.cpp;h=fc7f56b7cee601b21c03d7eb3bc53a0bd177d5d9;hb=a2c6ecf8db79b662d0405ee333da837b242b2c59;hp=3dd8120f299a35ea3c47e965202eda047be4f369;hpb=3a22e19184c369b130d4caa992a8e98e50c7a0ee;p=creaImageIO.git diff --git a/src/creaImageIODicomImageReader2.cpp b/src/creaImageIODicomImageReader2.cpp index 3dd8120..fc7f56b 100644 --- a/src/creaImageIODicomImageReader2.cpp +++ b/src/creaImageIODicomImageReader2.cpp @@ -1,5 +1,5 @@ #include - +#include "gdcmStringFilter.h" #include @@ -19,8 +19,8 @@ namespace creaImageIO //===================================================================== DicomImageReader::DicomImageReader() { - mReader = vtkGDCMImageReader::New(); - SetName ( "Dicom" ); + mReader = vtkGDCMImageReader::New(); + SetName ( "Dicom" ); }; //===================================================================== @@ -28,14 +28,14 @@ namespace creaImageIO //===================================================================== DicomImageReader::~DicomImageReader() { - mReader->Delete(); + mReader->Delete(); } //===================================================================== //===================================================================== bool DicomImageReader::CanRead(const std::string& filename) { - gdcm::Reader reader; + gdcm::Reader reader; reader.SetFileName( filename.c_str() ); return reader.Read(); @@ -67,8 +67,7 @@ namespace creaImageIO v.push_back("dcm"); v.push_back(""); } - //===================================================================== - + //======================================================================== std::string irclean(const std::string& str) { @@ -91,7 +90,30 @@ namespace creaImageIO return str; } //======================================================================== - + //===================================================================== + + + void DicomImageReader::getAttributes(const std::string filename, + std::map &infos, std::vector i_attr) + { + gdcm::Reader reader; + reader.SetFileName( filename.c_str() ); + if (reader.Read()) + { + std::vector::iterator it = i_attr.begin(); + for(;it != i_attr.end(); it++) + { + unsigned short el; + unsigned short gr; + sscanf((*it).c_str(),"D%04hx_%04hx",&gr,&el); + if ( ( gr!=0 ) && ( el!=0 ) ) + { + infos[(*it)] = ( GetStringValueFromTag(reader.GetFile().GetDataSet().GetDataElement(gdcm::Tag(gr,el))) ); + } + } + } + } + //===================================================================== void DicomImageReader::ReadAttributes(const std::string& filename, std::map& attr) @@ -100,50 +122,54 @@ namespace creaImageIO <::iterator i; - for (i=attr.begin();i!=attr.end();++i) - { - if ( i->first == "D0004_1500" ) - { - boost::filesystem::path full_path(filename); - std::string f = full_path.leaf(); - i->second = f; - } - else if ( i->first == "FullFileName" ) - { - i->second = filename; - } - else if ( i->first == "FullFileDirectory" ) - { - std::string::size_type last_pos = filename.find_last_of("//"); - //find first separator - i->second = filename.substr(0, last_pos); - } - else + gdcm::StringFilter sf; + sf.SetFile(reader.GetFile()); + std::map::iterator i; + for (i=attr.begin();i!=attr.end();++i) { - uint16_t el; - uint16_t gr; - - tree::AttributeDescriptor::GetDicomGroupElementFromKey(i->first,gr,el); - if ( ( gr!=0 ) && ( el!=0 ) ) - { - gdcm::DataElement de( gdcm::Tag(gr,el) ); - std::string val = GetStringValueFromTag(reader.GetFile().GetDataSet().GetDataElement(gdcm::Tag(gr,el))); - i->second = irclean(val); + if ( i->first == "D0004_1500" ) + { + boost::filesystem::path full_path(filename); + std::string f = full_path.leaf(); + i->second = f; + } + else if ( i->first == "FullFileName" ) + { + i->second = filename; + } + else if ( i->first == "FullFileDirectory" ) + { + std::string::size_type last_pos = filename.find_last_of("//"); + //find first separator + i->second = filename.substr(0, last_pos); + } + else + { + uint16_t el; + uint16_t gr; + tree::AttributeDescriptor::GetDicomGroupElementFromKey(i->first,gr,el); + //if ( ( gr!=0 ) && ( el!=0 ) ) + const gdcm::Tag tag(gr, el); + if( reader.GetFile().GetDataSet().FindDataElement( tag ) ) + { + i->second = irclean(sf.ToString(tag)); + } + else + { + i->second = ""; + } + } } - } } - } } void DicomImageReader::ReadAttributes2(const std::string& filename, std::map& attr) { - if(!b_loaded) { std::map::iterator i; @@ -197,22 +223,7 @@ void DicomImageReader::ReadAttributes2(const std::string& filename, } } - - - - - - - - - - - - - - - - const std::string DicomImageReader::GetStringValueFromTag(const gdcm::DataElement& de) +const std::string DicomImageReader::GetStringValueFromTag(const gdcm::DataElement& de) { static std::string buffer; buffer = ""; // cleanup previous call @@ -225,7 +236,6 @@ void DicomImageReader::ReadAttributes2(const std::string& filename, // Will be padded with at least one \0 } - // Since return is a const char* the very first \0 will be considered return buffer.c_str(); }