21 #include "vtkLinearTransform.h"
22 #include "vtkMatrix4x4.h"
23 #include "vtkProperty.h"
24 #include "vtkSmartPointer.h"
26 #include <itkConstantPadImageFilter.h>
30 this->m_UseProgressBar =
false;
31 this->m_ProgressStepSize = 1;
44 MITK_ERROR <<
"mitk::ImageToContourFilter: No input available. Please set the input!" << std::endl;
45 itkExceptionMacro(
"mitk::ImageToContourFilter: No input available. Please set the input!");
49 if (sliceImage->GetDimension() > 2 || sliceImage->GetDimension() < 2)
51 MITK_ERROR <<
"mitk::ImageToImageFilter::GenerateData() works only with 2D images. Please assure that your input "
55 "mitk::ImageToImageFilter::GenerateData() works only with 2D images. Please assure that your input image is 2D!");
59 m_SliceGeometry = sliceImage->GetGeometry();
64 if (this->m_UseProgressBar)
68 template <
typename TPixel,
unsigned int VImageDimension>
69 void mitk::ImageToContourFilter::Itk2DContourExtraction(
const itk::Image<TPixel, VImageDimension> *sliceImage)
71 typedef itk::Image<TPixel, VImageDimension>
ImageType;
74 typedef itk::ConstantPadImageFilter<ImageType, ImageType> PadFilterType;
76 typename ImageType::SizeType lowerExtendRegion;
77 lowerExtendRegion[0] = 1;
78 lowerExtendRegion[1] = 1;
80 typename ImageType::SizeType upperExtendRegion;
81 upperExtendRegion[0] = 1;
82 upperExtendRegion[1] = 1;
89 padFilter->SetInput(sliceImage);
90 padFilter->SetConstant(0);
91 padFilter->SetPadLowerBound(lowerExtendRegion);
92 padFilter->SetPadUpperBound(upperExtendRegion);
95 contourExtractor->SetInput(padFilter->GetOutput());
96 contourExtractor->SetContourValue(0.5);
98 contourExtractor->Update();
100 unsigned int foundPaths = contourExtractor->GetNumberOfOutputs();
106 unsigned int pointId(0);
108 for (
unsigned int i = 0; i < foundPaths; i++)
110 const ContourPath *currentPath = contourExtractor->GetOutput(i)->GetVertexList();
113 polygon->GetPointIds()->SetNumberOfIds(currentPath->Size());
118 for (
unsigned int j = 0; j < currentPath->Size(); j++)
120 currentPoint[0] = currentPath->ElementAt(j)[0];
121 currentPoint[1] = currentPath->ElementAt(j)[1];
124 m_SliceGeometry->IndexToWorld(currentPoint, currentWorldPoint);
126 points->InsertPoint(pointId, currentWorldPoint[0], currentWorldPoint[1], currentWorldPoint[2]);
127 polygon->GetPointIds()->SetId(j, pointId);
132 polygons->InsertNextCell(polygon);
136 contourSurface->SetPoints(points);
137 contourSurface->SetPolys(polygons);
138 contourSurface->BuildLinks();
141 finalSurface->SetVtkPolyData(contourSurface);
146 Superclass::GenerateOutputInformation();
151 this->m_UseProgressBar = status;
156 this->m_ProgressStepSize = stepSize;
void Progress(unsigned int steps=1)
Sets the current amount of progress to current progress + steps.
itk::SmartPointer< Self > Pointer
#define AccessFixedDimensionByItk(mitkImage, itkImageTypeFunction, dimension)
Access a mitk-image with known dimension by an itk-image.
const mitk::Image * GetInput(void)
itk::SmartPointer< Self > Pointer
static ProgressBar * GetInstance()
static method to get the GUI dependent ProgressBar-instance so the methods for steps to do and progre...
virtual void GenerateData() override
void SetProgressStepSize(unsigned int stepSize)
Set the stepsize which the progress bar should proceed.
map::core::discrete::Elements< 3 >::InternalImageType ImageType
void SetUseProgressBar(bool)
Set whether the mitkProgressBar should be used.
virtual void GenerateOutputInformation() override
virtual ~ImageToContourFilter()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.