20 #include <itkConstantPadImageFilter.h>
33 this->SetInput(0, input);
39 if (idx + 1 > this->GetNumberOfInputs())
41 this->SetNumberOfRequiredInputs(idx + 1);
43 if (input != static_cast<InputType *>(this->ProcessObject::GetInput(idx)))
45 this->ProcessObject::SetNthInput(idx, const_cast<InputType *>(input));
52 if (this->GetNumberOfInputs() < 1)
59 if (this->GetNumberOfInputs() < 1)
66 this->m_ContourValue = contourValue;
72 return this->m_ContourValue;
81 MITK_ERROR <<
"mitk::ImageToContourModelFilter: No input available. Please set the input!" << std::endl;
82 itkExceptionMacro(
"mitk::ImageToContourModelFilter: No input available. Please set the input!");
86 if (sliceImage->GetDimension() > 2 || sliceImage->GetDimension() < 2)
88 MITK_ERROR <<
"mitk::ImageToContourModelFilter::GenerateData() works only with 2D images. Please assure that your "
91 itkExceptionMacro(
"mitk::ImageToContourModelFilter::GenerateData() works only with 2D images. Please assure that "
92 "your input image is 2D!");
96 m_SliceGeometry = sliceImage->GetGeometry();
101 template <
typename TPixel,
unsigned int VImageDimension>
104 typedef itk::Image<TPixel, VImageDimension>
ImageType;
107 typedef itk::PolyLineParametricPath<2> PolyLineParametricPath2D;
108 typedef PolyLineParametricPath2D::VertexListType ContourPath;
110 typedef itk::ConstantPadImageFilter<ImageType, ImageType> PadFilterType;
112 typename ImageType::SizeType lowerExtendRegion;
113 lowerExtendRegion[0] = 1;
114 lowerExtendRegion[1] = 1;
116 typename ImageType::SizeType upperExtendRegion;
117 upperExtendRegion[0] = 1;
118 upperExtendRegion[1] = 1;
125 padFilter->SetInput(sliceImage);
126 padFilter->SetConstant(0);
127 padFilter->SetPadLowerBound(lowerExtendRegion);
128 padFilter->SetPadUpperBound(upperExtendRegion);
131 contourExtractor->SetInput(padFilter->GetOutput());
132 contourExtractor->SetContourValue(m_ContourValue);
134 contourExtractor->Update();
136 unsigned int foundPaths = contourExtractor->GetNumberOfOutputs();
137 this->SetNumberOfIndexedOutputs(foundPaths);
139 for (
unsigned int i = 0; i < foundPaths; i++)
141 const ContourPath *currentPath = contourExtractor->GetOutput(i)->GetVertexList();
147 if (contour.IsNull())
152 if (contour.IsNull())
155 for (
unsigned int j = 0; j < currentPath->Size(); j++)
157 currentPoint[0] = currentPath->ElementAt(j)[0];
158 currentPoint[1] = currentPath->ElementAt(j)[1];
161 m_SliceGeometry->IndexToWorld(currentPoint, currentWorldPoint);
163 contour->AddVertex(currentWorldPoint);
void GenerateData() override
itk::SmartPointer< Self > Pointer
#define AccessFixedDimensionByItk(mitkImage, itkImageTypeFunction, dimension)
Access a mitk-image with known dimension by an itk-image.
void Itk2DContourExtraction(const itk::Image< TPixel, VImageDimension > *sliceImage)
map::core::discrete::Elements< 3 >::InternalImageType ImageType
const InputType * GetInput(void)
Image class for storing images.
virtual ~ImageToContourModelFilter()
ImageToContourModelFilter()
virtual void SetInput(const InputType *input)
void SetContourValue(float contourValue)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.