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

mitk::RGBToRGBACastImageFilter Class Reference
[Process Classes]

#include <mitkRGBToRGBACastImageFilter.h>

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

List of all members.

Public Member Functions

 mitkClassMacro (RGBToRGBACastImageFilter, ImageToImageFilter)

Static Public Member Functions

static Pointer New ()
static bool IsRGBImage (const mitk::Image *image)

Protected Types

typedef itk::RGBPixel
< unsigned char > 
UCRGBPixelType
typedef itk::RGBPixel
< unsigned short > 
USRGBPixelType
typedef itk::RGBPixel< float > FloatRGBPixelType
typedef itk::RGBPixel< double > DoubleRGBPixelType

Protected Member Functions

 RGBToRGBACastImageFilter ()
 ~RGBToRGBACastImageFilter ()
virtual void GenerateInputRequestedRegion ()
virtual void GenerateOutputInformation ()
virtual void GenerateData ()
 A version of GenerateData() specific for image processing filters.
template<typename TPixel , unsigned int VImageDimension>
void InternalCast (itk::Image< TPixel, VImageDimension > *itkImage, mitk::RGBToRGBACastImageFilter *addComponentFilter, typename TPixel::ComponentType defaultAlpha)

Protected Attributes

mitk::ImageTimeSelector::Pointer m_InputTimeSelector
mitk::ImageTimeSelector::Pointer m_OutputTimeSelector
itk::TimeStamp m_TimeOfHeaderInitialization

Detailed Description

Definition at line 35 of file mitkRGBToRGBACastImageFilter.h.


Member Typedef Documentation

typedef itk::RGBPixel< double > mitk::RGBToRGBACastImageFilter::DoubleRGBPixelType [protected]

Definition at line 56 of file mitkRGBToRGBACastImageFilter.h.

typedef itk::RGBPixel< float > mitk::RGBToRGBACastImageFilter::FloatRGBPixelType [protected]

Definition at line 55 of file mitkRGBToRGBACastImageFilter.h.

typedef itk::RGBPixel< unsigned char > mitk::RGBToRGBACastImageFilter::UCRGBPixelType [protected]

Definition at line 53 of file mitkRGBToRGBACastImageFilter.h.

typedef itk::RGBPixel< unsigned short > mitk::RGBToRGBACastImageFilter::USRGBPixelType [protected]

Definition at line 54 of file mitkRGBToRGBACastImageFilter.h.


Constructor & Destructor Documentation

mitk::RGBToRGBACastImageFilter::RGBToRGBACastImageFilter (  ) [protected]

Definition at line 31 of file mitkRGBToRGBACastImageFilter.cpp.

References m_InputTimeSelector, m_OutputTimeSelector, and New().

{
  this->SetNumberOfInputs(1);
  this->SetNumberOfRequiredInputs(1);

  m_InputTimeSelector  = mitk::ImageTimeSelector::New();
  m_OutputTimeSelector = mitk::ImageTimeSelector::New();
}
mitk::RGBToRGBACastImageFilter::~RGBToRGBACastImageFilter (  ) [protected]

Definition at line 41 of file mitkRGBToRGBACastImageFilter.cpp.

{
}

Member Function Documentation

void mitk::RGBToRGBACastImageFilter::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 117 of file mitkRGBToRGBACastImageFilter.cpp.

References AccessFixedPixelTypeByItk_2, mitk::Image::GetPixelType(), mitk::TimeSlicedGeometry::MSToTimeStep(), QuadProgPP::t(), and mitk::TimeSlicedGeometry::TimeStepToMS().

{
  mitk::Image::ConstPointer input = this->GetInput();
  mitk::Image::Pointer output = this->GetOutput();

  if( !output->IsInitialized() )
  {
    return;
  }

  m_InputTimeSelector->SetInput(input);
  m_OutputTimeSelector->SetInput(this->GetOutput());

  mitk::Image::RegionType outputRegion = output->GetRequestedRegion();
  const mitk::TimeSlicedGeometry *outputTimeGeometry = output->GetTimeSlicedGeometry();
  const mitk::TimeSlicedGeometry *inputTimeGeometry = input->GetTimeSlicedGeometry();
  ScalarType timeInMS;

  int timestep=0;
  int tstart=outputRegion.GetIndex(3);
  int tmax=tstart+outputRegion.GetSize(3);

  int t;
  for(t=tstart;t<tmax;++t)
  {
    timeInMS = outputTimeGeometry->TimeStepToMS( t );

    timestep = inputTimeGeometry->MSToTimeStep( timeInMS );

    m_InputTimeSelector->SetTimeNr(timestep);
    m_InputTimeSelector->UpdateLargestPossibleRegion();
    m_OutputTimeSelector->SetTimeNr(t);
    m_OutputTimeSelector->UpdateLargestPossibleRegion();

    mitk::Image *image = m_InputTimeSelector->GetOutput();

    const mitk::PixelType &pixelType = image->GetPixelType();

    // Check if the pixel type is supported
    if ( pixelType == typeid( UCRGBPixelType ) )
    {
      AccessFixedPixelTypeByItk_2( image, InternalCast, UCRGBPixelType, this, 255 );
    }
    else if ( pixelType == typeid( USRGBPixelType ) )
    {
      AccessFixedPixelTypeByItk_2( image, InternalCast, USRGBPixelType, this, 65535 );
    }
    else if ( pixelType == typeid( FloatRGBPixelType ) )
    {
      AccessFixedPixelTypeByItk_2( image, InternalCast, FloatRGBPixelType, this, 1.0 );
    }
    else if ( pixelType == typeid( DoubleRGBPixelType ) )
    {
      AccessFixedPixelTypeByItk_2( image, InternalCast, DoubleRGBPixelType, this, 1.0 );
    }
    else
    {
      // Otherwise, write warning and graft input to output
      
      // ...TBD...
    }

  }

  m_TimeOfHeaderInitialization.Modified();
}
void mitk::RGBToRGBACastImageFilter::GenerateInputRequestedRegion (  ) [protected, virtual]

What is the input requested region that is required to produce the output requested region? The base assumption for image processing filters is that the input requested region can be set to match the output requested region. If a filter requires more input (for instance a filter that uses neighborhoods needs more input than output to avoid introducing artificial boundary conditions) or less input (for instance a magnify filter) will have to override this method. In doing so, it should call its superclass' implementation as its first step. Note that this imaging filters operate differently than the classes to this point in the class hierachy. Up till now, the base assumption has been that the largest possible region will be requested of the input.

See also:
ProcessObject::GenerateInputRequestedRegion(), ImageSource::GenerateInputRequestedRegion()

Reimplemented from mitk::ImageToImageFilter.

Definition at line 62 of file mitkRGBToRGBACastImageFilter.cpp.

References mitk::BaseData::IsInitialized(), and mitk::SlicedData::SetRequestedRegionToLargestPossibleRegion().

{
  Superclass::GenerateInputRequestedRegion();

  mitk::Image* output = this->GetOutput();
  mitk::Image* input = const_cast< mitk::Image * > ( this->GetInput() );
  if ( !output->IsInitialized() )
  {
    return;
  }

  input->SetRequestedRegionToLargestPossibleRegion();

  //GenerateTimeInInputRegion(output, input);
}
void mitk::RGBToRGBACastImageFilter::GenerateOutputInformation (  ) [protected, virtual]

Definition at line 78 of file mitkRGBToRGBACastImageFilter.cpp.

{
  mitk::Image::ConstPointer input = this->GetInput();
  mitk::Image::Pointer output = this->GetOutput();

  if ((output->IsInitialized()) && (this->GetMTime() <= m_TimeOfHeaderInitialization.GetMTime()))
    return;

  itkDebugMacro(<<"GenerateOutputInformation()");

  // Initialize RGBA output with same pixel type as input image
  const mitk::PixelType &inputPixelType = input->GetPixelType();
  if ( inputPixelType == typeid( UCRGBPixelType ) )
  {
    mitk::PixelType outputPixelType( typeid( unsigned char ), 4, itk::ImageIOBase::RGBA );
    output->Initialize( outputPixelType, *input->GetTimeSlicedGeometry() );
  }
  else if ( inputPixelType == typeid( USRGBPixelType ) )
  {
    mitk::PixelType outputPixelType( typeid( unsigned short ), 4, itk::ImageIOBase::RGBA );
    output->Initialize( outputPixelType, *input->GetTimeSlicedGeometry() );
  }
  else if ( inputPixelType == typeid( FloatRGBPixelType ) )
  {
    mitk::PixelType outputPixelType( typeid( float ), 4, itk::ImageIOBase::RGBA );
    output->Initialize( outputPixelType, *input->GetTimeSlicedGeometry() );
  }
  else if ( inputPixelType == typeid( DoubleRGBPixelType ) )
  {
    mitk::PixelType outputPixelType( typeid( double ), 4, itk::ImageIOBase::RGBA );
    output->Initialize( outputPixelType, *input->GetTimeSlicedGeometry() );
  }

  output->SetPropertyList(input->GetPropertyList()->Clone());    

  m_TimeOfHeaderInitialization.Modified();
}
template<typename TPixel , unsigned int VImageDimension>
void mitk::RGBToRGBACastImageFilter::InternalCast ( itk::Image< TPixel, VImageDimension > *  itkImage,
mitk::RGBToRGBACastImageFilter addComponentFilter,
typename TPixel::ComponentType  defaultAlpha 
) [protected]

Definition at line 186 of file mitkRGBToRGBACastImageFilter.cpp.

References m_OutputTimeSelector, and mitk::ImageToItk< TOutputImage >::SetInput().

{
  typedef TPixel InputPixelType;
  typedef itk::RGBAPixel< typename TPixel::ComponentType > OutputPixelType;
  typedef itk::Image< InputPixelType, VImageDimension > InputImageType;
  typedef itk::Image< OutputPixelType, VImageDimension > OutputImageType;

  typedef itk::ImageRegionConstIterator< InputImageType > InputImageIteratorType;
  typedef itk::ImageRegionIteratorWithIndex< OutputImageType > OutputImageIteratorType;

  typename mitk::ImageToItk< OutputImageType >::Pointer outputimagetoitk = 
    mitk::ImageToItk< OutputImageType >::New();
  outputimagetoitk->SetInput(addComponentFilter->m_OutputTimeSelector->GetOutput());
  outputimagetoitk->Update();
  typename OutputImageType::Pointer outputItkImage = outputimagetoitk->GetOutput();

  // create the iterators
  typename InputImageType::RegionType inputRegionOfInterest = 
    inputItkImage->GetLargestPossibleRegion();
  InputImageIteratorType  inputIt( inputItkImage, inputRegionOfInterest );
  OutputImageIteratorType outputIt( outputItkImage, inputRegionOfInterest );

  for ( inputIt.GoToBegin(), outputIt.GoToBegin();
        !inputIt.IsAtEnd(); 
        ++inputIt, ++outputIt )
  {
    typename InputPixelType::Iterator pixelInputIt = inputIt.Get().Begin();
    typename OutputPixelType::Iterator pixelOutputIt = outputIt.Get().Begin();

    *pixelOutputIt++ = *pixelInputIt++;
    *pixelOutputIt++ = *pixelInputIt++;
    *pixelOutputIt++ = *pixelInputIt++;
    *pixelOutputIt = defaultAlpha;
  }
}
bool mitk::RGBToRGBACastImageFilter::IsRGBImage ( const mitk::Image image ) [static]

Static convenience method to check if the passed mitk::Image is an RGB image in the sense of this converter filter.

Returns falsefor RGBA and all other images.

Definition at line 46 of file mitkRGBToRGBACastImageFilter.cpp.

References mitk::Image::GetPixelType().

{
  const mitk::PixelType &inputPixelType = image->GetPixelType();

  if ( (inputPixelType == typeid( UCRGBPixelType) ) 
    || (inputPixelType == typeid( USRGBPixelType) ) 
    || (inputPixelType == typeid( FloatRGBPixelType) ) 
    || (inputPixelType == typeid( DoubleRGBPixelType) ) )
  {
    return true;
  }

  return false;
}
mitk::RGBToRGBACastImageFilter::mitkClassMacro ( RGBToRGBACastImageFilter  ,
ImageToImageFilter   
)
static Pointer mitk::RGBToRGBACastImageFilter::New (  ) [static]

Method for creation through the object factory.

Reimplemented from mitk::ImageToImageFilter.

Referenced by RGBToRGBACastImageFilter().


Member Data Documentation

mitk::ImageTimeSelector::Pointer mitk::RGBToRGBACastImageFilter::m_InputTimeSelector [protected]

Definition at line 74 of file mitkRGBToRGBACastImageFilter.h.

Referenced by RGBToRGBACastImageFilter().

mitk::ImageTimeSelector::Pointer mitk::RGBToRGBACastImageFilter::m_OutputTimeSelector [protected]

Definition at line 75 of file mitkRGBToRGBACastImageFilter.h.

Referenced by InternalCast(), and RGBToRGBACastImageFilter().

Definition at line 79 of file mitkRGBToRGBACastImageFilter.h.


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