Public Member Functions | Protected Member Functions | Protected Attributes

creaImageIO::ImageReader Class Reference
[Image I/O classes]

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:
Inheritance graph
[legend]
Collaboration diagram for creaImageIO::ImageReader:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ImageReader ()
 ~ImageReader ()
void PushBackExtensions (std::vector< std::string > &)
 Pushes back all kwown extensions (without dot) in the vector given.
bool CanRead (const std::string &filename)
 Returns true iff the file is readable.
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.
const std::string & GetName () const
 Get the reader's name.

Protected Member Functions

void Register (boost::shared_ptr< AbstractImageReader >)
 Register a reader.
bool ShallNotRead (const std::string &filename)
void UnRegister (const std::string i_val)
void SetName (const std::string &s)
 Set the reader's name.

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 15 of file creaImageIOImageReader.h.


Constructor & Destructor Documentation

creaImageIO::ImageReader::ImageReader (  ) 

Definition at line 27 of file creaImageIOImageReader.cpp.

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

    :   
    mUnreadableImage(0),
    mLastFilename("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
  {
    //    std::cout << "#### ImageReader::ImageReader()"<<std::endl;
    if (mUnreadableImage!=0) return;
        
    Register( boost::shared_ptr<AbstractImageReader>(new VtkImageReader(vtkPNGReader::New(), "PNG", ".png")));
    Register(boost::shared_ptr<AbstractImageReader>(new VtkImageReader(vtkTIFFReader::New(), "JPEG", ".jpeg")));
    Register(boost::shared_ptr<AbstractImageReader>(new VtkImageReader(vtkJPEGReader::New())));
    Register(boost::shared_ptr<AbstractImageReader>(new VtkImageReader(vtkBMPReader::New())));
    Register(boost::shared_ptr<AbstractImageReader>(new VtkImageReader(vtkSLCReader::New())));
    Register(boost::shared_ptr<AbstractImageReader>(new VtkImageReader(vtkMetaImageReader::New(),"MHD",".mhd")));
    //   Register(new VtkImageReader(vtkGESignalReader::New()));
    Register(boost::shared_ptr<AbstractImageReader>(new DicomImageReader));
    Register(boost::shared_ptr<AbstractImageReader>(new UltrasonixImageReader));

        UnRegister(".txt");
 
    mUnreadableImage = vtkImageData::New();
    int dim[3];
    dim[0] = dim[1] = 128; 
    dim[2] = 1; 
    mUnreadableImage->SetDimensions ( dim );
    mUnreadableImage->SetScalarTypeToUnsignedChar();
    mUnreadableImage->AllocateScalars();    
    for (int i=0;i<dim[0];i++) 
      for (int j=0;j<dim[1];j++) 
        mUnreadableImage->SetScalarComponentFromFloat(i,j,0,0,0);
    for (int i=0;i<dim[0];i++) 
      {
        mUnreadableImage->SetScalarComponentFromFloat(i,i,0,0,255);
        mUnreadableImage->SetScalarComponentFromFloat(dim[0]-1-i,i,0,0,255);
      }
  }

Here is the call graph for this function:

creaImageIO::ImageReader::~ImageReader (  ) 

Definition at line 66 of file creaImageIOImageReader.cpp.

References mUnreadableImage.

  {

 //   for (i=mReader.begin(); i!=mReader.end(); i++)
 //     {
        //delete (*i);
 //     }
//    mReader.clear();
    if (mUnreadableImage!=0) 
      {
        mUnreadableImage->Delete();
        mUnreadableImage = 0;
      }
  }


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 119 of file creaImageIOImageReader.cpp.

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

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

  {
    bool ok = false;

        if( !ShallNotRead(filename))
        {
                return ok;
        }
        if(filename != "")
        {
                std::vector<boost::shared_ptr<AbstractImageReader> >::iterator i;
                for (i=mReader.begin(); i!=mReader.end(); i++)
                {
                        ok = (*i)->CanRead(filename);
                        if (ok) 
                        {
                                mLastFilename = filename;
                                mLastReader = *i;
                                break;
                        }
                }
        }
        return ok;
  }

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 168 of file creaImageIOImageReader.cpp.

References CanRead(), mLastFilename, and mLastReader.

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

  {
           if (mLastFilename!=filename)
      {
        if (!CanRead(filename)) 
          { 
            return;
          }
      }
    mLastReader->getAttributes(filename, infos, i_attr);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

const std::string& creaImageIO::AbstractImageReader::GetName (  )  const [inline, inherited]

Get the reader's name.

Definition at line 16 of file creaImageIOAbstractImageReader.h.

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

{

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 198 of file creaImageIOImageReader.cpp.

References mReader.

  {
          std::vector<boost::shared_ptr<AbstractImageReader> >::iterator i;
    for (i=mReader.begin(); i!=mReader.end(); i++)
      {
        (*i)->PushBackExtensions(v);
      }
  }

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.

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

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 147 of file creaImageIOImageReader.cpp.

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

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

  {
          if (mLastFilename!=filename)
      {
        if (!CanRead(filename))  
          { 
            vtkImageData* im = vtkImageData::New();
            im->ShallowCopy(mUnreadableImage);
            return im;
          }
      }
    vtkImageData* i = mLastReader->ReadImage(mLastFilename);
    if (i==0) 
      {
        i = vtkImageData::New();
        i->ShallowCopy(mUnreadableImage);
      }
    return i;
  }

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 83 of file creaImageIOImageReader.cpp.

References mReader.

Referenced by ImageReader().

  {
    mReader.push_back(r);

  }

Here is the caller graph for this function:

void creaImageIO::AbstractImageReader::SetName ( const std::string &  s  )  [inline, protected, inherited]
bool creaImageIO::ImageReader::ShallNotRead ( const std::string &  filename  )  [protected]

Definition at line 98 of file creaImageIOImageReader.cpp.

References mUnReader.

Referenced by CanRead().

  {
    bool ok = true;
        if(filename != "")
        {
                std::vector<std::string >::iterator i ;
                for (i=mUnReader.begin(); i!=mUnReader.end(); i++)
                {
                        
                        if ( (*i).c_str() == filename) 
                        {
                                ok = false;
                                break;
                        }
                }
        }
        return ok;
  }

Here is the caller graph for this function:

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

Definition at line 89 of file creaImageIOImageReader.cpp.

References mUnReader.

Referenced by ImageReader().

  {
    mUnReader.push_back(i_val);

  }

Here is the caller graph for this function:


Member Data Documentation

std::string creaImageIO::ImageReader::mLastFilename [protected]

Definition at line 54 of file creaImageIOImageReader.h.

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

Definition at line 55 of file creaImageIOImageReader.h.

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

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

Definition at line 51 of file creaImageIOImageReader.h.

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

vtkImageData* creaImageIO::ImageReader::mUnreadableImage [protected]

Definition at line 52 of file creaImageIOImageReader.h.

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

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

Definition at line 61 of file creaImageIOImageReader.h.

Referenced by ShallNotRead(), and UnRegister().


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