30 #include <boost/filesystem.hpp>
31 #include "boost/algorithm/string.hpp"
32 #include "boost/filesystem/path.hpp"
36 #pragma warning(disable: 4996)
48 mReader = vtkGDCMImageReader::New();
67 std::map<std::string,std::string>::iterator i;
69 for (i=attr.begin();i!=attr.end();++i, j++)
71 if ( i->first ==
"D0004_1500" || i->first ==
"FullFileName" || i->first ==
"FullFileDirectory" )
81 mscan.AddTag(gdcm::Tag(gr,el) );
89 boost::algorithm::replace_all(filename,
"\\",
"/");
90 d.Load(filename.c_str(),
true);
91 mscan.Scan(d.GetFilenames());
101 vtkImageData* im = 0;
104 mReader->SetFileName(filename.c_str());
106 im = vtkImageData::New();
107 im->ShallowCopy(
mReader->GetOutput());
111 if (im!=0) im->Delete();
125 if (str ==
"GDCM::Unfound")
129 if (str[str.size()-1]==
' ')
131 return irclean(str.substr(0,str.size()-1));
133 if (str[str.size()-1]==0)
135 return irclean(str.substr(0,str.size()-1));
146 std::map<std::string,std::string>& attr)
148 std::string name =
"E:\\data-images\\dicoms\\CD1\\DICOM\\09112417\\37390000/31582235";
150 bool b =
mscan.IsKey(filename.c_str());
152 const gdcm::Scanner::TagToValue &mapping =
mscan.GetMapping(filename.c_str());
153 gdcm::Scanner::TagToValue::const_iterator it = mapping.begin();
155 std::map<std::string, std::string>::iterator i;
157 for (;it != mapping.end(); ++it)
159 sprintf(key,
"D%04x_%04x", it->first.GetGroup(), it->first.GetElement());
160 attr[key] =
irclean(it->second);
169 if ( attr.find(
"D0004_1500") != attr.end())
171 boost::filesystem::path full_path(filename);
172 std::string f = full_path.leaf().string();
173 attr[
"D0004_1500"] = f;
175 if ( attr.find(
"FullFileName")!= attr.end())
177 attr[
"FullFileName"] = filename;
179 if ( attr.find(
"FullFileDirectory" )!= attr.end())
181 std::string::size_type last_pos = filename.find_last_of(
"//");
183 attr[
"FullFileDirectory" ] = filename.substr(0, last_pos);
220 static std::string buffer;
224 const gdcm::ByteValue *bv = de.GetByteValue();
227 buffer = std::string( bv->GetPointer(), bv->GetLength() );
233 return buffer.c_str();