creaImageIO_lib
creaImageIO::DicomImageReader Class Reference

Concrete image reader for DICOM images. More...

#include <creaImageIODicomImageReader.h>

Inheritance diagram for creaImageIO::DicomImageReader:
Collaboration diagram for creaImageIO::DicomImageReader:

Classes

struct  deleter
 

Public Member Functions

 DicomImageReader ()
 
virtual ~DicomImageReader ()
 
virtual void PushBackExtensions (std::vector< std::string > &)
 Add file extensions read by the reader. More...
 
virtual bool CanRead (const std::string &filename)
 Test if file is read by this 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 getAttributes (const std::string filename, std::map< std::string, std::string > &infos, std::vector< std::string > i_attr)
 Another function to read attributes for a file. More...
 
 DicomImageReader ()
 
virtual ~DicomImageReader ()
 
virtual void PushBackExtensions (std::vector< std::string > &)
 Add file extensions read by the reader. More...
 
virtual bool CanRead (const std::string &filename)
 Test if file is read by this 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)
 
void getAttributes (const std::string filename, std::map< std::string, std::string > &infos, std::vector< std::string > i_attr)
 Another function to read attributes for a file. More...
 
const std::string & GetName () const
 Get the reader's name. More...
 

Protected Member Functions

void SetName (const std::string &s)
 Set the reader's name. More...
 

Private Member Functions

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

Private Attributes

vtkGdcmReader * mReader
 
vtkGDCMImageReader * mReader
 
gdcm::Scanner mscan
 
bool b_loaded
 

Friends

struct deleter
 

Detailed Description

Concrete image reader for DICOM images.

Definition at line 48 of file creaImageIODicomImageReader.h.

Constructor & Destructor Documentation

creaImageIO::DicomImageReader::DicomImageReader ( )

Definition at line 44 of file creaImageIODicomImageReader.cpp.

References mReader, and creaImageIO::AbstractImageReader::SetName().

45  {
46  mReader = vtkGdcmReader::New();
47 
48 //EED 21 mars 2012 FLIP probleme ..PLOP..
49  mReader->SetFlipY(false);
50 
51  SetName ( "Dicom" );
52 
53  };

Here is the call graph for this function:

creaImageIO::DicomImageReader::~DicomImageReader ( )
virtual

Definition at line 57 of file creaImageIODicomImageReader.cpp.

References mReader.

58  {
59  mReader->Delete();
60  }
creaImageIO::DicomImageReader::DicomImageReader ( )
virtual creaImageIO::DicomImageReader::~DicomImageReader ( )
virtual

Member Function Documentation

bool creaImageIO::DicomImageReader::CanRead ( const std::string &  filename)
virtual

Test if file is read by this reader.

Reimplemented from creaImageIO::AbstractImageReader.

Definition at line 64 of file creaImageIODicomImageReader.cpp.

65  {
66  GDCM_NAME_SPACE::Document*doc;
67  GDCM_NAME_SPACE::File* file = GDCM_NAME_SPACE::File::New();
68  file->SetLoadMode( GDCM_NAME_SPACE::LD_ALL);
69  file->SetFileName(filename.c_str());
70  file->Load();
71  bool ok = file->IsReadable();
72  if(!ok)
73  {
74  doc = (GDCM_NAME_SPACE::Document*)file;
75  ok = doc->IsReadable();
76  }
77  file->Delete();
78  return ok;
79  }
virtual bool creaImageIO::DicomImageReader::CanRead ( const std::string &  filename)
virtual

Test if file is read by this reader.

Reimplemented from creaImageIO::AbstractImageReader.

void creaImageIO::DicomImageReader::getAttributes ( const std::string  filename,
std::map< std::string, std::string > &  infos,
std::vector< std::string >  i_attr 
)
virtual

Another function to read attributes for a file.

Reimplemented from creaImageIO::AbstractImageReader.

Definition at line 131 of file creaImageIODicomImageReader.cpp.

References ReadAttributes().

133  {
134  std::vector<std::string>::iterator it = i_attr.begin();
135  for(; it != i_attr.end(); it++)
136  {
137  infos[(*it)] = "";
138  }
139  ReadAttributes(filename, infos);
140  }

Here is the call graph for this function:

void creaImageIO::DicomImageReader::getAttributes ( const std::string  filename,
std::map< std::string, std::string > &  infos,
std::vector< std::string >  i_attr 
)
virtual

Another function to read attributes for a file.

Reimplemented from creaImageIO::AbstractImageReader.

const std::string& creaImageIO::AbstractImageReader::GetName ( ) const
inlineinherited

Get the reader's name.

Definition at line 56 of file creaImageIOAbstractImageReader.h.

References creaImageIO::AbstractImageReader::mName.

Referenced by creaImageIO::VtkImageReader::ReadImage().

56 { return mName; }

Here is the caller graph for this function:

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

Definition at line 268 of file creaImageIODicomImageReader2.cpp.

269 {
270  static std::string buffer;
271  buffer = ""; // cleanup previous call
272 
273 
274  const gdcm::ByteValue *bv = de.GetByteValue();
275  if( bv ) // Can be Type 2
276  {
277  buffer = std::string( bv->GetPointer(), bv->GetLength() );
278  // Will be padded with at least one \0
279  }
280 
281  // Since return is a const char* the very first \0 will be considered
282  return buffer.c_str();
283 }
void creaImageIO::DicomImageReader::PushBackExtensions ( std::vector< std::string > &  v)
virtual

Add file extensions read by the reader.

Reimplemented from creaImageIO::AbstractImageReader.

Definition at line 102 of file creaImageIODicomImageReader.cpp.

103  {
104  v.push_back("dcm");
105  v.push_back("");
106  }
virtual void creaImageIO::DicomImageReader::PushBackExtensions ( std::vector< std::string > &  )
virtual

Add file extensions read by the reader.

Reimplemented from creaImageIO::AbstractImageReader.

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

Read the attributes for a file.

Reimplemented from creaImageIO::AbstractImageReader.

Definition at line 142 of file creaImageIODicomImageReader.cpp.

References creaImageIO::tree::AttributeDescriptor::GetDicomGroupElementFromKey(), GimmickMessage, and creaImageIO::irclean().

Referenced by getAttributes().

144  {
145  GimmickMessage(2,"Reading attributes from DICOM file '"
146  <<filename<<"'"<<std::endl);
147 
148  GDCM_NAME_SPACE::File* file = GDCM_NAME_SPACE::File::New();
149  //boost::shared_ptr<GDCM_NAME_SPACE::File> file(GDCM_NAME_SPACE::File::New());//, DicomImageReader::deleter());
150 
151  GDCM_NAME_SPACE::Document *doc= GDCM_NAME_SPACE::File::New();
152  doc->SetLoadMode( GDCM_NAME_SPACE::LD_ALL);
153  doc->SetFileName(filename.c_str());
154  doc->Load();
155  file->SetLoadMode( GDCM_NAME_SPACE::LD_ALL);
156  file->SetFileName(filename.c_str());
157  file->Load();
158  if (file->IsReadable())// ||((GDCM_NAME_SPACE::Document*) file)->IsReadable())
159  {
160  std::map<std::string,std::string>::iterator i;
161  for (i=attr.begin();i!=attr.end();++i)
162  {
163  if ( i->first == "D0004_1500" )
164  {
165  boost::filesystem::path full_path(filename);
166  std::string f = full_path.leaf().string();
167  i->second = f;
168  }
169  else if ( i->first == "FullFileName" )
170  {
171  i->second = filename;
172  }
173  else if ( i->first == "FullFileDirectory" )
174  {
175  std::string::size_type last_pos = filename.find_last_of("//");
176  //find first separator
177  i->second = filename.substr(0, last_pos);
178  }
179  else
180  {
181  uint16_t el;
182  uint16_t gr;
183 
185  if ( ( gr!=0 ) && ( el!=0 ) )
186  {
187  std::string val = file->GetEntryString(gr,el);
188  i->second = irclean(val);
189  }
190  }
191  }
192  }
193  }

Here is the call graph for this function:

Here is the caller graph for this function:

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

Read the attributes for a file.

Reimplemented from creaImageIO::AbstractImageReader.

void creaImageIO::DicomImageReader::ReadAttributes2 ( const std::string &  filename,
tree::AttributeMapType attr 
)

Definition at line 212 of file creaImageIODicomImageReader2.cpp.

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

214  {
215  if(!b_loaded)
216  {
217  std::map<std::string,std::string>::iterator i;
218  for (i=attr.begin();i!=attr.end();++i)
219  {
220  if ( i->first == "D0004_1500" || i->first == "FullFileName" || i->first == "FullFileDirectory" )
221  {
222 
223  }
224  else
225  {
226  uint16_t el;
227  uint16_t gr;
228 
230  mscan.AddTag(gdcm::Tag(gr,el) );
231  }
232  }
233  b_loaded = true;
234  }
235  bool b = mscan.IsKey(filename.c_str());
236  if( b )
237  {
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)
242  {
243  if ( i->first == "D0004_1500" )
244  {
245  boost::filesystem::path full_path(filename);
246  std::string f = full_path.leaf().string();
247  i->second = f;
248  }
249  else if ( i->first == "FullFileName" )
250  {
251  i->second = filename;
252  }
253  else if ( i->first == "FullFileDirectory" )
254  {
255  std::string::size_type last_pos = filename.find_last_of("//");
256  //find first separator
257  i->second = filename.substr(0, last_pos);
258  }
259  else
260  {
261  const char *value = it->second;
262  i->second = irclean(it->second);
263  }
264  }
265  }
266 }

Here is the call graph for this function:

vtkImageData * creaImageIO::DicomImageReader::ReadImage ( const std::string &  filename)
virtual

return for a file a 2D VTkImage

Reimplemented from creaImageIO::AbstractImageReader.

Definition at line 83 of file creaImageIODicomImageReader.cpp.

References mReader.

84  {
85  vtkImageData* im = 0;
86  try
87  {
88  mReader->SetFileName(filename.c_str());
89  mReader->Update();
90  im = vtkImageData::New();
91  im->ShallowCopy(mReader->GetOutput());
92  }
93  catch (...)
94  {
95  if (im!=0) im->Delete();
96  im = 0;
97  }
98  return im;
99  }
virtual vtkImageData* creaImageIO::DicomImageReader::ReadImage ( const std::string &  filename)
virtual

return for a file a 2D VTkImage

Reimplemented from creaImageIO::AbstractImageReader.

void creaImageIO::AbstractImageReader::SetName ( const std::string &  s)
inlineprotectedinherited

Set the reader's name.

Definition at line 79 of file creaImageIOAbstractImageReader.h.

References creaImageIO::AbstractImageReader::mName.

Referenced by DicomImageReader(), creaImageIO::UltrasonixImageReader::UltrasonixImageReader(), and creaImageIO::VtkImageReader::VtkImageReader().

79 { mName = s; }

Here is the caller graph for this function:

Friends And Related Function Documentation

deleter
friend

Definition at line 73 of file creaImageIODicomImageReader.h.

Member Data Documentation

bool creaImageIO::DicomImageReader::b_loaded
private

Definition at line 77 of file creaImageIODicomImageReader2.h.

Referenced by ReadAttributes2().

vtkGdcmReader* creaImageIO::DicomImageReader::mReader
private

Definition at line 68 of file creaImageIODicomImageReader.h.

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

vtkGDCMImageReader* creaImageIO::DicomImageReader::mReader
private

Definition at line 75 of file creaImageIODicomImageReader2.h.

gdcm::Scanner creaImageIO::DicomImageReader::mscan
private

Definition at line 76 of file creaImageIODicomImageReader2.h.

Referenced by ReadAttributes2().


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