#include <mitkLabeledImageToSurfaceFilter.h>
Public Types | |
typedef LabeledImageToSurfaceFilter | Self |
typedef ImageToSurfaceFilter | Superclass |
typedef itk::SmartPointer< Self > | Pointer |
typedef itk::SmartPointer < const Self > | ConstPointer |
typedef int | LabelType |
typedef std::map< LabelType, unsigned long > | LabelMapType |
typedef std::map< unsigned int, LabelType > | IdxToLabelMapType |
Public Member Functions | |
virtual const char * | GetClassName () const |
virtual void | SetGenerateAllLabels (bool _arg) |
virtual bool | GetGenerateAllLabels () |
virtual void | GenerateAllLabelsOn () |
virtual void | GenerateAllLabelsOff () |
virtual void | SetLabel (LabelType _arg) |
virtual LabelType | GetLabel () |
virtual void | SetBackgroundLabel (LabelType _arg) |
virtual LabelType | GetBackgroundLabel () |
virtual void | SetGaussianStandardDeviation (double _arg) |
virtual double | GetGaussianStandardDeviation () |
LabelType | GetLabelForNthOutput (const unsigned int &i) |
mitk::ScalarType | GetVolumeForNthOutput (const unsigned int &i) |
mitk::ScalarType | GetVolumeForLabel (const LabelType &label) |
Static Public Member Functions | |
static Pointer | New () |
Protected Member Functions | |
virtual void | GenerateData () |
virtual void | GenerateOutputInformation () |
virtual void | CreateSurface (int time, vtkImageData *vtkimage, mitk::Surface *surface, LabelType label) |
virtual LabelMapType | GetAvailableLabels () |
LabeledImageToSurfaceFilter () | |
virtual | ~LabeledImageToSurfaceFilter () |
Protected Attributes | |
double | m_GaussianStandardDeviation |
bool | m_GenerateAllLabels |
LabelType | m_Label |
LabelType | m_BackgroundLabel |
LabelMapType | m_AvailableLabels |
IdxToLabelMapType | m_IdxToLabels |
Calculates surfaces for labeled images. If you have a labeled image containing 5 different labeled regions plus the background, this class creates 5 surface representations from the regions. Each surface is assigned to one output of the filter. You can figure out, which label corresponds to which output using the GetLabelForNthOutput() method. If you want to calculate a surface representation only for one specific label, you may call GenerateAllLabelsOff() and set the desired label by SetLabel(label).
Definition at line 40 of file mitkLabeledImageToSurfaceFilter.h.
typedef itk::SmartPointer<const Self> mitk::LabeledImageToSurfaceFilter::ConstPointer |
Reimplemented from mitk::ImageToSurfaceFilter.
Definition at line 44 of file mitkLabeledImageToSurfaceFilter.h.
typedef std::map<unsigned int, LabelType> mitk::LabeledImageToSurfaceFilter::IdxToLabelMapType |
Definition at line 52 of file mitkLabeledImageToSurfaceFilter.h.
typedef std::map<LabelType, unsigned long> mitk::LabeledImageToSurfaceFilter::LabelMapType |
Definition at line 50 of file mitkLabeledImageToSurfaceFilter.h.
typedef int mitk::LabeledImageToSurfaceFilter::LabelType |
Definition at line 46 of file mitkLabeledImageToSurfaceFilter.h.
typedef itk::SmartPointer<Self> mitk::LabeledImageToSurfaceFilter::Pointer |
Reimplemented from mitk::ImageToSurfaceFilter.
Definition at line 44 of file mitkLabeledImageToSurfaceFilter.h.
Reimplemented from mitk::ImageToSurfaceFilter.
Definition at line 44 of file mitkLabeledImageToSurfaceFilter.h.
Reimplemented from mitk::ImageToSurfaceFilter.
Definition at line 44 of file mitkLabeledImageToSurfaceFilter.h.
mitk::LabeledImageToSurfaceFilter::LabeledImageToSurfaceFilter | ( | ) | [protected] |
Definition at line 38 of file mitkLabeledImageToSurfaceFilter.cpp.
: m_GaussianStandardDeviation(1.5), m_GenerateAllLabels(true), m_Label(1), m_BackgroundLabel(0) { }
mitk::LabeledImageToSurfaceFilter::~LabeledImageToSurfaceFilter | ( | ) | [protected, virtual] |
Definition at line 46 of file mitkLabeledImageToSurfaceFilter.cpp.
{ }
void mitk::LabeledImageToSurfaceFilter::CreateSurface | ( | int | time, |
vtkImageData * | vtkimage, | ||
mitk::Surface * | surface, | ||
LabelType | label | ||
) | [protected, virtual] |
Definition at line 169 of file mitkLabeledImageToSurfaceFilter.cpp.
References matrix(), and mitk::Surface::SetVtkPolyData().
{ vtkImageChangeInformation *indexCoordinatesImageFilter = vtkImageChangeInformation::New(); indexCoordinatesImageFilter->SetInput(vtkimage); indexCoordinatesImageFilter->SetOutputOrigin(0.0,0.0,0.0); vtkImageThreshold* threshold = vtkImageThreshold::New(); threshold->SetInput( indexCoordinatesImageFilter->GetOutput() ); //indexCoordinatesImageFilter->Delete(); threshold->SetInValue( 100 ); threshold->SetOutValue( 0 ); threshold->ThresholdBetween( label, label ); threshold->SetOutputScalarTypeToUnsignedChar(); threshold->ReleaseDataFlagOn(); vtkImageGaussianSmooth *gaussian = vtkImageGaussianSmooth::New(); gaussian->SetInput( threshold->GetOutput() ); //threshold->Delete(); gaussian->SetDimensionality( 3 ); gaussian->SetRadiusFactor( 0.49 ); gaussian->SetStandardDeviation( GetGaussianStandardDeviation() ); gaussian->ReleaseDataFlagOn(); gaussian->UpdateInformation(); gaussian->Update(); //MarchingCube -->create Surface vtkMarchingCubes *skinExtractor = vtkMarchingCubes::New(); skinExtractor->ReleaseDataFlagOn(); skinExtractor->SetInput(gaussian->GetOutput());//RC++ indexCoordinatesImageFilter->Delete(); skinExtractor->SetValue(0, 50); 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(); } // //#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(); 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(); } surface->SetVtkPolyData(polydata, time); polydata->UnRegister(NULL); gaussian->Delete(); threshold->Delete(); }
virtual void mitk::LabeledImageToSurfaceFilter::GenerateAllLabelsOff | ( | ) | [virtual] |
virtual void mitk::LabeledImageToSurfaceFilter::GenerateAllLabelsOn | ( | ) | [virtual] |
void mitk::LabeledImageToSurfaceFilter::GenerateData | ( | ) | [protected, virtual] |
For each image time slice a surface will be created. This method is called by Update().
Reimplemented from mitk::ImageToSurfaceFilter.
Definition at line 125 of file mitkLabeledImageToSurfaceFilter.cpp.
References mitk::SlicedData::GetRequestedRegion(), mitk::Image::GetVtkImageData(), and QuadProgPP::t().
{ mitk::Image* image = ( mitk::Image* )GetInput(); if ( image == NULL ) { itkWarningMacro("Image is NULL"); return; } mitk::Image::RegionType outputRegion = image->GetRequestedRegion(); m_IdxToLabels.clear(); if ( this->GetNumberOfOutputs() == 0 ) return; // // traverse the known labels and create surfaces for them. // unsigned int currentOutputIndex = 0; for ( LabelMapType::iterator it = m_AvailableLabels.begin() ; it != m_AvailableLabels.end() ; ++it ) { if ( it->first == m_BackgroundLabel ) continue; if ( ( it->second == 0 ) && m_GenerateAllLabels ) continue; assert ( currentOutputIndex < this->GetNumberOfOutputs() ); mitk::Surface::Pointer surface = this->GetOutput( currentOutputIndex ); assert( surface.IsNotNull() ); int tstart=outputRegion.GetIndex(3); int tmax=tstart+outputRegion.GetSize(3); //GetSize()==1 - will aber 0 haben, wenn nicht zeitaufgeloet int t; for( t=tstart; t < tmax; ++t) { vtkImageData *vtkimagedata = image->GetVtkImageData( t ); CreateSurface( t,vtkimagedata,surface.GetPointer(), it->first ); } m_IdxToLabels[ currentOutputIndex ] = it->first; currentOutputIndex++; } }
void mitk::LabeledImageToSurfaceFilter::GenerateOutputInformation | ( | void | ) | [protected, virtual] |
Initializes the output information ( i.e. the geometry information ) of the output of the filter
Reimplemented from mitk::ImageToSurfaceFilter.
Definition at line 50 of file mitkLabeledImageToSurfaceFilter.cpp.
References mitk::Surface::Expand(), mitk::BaseData::GetTimeSlicedGeometry(), and mitk::TimeSlicedGeometry::GetTimeSteps().
{ Superclass::GenerateOutputInformation(); // // check which labels are available in the image // m_AvailableLabels = this->GetAvailableLabels(); m_IdxToLabels.clear(); // // if we don't want to generate surfaces for all labels // we have to remove all labels except m_Label and m_BackgroundLabel // from the list of available labels // if ( ! m_GenerateAllLabels ) { LabelMapType tmp; LabelMapType::iterator it; it = m_AvailableLabels.find( m_Label ); if ( it != m_AvailableLabels.end() ) tmp[m_Label] = it->second; else tmp[m_Label] = 0; it = m_AvailableLabels.find( m_BackgroundLabel ); if ( it != m_AvailableLabels.end() ) tmp[m_BackgroundLabel] = it->second; else tmp[m_BackgroundLabel] = 0; m_AvailableLabels = tmp; } // // check for the number of labels: if the whole image is filled, no // background is available and thus the numberOfOutpus is equal to the // number of available labels in the image (which is a special case). // If we have background voxels, the number of outputs is one less than // then number of available labels. // unsigned int numberOfOutputs = 0; if ( m_AvailableLabels.find( m_BackgroundLabel ) == m_AvailableLabels.end() ) numberOfOutputs = m_AvailableLabels.size(); else numberOfOutputs = m_AvailableLabels.size() - 1; if ( numberOfOutputs == 0 ) { itkWarningMacro("Number of outputs == 0"); } // // determine the number of time steps of the input image // mitk::Image* image = ( mitk::Image* )GetInput(); unsigned int numberOfTimeSteps = image->GetTimeSlicedGeometry()->GetTimeSteps(); // // set the number of outputs to the number of labels used. // initialize the output surfaces accordingly (incl. time steps) // this->SetNumberOfOutputs( numberOfOutputs ); this->SetNumberOfRequiredOutputs( numberOfOutputs ); for ( unsigned int i = 0 ; i < numberOfOutputs; ++i ) { if ( ! this->GetOutput( i ) ) { mitk::Surface::Pointer output = static_cast<mitk::Surface*>( this->MakeOutput(0).GetPointer() ); assert ( output.IsNotNull() ); output->Expand( numberOfTimeSteps ); this->SetNthOutput( i, output.GetPointer() ); } } }
mitk::LabeledImageToSurfaceFilter::LabelMapType mitk::LabeledImageToSurfaceFilter::GetAvailableLabels | ( | ) | [protected, virtual] |
Definition at line 334 of file mitkLabeledImageToSurfaceFilter.cpp.
References AccessFixedDimensionByItk_1, and GetAvailableLabelsInternal().
{ mitk::Image::Pointer image = ( mitk::Image* )GetInput(); LabelMapType availableLabels; AccessFixedDimensionByItk_1( image, GetAvailableLabelsInternal, 3, availableLabels ); return availableLabels; }
virtual LabelType mitk::LabeledImageToSurfaceFilter::GetBackgroundLabel | ( | ) | [virtual] |
Returns the label of the background. No surface will be generated for this label!
virtual const char* mitk::LabeledImageToSurfaceFilter::GetClassName | ( | ) | const [virtual] |
Reimplemented from mitk::ImageToSurfaceFilter.
virtual double mitk::LabeledImageToSurfaceFilter::GetGaussianStandardDeviation | ( | ) | [virtual] |
Returns the standard deviation of the Gaussian filter which will be used when filter is enabled.
virtual bool mitk::LabeledImageToSurfaceFilter::GetGenerateAllLabels | ( | ) | [virtual] |
virtual LabelType mitk::LabeledImageToSurfaceFilter::GetLabel | ( | ) | [virtual] |
Returns the label you want to extract. This method only has an effect, if GenerateAllLabels() is set to false
mitk::LabeledImageToSurfaceFilter::LabelType mitk::LabeledImageToSurfaceFilter::GetLabelForNthOutput | ( | const unsigned int & | i ) |
Lets you retrieve the label which was used for generating the Nth output of this filter. If GenerateAllLabels() is set to false, this filter only knows about the label provided via SetLabel(). All other labels in the image are not known.
i | the index of the Nth output. |
Definition at line 349 of file mitkLabeledImageToSurfaceFilter.cpp.
References QuadProgPP::max().
{ IdxToLabelMapType::iterator it = m_IdxToLabels.find( idx ); if ( it != m_IdxToLabels.end() ) { return it->second; } else { itkWarningMacro( "Unknown index encountered: " << idx << ". There are " << this->GetNumberOfOutputs() << " outputs available." ); return itk::NumericTraits<LabelType>::max(); } }
mitk::ScalarType mitk::LabeledImageToSurfaceFilter::GetVolumeForLabel | ( | const LabelType & | label ) |
Lets you retrieve the volume in milliliters of the region with the given label. If GenerateAllLabels is set to false, you may only call this method for the label provided using the SetLabel() method.
label | the label of the region you want to get the volume of |
Definition at line 368 of file mitkLabeledImageToSurfaceFilter.cpp.
References mitk::Geometry3D::GetFloatSpacing(), and mitk::SlicedData::GetSlicedGeometry().
{ // get the image spacing mitk::Image* image = ( mitk::Image* )GetInput(); const float* spacing = image->GetSlicedGeometry()->GetFloatSpacing(); // get the number of voxels encountered for the given label, // calculate the volume and return it. LabelMapType::iterator it = m_AvailableLabels.find( label ); if ( it != m_AvailableLabels.end() ) { return static_cast<float>(it->second) * ( spacing[0] * spacing[1] * spacing[2] / 1000.0f ); } else { itkWarningMacro( "Unknown label encountered: " << label ); return 0.0; } }
mitk::ScalarType mitk::LabeledImageToSurfaceFilter::GetVolumeForNthOutput | ( | const unsigned int & | i ) |
Lets you retrieve the volume in milliliters of the region used to generate the Nth output.
i | the index of the Nth output. |
Definition at line 363 of file mitkLabeledImageToSurfaceFilter.cpp.
{ return GetVolumeForLabel( GetLabelForNthOutput( i ) ); }
static Pointer mitk::LabeledImageToSurfaceFilter::New | ( | ) | [static] |
Reimplemented from mitk::ImageToSurfaceFilter.
Referenced by mitkLabeledImageToSurfaceFilterTest().
virtual void mitk::LabeledImageToSurfaceFilter::SetBackgroundLabel | ( | LabelType | _arg ) | [virtual] |
Set the label of the background. No surface will be generated for this label!
_arg | the label of the background, by default 0 |
virtual void mitk::LabeledImageToSurfaceFilter::SetGaussianStandardDeviation | ( | double | _arg ) | [virtual] |
Set standard deviation for Gaussian Filter.
_arg | by default 1.5 |
virtual void mitk::LabeledImageToSurfaceFilter::SetGenerateAllLabels | ( | bool | _arg ) | [virtual] |
Set whether you want to extract all (true) or only a specific label (false)
_arg | true by default |
virtual void mitk::LabeledImageToSurfaceFilter::SetLabel | ( | LabelType | _arg ) | [virtual] |
Set the label you want to extract. This method only has an effect, if GenerateAllLabels() is set to false
_arg | the label to extract, by default 1 |
Definition at line 145 of file mitkLabeledImageToSurfaceFilter.h.
Definition at line 143 of file mitkLabeledImageToSurfaceFilter.h.
double mitk::LabeledImageToSurfaceFilter::m_GaussianStandardDeviation [protected] |
Definition at line 137 of file mitkLabeledImageToSurfaceFilter.h.
bool mitk::LabeledImageToSurfaceFilter::m_GenerateAllLabels [protected] |
Definition at line 139 of file mitkLabeledImageToSurfaceFilter.h.
Definition at line 147 of file mitkLabeledImageToSurfaceFilter.h.
LabelType mitk::LabeledImageToSurfaceFilter::m_Label [protected] |
Definition at line 141 of file mitkLabeledImageToSurfaceFilter.h.