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

mitk::ImageToSurfaceFilter Class Reference
[Process Classes]

Converts pixel data to surface data by using a threshold The mitkImageToSurfaceFilter is used to create a new surface out of an mitk image. The filter uses a threshold to define the surface. It is based on the vtkMarchingCube algorithm. By default a vtkPolyData surface based on an input threshold for the input image will be created. Optional it is possible to reduce the number of triangles/polygones [SetDecimate(mitk::ImageToSurfaceFilter::DecimatePro) and SetTargetReduction (float _arg)] or smooth the surface-data [SetSmooth(true), SetSmoothIteration(int smoothIteration) and SetSmoothRelaxation(float smoothRelaxation)]. More...

#include <mitkImageToSurfaceFilter.h>

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

List of all members.

Public Types

enum  DecimationType { NoDecimation, DecimatePro }
typedef ImageToSurfaceFilter Self
typedef SurfaceSource Superclass
typedef itk::SmartPointer< SelfPointer
typedef itk::SmartPointer
< const Self
ConstPointer

Public Member Functions

virtual const char * GetClassName () const
virtual void GenerateData ()
virtual void GenerateOutputInformation ()
const mitk::ImageGetInput (void)
virtual void SetInput (const mitk::Image *image)
void SetSmoothIteration (int smoothIteration)
void SetSmoothRelaxation (float smoothRelaxation)
virtual void SetThreshold (ScalarType _arg)
virtual ScalarType GetThreshold () const
virtual void SetSmooth (bool _arg)
virtual void SmoothOn ()
virtual void SmoothOff ()
virtual bool GetSmooth () const
virtual DecimationType GetDecimate () const
virtual void SetDecimate (DecimationType _arg)
virtual void SetTargetReduction (float _arg)
virtual float GetTargetReduction () const
template<class T1 , class T2 , class T3 >
void mitkVtkLinearTransformPoint (T1 matrix[4][4], T2 in[3], T3 out[3])

Static Public Member Functions

static Pointer New ()

Protected Member Functions

 ImageToSurfaceFilter ()
virtual ~ImageToSurfaceFilter ()
void CreateSurface (int time, vtkImageData *vtkimage, mitk::Surface *surface, const ScalarType threshold)

Protected Attributes

bool m_Smooth
DecimationType m_Decimate
ScalarType m_Threshold
float m_TargetReduction
int m_SmoothIteration
float m_SmoothRelaxation

Detailed Description

Converts pixel data to surface data by using a threshold The mitkImageToSurfaceFilter is used to create a new surface out of an mitk image. The filter uses a threshold to define the surface. It is based on the vtkMarchingCube algorithm. By default a vtkPolyData surface based on an input threshold for the input image will be created. Optional it is possible to reduce the number of triangles/polygones [SetDecimate(mitk::ImageToSurfaceFilter::DecimatePro) and SetTargetReduction (float _arg)] or smooth the surface-data [SetSmooth(true), SetSmoothIteration(int smoothIteration) and SetSmoothRelaxation(float smoothRelaxation)].

The resulting vtk-surface has the same size as the input image. The surface can be generally smoothed by vtkDecimatePro reduce complexity of triangles and vtkSmoothPolyDataFilter to relax the mesh. Both are enabled by default and connected in the common way of pipelining in ITK. It's also possible to create time sliced surfaces.

Definition at line 53 of file mitkImageToSurfaceFilter.h.


Member Typedef Documentation

typedef itk::SmartPointer<const Self> mitk::ImageToSurfaceFilter::ConstPointer
typedef itk::SmartPointer<Self> mitk::ImageToSurfaceFilter::Pointer

Member Enumeration Documentation

Enumerator:
NoDecimation 
DecimatePro 

Definition at line 63 of file mitkImageToSurfaceFilter.h.


Constructor & Destructor Documentation

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

Destructor

Definition at line 44 of file mitkImageToSurfaceFilter.cpp.

{
}

Member Function Documentation

void mitk::ImageToSurfaceFilter::CreateSurface ( int  time,
vtkImageData *  vtkimage,
mitk::Surface surface,
const ScalarType  threshold 
) [protected]

With the given threshold vtkMarchingCube creates the surface. By default nothing a vtkPolyData surface based on a threshold of the input image will be created. Optional it is possible to reduce the number of triangles/polygones [SetDecimate(mitk::ImageToSurfaceFilter::DecimatePro) and SetTargetReduction (float _arg)] or smooth the data [SetSmooth(true), SetSmoothIteration(int smoothIteration) and SetSmoothRelaxation(float smoothRelaxation)].

Parameters:
timeselected slice or "0" for single
*vtkimageinput image
*surfaceoutput
thresholdcan be different from SetThreshold()

Definition at line 48 of file mitkImageToSurfaceFilter.cpp.

References mitk::ProgressBar::GetInstance(), matrix(), mitk::ProgressBar::Progress(), and mitk::Surface::SetVtkPolyData().

{
  vtkImageChangeInformation *indexCoordinatesImageFilter = vtkImageChangeInformation::New();
  indexCoordinatesImageFilter->SetInput(vtkimage);
  indexCoordinatesImageFilter->SetOutputOrigin(0.0,0.0,0.0);

  //MarchingCube -->create Surface
  vtkMarchingCubes *skinExtractor = vtkMarchingCubes::New();
  skinExtractor->ComputeScalarsOff();
  skinExtractor->SetInput(indexCoordinatesImageFilter->GetOutput());//RC++
  indexCoordinatesImageFilter->Delete();
  skinExtractor->SetValue(0, threshold);

  vtkPolyData *polydata;
  polydata = skinExtractor->GetOutput();
  polydata->Register(NULL);//RC++
  skinExtractor->Delete();

  if (m_Smooth)
  {
    vtkSmoothPolyDataFilter *smoother = vtkSmoothPolyDataFilter::New();
    //read poly1 (poly1 can be the original polygon, or the decimated polygon)
    smoother->SetInput(polydata);//RC++
    smoother->SetNumberOfIterations( m_SmoothIteration );
    smoother->SetRelaxationFactor( m_SmoothRelaxation );
    smoother->SetFeatureAngle( 60 );
    smoother->FeatureEdgeSmoothingOff();
    smoother->BoundarySmoothingOff();
    smoother->SetConvergence( 0 );

    polydata->Delete();//RC--
    polydata = smoother->GetOutput();
    polydata->Register(NULL);//RC++
    smoother->Delete();
  }
  ProgressBar::GetInstance()->Progress();

//#if (VTK_MAJOR_VERSION >= 5)
//  if (m_Decimate == Decimate )
//  {
//    MITK_ERROR << "vtkDecimate not available for VTK 5.0 and above.";
//    MITK_ERROR << " Using vtkDecimatePro instead." << std::endl;
//    m_Decimate = DecimatePro;
//  }
//#endif

  //decimate = to reduce number of polygons
  if(m_Decimate==DecimatePro)
  {
    vtkDecimatePro *decimate = vtkDecimatePro::New();
    decimate->SplittingOff();
    decimate->SetErrorIsAbsolute(5);
    decimate->SetFeatureAngle(30);
    decimate->PreserveTopologyOn();
    decimate->BoundaryVertexDeletionOff();
    decimate->SetDegree(10); //std-value is 25!

    decimate->SetInput(polydata);//RC++
    decimate->SetTargetReduction(m_TargetReduction);
    decimate->SetMaximumError(0.002);

    polydata->Delete();//RC--
    polydata = decimate->GetOutput();
    polydata->Register(NULL);//RC++
    decimate->Delete();
  }
#if (VTK_MAJOR_VERSION < 5)
  else if (m_Decimate==Decimate)
  {
    vtkDecimate *decimate = vtkDecimate::New();
    decimate->SetInput( polydata );
    decimate->PreserveTopologyOn();
    decimate->BoundaryVertexDeletionOff();
    decimate->SetTargetReduction( m_TargetReduction );
    polydata->Delete();//RC--
    polydata = decimate->GetOutput();
    polydata->Register(NULL);//RC++
    decimate->Delete();
  }
#endif

  polydata->Update();
  ProgressBar::GetInstance()->Progress();

  polydata->SetSource(NULL);

  if(polydata->GetNumberOfPoints() > 0)
  {
    mitk::Vector3D spacing = GetInput()->GetGeometry(time)->GetSpacing();

    vtkPoints * points = polydata->GetPoints();
    vtkMatrix4x4 *vtkmatrix = vtkMatrix4x4::New();
    GetInput()->GetGeometry(time)->GetVtkTransform()->GetMatrix(vtkmatrix);
    double (*matrix)[4] = vtkmatrix->Element;

    unsigned int i,j;
    for(i=0;i<3;++i)
      for(j=0;j<3;++j)
        matrix[i][j]/=spacing[j];

    unsigned int n = points->GetNumberOfPoints();
    vtkFloatingPointType point[3];

    for (i = 0; i < n; i++)
    {
      points->GetPoint(i, point);
      mitkVtkLinearTransformPoint(matrix,point,point);
      points->SetPoint(i, point);
    }
    vtkmatrix->Delete();
  }
  ProgressBar::GetInstance()->Progress();

  surface->SetVtkPolyData(polydata, time);
  polydata->UnRegister(NULL);
}
void mitk::ImageToSurfaceFilter::GenerateData (  ) [virtual]

For each image time slice a surface will be created. This method is called by Update().

Reimplemented in mitk::LabeledImageToSurfaceFilter, and mitk::ManualSegmentationToSurfaceFilter.

Definition at line 166 of file mitkImageToSurfaceFilter.cpp.

References mitk::ProgressBar::AddStepsToDo(), mitk::ProgressBar::GetInstance(), mitk::SlicedData::GetRequestedRegion(), mitk::Image::GetVtkImageData(), mitk::ProgressBar::Progress(), and QuadProgPP::t().

{
  mitk::Surface *surface = this->GetOutput();
  mitk::Image * image        =  (mitk::Image*)GetInput();
  mitk::Image::RegionType outputRegion = image->GetRequestedRegion();

  int tstart=outputRegion.GetIndex(3);
  int tmax=tstart+outputRegion.GetSize(3); //GetSize()==1 - will aber 0 haben, wenn nicht zeitaufgeloest

  if ((tmax-tstart) > 0)
  {
    ProgressBar::GetInstance()->AddStepsToDo( 4 * (tmax - tstart)  );
  }


  int t;
  for( t=tstart; t < tmax; ++t)
  {
    vtkImageData *vtkimagedata =  image->GetVtkImageData(t);
    CreateSurface(t,vtkimagedata,surface,m_Threshold);
    ProgressBar::GetInstance()->Progress();
  }
}
void mitk::ImageToSurfaceFilter::GenerateOutputInformation ( void   ) [virtual]

Initializes the output information ( i.e. the geometry information ) of the output of the filter

Reimplemented in mitk::LabeledImageToSurfaceFilter.

Definition at line 219 of file mitkImageToSurfaceFilter.cpp.

{
  mitk::Image::ConstPointer inputImage  =(mitk::Image*) this->GetInput();

  //mitk::Image *inputImage = (mitk::Image*)this->GetImage();
  mitk::Surface::Pointer output = this->GetOutput();

  itkDebugMacro(<<"GenerateOutputInformation()");

  if(inputImage.IsNull()) return;

  //Set Data
}
virtual const char* mitk::ImageToSurfaceFilter::GetClassName (  ) const [virtual]
virtual DecimationType mitk::ImageToSurfaceFilter::GetDecimate (  ) const [virtual]

Get the state of decimation mode to reduce triangle in the surface represantation. Modes can only be NoDecimation or DecimatePro (till vtk 4.x also Decimate)

const mitk::Image * mitk::ImageToSurfaceFilter::GetInput ( void   )

Returns a const reference to the input image (e.g. the original input image that ist used to create the surface)

Definition at line 207 of file mitkImageToSurfaceFilter.cpp.

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

  return static_cast<const mitk::Image * >
    ( this->ProcessObject::GetInput(0) );
}
virtual bool mitk::ImageToSurfaceFilter::GetSmooth (  ) const [virtual]
virtual float mitk::ImageToSurfaceFilter::GetTargetReduction (  ) const [virtual]

Returns the reduction factor for the VtkDecimatePro Decimation Filter as a float value

virtual ScalarType mitk::ImageToSurfaceFilter::GetThreshold (  ) const [virtual]

Get Threshold from vtkMarchingCube. Threshold can be manipulated by inherited classes.

template<class T1 , class T2 , class T3 >
void mitk::ImageToSurfaceFilter::mitkVtkLinearTransformPoint ( T1  matrix[4][4],
T2  in[3],
T3  out[3] 
) [inline]

Transforms a point by a 4x4 matrix

Definition at line 172 of file mitkImageToSurfaceFilter.h.

      {
        T3 x = matrix[0][0]*in[0]+matrix[0][1]*in[1]+matrix[0][2]*in[2]+matrix[0][3];
        T3 y = matrix[1][0]*in[0]+matrix[1][1]*in[1]+matrix[1][2]*in[2]+matrix[1][3];
        T3 z = matrix[2][0]*in[0]+matrix[2][1]*in[1]+matrix[2][2]*in[2]+matrix[2][3];
        out[0] = x;
        out[1] = y;
        out[2] = z;
      }
static Pointer mitk::ImageToSurfaceFilter::New (  ) [static]
virtual void mitk::ImageToSurfaceFilter::SetDecimate ( DecimationType  _arg ) [virtual]

Enable the decimation filter to reduce the number of triangles in the mesh and produce a good approximation to the original image. The filter has support for vtk-5 and earlier versions. More detailed information check the vtkDecimatePro and vtkDecimate.

void mitk::ImageToSurfaceFilter::SetInput ( const mitk::Image image ) [virtual]

Set the source image to create a surface for this filter class. As input every mitk 3D or 3D+t image can be used.

Definition at line 200 of file mitkImageToSurfaceFilter.cpp.

{
  // Process object is not const-correct so the const_cast is required here
  this->ProcessObject::SetNthInput(0, const_cast< mitk::Image * >( image ) );
}
virtual void mitk::ImageToSurfaceFilter::SetSmooth ( bool  _arg ) [virtual]

Enables vtkSmoothPolyDataFilter. With Laplacian smoothing this filter will relax the surface. You can control the Filter by manipulating the number of iterations and the relaxing factor.

void mitk::ImageToSurfaceFilter::SetSmoothIteration ( int  smoothIteration )

Set the number of iterations that is used to smooth the surface. Used is the vtkSmoothPolydataFilter that uses the laplacian filter. The higher the number of iterations that stronger the smooth-result

Parameters:
smoothIterationAs smoothIteration default in that case 50 was choosen. The VTK documentation recommends small relaxation factors and large numbers of iterations.

Definition at line 190 of file mitkImageToSurfaceFilter.cpp.

{
  m_SmoothIteration = smoothIteration;
}
void mitk::ImageToSurfaceFilter::SetSmoothRelaxation ( float  smoothRelaxation )

Set number of relaxation. Specify the relaxation factor for Laplacian smoothing. The VTK documentation recommends small relaxation factors and large numbers of iterations.

Parameters:
smoothRelaxationAs smoothRelaxation default in that case 0.1 was choosen. The VTK documentation recommends small relaxation factors and large numbers of iterations.

Definition at line 195 of file mitkImageToSurfaceFilter.cpp.

{
  m_SmoothRelaxation = smoothRelaxation;
}
virtual void mitk::ImageToSurfaceFilter::SetTargetReduction ( float  _arg ) [virtual]

Set desired TargetReduction of triangles in the range from 0.0 to 1.0. The destroyed triangles are in relation with the size of data. For example 0.9 will reduce the data set to 10%.

Parameters:
Seta TargetReduction float-value from 0.0 to 1.0
virtual void mitk::ImageToSurfaceFilter::SetThreshold ( ScalarType  _arg ) [virtual]

Threshold that is used to create the surface. All pixel in the input image that are higher than that value will be considered in the surface. The threshold referees to vtkMarchingCube. Default value is 1. See also SetThreshold (ScalarType _arg)

virtual void mitk::ImageToSurfaceFilter::SmoothOff (  ) [virtual]
virtual void mitk::ImageToSurfaceFilter::SmoothOn (  ) [virtual]

Member Data Documentation

Decimation mode, default mode is "NoDecimation". See also SetDecimate (DecimationType _arg)

Definition at line 213 of file mitkImageToSurfaceFilter.h.

Flag whether the created surface shall be smoothed or not (default is "false"). SetSmooth (bool _arg)

Definition at line 208 of file mitkImageToSurfaceFilter.h.

The Iteration value for the Smooth Filter of the created surface. See also SetSmoothIteration (int smoothIteration)

Definition at line 229 of file mitkImageToSurfaceFilter.h.

The Relaxation value for the Smooth Filter of the created surface. See also SetSmoothRelaxation (float smoothRelaxation)

Definition at line 234 of file mitkImageToSurfaceFilter.h.

The Reduction factor of the Decimation Filter for the created surface. See also SetTargetReduction (float _arg)

Definition at line 224 of file mitkImageToSurfaceFilter.h.

Threshold that is used to create the surface. All pixel in the input image that are higher than that value will be considered in the surface. Default value is 1. See also SetThreshold (ScalarType _arg)

Definition at line 219 of file mitkImageToSurfaceFilter.h.


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