31 #include "gdcmStringFilter.h"
33 #include "boost/filesystem/path.hpp"
35 #include "vtkGDCMImageReader.h"
36 #include <vtkStringArray.h>
38 #pragma warning(disable: 4996)
50 mReader = vtkGDCMImageReader::New();
67 reader.SetFileName( filename.c_str() );
79 mReader->SetFileName(filename.c_str());
81 im = vtkImageData::New();
82 im->ShallowCopy(
mReader->GetOutput());
86 if (im!=0) im->Delete();
110 std::string
irclean(
const std::string& str)
114 if (str ==
"GDCM::Unfound")
118 if (str[str.size()-1]==
' ')
120 return irclean(str.substr(0,str.size()-1));
122 if (str[str.size()-1]==0)
124 return irclean(str.substr(0,str.size()-1));
135 std::map <std::string , std::string> &infos, std::vector<std::string> i_attr)
138 reader.SetFileName( filename.c_str() );
141 std::vector<std::string>::iterator it = i_attr.begin();
142 for(;it != i_attr.end(); it++)
146 sscanf((*it).c_str(),
"D%04hx_%04hx",&gr,&el);
147 if ( ( gr!=0 ) && ( el!=0 ) )
149 infos[(*it)] = (
GetStringValueFromTag(reader.GetFile().GetDataSet().GetDataElement(gdcm::Tag(gr,el))) );
157 std::map<std::string,std::string>& attr)
162 reader.SetFileName( filename.c_str() );
165 gdcm::StringFilter sf;
166 sf.SetFile(reader.GetFile());
167 std::map<std::string,std::string>::iterator i;
168 for (i=attr.begin();i!=attr.end();++i)
170 if ( i->first ==
"D0004_1500" )
172 boost::filesystem::path full_path(filename);
173 std::string f = full_path.leaf().string();
176 else if ( i->first ==
"FullFileName" )
178 i->second = filename;
180 else if ( i->first ==
"FullFileDirectory" )
182 std::string::size_type last_pos = filename.find_last_of(
"//");
184 i->second = filename.substr(0, last_pos);
191 gdcm::Attribute< 0x0008,0x103e> at;
198 const gdcm::Tag tag(gr, el);
199 if( reader.GetFile().GetDataSet().FindDataElement( tag ) )
201 i->second =
irclean(sf.ToString(tag));
213 std::map<std::string,std::string>& attr)
217 std::map<std::string,std::string>::iterator i;
218 for (i=attr.begin();i!=attr.end();++i)
220 if ( i->first ==
"D0004_1500" || i->first ==
"FullFileName" || i->first ==
"FullFileDirectory" )
230 mscan.AddTag(gdcm::Tag(gr,el) );
235 bool b =
mscan.IsKey(filename.c_str());
238 const gdcm::Scanner::TagToValue &mapping =
mscan.GetMapping(filename.c_str());
239 gdcm::Scanner::TagToValue::const_iterator it = mapping.begin();
240 std::map<std::string, std::string>::iterator i;
241 for (i=attr.begin();i!=attr.end();++i, ++it)
243 if ( i->first ==
"D0004_1500" )
245 boost::filesystem::path full_path(filename);
246 std::string f = full_path.leaf().string();
249 else if ( i->first ==
"FullFileName" )
251 i->second = filename;
253 else if ( i->first ==
"FullFileDirectory" )
255 std::string::size_type last_pos = filename.find_last_of(
"//");
257 i->second = filename.substr(0, last_pos);
261 const char *value = it->second;
262 i->second =
irclean(it->second);
270 static std::string buffer;
274 const gdcm::ByteValue *bv = de.GetByteValue();
277 buffer = std::string( bv->GetPointer(), bv->GetLength() );
282 return buffer.c_str();