creaImageIO_lib
creaImageIO::ImageReader Class Reference

Generic image reader which uses all the specific concrete image reader of the lib (tif, jpg, dicom, ...) More...

#include <creaImageIOImageReader.h>

Inheritance diagram for creaImageIO::ImageReader:
Collaboration diagram for creaImageIO::ImageReader:

Public Member Functions

 ImageReader ()
 
 ~ImageReader ()
 
void PushBackExtensions (std::vector< std::string > &)
 Pushes back all kwown extensions (without dot) in the vector given. More...
 
bool CanRead (const std::string &filename)
 Returns true iff the file is readable. More...
 
vtkImageData * ReadImage (const std::string &filename)
 
void ReadAttributes (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 Register (boost::shared_ptr< AbstractImageReader >)
 Register a reader. More...
 
bool ShallNotRead (const std::string &filename)
 
void UnRegister (const std::string i_val)
 
void SetName (const std::string &s)
 Set the reader's name. More...
 

Protected Attributes

std::vector< boost::shared_ptr
< AbstractImageReader > > 
mReader
 
vtkImageData * mUnreadableImage
 
std::string mLastFilename
 
boost::shared_ptr
< AbstractImageReader
mLastReader
 
std::vector< std::string > mUnReader
 

Detailed Description

Generic image reader which uses all the specific concrete image reader of the lib (tif, jpg, dicom, ...)

Definition at line 43 of file creaImageIOImageReader.h.

Constructor & Destructor Documentation

creaImageIO::ImageReader::ImageReader ( )

Definition at line 55 of file creaImageIOImageReader.cpp.

References mUnreadableImage, Register(), and UnRegister().

56  :
58  mLastFilename("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
59  {
60  // std::cout << "#### ImageReader::ImageReader()"<<std::endl;
61  if (mUnreadableImage!=0) return;
62 
63 
64  Register( boost::shared_ptr<AbstractImageReader>(new VtkImageReader(vtkPNGReader::New() , "PNG", ".png")));
65  Register(boost::shared_ptr<AbstractImageReader>(new VtkImageReader(vtkTIFFReader::New(), "TIFF", ".tiff")));
66  Register(boost::shared_ptr<AbstractImageReader>(new VtkImageReader(vtkJPEGReader::New(), "JPEG", ".jpeg")));
67  Register(boost::shared_ptr<AbstractImageReader>(new VtkImageReader(vtkBMPReader::New(), "BMP", ".bmp")));
68  Register(boost::shared_ptr<AbstractImageReader>(new VtkImageReader(vtkSLCReader::New())));
69  Register(boost::shared_ptr<AbstractImageReader>(new VtkImageReader(vtkMetaImageReader::New(),"MHD",".mhd")));
70  // Register(new VtkImageReader(vtkGESignalReader::New()));
71  Register(boost::shared_ptr<AbstractImageReader>(new DicomImageReader));
72  Register(boost::shared_ptr<AbstractImageReader>(new UltrasonixImageReader));
73 
74  UnRegister(".txt");
75 
76  mUnreadableImage = vtkImageData::New();
77  int dim[3];
78  dim[0] = dim[1] = 128;
79  dim[2] = 1;
80  mUnreadableImage->SetDimensions ( dim );
81  mUnreadableImage->SetScalarTypeToUnsignedChar();
82  mUnreadableImage->AllocateScalars();
83  for (int i=0;i<dim[0];i++)
84  for (int j=0;j<dim[1];j++)
85  mUnreadableImage->SetScalarComponentFromFloat(i,j,0,0,0);
86  for (int i=0;i<dim[0];i++)
87  {
88  mUnreadableImage->SetScalarComponentFromFloat(i,i,0,0,255);
89  mUnreadableImage->SetScalarComponentFromFloat(dim[0]-1-i,i,0,0,255);
90  }
91  }

Here is the call graph for this function:

creaImageIO::ImageReader::~ImageReader ( )

Definition at line 95 of file creaImageIOImageReader.cpp.

References mUnreadableImage.

96  {
97 
98  // for (i=mReader.begin(); i!=mReader.end(); i++)
99  // {
100  //delete (*i);
101  // }
102 // mReader.clear();
103  if (mUnreadableImage!=0)
104  {
105  mUnreadableImage->Delete();
106  mUnreadableImage = 0;
107  }
108  }

Member Function Documentation

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

Returns true iff the file is readable.

Reimplemented from creaImageIO::AbstractImageReader.

Definition at line 148 of file creaImageIOImageReader.cpp.

References mLastFilename, mLastReader, mReader, and ShallNotRead().

Referenced by getAttributes(), creaImageIO::TreeHandlerImageAdder::IsHandledFile(), ReadAttributes(), creaImageIO::SimpleView::readDirectory(), creaImageIO::SimpleView::readFile(), and ReadImage().

149  {
150  bool ok = false;
151 
152  if( !ShallNotRead(filename))
153  {
154  return ok;
155  }
156  if(filename != "")
157  {
158  std::vector<boost::shared_ptr<AbstractImageReader> >::iterator i;
159  for (i=mReader.begin(); i!=mReader.end(); i++)
160  {
161  ok = (*i)->CanRead(filename);
162  if (ok)
163  {
164  mLastFilename = filename;
165  mLastReader = *i;
166  break;
167  }
168  }
169  }
170  return ok;
171  }

Here is the call graph for this function:

Here is the caller graph for this function:

void creaImageIO::ImageReader::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.

Exclude specific readers TO DO...

Reimplemented from creaImageIO::AbstractImageReader.

Definition at line 197 of file creaImageIOImageReader.cpp.

References CanRead(), mLastFilename, and mLastReader.

Referenced by creaImageIO::MultiThreadImageReader::getAttributes().

199  {
200  if (mLastFilename!=filename)
201  {
202  if (!CanRead(filename))
203  {
204  return;
205  }
206  }
207  mLastReader->getAttributes(filename, infos, i_attr);
208  }

Here is the call graph for this function:

Here is the caller graph for this function:

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:

void creaImageIO::ImageReader::PushBackExtensions ( std::vector< std::string > &  v)
virtual

Pushes back all kwown extensions (without dot) in the vector given.

Reimplemented from creaImageIO::AbstractImageReader.

Definition at line 227 of file creaImageIOImageReader.cpp.

References mReader.

228  {
229  std::vector<boost::shared_ptr<AbstractImageReader> >::iterator i;
230  for (i=mReader.begin(); i!=mReader.end(); i++)
231  {
232  (*i)->PushBackExtensions(v);
233  }
234  }
void creaImageIO::ImageReader::ReadAttributes ( const std::string &  filename,
tree::AttributeMapType attr 
)
virtual

Reads the attributes of the image. Requested attributes names are provided as keys in a string to string map On return, the values of the map are the values of the attributes (empty string if not available).

Reimplemented from creaImageIO::AbstractImageReader.

Definition at line 210 of file creaImageIOImageReader.cpp.

References CanRead(), mLastFilename, and mLastReader.

Referenced by creaImageIO::TreeHandlerImageAdder::AddFile(), creaImageIO::Synchronizer::AttributesMatch(), and creaImageIO::TreeHandlerImageAdder::CheckAttributes().

212  {
213  if (mLastFilename!=filename)
214  {
215  if (!CanRead(filename))
216  {
217  return;
218  }
219  }
220  mLastReader->ReadAttributes(mLastFilename,attr);
221  }

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reads and returns the image data. Returns an "Unreadable image" picture if fails

Reimplemented from creaImageIO::AbstractImageReader.

Definition at line 176 of file creaImageIOImageReader.cpp.

References CanRead(), mLastFilename, mLastReader, and mUnreadableImage.

Referenced by creaImageIO::MultiThreadImageReader::GetImage(), creaImageIO::ThreadedImageReader::Read(), creaImageIO::SimpleView::readDirectory(), creaImageIO::SimpleView::readFile(), and creaImageIO::MultiThreadImageReader::Request().

177  {
178  if (mLastFilename!=filename)
179  {
180  if (!CanRead(filename))
181  {
182  vtkImageData* im = vtkImageData::New();
183  im->ShallowCopy(mUnreadableImage);
184  return im;
185  }
186  }
187  vtkImageData* i = mLastReader->ReadImage(mLastFilename);
188  if (i==0)
189  {
190  i = vtkImageData::New();
191  i->ShallowCopy(mUnreadableImage);
192  }
193  return i;
194  }

Here is the call graph for this function:

Here is the caller graph for this function:

void creaImageIO::ImageReader::Register ( boost::shared_ptr< AbstractImageReader r)
protected

Register a reader.

Definition at line 112 of file creaImageIOImageReader.cpp.

References mReader.

Referenced by ImageReader().

113  {
114  mReader.push_back(r);
115 
116  }

Here is the caller graph for this function:

void creaImageIO::AbstractImageReader::SetName ( const std::string &  s)
inlineprotectedinherited
bool creaImageIO::ImageReader::ShallNotRead ( const std::string &  filename)
protected

Definition at line 127 of file creaImageIOImageReader.cpp.

References mUnReader.

Referenced by CanRead().

128  {
129  bool ok = true;
130  if(filename != "")
131  {
132  std::vector<std::string >::iterator i ;
133  for (i=mUnReader.begin(); i!=mUnReader.end(); i++)
134  {
135 
136  if ( (*i).c_str() == filename)
137  {
138  ok = false;
139  break;
140  }
141  }
142  }
143  return ok;
144  }

Here is the caller graph for this function:

void creaImageIO::ImageReader::UnRegister ( const std::string  i_val)
protected

Definition at line 118 of file creaImageIOImageReader.cpp.

References mUnReader.

Referenced by ImageReader().

119  {
120  mUnReader.push_back(i_val);
121 
122  }

Here is the caller graph for this function:

Member Data Documentation

std::string creaImageIO::ImageReader::mLastFilename
protected

Definition at line 82 of file creaImageIOImageReader.h.

Referenced by CanRead(), getAttributes(), ReadAttributes(), and ReadImage().

boost::shared_ptr<AbstractImageReader> creaImageIO::ImageReader::mLastReader
protected

Definition at line 83 of file creaImageIOImageReader.h.

Referenced by CanRead(), getAttributes(), ReadAttributes(), and ReadImage().

std::vector<boost::shared_ptr<AbstractImageReader> > creaImageIO::ImageReader::mReader
protected

Definition at line 79 of file creaImageIOImageReader.h.

Referenced by CanRead(), PushBackExtensions(), and Register().

vtkImageData* creaImageIO::ImageReader::mUnreadableImage
protected

Definition at line 80 of file creaImageIOImageReader.h.

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

std::vector<std::string> creaImageIO::ImageReader::mUnReader
protected

Definition at line 89 of file creaImageIOImageReader.h.

Referenced by ShallNotRead(), and UnRegister().


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