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

mitk::HeightFieldSurfaceClipImageFilter Class Reference
[Process Classes]

Filter for clipping an image with an height-field represented by an mitk::Surface. More...

#include <mitkHeightFieldSurfaceClipImageFilter.h>

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

List of all members.

Public Types

enum  { CLIPPING_MODE_CONSTANT = 0, CLIPPING_MODE_MULTIPLYBYFACTOR }
typedef
HeightFieldSurfaceClipImageFilter 
Self
typedef ImageToImageFilter Superclass
typedef itk::SmartPointer< SelfPointer
typedef itk::SmartPointer
< const Self
ConstPointer

Public Member Functions

virtual const char * GetClassName () const
void SetClippingSurface (Surface *clippingSurface)
 Set/Get the surface defining a height field as a triangle mesh.
const SurfaceGetClippingSurface () const
 Set/Get the surface defining a height field as a triangle mesh.
void SetClippingMode (int mode)
 Specifies whether clipped part of the image shall be replaced by a constant or multiplied by a user-set factor.
int GetClippingMode ()
 Specifies whether clipped part of the image shall be replaced by a constant or multiplied by a user-set factor.
void SetClippingModeToConstant ()
 Specifies whether clipped part of the image shall be replaced by a constant or multiplied by a user-set factor.
void SetClippingModeToMultiplyByFactor ()
 Specifies whether clipped part of the image shall be replaced by a constant or multiplied by a user-set factor.
virtual void SetClippingConstant (ScalarType _arg)
 Set/Get constant gray-value for clipping in CONSTANT mode.
virtual ScalarType GetClippingConstant () const
 Set/Get constant gray-value for clipping in CONSTANT mode.
virtual void SetMultiplicationFactor (ScalarType _arg)
 Set/Get multiplaction factor for clipping in MULTIPLYBYFACTOR mode.
virtual ScalarType GetMultiplicationFactor () const
 Set/Get multiplaction factor for clipping in MULTIPLYBYFACTOR mode.
virtual void SetHeightFieldResolutionX (unsigned int _arg)
 Set/Get x-resolution of height-field sampling (default: 256).
virtual unsigned int GetHeightFieldResolutionX () const
 Set/Get x-resolution of height-field sampling (default: 256).
virtual void SetHeightFieldResolutionY (unsigned int _arg)
 Set/Get y-resolution of height-field sampling (default: 256).
virtual unsigned int GetHeightFieldResolutionY () const
 Set/Get y-resolution of height-field sampling (default: 256).

Static Public Member Functions

static Pointer New ()

Protected Member Functions

 HeightFieldSurfaceClipImageFilter ()
 ~HeightFieldSurfaceClipImageFilter ()
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 _InternalComputeClippedImage (itk::Image< TPixel, VImageDimension > *itkImage, HeightFieldSurfaceClipImageFilter *clipImageFilter, vtkPolyData *clippingPolyData, AffineTransform3D *imageToPlaneTransform)

Protected Attributes

ImageTimeSelector::Pointer m_InputTimeSelector
ImageTimeSelector::Pointer m_OutputTimeSelector
int m_ClippingMode
ScalarType m_ClippingConstant
ScalarType m_MultiplicationFactor
unsigned int m_HeightFieldResolutionX
unsigned int m_HeightFieldResolutionY
double m_MaxHeight
itk::TimeStamp m_TimeOfHeaderInitialization
 Time when Header was last initialized.

Detailed Description

Filter for clipping an image with an height-field represented by an mitk::Surface.

The filter assumes that the surface represents a height field as seen from the plane defined by (1.0/0.0/0.0), (0.0/1.0/0.0). All voxels lying on one side of the height field will be clipped, i.e., set to 0. In addition, any voxels which are out of bounds when projected on this plane will be clipped as well.

Definition at line 48 of file mitkHeightFieldSurfaceClipImageFilter.h.


Member Typedef Documentation

Definition at line 51 of file mitkHeightFieldSurfaceClipImageFilter.h.

Definition at line 51 of file mitkHeightFieldSurfaceClipImageFilter.h.

Definition at line 51 of file mitkHeightFieldSurfaceClipImageFilter.h.

Definition at line 51 of file mitkHeightFieldSurfaceClipImageFilter.h.


Member Enumeration Documentation

anonymous enum
Enumerator:
CLIPPING_MODE_CONSTANT 
CLIPPING_MODE_MULTIPLYBYFACTOR 

Definition at line 61 of file mitkHeightFieldSurfaceClipImageFilter.h.


Constructor & Destructor Documentation

mitk::HeightFieldSurfaceClipImageFilter::HeightFieldSurfaceClipImageFilter (  ) [protected]
mitk::HeightFieldSurfaceClipImageFilter::~HeightFieldSurfaceClipImageFilter (  ) [protected]

Member Function Documentation

template<typename TPixel , unsigned int VImageDimension>
void mitk::HeightFieldSurfaceClipImageFilter::_InternalComputeClippedImage ( itk::Image< TPixel, VImageDimension > *  itkImage,
HeightFieldSurfaceClipImageFilter clipImageFilter,
vtkPolyData *  clippingPolyData,
AffineTransform3D imageToPlaneTransform 
) [protected]

Definition at line 135 of file mitkHeightFieldSurfaceClipImageFilter.cpp.

{
  typedef itk::Image< TPixel, VImageDimension > ItkInputImageType;
  typedef itk::Image< TPixel, VImageDimension > ItkOutputImageType;

  typedef itk::ImageSliceConstIteratorWithIndex< ItkInputImageType > ItkInputImageIteratorType;
  typedef itk::ImageRegionIteratorWithIndex< ItkOutputImageType > ItkOutputImageIteratorType;

  typename ImageToItk<ItkOutputImageType >::Pointer outputimagetoitk = 
    ImageToItk<ItkOutputImageType>::New();
  outputimagetoitk->SetInput( clipImageFilter->m_OutputTimeSelector->GetOutput() );
  outputimagetoitk->Update();

  typename ItkOutputImageType::Pointer outputItkImage = outputimagetoitk->GetOutput();

  
  // create the iterators
  typename ItkInputImageType::RegionType inputRegionOfInterest = 
    inputItkImage->GetLargestPossibleRegion();
  ItkInputImageIteratorType  inputIt( inputItkImage, inputRegionOfInterest );
  ItkOutputImageIteratorType outputIt( outputItkImage, inputRegionOfInterest );

  // Get bounds of clipping data
  clippingPolyData->ComputeBounds();
  vtkFloatingPointType *bounds = clippingPolyData->GetBounds();

  double xWidth = bounds[1] - bounds[0];
  double yWidth = bounds[3] - bounds[2];

  // Create vtkCellLocator for clipping poly data
  vtkCellLocator *cellLocator = vtkCellLocator::New();
  cellLocator->SetDataSet( clippingPolyData );
  cellLocator->CacheCellBoundsOn();
  cellLocator->AutomaticOn();
  cellLocator->BuildLocator();

  // Allocate memory for 2D image to hold the height field generated by
  // projecting the clipping data onto the plane
  double *heightField = new double[m_HeightFieldResolutionX * m_HeightFieldResolutionY];

  // Walk through height field and for each entry calculate height of the
  // clipping poly data at this point by means of vtkCellLocator. The
  // clipping data x/y bounds are used for converting from poly data space to
  // image (height-field) space.
  MITK_INFO << "Calculating Height Field..." << std::endl;
  for ( unsigned int y = 0; y < m_HeightFieldResolutionY; ++y )
  {
    for ( unsigned int x = 0; x < m_HeightFieldResolutionX; ++x )
    {
      vtkFloatingPointType p0[3], p1[3], surfacePoint[3], pcoords[3];
      p0[0] = bounds[0] + xWidth * x / (double) m_HeightFieldResolutionX;
      p0[1] = bounds[2] + yWidth * y / (double) m_HeightFieldResolutionY;
      p0[2] = -m_MaxHeight;

      p1[0] = p0[0];
      p1[1] = p0[1];
      p1[2] = m_MaxHeight;

      double t, distance;
      int subId;
      if ( cellLocator->IntersectWithLine( p0, p1, 0.1, t, surfacePoint, pcoords, subId ) )
      {
        distance = (2.0 * t - 1.0) * m_MaxHeight;
      }
      else
      {
        distance = -65536.0;
      }
      heightField[y * m_HeightFieldResolutionX + x] = distance;
    }
  }


  // Walk through entire input image and for each point determine its distance
  // from the x/y plane.
  MITK_INFO << "Performing clipping..." << std::endl;

  TPixel factor = static_cast< TPixel >( clipImageFilter->m_MultiplicationFactor );
  TPixel clippingConstant = clipImageFilter->m_ClippingConstant;

  inputIt.SetFirstDirection( 0 );
  inputIt.SetSecondDirection( 1 );

  for ( inputIt.GoToBegin(), outputIt.GoToBegin();
        !inputIt.IsAtEnd(); 
        inputIt.NextSlice() )
  {
    for ( ; !inputIt.IsAtEndOfSlice(); inputIt.NextLine() )
    {
      Point3D imageP0, planeP0;
      imageP0[0] = inputIt.GetIndex()[0];
      imageP0[1] = inputIt.GetIndex()[1];
      imageP0[2] = inputIt.GetIndex()[2];
      planeP0 = imageToPlaneTransform->TransformPoint( imageP0 );

      Point3D imageP1, planeP1;
      imageP1[0] = imageP0[0] + inputRegionOfInterest.GetSize( 0 );
      imageP1[1] = imageP0[1];
      imageP1[2] = imageP0[2];
      planeP1 = imageToPlaneTransform->TransformPoint( imageP1 );

      Vector3D step = (planeP1 - planeP0) / (double) inputRegionOfInterest.GetSize( 0 );


      for ( ; !inputIt.IsAtEndOfLine(); ++inputIt, ++outputIt, planeP0 += step )
      {
        if ( (clipImageFilter->m_ClippingMode == CLIPPING_MODE_CONSTANT)
          && ((TPixel)inputIt.Get() == clippingConstant ) )
        {
          outputIt.Set( clippingConstant );
        }
        else
        {
          int x0 = (int) ((double)(m_HeightFieldResolutionX) * (planeP0[0] - bounds[0]) / xWidth);
          int y0 = (int) ((double)(m_HeightFieldResolutionY) * (planeP0[1] - bounds[2]) / yWidth);

          bool clip;
          if ( (x0 < 0) || (x0 >= (int)m_HeightFieldResolutionX)
            || (y0 < 0) || (y0 >= (int)m_HeightFieldResolutionY) )
          {
            clip = true;
          }
          else
          {
            // Calculate bilinearly interpolated height field value at plane point
            int x1 = x0 + 1;
            int y1 = y0 + 1;
            if ( x1 >= (int)m_HeightFieldResolutionX ) { x1 = x0; }
            if ( y1 >= (int)m_HeightFieldResolutionY ) { y1 = y0; }

            ScalarType q00, q01, q10, q11;
            q00 = heightField[y0 * m_HeightFieldResolutionX + x0];
            q01 = heightField[y0 * m_HeightFieldResolutionX + x1];
            q10 = heightField[y1 * m_HeightFieldResolutionX + x0];
            q11 = heightField[y1 * m_HeightFieldResolutionX + x1];

            ScalarType q =
                q00 * ((double) x1 - planeP0[0]) * ((double) y1 - planeP0[1])
              + q01 * (planeP0[0] - (double) x0) * ((double) y1 - planeP0[1])
              + q10 * ((double) x1 - planeP0[0]) * (planeP0[1] - (double) y0)
              + q11 * (planeP0[0] - (double) x0) * (planeP0[1] - (double) y0);

            if ( q - planeP0[2] < 0 )
            {
              clip = true;
            }
            else
            {
              clip = false;
            }
          }

          if ( clip )
          {
            if ( clipImageFilter->m_ClippingMode == CLIPPING_MODE_CONSTANT )
            {
              outputIt.Set( clipImageFilter->m_ClippingConstant );
            }
            else if ( clipImageFilter->m_ClippingMode == CLIPPING_MODE_MULTIPLYBYFACTOR )
            {
void mitk::HeightFieldSurfaceClipImageFilter::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 319 of file mitkHeightFieldSurfaceClipImageFilter.cpp.

          {
            outputIt.Set( inputIt.Get() );
          }
        }
      }
    }
  }

  MITK_INFO << "DONE!" << std::endl;


  // Clean-up
  cellLocator->Delete();
}


void HeightFieldSurfaceClipImageFilter::GenerateData()
{
  const Image *inputImage = this->GetInput( 0 );
  Surface *inputSurface = const_cast< Surface * >(
    dynamic_cast< Surface * >( itk::ProcessObject::GetInput( 1 ) ) );

  const Image *outputImage = this->GetOutput();

  MITK_INFO << "Clipping: Start\n";

  if ( !outputImage->IsInitialized() || inputSurface == NULL )
    return;


  //const Geometry2D *clippingGeometryOfCurrentTimeStep = NULL;

  m_InputTimeSelector->SetInput( inputImage );
  m_OutputTimeSelector->SetInput( outputImage );

  Image::RegionType outputRegion = outputImage->GetRequestedRegion();
  const TimeSlicedGeometry *outputTimeGeometry = outputImage->GetTimeSlicedGeometry();
  const TimeSlicedGeometry *inputTimeGeometry = inputImage->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();

    // Compose IndexToWorld transform of image with WorldToIndexTransform of
    // clipping data for conversion from image index space to plane index space
    AffineTransform3D::Pointer planeWorldToIndexTransform = AffineTransform3D::New();
    inputSurface->GetGeometry( t )->GetIndexToWorldTransform()
      ->GetInverse( planeWorldToIndexTransform );
   
    AffineTransform3D::Pointer imageToPlaneTransform =
void mitk::HeightFieldSurfaceClipImageFilter::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 80 of file mitkHeightFieldSurfaceClipImageFilter.cpp.

References m_ClippingMode.

void mitk::HeightFieldSurfaceClipImageFilter::GenerateOutputInformation ( void   ) [protected, virtual]

Definition at line 97 of file mitkHeightFieldSurfaceClipImageFilter.cpp.

References mitk::GenerateTimeInInputRegion(), mitk::ImageToImageFilter::GetInput(), mitk::ImageSource::GetOutput(), mitk::BaseData::IsInitialized(), and mitk::SlicedData::SetRequestedRegionToLargestPossibleRegion().

{
  Image *outputImage = this->GetOutput();
  Image *inputImage = const_cast< Image * >( this->GetInput( 0 ) );
  const Surface *inputSurface = dynamic_cast< const Surface * >( this->GetInput( 1 ) );

  if ( !outputImage->IsInitialized() || inputSurface == NULL )
  {
    return;
  }

  inputImage->SetRequestedRegionToLargestPossibleRegion();

  GenerateTimeInInputRegion( outputImage, inputImage );
}


void HeightFieldSurfaceClipImageFilter::GenerateOutputInformation()
{
  const Image *inputImage = this->GetInput( 0 );
  Image *outputImage = this->GetOutput();

  if ( outputImage->IsInitialized()
    && (this->GetMTime() <= m_TimeOfHeaderInitialization.GetMTime()) )
  {
    return;
  }

  itkDebugMacro(<<"GenerateOutputInformation()");

  unsigned int i;
  unsigned int *tmpDimensions = new unsigned int[inputImage->GetDimension()];

  for ( i = 0; i < inputImage->GetDimension(); ++i )
virtual const char* mitk::HeightFieldSurfaceClipImageFilter::GetClassName (  ) const [virtual]
virtual ScalarType mitk::HeightFieldSurfaceClipImageFilter::GetClippingConstant (  ) const [virtual]

Set/Get constant gray-value for clipping in CONSTANT mode.

int mitk::HeightFieldSurfaceClipImageFilter::GetClippingMode (  )

Specifies whether clipped part of the image shall be replaced by a constant or multiplied by a user-set factor.

Definition at line 62 of file mitkHeightFieldSurfaceClipImageFilter.cpp.

{
  this->SetNthInput( 1, clippingSurface );
}
const Surface * mitk::HeightFieldSurfaceClipImageFilter::GetClippingSurface (  ) const

Set/Get the surface defining a height field as a triangle mesh.

Definition at line 50 of file mitkHeightFieldSurfaceClipImageFilter.cpp.

virtual unsigned int mitk::HeightFieldSurfaceClipImageFilter::GetHeightFieldResolutionX (  ) const [virtual]

Set/Get x-resolution of height-field sampling (default: 256).

virtual unsigned int mitk::HeightFieldSurfaceClipImageFilter::GetHeightFieldResolutionY (  ) const [virtual]

Set/Get y-resolution of height-field sampling (default: 256).

virtual ScalarType mitk::HeightFieldSurfaceClipImageFilter::GetMultiplicationFactor (  ) const [virtual]

Set/Get multiplaction factor for clipping in MULTIPLYBYFACTOR mode.

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

Method for creation through the object factory.

Reimplemented from mitk::ImageToImageFilter.

virtual void mitk::HeightFieldSurfaceClipImageFilter::SetClippingConstant ( ScalarType  _arg ) [virtual]

Set/Get constant gray-value for clipping in CONSTANT mode.

void mitk::HeightFieldSurfaceClipImageFilter::SetClippingMode ( int  mode )

Specifies whether clipped part of the image shall be replaced by a constant or multiplied by a user-set factor.

Definition at line 56 of file mitkHeightFieldSurfaceClipImageFilter.cpp.

{
}

void mitk::HeightFieldSurfaceClipImageFilter::SetClippingModeToConstant (  )

Specifies whether clipped part of the image shall be replaced by a constant or multiplied by a user-set factor.

Definition at line 68 of file mitkHeightFieldSurfaceClipImageFilter.cpp.

References mitk::ImageToImageFilter::GetInput().

{
  return dynamic_cast< const Surface * >( itk::ProcessObject::GetInput( 1 ) );
}
void mitk::HeightFieldSurfaceClipImageFilter::SetClippingModeToMultiplyByFactor (  )

Specifies whether clipped part of the image shall be replaced by a constant or multiplied by a user-set factor.

Definition at line 74 of file mitkHeightFieldSurfaceClipImageFilter.cpp.

References m_ClippingMode.

{
  m_ClippingMode = mode;
}
void mitk::HeightFieldSurfaceClipImageFilter::SetClippingSurface ( Surface clippingSurface )

Set/Get the surface defining a height field as a triangle mesh.

Definition at line 43 of file mitkHeightFieldSurfaceClipImageFilter.cpp.

{
virtual void mitk::HeightFieldSurfaceClipImageFilter::SetHeightFieldResolutionX ( unsigned int  _arg ) [virtual]

Set/Get x-resolution of height-field sampling (default: 256).

virtual void mitk::HeightFieldSurfaceClipImageFilter::SetHeightFieldResolutionY ( unsigned int  _arg ) [virtual]

Set/Get y-resolution of height-field sampling (default: 256).

virtual void mitk::HeightFieldSurfaceClipImageFilter::SetMultiplicationFactor ( ScalarType  _arg ) [virtual]

Set/Get multiplaction factor for clipping in MULTIPLYBYFACTOR mode.


Member Data Documentation

Definition at line 130 of file mitkHeightFieldSurfaceClipImageFilter.h.

Definition at line 133 of file mitkHeightFieldSurfaceClipImageFilter.h.

Definition at line 134 of file mitkHeightFieldSurfaceClipImageFilter.h.

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

Definition at line 125 of file mitkHeightFieldSurfaceClipImageFilter.h.

Definition at line 136 of file mitkHeightFieldSurfaceClipImageFilter.h.

Definition at line 131 of file mitkHeightFieldSurfaceClipImageFilter.h.

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

Definition at line 126 of file mitkHeightFieldSurfaceClipImageFilter.h.

Time when Header was last initialized.

Definition at line 140 of file mitkHeightFieldSurfaceClipImageFilter.h.


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