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

mitk::BoundingObjectCutter Class Reference
[Process Classes]

Cuts an Boundingobject out of an mitk Image. More...

#include <mitkBoundingObjectCutter.h>

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

List of all members.

Public Types

typedef BoundingObjectCutter Self
typedef ImageToImageFilter Superclass
typedef itk::SmartPointer< SelfPointer
typedef itk::SmartPointer
< const Self
ConstPointer

Public Member Functions

virtual const char * GetClassName () const
void SetBoundingObject (const mitk::BoundingObject *boundingObject)
const mitk::BoundingObjectGetBoundingObject () const
virtual void SetInsideValue (ScalarType _arg)
virtual ScalarType GetInsideValue ()
virtual void SetOutsideValue (ScalarType _arg)
virtual ScalarType GetOutsideValue ()
virtual void SetUseInsideValue (bool _arg)
virtual bool GetUseInsideValue ()
virtual void UseInsideValueOn ()
virtual void UseInsideValueOff ()
virtual void SetAutoOutsideValue (bool _arg)
virtual bool GetAutoOutsideValue ()
virtual void AutoOutsideValueOn ()
virtual void AutoOutsideValueOff ()
virtual unsigned int GetInsidePixelCount ()
virtual unsigned int GetOutsidePixelCount ()
virtual void SetUseWholeInputRegion (bool _arg)
virtual bool GetUseWholeInputRegion ()

Static Public Member Functions

static Pointer New ()

Protected Member Functions

 BoundingObjectCutter ()
virtual ~BoundingObjectCutter ()
virtual const std::type_info & GetOutputPixelType ()
virtual void GenerateInputRequestedRegion ()
virtual void GenerateOutputInformation ()
virtual void GenerateData ()
 A version of GenerateData() specific for image processing filters.
virtual void ComputeData (mitk::Image *input3D, int boTimeStep)

Protected Attributes

mitk::BoundingObject::Pointer m_BoundingObject
ScalarType m_InsideValue
ScalarType m_OutsideValue
bool m_AutoOutsideValue
bool m_UseInsideValue
unsigned int m_OutsidePixelCount
unsigned int m_InsidePixelCount
mitk::SlicedData::RegionType m_InputRequestedRegion
itk::TimeStamp m_TimeOfHeaderInitialization
mitk::ImageTimeSelector::Pointer m_InputTimeSelector
mitk::ImageTimeSelector::Pointer m_OutputTimeSelector
bool m_UseWholeInputRegion

Friends

template<typename TPixel , unsigned int VImageDimension, typename TOutputPixel >
void CutImageWithOutputTypeSelect (itk::Image< TPixel, VImageDimension > *inputItkImage, mitk::BoundingObjectCutter *cutter, int boTimeStep=0, TOutputPixel *dummy=NULL)
template<typename TPixel , unsigned int VImageDimension>
void CutImage (itk::Image< TPixel, VImageDimension > *itkImage, mitk::BoundingObjectCutter *cutter, int boTimeStep)

Detailed Description

Cuts an Boundingobject out of an mitk Image.

Input Parameters are a mitk::BoundingObject and optionally an mitk::Image if no mitk::Image is provided, the resulting image will have m_InsideValue as pixelvalue on inside pixel, otherwise it will have the pixelvalue of the input image. Pixel on the outside of the BoundingObject will have a pixelvalue of m_OutsideValue

Definition at line 41 of file mitkBoundingObjectCutter.h.


Member Typedef Documentation

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

Reimplemented in mitk::BoundingObjectCutAndCast< TPixel >.

Definition at line 44 of file mitkBoundingObjectCutter.h.

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

Reimplemented in mitk::BoundingObjectCutAndCast< TPixel >.

Definition at line 44 of file mitkBoundingObjectCutter.h.

Reimplemented in mitk::BoundingObjectCutAndCast< TPixel >.

Definition at line 44 of file mitkBoundingObjectCutter.h.

Reimplemented in mitk::BoundingObjectCutAndCast< TPixel >.

Definition at line 44 of file mitkBoundingObjectCutter.h.


Constructor & Destructor Documentation

mitk::BoundingObjectCutter::BoundingObjectCutter (  ) [protected]
mitk::BoundingObjectCutter::~BoundingObjectCutter (  ) [protected, virtual]

Definition at line 51 of file mitkBoundingObjectCutter.cpp.


Member Function Documentation

virtual void mitk::BoundingObjectCutter::AutoOutsideValueOff (  ) [virtual]
virtual void mitk::BoundingObjectCutter::AutoOutsideValueOn (  ) [virtual]
void mitk::BoundingObjectCutter::ComputeData ( mitk::Image input3D,
int  boTimeStep 
) [protected, virtual]

Reimplemented in mitk::BoundingObjectCutAndCast< TPixel >.

Definition at line 170 of file mitkBoundingObjectCutter.cpp.

void mitk::BoundingObjectCutter::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 175 of file mitkBoundingObjectCutter.cpp.

References AccessFixedDimensionByItk_2, and CutImage.

{
  AccessFixedDimensionByItk_2(input3D, CutImage, 3, this, boTimeStep);
}

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

  if(input.IsNull())
    return;  

  if((output->IsInitialized()==false) || (m_BoundingObject.IsNull()) || (m_BoundingObject->GetTimeSlicedGeometry()->GetTimeSteps() == 0))
    return;

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

  mitk::Surface::RegionType outputRegion = output->GetRequestedRegion();
  const mitk::TimeSlicedGeometry *outputTimeGeometry = output->GetTimeSlicedGeometry();
  const mitk::TimeSlicedGeometry *inputTimeGeometry = input->GetTimeSlicedGeometry();
  const mitk::TimeSlicedGeometry *boundingObjectTimeGeometry = m_BoundingObject->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();

    timestep = boundingObjectTimeGeometry->MSToTimeStep( timeInMS );

    ComputeData(m_InputTimeSelector->GetOutput(), timestep);
  }
void mitk::BoundingObjectCutter::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 60 of file mitkBoundingObjectCutter.cpp.

References mitk::ImageToImageFilter::GetInput(), mitk::Image::GetPixelType(), and mitk::PixelType::GetTypeId().

{
  return *this->GetInput()->GetPixelType().GetTypeId();
}

void BoundingObjectCutter::GenerateInputRequestedRegion()
{
  mitk::Image* output = this->GetOutput();
  if((output->IsInitialized()==false) || (m_BoundingObject.IsNull()) || (m_BoundingObject->GetTimeSlicedGeometry()->GetTimeSteps() == 0))
    return;
  // we have already calculated the spatial part of the 
void mitk::BoundingObjectCutter::GenerateOutputInformation ( void   ) [protected, virtual]

Definition at line 73 of file mitkBoundingObjectCutter.cpp.

{
  mitk::Image::Pointer output = this->GetOutput();
  if ((output->IsInitialized()) && (output->GetPipelineMTime() <= m_TimeOfHeaderInitialization.GetMTime()))
    return;

  mitk::Image::Pointer input = const_cast< mitk::Image * > ( this->GetInput() );

  itkDebugMacro(<<"GenerateOutputInformation()");

  if(input.IsNull())
    return;  

  if((m_BoundingObject.IsNull()) || (m_BoundingObject->GetTimeSlicedGeometry()->GetTimeSteps() == 0))
    return;

  mitk::Geometry3D* boGeometry =  m_BoundingObject->GetGeometry(); 
  mitk::Geometry3D* inputImageGeometry = input->GetSlicedGeometry();
  // calculate bounding box of bounding-object relative to the geometry 
  // of the input image. The result is in pixel coordinates of the input
  // image (because the m_IndexToWorldTransform includes the spacing).
  mitk::BoundingBox::Pointer boBoxRelativeToImage = boGeometry->CalculateBoundingBoxRelativeToTransform( inputImageGeometry->GetIndexToWorldTransform() );

  // PART I: initialize input requested region. We do this already here (and not 
  // later when GenerateInputRequestedRegion() is called), because we 
  // also need the information to setup the output.

  // pre-initialize input-requested-region to largest-possible-region
  // and correct time-region; spatial part will be cropped by 
  // bounding-box of bounding-object below
  m_InputRequestedRegion = input->GetLargestPossibleRegion();

  // build region out of bounding-box of bounding-object
  mitk::SlicedData::IndexType  index=m_InputRequestedRegion.GetIndex(); //init times and channels
  mitk::BoundingBox::PointType min = boBoxRelativeToImage->GetMinimum();
  index[0] = (mitk::SlicedData::IndexType::IndexValueType)(min[0]+0.5);
  index[1] = (mitk::SlicedData::IndexType::IndexValueType)(min[1]+0.5);
  index[2] = (mitk::SlicedData::IndexType::IndexValueType)(min[2]+0.5);

  mitk::SlicedData::SizeType   size = m_InputRequestedRegion.GetSize(); //init times and channels
  mitk::BoundingBox::PointType max = boBoxRelativeToImage->GetMaximum();
  size[0] = (mitk::SlicedData::SizeType::SizeValueType)(max[0]+0.5)-index[0];
  size[1] = (mitk::SlicedData::SizeType::SizeValueType)(max[1]+0.5)-index[1];
  size[2] = (mitk::SlicedData::SizeType::SizeValueType)(max[2]+0.5)-index[2];

  mitk::SlicedData::RegionType boRegion(index, size);
  
  if(m_UseWholeInputRegion == false)
  {
          // crop input-requested-region with region of bounding-object
          if(m_InputRequestedRegion.Crop(boRegion)==false)
          {
                // crop not possible => do nothing: set time size to 0.
                size.Fill(0);
                m_InputRequestedRegion.SetSize(size);
                boRegion.SetSize(size);
                m_BoundingObject->SetRequestedRegion(&boRegion);
                return;
          }
  }

  // set input-requested-region, because we access it later in
  // GenerateInputRequestedRegion (there we just set the time)
  input->SetRequestedRegion(&m_InputRequestedRegion);

  // PART II: initialize output image
  
  unsigned int dimension = input->GetDimension();
  unsigned int *dimensions = new unsigned int [dimension];
  itk2vtk(m_InputRequestedRegion.GetSize(), dimensions);
  if(dimension>3)
    memcpy(dimensions+3, input->GetDimensions()+3, (dimension-3)*sizeof(unsigned int));
  output->Initialize(mitk::PixelType(GetOutputPixelType()), dimension, dimensions);
  delete [] dimensions;

  // now we have everything to initialize the transform of the output
  mitk::SlicedGeometry3D* slicedGeometry = output->GetSlicedGeometry();

  // set the transform: use the transform of the input; 
  // the origin will be replaced afterwards
  AffineTransform3D::Pointer indexToWorldTransform = AffineTransform3D::New();
  indexToWorldTransform->SetParameters(input->GetSlicedGeometry()->GetIndexToWorldTransform()->GetParameters());
  slicedGeometry->SetIndexToWorldTransform(indexToWorldTransform);
  
  // Position the output Image to match the corresponding region of the input image
  const mitk::SlicedData::IndexType& start = m_InputRequestedRegion.GetIndex();
  mitk::Point3D origin; vtk2itk(start, origin);
  inputImageGeometry->IndexToWorld(origin, origin);
  slicedGeometry->SetOrigin(origin);

virtual bool mitk::BoundingObjectCutter::GetAutoOutsideValue (  ) [virtual]
const mitk::BoundingObject * mitk::BoundingObjectCutter::GetBoundingObject (  ) const

Definition at line 36 of file mitkBoundingObjectCutter.cpp.

virtual const char* mitk::BoundingObjectCutter::GetClassName (  ) const [virtual]
virtual unsigned int mitk::BoundingObjectCutter::GetInsidePixelCount (  ) [virtual]
virtual ScalarType mitk::BoundingObjectCutter::GetInsideValue (  ) [virtual]
const std::type_info & mitk::BoundingObjectCutter::GetOutputPixelType (  ) [protected, virtual]

Reimplemented in mitk::BoundingObjectCutAndCast< TPixel >.

Definition at line 55 of file mitkBoundingObjectCutter.cpp.

{
virtual unsigned int mitk::BoundingObjectCutter::GetOutsidePixelCount (  ) [virtual]
virtual ScalarType mitk::BoundingObjectCutter::GetOutsideValue (  ) [virtual]
virtual bool mitk::BoundingObjectCutter::GetUseInsideValue (  ) [virtual]
virtual bool mitk::BoundingObjectCutter::GetUseWholeInputRegion (  ) [virtual]
static Pointer mitk::BoundingObjectCutter::New (  ) [static]

Method for creation through the object factory.

Reimplemented from mitk::ImageToImageFilter.

Reimplemented in mitk::BoundingObjectCutAndCast< TPixel >.

Referenced by QmitkImageCropper::CropImage(), and mitkBoundingObjectCutterTest().

virtual void mitk::BoundingObjectCutter::SetAutoOutsideValue ( bool  _arg ) [virtual]
void mitk::BoundingObjectCutter::SetBoundingObject ( const mitk::BoundingObject boundingObject )

Definition at line 28 of file mitkBoundingObjectCutter.cpp.

virtual void mitk::BoundingObjectCutter::SetInsideValue ( ScalarType  _arg ) [virtual]
virtual void mitk::BoundingObjectCutter::SetOutsideValue ( ScalarType  _arg ) [virtual]
virtual void mitk::BoundingObjectCutter::SetUseInsideValue ( bool  _arg ) [virtual]
virtual void mitk::BoundingObjectCutter::SetUseWholeInputRegion ( bool  _arg ) [virtual]
virtual void mitk::BoundingObjectCutter::UseInsideValueOff (  ) [virtual]
virtual void mitk::BoundingObjectCutter::UseInsideValueOn (  ) [virtual]

Friends And Related Function Documentation

template<typename TPixel , unsigned int VImageDimension>
void CutImage ( itk::Image< TPixel, VImageDimension > *  itkImage,
mitk::BoundingObjectCutter cutter,
int  boTimeStep 
) [friend]

Definition at line 144 of file mitkBoundingObjectCutter.txx.

Referenced by GenerateData().

{
  TPixel* dummy = NULL;
  CutImageWithOutputTypeSelect<TPixel, VImageDimension, TPixel>(inputItkImage, cutter, boTimeStep, dummy);
}
template<typename TPixel , unsigned int VImageDimension, typename TOutputPixel >
void CutImageWithOutputTypeSelect ( itk::Image< TPixel, VImageDimension > *  inputItkImage,
mitk::BoundingObjectCutter cutter,
int  boTimeStep = 0,
TOutputPixel *  dummy = NULL 
) [friend]

Definition at line 32 of file mitkBoundingObjectCutter.txx.

{
  typedef itk::Image<TPixel, VImageDimension> ItkInputImageType;
  typedef itk::Image<TOutputPixel, VImageDimension> ItkOutputImageType;
  typedef typename itk::ImageBase<VImageDimension>::RegionType ItkRegionType;
  typedef itk::ImageRegionIteratorWithIndex< ItkInputImageType > ItkInputImageIteratorType;
  typedef itk::ImageRegionIteratorWithIndex< ItkOutputImageType > ItkOutputImageIteratorType;

  if(cutter->m_BoundingObject.IsNull())
    return;

  if (inputItkImage == NULL)
  {
    mitk::StatusBar::GetInstance()->DisplayErrorText ("An internal error occurred. Can't convert Image. Please report to bugs@mitk.org");
    std::cout << " image is NULL...returning" << std::endl;
    return; 
  }

  // PART 1: convert m_InputRequestedRegion (type mitk::SlicedData::RegionType)
  // into ITK-image-region (ItkImageType::RegionType)
  // unfortunately, we cannot use input->GetRequestedRegion(), because it
  // has been destroyed by the mitk::CastToItkImage call of PART 1
  // (which sets the m_RequestedRegion to the LargestPossibleRegion).
  // Thus, use our own member m_InputRequestedRegion insead.
  
  // first convert the index
  typename ItkRegionType::IndexType::IndexValueType tmpIndex[3];
  itk2vtk(cutter->m_InputRequestedRegion.GetIndex(), tmpIndex);
  typename ItkRegionType::IndexType index;
  index.SetIndex(tmpIndex);
  
  // then convert the size
  typename ItkRegionType::SizeType::SizeValueType tmpSize[3];
  itk2vtk(cutter->m_InputRequestedRegion.GetSize(), tmpSize);
  typename ItkRegionType::SizeType size;
  size.SetSize(tmpSize);
  
  //create the ITK-image-region out of index and size
  ItkRegionType inputRegionOfInterest(index, size);

  // PART 2: get access to the MITK output image via an ITK image
  typename mitk::ImageToItk<ItkOutputImageType>::Pointer outputimagetoitk = mitk::ImageToItk<ItkOutputImageType>::New();
  outputimagetoitk->SetInput(cutter->m_OutputTimeSelector->GetOutput());
  outputimagetoitk->Update();
  typename ItkOutputImageType::Pointer outputItkImage = outputimagetoitk->GetOutput();

  // PART 3: iterate over input and output using ITK iterators
  
  // create the iterators
  ItkInputImageIteratorType  inputIt( inputItkImage, inputRegionOfInterest );
  ItkOutputImageIteratorType outputIt( outputItkImage, outputItkImage->GetLargestPossibleRegion() );

  // Cut the boundingbox out of the image by iterating through 
  // all pixels and checking if they are inside using IsInside()
  cutter->m_OutsidePixelCount = 0;
  cutter->m_InsidePixelCount = 0;
  mitk::Point3D p;
  mitk::Geometry3D* inputGeometry = cutter->GetInput()->GetGeometry();

  TOutputPixel outsideValue;
  if(cutter->m_AutoOutsideValue)
  {
    outsideValue = itk::NumericTraits<TOutputPixel>::min();
  }
  else
  {
    outsideValue = (TOutputPixel) cutter->m_OutsideValue;
  }

  //shall we use a fixed value for each inside pixel?
  if (cutter->GetUseInsideValue())
  {
    TOutputPixel insideValue  = (TOutputPixel) cutter->m_InsideValue;
    // yes, use a fixed value for each inside pixel (create a binary mask of the bounding object)
    for ( inputIt.GoToBegin(), outputIt.GoToBegin(); !inputIt.IsAtEnd(); ++inputIt, ++outputIt)
    {
      vtk2itk(inputIt.GetIndex(), p);
      inputGeometry->IndexToWorld(p, p);
      if(cutter->m_BoundingObject->IsInside(p))
      {
        outputIt.Set(insideValue);
        ++cutter->m_InsidePixelCount;
      }
      else
      {
        outputIt.Set(outsideValue);
        ++cutter->m_OutsidePixelCount;
      }
    }
  }
  else 
  {
    // no, use the pixel value of the original image (normal cutting)
    for ( inputIt.GoToBegin(), outputIt.GoToBegin(); !inputIt.IsAtEnd(); ++inputIt, ++outputIt)
    {
      vtk2itk(inputIt.GetIndex(), p);
      inputGeometry->IndexToWorld(p, p);
      if(cutter->m_BoundingObject->IsInside(p))
      {
        outputIt.Set( (TOutputPixel) inputIt.Value() );
        ++cutter->m_InsidePixelCount;
      }
      else
      {
        outputIt.Set( outsideValue );
        ++cutter->m_OutsidePixelCount;
      }
    }
  }
}

Member Data Documentation

Definition at line 105 of file mitkBoundingObjectCutter.h.

Referenced by mitk::CutImageWithOutputTypeSelect().

Definition at line 120 of file mitkBoundingObjectCutter.h.

Referenced by mitk::CutImageWithOutputTypeSelect().

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

Definition at line 126 of file mitkBoundingObjectCutter.h.

Definition at line 116 of file mitkBoundingObjectCutter.h.

Referenced by mitk::CutImageWithOutputTypeSelect().

Definition at line 96 of file mitkBoundingObjectCutter.h.

Referenced by mitk::CutImageWithOutputTypeSelect().

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

Definition at line 127 of file mitkBoundingObjectCutter.h.

Referenced by mitk::CutImageWithOutputTypeSelect().

Definition at line 115 of file mitkBoundingObjectCutter.h.

Referenced by mitk::CutImageWithOutputTypeSelect().

Definition at line 101 of file mitkBoundingObjectCutter.h.

Referenced by mitk::CutImageWithOutputTypeSelect().

Definition at line 124 of file mitkBoundingObjectCutter.h.

Definition at line 113 of file mitkBoundingObjectCutter.h.

Definition at line 129 of file mitkBoundingObjectCutter.h.


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