Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes

mitk::RawImageFileReader Class Reference

Reader to read raw image files. More...

#include <mitkRawImageFileReader.h>

Inheritance diagram for mitk::RawImageFileReader:
Inheritance graph
[legend]
Collaboration diagram for mitk::RawImageFileReader:
Collaboration graph
[legend]

List of all members.

Public Types

enum  IOPixelType {
  UCHAR, SCHAR, USHORT, SSHORT,
  UINT, SINT, FLOAT, DOUBLE
}
enum  EndianityType { LITTLE, BIG }
typedef RawImageFileReader Self
typedef FileReader Superclass
typedef itk::SmartPointer< SelfPointer
typedef itk::SmartPointer
< const Self
ConstPointer

Public Member Functions

virtual const char * GetClassName () const
virtual void SetFileName (std::string _arg)
virtual void SetFileName (const char *_arg)
 Specify the file to load.
virtual std::string GetFileName ()
virtual const char * GetFileName () const
 Get the specified the file to load.
virtual void SetFilePrefix (std::string _arg)
virtual void SetFilePrefix (const char *_arg)
 Specify file prefix for the file(s) to load.
virtual std::string GetFilePrefix ()
virtual const char * GetFilePrefix () const
 Get the specified file prefix for the file(s) to load.
virtual void SetFilePattern (std::string _arg)
virtual void SetFilePattern (const char *_arg)
 Specified file pattern for the file(s) to load. The sprintf format used to build filename from FilePrefix and number.
virtual std::string GetFilePattern ()
virtual const char * GetFilePattern () const
 Get the specified file pattern for the file(s) to load. The sprintf format used to build filename from FilePrefix and number.
virtual void SetPixelType (IOPixelType _arg)
virtual void SetEndianity (EndianityType _arg)
virtual void SetDimensionality (int _arg)
virtual int GetDimensionality ()
void SetDimensions (unsigned int i, unsigned int dim)
unsigned int GetDimensions (unsigned int i) const

Static Public Member Functions

static Pointer New ()
static bool CanReadFile (const std::string filename, const std::string filePrefix, const std::string filePattern)

Protected Member Functions

 RawImageFileReader ()
 ~RawImageFileReader ()
virtual void GenerateData ()
 A version of GenerateData() specific for image processing filters.
template<typename TPixel , unsigned int VImageDimensions>
void TypedGenerateData ()

Protected Attributes

std::string m_FileName
std::string m_FilePrefix
std::string m_FilePattern
IOPixelType m_PixelType
int m_Dimensionality
EndianityType m_Endianity
itk::Vector< int, 3 > m_Dimensions

Detailed Description

Reader to read raw image files.

The user must set the dimensionality, the dimensions and the pixel type. If they are incorrect, the image will not be opened or the visualization will be incorrect.

Definition at line 33 of file mitkRawImageFileReader.h.


Member Typedef Documentation

typedef itk::SmartPointer<const Self> mitk::RawImageFileReader::ConstPointer

Definition at line 36 of file mitkRawImageFileReader.h.

typedef itk::SmartPointer<Self> mitk::RawImageFileReader::Pointer

Definition at line 36 of file mitkRawImageFileReader.h.

Definition at line 36 of file mitkRawImageFileReader.h.

Definition at line 36 of file mitkRawImageFileReader.h.


Member Enumeration Documentation

Endianity of bits.

Enumerator:
LITTLE 
BIG 

Definition at line 61 of file mitkRawImageFileReader.h.

Supported pixel types.

Enumerator:
UCHAR 
SCHAR 
USHORT 
SSHORT 
UINT 
SINT 
FLOAT 
DOUBLE 

Definition at line 57 of file mitkRawImageFileReader.h.


Constructor & Destructor Documentation

mitk::RawImageFileReader::RawImageFileReader (  ) [protected]

Definition at line 26 of file mitkRawImageFileReader.cpp.

    : m_FileName(""), m_FilePrefix(""), m_FilePattern("")
{
}
mitk::RawImageFileReader::~RawImageFileReader (  ) [protected]

Definition at line 31 of file mitkRawImageFileReader.cpp.

{
}

Member Function Documentation

bool mitk::RawImageFileReader::CanReadFile ( const std::string  filename,
const std::string  filePrefix,
const std::string  filePattern 
) [static]

Definition at line 51 of file mitkRawImageFileReader.cpp.

{
  // First check the extension
  if(  filename == "" )
    return false;

  // check if image is serie
  if( filePattern != "" && filePrefix != "" )
    return false;

  return true;
}
void mitk::RawImageFileReader::GenerateData (  ) [protected, virtual]

A version of GenerateData() specific for image processing filters.

This implementation will split the processing across multiple threads. The buffer is allocated by this method. Then the BeforeThreadedGenerateData() method is called (if provided). Then, a series of threads are spawned each calling ThreadedGenerateData(). After all the threads have completed processing, the AfterThreadedGenerateData() method is called (if provided). If an image processing filter cannot be threaded, the filter should provide an implementation of GenerateData(). That implementation is responsible for allocating the output buffer. If a filter an be threaded, it should NOT provide a GenerateData() method but should provide a ThreadedGenerateData() instead.

See also:
ThreadedGenerateData()

Reimplemented from mitk::ImageSource.

Definition at line 64 of file mitkRawImageFileReader.cpp.

References MITK_INFO.

{
  mitk::Image::Pointer output = this->GetOutput();
  
  if (this->GetOutput()==NULL)
  {
    MITK_INFO << "Error" << std::endl;
  }

  // Check to see if we can read the file given the name or prefix
  if ( m_FileName == "" )
  {
    itkWarningMacro( << "File Type not supported!" );
    return ;
  }

  // check file dimensionality and pixel type and perform reading according to it
  if (m_Dimensionality == 2)
  {
         if (m_PixelType == SCHAR) TypedGenerateData<signed char, 2 >();
    else if (m_PixelType == UCHAR) TypedGenerateData<unsigned char, 2 >();
    else if (m_PixelType == SSHORT) TypedGenerateData<signed short int, 2 >();
    else if (m_PixelType == USHORT) TypedGenerateData<unsigned short int, 2 >();
    else if (m_PixelType == UINT)   TypedGenerateData<unsigned int, 2 >();
    else if (m_PixelType == SINT)   TypedGenerateData<signed int, 2 >();
    else if (m_PixelType == FLOAT)  TypedGenerateData<float, 2 >();
    else if (m_PixelType == DOUBLE) TypedGenerateData<double, 2 >();
    else
    {
      MITK_INFO << "Error while reading raw file: Dimensionality or pixel type not supported or not properly set" << std::endl;
      return;
    }
   }
  else if (m_Dimensionality==3)
  {
         if (m_PixelType == SCHAR) TypedGenerateData<signed char, 3 >();
    else if (m_PixelType == UCHAR) TypedGenerateData<unsigned char, 3 >();
    else if (m_PixelType == SSHORT) TypedGenerateData<signed short int, 3 >();
    else if (m_PixelType == USHORT) TypedGenerateData<unsigned short int, 3 >();
    else if (m_PixelType == UINT)   TypedGenerateData<unsigned int, 3 >();
    else if (m_PixelType == SINT)   TypedGenerateData<signed int, 3 >();
    else if (m_PixelType == FLOAT)  TypedGenerateData<float, 3 >();
    else if (m_PixelType == DOUBLE) TypedGenerateData<double, 3 >();
    else
    {
      MITK_INFO << "Error while reading raw file: Dimensionality or pixel type not supported or not properly set" << std::endl;
      return;
    }
  }  
  else
  {
    MITK_INFO << "Error while reading raw file: Dimensionality not supported" << std::endl;
    return;
      
  }   
      
  MITK_INFO << "...reading raw finished!" << std::endl;
}
virtual const char* mitk::RawImageFileReader::GetClassName (  ) const [virtual]
virtual int mitk::RawImageFileReader::GetDimensionality (  ) [virtual]
unsigned int mitk::RawImageFileReader::GetDimensions ( unsigned int  i ) const

Definition at line 44 of file mitkRawImageFileReader.cpp.

{
  if ( i > 2 ) return 0;

  return m_Dimensions[i];
}
virtual std::string mitk::RawImageFileReader::GetFileName (  ) [virtual]
virtual const char* mitk::RawImageFileReader::GetFileName (  ) const [virtual]

Get the specified the file to load.

Either the FileName or FilePrefix plus FilePattern are used to read.

Implements mitk::FileReader.

virtual std::string mitk::RawImageFileReader::GetFilePattern (  ) [virtual]
virtual const char* mitk::RawImageFileReader::GetFilePattern (  ) const [virtual]

Get the specified file pattern for the file(s) to load. The sprintf format used to build filename from FilePrefix and number.

You should specify either a FileName or FilePrefix. Use FilePrefix if the data is stored in multiple files.

Implements mitk::FileReader.

virtual std::string mitk::RawImageFileReader::GetFilePrefix (  ) [virtual]
virtual const char* mitk::RawImageFileReader::GetFilePrefix (  ) const [virtual]

Get the specified file prefix for the file(s) to load.

You should specify either a FileName or FilePrefix. Use FilePrefix if the data is stored in multiple files.

Implements mitk::FileReader.

static Pointer mitk::RawImageFileReader::New (  ) [static]

Method for creation through the object factory.

Reimplemented from mitk::ImageSource.

Referenced by mitkRawImageFileReaderTest().

virtual void mitk::RawImageFileReader::SetDimensionality ( int  _arg ) [virtual]
void mitk::RawImageFileReader::SetDimensions ( unsigned int  i,
unsigned int  dim 
)

Image dimensions must be set one by one, starting from dimension 0.

Definition at line 35 of file mitkRawImageFileReader.cpp.

{ 
  if ( i > 2 ) return;

  this->Modified();               // TODO: this order (first modified, then set the variable) is intended??
  m_Dimensions[i] = dim;
}
virtual void mitk::RawImageFileReader::SetEndianity ( EndianityType  _arg ) [virtual]
virtual void mitk::RawImageFileReader::SetFileName ( const char *  aFileName ) [virtual]

Specify the file to load.

Either the FileName or FilePrefix plus FilePattern are used to read.

Implements mitk::FileReader.

virtual void mitk::RawImageFileReader::SetFileName ( std::string  _arg ) [virtual]
virtual void mitk::RawImageFileReader::SetFilePattern ( const char *  aFilePattern ) [virtual]

Specified file pattern for the file(s) to load. The sprintf format used to build filename from FilePrefix and number.

You should specify either a FileName or FilePrefix. Use FilePrefix if the data is stored in multiple files.

Implements mitk::FileReader.

virtual void mitk::RawImageFileReader::SetFilePattern ( std::string  _arg ) [virtual]
virtual void mitk::RawImageFileReader::SetFilePrefix ( const char *  aFilePrefix ) [virtual]

Specify file prefix for the file(s) to load.

You should specify either a FileName or FilePrefix. Use FilePrefix if the data is stored in multiple files.

Implements mitk::FileReader.

virtual void mitk::RawImageFileReader::SetFilePrefix ( std::string  _arg ) [virtual]
virtual void mitk::RawImageFileReader::SetPixelType ( IOPixelType  _arg ) [virtual]
template<typename TPixel , unsigned int VImageDimensions>
void mitk::RawImageFileReader::TypedGenerateData (  ) [protected]

Definition at line 124 of file mitkRawImageFileReader.cpp.

References mitk::CastToMitkImage(), MITK_ERROR, MITK_INFO, and mitk::Image::New().

{
  mitk::Image::Pointer output = this->GetOutput();
  
  if (this->GetOutput()==NULL)
  {
    MITK_INFO << "Error" << std::endl;
  }
  
  MITK_INFO << "loading " << m_FileName << " via itk::ImageIOFactory... " << std::endl;

  // Check to see if we can read the file given the name or prefix
  if ( m_FileName == "" )
  {
    itkWarningMacro( << "File Type not supported!" );
    return ;
  }

  typedef itk::Image< TPixel, VImageDimensions > ImageType;
  typedef itk::ImageFileReader< ImageType > ReaderType;
  typedef itk::RawImageIO< TPixel, VImageDimensions >  IOType;
  
  typename ReaderType::Pointer reader = ReaderType::New();
  typename IOType::Pointer io = IOType::New();

  io->SetFileDimensionality(VImageDimensions);
  
  for (unsigned short int dim = 0; dim < VImageDimensions; ++dim)
  { 
    io->SetDimensions(dim, m_Dimensions[dim] );
  }

  if (m_Endianity == LITTLE)
  {
    io->SetByteOrderToLittleEndian();
  }
  else if (m_Endianity == BIG)
  {
    io->SetByteOrderToBigEndian();
  }
  else
  {
    MITK_INFO << "Warning: endianity not properly set. Resulting image might be incorrect";
  }

  reader->SetImageIO( io );
  reader->SetFileName(m_FileName.c_str());

  try
  {
    reader->Update();
  }
  catch( itk::ExceptionObject & err )
  {
    MITK_ERROR <<"An error occurred during the raw image reading process: ";
    MITK_INFO << err << std::endl;
  }

  mitk::Image::Pointer image = mitk::Image::New();
  mitk::CastToMitkImage(reader->GetOutput(), image);
  output->Initialize( image );
  output->SetVolume(  reader->GetOutput()->GetBufferPointer());
} 

Member Data Documentation

Dimensionality of file to be read. Can be 2 or 3.

Definition at line 97 of file mitkRawImageFileReader.h.

itk::Vector<int, 3> mitk::RawImageFileReader::m_Dimensions [protected]

Vector containing dimensions of image to be read.

Definition at line 103 of file mitkRawImageFileReader.h.

Endianity. Must be set to LITTLE or BIG. Default is BIG.

Definition at line 100 of file mitkRawImageFileReader.h.

std::string mitk::RawImageFileReader::m_FileName [protected]

Name of file to be read.

Definition at line 85 of file mitkRawImageFileReader.h.

std::string mitk::RawImageFileReader::m_FilePattern [protected]

File pattern.

Definition at line 91 of file mitkRawImageFileReader.h.

std::string mitk::RawImageFileReader::m_FilePrefix [protected]

File prefix.

Definition at line 88 of file mitkRawImageFileReader.h.

Pixel type of image to be read. Must be of type IOPixelType.

Definition at line 94 of file mitkRawImageFileReader.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines