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

mitk::ImageToItk< TOutputImage > Class Template Reference
[Adaptor Classes]

#include <mitkImageToItk.h>

List of all members.

Public Types

typedef ImageToItk Self
typedef itk::ImageSource
< TOutputImage > 
Superclass
typedef itk::SmartPointer< SelfPointer
typedef itk::SmartPointer
< const Self
ConstPointer
typedef
Superclass::OutputImageRegionType 
OutputImageRegionType
typedef mitk::Image InputImageType
typedef InputImageType::Pointer InputImagePointer
typedef
InputImageType::ConstPointer 
InputImageConstPointer
typedef SlicedData::RegionType InputImageRegionType
typedef TOutputImage::SizeType SizeType
typedef TOutputImage::IndexType IndexType
typedef TOutputImage::RegionType RegionType
typedef TOutputImage::PixelType PixelType

Public Member Functions

const mitk::ImageGetInput (void)
const mitk::ImageGetInput (unsigned int idx)
virtual void SetInput (const mitk::Image *input)
virtual void SetInput (unsigned int index, const mitk::Image *image)
virtual void UpdateOutputInformation ()
virtual int GetChannel ()
virtual void SetChannel (int _arg)
virtual void SetCopyMemFlag (bool _arg)
virtual bool GetCopyMemFlag ()
virtual void CopyMemFlagOn ()
virtual void CopyMemFlagOff ()

Static Public Member Functions

static Pointer New ()

Protected Member Functions

 ImageToItk ()
virtual ~ImageToItk ()
void PrintSelf (std::ostream &os, itk::Indent indent) const
virtual void GenerateData ()
virtual void GenerateOutputInformation ()

Protected Attributes

mitk::Image::Pointer m_MitkImage
mitk::ImageDataItem::Pointer m_ImageDataItem

Detailed Description

template<class TOutputImage>
class mitk::ImageToItk< TOutputImage >

Create itk::ImageSource for mitk::Image

Warning:
2D MITK images will get a 2D identity matrix in ITK

Definition at line 41 of file mitkImageToItk.h.


Member Typedef Documentation

template<class TOutputImage>
typedef itk::SmartPointer<const Self> mitk::ImageToItk< TOutputImage >::ConstPointer

Definition at line 51 of file mitkImageToItk.h.

template<class TOutputImage>
typedef TOutputImage::IndexType mitk::ImageToItk< TOutputImage >::IndexType

Definition at line 65 of file mitkImageToItk.h.

template<class TOutputImage>
typedef InputImageType::ConstPointer mitk::ImageToItk< TOutputImage >::InputImageConstPointer

Definition at line 62 of file mitkImageToItk.h.

template<class TOutputImage>
typedef InputImageType::Pointer mitk::ImageToItk< TOutputImage >::InputImagePointer

Definition at line 61 of file mitkImageToItk.h.

template<class TOutputImage>
typedef SlicedData::RegionType mitk::ImageToItk< TOutputImage >::InputImageRegionType

Definition at line 63 of file mitkImageToItk.h.

template<class TOutputImage>
typedef mitk::Image mitk::ImageToItk< TOutputImage >::InputImageType

Some convenient typedefs.

Definition at line 60 of file mitkImageToItk.h.

template<class TOutputImage>
typedef Superclass::OutputImageRegionType mitk::ImageToItk< TOutputImage >::OutputImageRegionType

Superclass typedefs.

Definition at line 54 of file mitkImageToItk.h.

template<class TOutputImage>
typedef TOutputImage::PixelType mitk::ImageToItk< TOutputImage >::PixelType

Definition at line 67 of file mitkImageToItk.h.

template<class TOutputImage>
typedef itk::SmartPointer<Self> mitk::ImageToItk< TOutputImage >::Pointer

Definition at line 50 of file mitkImageToItk.h.

template<class TOutputImage>
typedef TOutputImage::RegionType mitk::ImageToItk< TOutputImage >::RegionType

Definition at line 66 of file mitkImageToItk.h.

template<class TOutputImage>
typedef ImageToItk mitk::ImageToItk< TOutputImage >::Self

Definition at line 48 of file mitkImageToItk.h.

template<class TOutputImage>
typedef TOutputImage::SizeType mitk::ImageToItk< TOutputImage >::SizeType

Definition at line 64 of file mitkImageToItk.h.

template<class TOutputImage>
typedef itk::ImageSource<TOutputImage> mitk::ImageToItk< TOutputImage >::Superclass

Definition at line 49 of file mitkImageToItk.h.


Constructor & Destructor Documentation

template<class TOutputImage>
mitk::ImageToItk< TOutputImage >::ImageToItk (  ) [inline, protected]

Definition at line 85 of file mitkImageToItk.h.

              : m_CopyMemFlag(false), m_Channel(0)
  {
  }
template<class TOutputImage>
virtual mitk::ImageToItk< TOutputImage >::~ImageToItk (  ) [inline, protected, virtual]

Definition at line 89 of file mitkImageToItk.h.

  {
  }

Member Function Documentation

template<class TOutputImage>
virtual void mitk::ImageToItk< TOutputImage >::CopyMemFlagOff (  ) [virtual]
template<class TOutputImage>
virtual void mitk::ImageToItk< TOutputImage >::CopyMemFlagOn (  ) [virtual]
template<class TOutputImage >
void mitk::ImageToItk< TOutputImage >::GenerateData (  ) [protected, virtual]

Definition at line 88 of file mitkImageToItk.txx.

{
  // Allocate output
  mitk::Image::ConstPointer input = this->GetInput();
  typename Superclass::OutputImageType::Pointer output = this->GetOutput();
  
  
  unsigned long noBytes = input->GetDimension(0);
  for (unsigned int i=1; i<TOutputImage::GetImageDimension(); ++i)
  {
    noBytes = noBytes * input->GetDimension(i);
  }
  
  // hier wird momentan wohl nur der erste Channel verwendet??!!
  m_ImageDataItem = const_cast<mitk::Image*>(input.GetPointer())->GetChannelData( m_Channel );
  if(m_ImageDataItem.GetPointer() == NULL)
  {
    itkWarningMacro(<< "no image data to import in ITK image");

    RegionType bufferedRegion;
    output->SetBufferedRegion(bufferedRegion);
    return;
  }
  
  if (m_CopyMemFlag)
  {
    itkDebugMacro("copyMem ...");

    output->Allocate();
    
    memcpy( (PixelType *) output->GetBufferPointer(), m_ImageDataItem->GetData(), sizeof(PixelType)*noBytes);
    
  }
  else
  {
    itkDebugMacro("do not copyMem ...");
    typedef itk::ImportMitkImageContainer< unsigned long, PixelType >   ImportContainerType;
    typename ImportContainerType::Pointer import;

    import = ImportContainerType::New();
    import->Initialize();

    itkDebugMacro( << "size of container = " << import->Size() );
    import->SetImageDataItem(m_ImageDataItem);

    output->SetPixelContainer(import);
    itkDebugMacro( << "size of container = " << import->Size() );
  }
}
template<class TOutputImage >
void mitk::ImageToItk< TOutputImage >::GenerateOutputInformation (  ) [protected, virtual]

Warning:
2D MITK images will get a 2D identity matrix in ITK

Definition at line 162 of file mitkImageToItk.txx.

References matrix().

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

  // allocate size, origin, spacing, direction in types of output image
  SizeType  size;
  const unsigned int itkDimMin3 = (TOutputImage::ImageDimension > 3 ? TOutputImage::ImageDimension : 3);
  const unsigned int itkDimMax3 = (TOutputImage::ImageDimension < 3 ? TOutputImage::ImageDimension : 3);
  typename Superclass::OutputImageType::PointType::ValueType origin[ itkDimMin3 ];   
  typename Superclass::OutputImageType::SpacingType::ComponentType spacing[ itkDimMin3 ];
  typename Superclass::OutputImageType::DirectionType direction;

  // copy as much information as possible into size and spacing
  unsigned int i;
  for ( i=0; i < itkDimMax3; ++i)
  {
    size[i]    = input->GetDimension(i);
    spacing[i] = input->GetGeometry()->GetSpacing()[i];
  }
  for ( ; i < TOutputImage::ImageDimension; ++i)
  {
    origin[i]  = 0.0;
    size[i]    = input->GetDimension(i);
    spacing[i] = 1.0;
  }

  // build region from size  
  IndexType start;
  start.Fill( 0 );
  RegionType region;
  region.SetIndex( start );
  region.SetSize(  size  );
  
  // copy as much information as possible into origin
  const mitk::Point3D& mitkorigin = input->GetGeometry()->GetOrigin();
  itk2vtk(mitkorigin, origin);
  
  // copy as much information as possible into direction
  direction.SetIdentity();
  unsigned int j;
  const AffineTransform3D::MatrixType& matrix = input->GetGeometry()->GetIndexToWorldTransform()->GetMatrix();
  
  
  // the following loop devides by spacing now to normalize columns.
  // counterpart of InitializeByItk in mitkImage.h line 372 of revision 15092. 
  if ( itkDimMax3 >= 3)
  {
    for ( i=0; i < itkDimMax3; ++i)
      for( j=0; j < itkDimMax3; ++j )
        direction[i][j] = matrix[i][j]/spacing[j];
  }

  // set information into output image
  output->SetRegions( region );
  output->SetOrigin( origin );
  output->SetSpacing( spacing );
  output->SetDirection( direction );
}
template<class TOutputImage>
virtual int mitk::ImageToItk< TOutputImage >::GetChannel (  ) [virtual]
template<class TOutputImage>
virtual bool mitk::ImageToItk< TOutputImage >::GetCopyMemFlag (  ) [virtual]
template<class TOutputImage >
const mitk::Image * mitk::ImageToItk< TOutputImage >::GetInput ( void   )

Definition at line 68 of file mitkImageToItk.txx.

{
  if (this->GetNumberOfInputs() < 1)
  {
    return 0;
  }

  return static_cast< const mitk::Image * >
    (itk::ProcessObject::GetInput(0) );
}
template<class TOutputImage >
const mitk::Image * mitk::ImageToItk< TOutputImage >::GetInput ( unsigned int  idx )

Definition at line 80 of file mitkImageToItk.txx.

{
  return static_cast< mitk::Image * >
    (itk::ProcessObject::GetInput(idx));
}
template<class TOutputImage>
static Pointer mitk::ImageToItk< TOutputImage >::New (  ) [static]

Method for creation through the object factory.

Referenced by testImageToItkAndBack().

template<class TOutputImage >
void mitk::ImageToItk< TOutputImage >::PrintSelf ( std::ostream &  os,
itk::Indent  indent 
) const [protected]

Definition at line 227 of file mitkImageToItk.txx.

{
  Superclass::PrintSelf(os,indent);
}
template<class TOutputImage>
virtual void mitk::ImageToItk< TOutputImage >::SetChannel ( int  _arg ) [virtual]
template<class TOutputImage>
virtual void mitk::ImageToItk< TOutputImage >::SetCopyMemFlag ( bool  _arg ) [virtual]
template<class TOutputImage >
void mitk::ImageToItk< TOutputImage >::SetInput ( const mitk::Image input ) [virtual]

Definition at line 29 of file mitkImageToItk.txx.

References mitk::Image::GetDimension(), and mitk::Image::GetPixelType().

Referenced by mitk::CutImageWithOutputTypeSelect(), mitk::RGBToRGBACastImageFilter::InternalCast(), mitk::MaskImageFilter::InternalComputeMask(), and testImageToItkAndBack().

{
  if(input == NULL)
    itkExceptionMacro( << "image is null" );
  if(input->GetDimension()!=TOutputImage::GetImageDimension())
    itkExceptionMacro( << "image has dimension " << input->GetDimension() << " instead of " << TOutputImage::GetImageDimension() );
  
  
  if(!(input->GetPixelType() == typeid(PixelType)))
    itkExceptionMacro( << "image has wrong pixel type " );
  
  // Process object is not const-correct so the const_cast is required here
  itk::ProcessObject::SetNthInput(0, 
    const_cast< mitk::Image * >( input ) );
}
template<class TOutputImage >
void mitk::ImageToItk< TOutputImage >::SetInput ( unsigned int  index,
const mitk::Image image 
) [virtual]

Definition at line 46 of file mitkImageToItk.txx.

References mitk::Image::GetDimension(), and mitk::Image::GetPixelType().

{
  if( index+1 > this->GetNumberOfInputs() )
  {
    this->SetNumberOfRequiredInputs( index + 1 );
  }

  if(input == NULL)
    itkExceptionMacro( << "image is null" );
  if(input->GetDimension()!=TOutputImage::GetImageDimension())
    itkExceptionMacro( << "image has dimension " << input->GetDimension() << " instead of " << TOutputImage::GetImageDimension() );
  
  
  if(!(input->GetPixelType() == typeid(PixelType)))
    itkExceptionMacro( << "image has wrong pixel type " );

  // Process object is not const-correct so the const_cast is required here
  itk::ProcessObject::SetNthInput(index, 
    const_cast< mitk::Image *>( input ) );
}
template<class TOutputImage >
void mitk::ImageToItk< TOutputImage >::UpdateOutputInformation (  ) [virtual]

Definition at line 140 of file mitkImageToItk.txx.

{
  mitk::Image::ConstPointer input = this->GetInput();
  if(input.IsNotNull() && (input->GetSource()!=NULL) && input->GetSource()->Updating())
  {
    typename Superclass::OutputImageType::Pointer output = this->GetOutput();
    unsigned long t1 = input->GetUpdateMTime()+1;
    if (t1 > this->m_OutputInformationMTime.GetMTime())
    {
      output->SetPipelineMTime(t1);

      this->GenerateOutputInformation();

      this->m_OutputInformationMTime.Modified();
    }
    return;
  }
  Superclass::UpdateOutputInformation();
}

Member Data Documentation

template<class TOutputImage>
mitk::ImageDataItem::Pointer mitk::ImageToItk< TOutputImage >::m_ImageDataItem [protected]

Definition at line 45 of file mitkImageToItk.h.

template<class TOutputImage>
mitk::Image::Pointer mitk::ImageToItk< TOutputImage >::m_MitkImage [protected]

Definition at line 44 of file mitkImageToItk.h.


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