17 #include "vtkLinearTransform.h" 18 #include "vtkMatrix4x4.h" 19 #include "vtkProperty.h" 20 #include "vtkSmartPointer.h" 22 #include <itkConstantPadImageFilter.h> 26 this->m_UseProgressBar =
false;
27 this->m_ProgressStepSize = 1;
28 this->m_SliceGeometry =
nullptr;
41 MITK_ERROR <<
"mitk::ImageToContourFilter: No input available. Please set the input!" << std::endl;
42 itkExceptionMacro(
"mitk::ImageToContourFilter: No input available. Please set the input!");
46 if (sliceImage->GetDimension() > 2 || sliceImage->GetDimension() < 2)
48 MITK_ERROR <<
"mitk::ImageToImageFilter::GenerateData() works only with 2D images. Please assure that your input " 52 "mitk::ImageToImageFilter::GenerateData() works only with 2D images. Please assure that your input image is 2D!");
56 m_SliceGeometry = sliceImage->GetGeometry();
61 if (this->m_UseProgressBar)
65 template <
typename TPixel,
unsigned int VImageDimension>
66 void mitk::ImageToContourFilter::Itk2DContourExtraction(
const itk::Image<TPixel, VImageDimension> *sliceImage)
68 typedef itk::Image<TPixel, VImageDimension>
ImageType;
71 typedef itk::ConstantPadImageFilter<ImageType, ImageType> PadFilterType;
72 typename PadFilterType::Pointer padFilter = PadFilterType::New();
73 typename ImageType::SizeType lowerExtendRegion;
74 lowerExtendRegion[0] = 1;
75 lowerExtendRegion[1] = 1;
77 typename ImageType::SizeType upperExtendRegion;
78 upperExtendRegion[0] = 1;
79 upperExtendRegion[1] = 1;
86 padFilter->SetInput(sliceImage);
87 padFilter->SetConstant(0);
88 padFilter->SetPadLowerBound(lowerExtendRegion);
89 padFilter->SetPadUpperBound(upperExtendRegion);
91 typename ContourExtractor::Pointer contourExtractor = ContourExtractor::New();
92 contourExtractor->SetInput(padFilter->GetOutput());
93 contourExtractor->SetContourValue(0.5);
95 contourExtractor->Update();
97 unsigned int foundPaths = contourExtractor->GetNumberOfOutputs();
99 vtkSmartPointer<vtkPolyData> contourSurface = vtkSmartPointer<vtkPolyData>::New();
100 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
101 vtkSmartPointer<vtkCellArray> polygons = vtkSmartPointer<vtkCellArray>::New();
103 unsigned int pointId(0);
105 for (
unsigned int i = 0; i < foundPaths; i++)
107 const ContourPath *currentPath = contourExtractor->GetOutput(i)->GetVertexList();
109 vtkSmartPointer<vtkPolygon> polygon = vtkSmartPointer<vtkPolygon>::New();
110 polygon->GetPointIds()->SetNumberOfIds(currentPath->Size());
115 for (
unsigned int j = 0; j < currentPath->Size(); j++)
117 currentPoint[0] = currentPath->ElementAt(j)[0];
118 currentPoint[1] = currentPath->ElementAt(j)[1];
121 m_SliceGeometry->
IndexToWorld(currentPoint, currentWorldPoint);
123 points->InsertPoint(pointId, currentWorldPoint[0], currentWorldPoint[1], currentWorldPoint[2]);
124 polygon->GetPointIds()->SetId(j, pointId);
129 polygons->InsertNextCell(polygon);
133 contourSurface->SetPoints(points);
134 contourSurface->SetPolys(polygons);
135 contourSurface->BuildLinks();
138 finalSurface->SetVtkPolyData(contourSurface);
143 Superclass::GenerateOutputInformation();
148 this->m_UseProgressBar = status;
153 this->m_ProgressStepSize = stepSize;
void Progress(unsigned int steps=1)
Sets the current amount of progress to current progress + steps.
void IndexToWorld(const mitk::Vector3D &vec_units, mitk::Vector3D &vec_mm) const
Convert (continuous or discrete) index coordinates of a vector vec_units to world coordinates (in mm)...
#define AccessFixedDimensionByItk(mitkImage, itkImageTypeFunction, dimension)
Access a mitk-image with known dimension by an itk-image.
itk::Image< unsigned char, 3 > ImageType
const mitk::Image * GetInput(void)
PolyLineParametricPath2D::VertexListType ContourPath
static ProgressBar * GetInstance()
static method to get the GUI dependent ProgressBar-instance so the methods for steps to do and progre...
void GenerateData() override
void SetProgressStepSize(unsigned int stepSize)
Set the stepsize which the progress bar should proceed.
void SetUseProgressBar(bool)
Set whether the mitkProgressBar should be used.
void GenerateOutputInformation() override
~ImageToContourFilter() override