creaImageIO_lib
creaImageIO::DicomImageScanner Class Reference

Concrete image reader for DICOM images. More...

#include <creaImageIODicomScanner.h>

Public Member Functions

 DicomImageScanner ()
 
virtual ~DicomImageScanner ()
 
bool addDirectory (std::string &filename, std::map< std::string, std::string > &attr)
 Add file extensions read by the reader. More...
 
virtual vtkImageData * ReadImage (const std::string &filename)
 return for a file a 2D VTkImage More...
 
virtual void ReadAttributes (const std::string &filename, tree::AttributeMapType &attr)
 Read the attributes for a file. More...
 
void ReadAttributes2 (const std::string &filename, tree::AttributeMapType &attr)
 
std::string irclean (const std::string &str)
 

Private Member Functions

const std::string GetStringValueFromTag (const gdcm::DataElement &ds)
 

Private Attributes

vtkGDCMImageReader * mReader
 
gdcm::Scanner mscan
 
bool b_loaded
 

Detailed Description

Concrete image reader for DICOM images.

Definition at line 53 of file creaImageIODicomScanner.h.

Constructor & Destructor Documentation

creaImageIO::DicomImageScanner::DicomImageScanner ( )

Definition at line 46 of file creaImageIODicomScanner.cpp.

References b_loaded, mReader, and mscan.

47  {
48  mReader = vtkGDCMImageReader::New();
49  mscan.ClearTags();
50  b_loaded = false;
51  };
creaImageIO::DicomImageScanner::~DicomImageScanner ( )
virtual

Definition at line 55 of file creaImageIODicomScanner.cpp.

References mReader.

56  {
57  mReader->Delete();
58  }

Member Function Documentation

bool creaImageIO::DicomImageScanner::addDirectory ( std::string &  filename,
std::map< std::string, std::string > &  attr 
)

Add file extensions read by the reader.

Definition at line 62 of file creaImageIODicomScanner.cpp.

References b_loaded, creaImageIO::tree::AttributeDescriptor::GetDicomGroupElementFromKey(), and mscan.

63  {
64  if(!b_loaded)
65  {
66  mscan.ClearTags();
67  std::map<std::string,std::string>::iterator i;
68  int j= 0;
69  for (i=attr.begin();i!=attr.end();++i, j++)
70  {
71  if ( i->first == "D0004_1500" || i->first == "FullFileName" || i->first == "FullFileDirectory" )
72  {
73 
74  }
75  else
76  {
77  uint16_t el;
78  uint16_t gr;
79 
81  mscan.AddTag(gdcm::Tag(gr,el) );
82 
83  }
84  }
85  b_loaded = true;
86  }
87  gdcm::Directory d;
88 
89  boost::algorithm::replace_all(filename,"\\", "/");
90  d.Load(filename.c_str(),true);
91  mscan.Scan(d.GetFilenames());
92 
93  return true;
94 
95  }

Here is the call graph for this function:

const std::string creaImageIO::DicomImageScanner::GetStringValueFromTag ( const gdcm::DataElement &  ds)
private

Definition at line 218 of file creaImageIODicomScanner.cpp.

219 {
220  static std::string buffer;
221  buffer = ""; // cleanup previous call
222 
223 
224  const gdcm::ByteValue *bv = de.GetByteValue();
225  if( bv ) // Can be Type 2
226  {
227  buffer = std::string( bv->GetPointer(), bv->GetLength() );
228  // Will be padded with at least one \0
229  }
230 
231 
232  // Since return is a const char* the very first \0 will be considered
233  return buffer.c_str();
234 }
std::string creaImageIO::DicomImageScanner::irclean ( const std::string &  str)

Definition at line 121 of file creaImageIODicomScanner.cpp.

Referenced by ReadAttributes().

122  {
123  if(str.size() > 0)
124  {
125  if (str == "GDCM::Unfound")
126  {
127  return "";
128  }
129  if (str[str.size()-1]==' ')
130  {
131  return irclean(str.substr(0,str.size()-1));
132  }
133  if (str[str.size()-1]==0)
134  {
135  return irclean(str.substr(0,str.size()-1));
136  }
137  }
138 
139  return str;
140  }

Here is the caller graph for this function:

void creaImageIO::DicomImageScanner::ReadAttributes ( const std::string &  filename,
tree::AttributeMapType attr 
)
virtual

Read the attributes for a file.

Definition at line 145 of file creaImageIODicomScanner.cpp.

References irclean(), and mscan.

147  {
148  std::string name = "E:\\data-images\\dicoms\\CD1\\DICOM\\09112417\\37390000/31582235";
149 
150  bool b = mscan.IsKey(filename.c_str());
151  if( b ) {
152  const gdcm::Scanner::TagToValue &mapping = mscan.GetMapping(filename.c_str());
153  gdcm::Scanner::TagToValue::const_iterator it = mapping.begin();
154 
155  std::map<std::string, std::string>::iterator i;
156 
157  for (;it != mapping.end(); ++it)
158  { char key[12] ;
159  sprintf(key,"D%04x_%04x", it->first.GetGroup(), it->first.GetElement());
160  attr[key] = irclean(it->second);
161  }
162 
163 
164  /*
165 
166 
167  for (i=attr.begin();i!=attr.end();++i, j++)
168  {*/
169  if ( attr.find("D0004_1500") != attr.end())
170  {
171  boost::filesystem::path full_path(filename);
172  std::string f = full_path.leaf().string();
173  attr["D0004_1500"] = f;
174  }
175  if ( attr.find("FullFileName")!= attr.end())
176  {
177  attr["FullFileName"] = filename;
178  }
179  if ( attr.find("FullFileDirectory" )!= attr.end())
180  {
181  std::string::size_type last_pos = filename.find_last_of("//");
182  //find first separator
183  attr["FullFileDirectory" ] = filename.substr(0, last_pos);
184  }
185  // else
186  // {
187 
188  // uint16_t el;
189  // uint16_t gr;
190 
191  // tree::AttributeDescriptor::GetDicomGroupElementFromKey(i->first,gr,el);
192 
193  // mscan.AddTag(gdcm::Tag(gr,el) );
194 
195  // // const char *value = it->second;
196  // i->second = irclean(it->second);
197  // ++it;
198  // }
199  //}
200  }
201 }

Here is the call graph for this function:

void creaImageIO::DicomImageScanner::ReadAttributes2 ( const std::string &  filename,
tree::AttributeMapType attr 
)
vtkImageData * creaImageIO::DicomImageScanner::ReadImage ( const std::string &  filename)
virtual

return for a file a 2D VTkImage

Definition at line 99 of file creaImageIODicomScanner.cpp.

References mReader.

100  {
101  vtkImageData* im = 0;
102  try
103  {
104  mReader->SetFileName(filename.c_str());
105  mReader->Update();
106  im = vtkImageData::New();
107  im->ShallowCopy(mReader->GetOutput());
108  }
109  catch (...)
110  {
111  if (im!=0) im->Delete();
112  im = 0;
113  }
114  return im;
115  }

Member Data Documentation

bool creaImageIO::DicomImageScanner::b_loaded
private

Definition at line 75 of file creaImageIODicomScanner.h.

Referenced by addDirectory(), and DicomImageScanner().

vtkGDCMImageReader* creaImageIO::DicomImageScanner::mReader
private

Definition at line 73 of file creaImageIODicomScanner.h.

Referenced by DicomImageScanner(), ReadImage(), and ~DicomImageScanner().

gdcm::Scanner creaImageIO::DicomImageScanner::mscan
private

Definition at line 74 of file creaImageIODicomScanner.h.

Referenced by addDirectory(), DicomImageScanner(), and ReadAttributes().


The documentation for this class was generated from the following files: