23 #include <itkAntiAliasBinaryImageFilter.h>
24 #include <itkAutoCropLabelMapFilter.h>
25 #include <itkBinaryThresholdImageFilter.h>
26 #include <itkLabelImageToLabelMapFilter.h>
27 #include <itkLabelMap.h>
28 #include <itkLabelMapToLabelImageFilter.h>
29 #include <itkLabelObject.h>
30 #include <itkNumericTraits.h>
31 #include <itkSmoothingRecursiveGaussianImageFilter.h>
34 #include <vtkCleanPolyData.h>
35 #include <vtkImageChangeInformation.h>
36 #include <vtkImageData.h>
37 #include <vtkLinearTransform.h>
38 #include <vtkMarchingCubes.h>
39 #include <vtkSmartPointer.h>
42 : m_GenerateAllLabels(false), m_RequestedLabel(1), m_BackgroundLabel(0), m_UseSmoothing(0), m_Sigma(0.1)
53 this->ProcessObject::SetNthInput(0, const_cast<mitk::Image *>(image));
63 if (this->GetNumberOfInputs() < 1)
68 return static_cast<const mitk::Image *
>(this->ProcessObject::GetInput(0));
73 itkDebugMacro(<<
"GenerateOutputInformation()");
79 if (inputImage.IsNull())
89 template <
typename TPixel,
unsigned int VDimension>
93 typedef itk::Image<TPixel, VDimension>
ImageType;
95 typedef itk::BinaryThresholdImageFilter<ImageType, ImageType> BinaryThresholdFilterType;
96 typedef itk::LabelObject<TPixel, VDimension> LabelObjectType;
98 typedef itk::LabelImageToLabelMapFilter<ImageType, LabelMapType> Image2LabelMapType;
99 typedef itk::AutoCropLabelMapFilter<LabelMapType> AutoCropType;
100 typedef itk::LabelMapToLabelImageFilter<LabelMapType, ImageType> LabelMap2ImageType;
102 typedef itk::Image<float, VDimension> RealImageType;
104 typedef itk::AntiAliasBinaryImageFilter<ImageType, RealImageType> AntiAliasFilterType;
105 typedef itk::SmoothingRecursiveGaussianImageFilter<RealImageType, RealImageType> GaussianFilterType;
108 thresholdFilter->SetInput(input);
109 thresholdFilter->SetLowerThreshold(m_RequestedLabel);
110 thresholdFilter->SetUpperThreshold(m_RequestedLabel);
111 thresholdFilter->SetOutsideValue(0);
112 thresholdFilter->SetInsideValue(1);
114 thresholdFilter->Update();
117 image2label->SetInput(thresholdFilter->GetOutput());
119 typename AutoCropType::SizeType border;
125 autoCropFilter->SetInput(image2label->GetOutput());
126 autoCropFilter->SetCropBorder(border);
127 autoCropFilter->InPlaceOn();
130 label2image->SetInput(autoCropFilter->GetOutput());
132 label2image->Update();
135 antiAliasFilter->SetInput(label2image->GetOutput());
136 antiAliasFilter->SetMaximumRMSError(0.001);
137 antiAliasFilter->SetNumberOfLayers(3);
138 antiAliasFilter->SetUseImageSpacing(
false);
139 antiAliasFilter->SetNumberOfIterations(40);
141 antiAliasFilter->Update();
148 gaussianFilter->SetSigma(m_Sigma);
149 gaussianFilter->SetInput(antiAliasFilter->GetOutput());
150 gaussianFilter->Update();
151 result = gaussianFilter->GetOutput();
155 result = antiAliasFilter->GetOutput();
158 result->DisconnectPipeline();
160 typename ImageType::RegionType cropRegion;
161 cropRegion = autoCropFilter->GetOutput()->GetLargestPossibleRegion();
163 const typename ImageType::IndexType &cropIndex = cropRegion.GetIndex();
171 this->GetInput()->GetGeometry()->IndexToWorld(origin, origin);
174 vtkImageData *vtkimage =
const_cast<vtkImageData *
>(m_ResultImage->GetVtkImageData(0));
176 vtkSmartPointer<vtkImageChangeInformation> indexCoordinatesImageFilter =
178 indexCoordinatesImageFilter->SetInputData(vtkimage);
179 indexCoordinatesImageFilter->SetOutputOrigin(0.0, 0.0, 0.0);
182 marching->ComputeScalarsOff();
183 marching->ComputeNormalsOn();
184 marching->ComputeGradientsOn();
185 marching->SetInputConnection(indexCoordinatesImageFilter->GetOutputPort());
186 marching->SetValue(0, 0.0);
190 vtkPolyData *polydata = marching->GetOutput();
192 if ((!polydata) || (!polydata->GetNumberOfPoints()))
193 throw itk::ExceptionObject(__FILE__, __LINE__,
"marching cubes has failed.");
197 vtkPoints *points = polydata->GetPoints();
200 double(*matrix)[4] = vtkmatrix->Element;
202 for (
int i = 0; i < 3; ++i)
203 for (
int j = 0; j < 3; ++j)
204 matrix[i][j] /= spacing[j];
206 unsigned int n = points->GetNumberOfPoints();
209 for (
unsigned int i = 0; i < n; i++)
211 points->GetPoint(i, point);
212 mitkVtkLinearTransformPoint(matrix, point, point);
213 points->SetPoint(i, point);
218 cleanPolyDataFilter->SetInputData(polydata);
219 cleanPolyDataFilter->PieceInvariantOff();
220 cleanPolyDataFilter->ConvertLinesToPointsOff();
221 cleanPolyDataFilter->ConvertPolysToLinesOff();
222 cleanPolyDataFilter->ConvertStripsToPolysOff();
223 cleanPolyDataFilter->PointMergingOn();
224 cleanPolyDataFilter->Update();
227 output->SetVtkPolyData(cleanPolyDataFilter->GetOutput(), 0);
const mitk::Image * GetInput(void)
Class for storing surfaces (vtkPolyData).
itk::SmartPointer< Self > Pointer
void InternalProcessing(const itk::Image< TPixel, VImageDimension > *input, mitk::Surface *surface)
virtual void GenerateData() override
const mitk::Vector3D GetSpacing() const
Get the spacing (size of a pixel).
std::map< LabelType, unsigned long > LabelMapType
map::core::discrete::Elements< 3 >::InternalImageType ImageType
void SetOrigin(const Point3D &origin)
Set the origin, i.e. the upper-left corner of the plane.
Image class for storing images.
void vtk2itk(const Tin &in, Tout &out)
LabelSetImageToSurfaceFilter()
virtual void GenerateOutputInformation() override
#define AccessFixedDimensionByItk_1(mitkImage, itkImageTypeFunction, dimension, arg1)
void CastToMitkImage(const itk::SmartPointer< ItkOutputImageType > &itkimage, itk::SmartPointer< mitk::Image > &mitkoutputimage)
Cast an itk::Image (with a specific type) to an mitk::Image.
virtual ~LabelSetImageToSurfaceFilter()
vtkLinearTransform * GetVtkTransform() const
Get the m_IndexToWorldTransform as a vtkLinearTransform.
virtual void SetInput(const mitk::Image *image)
BaseGeometry Describes the geometry of a data object.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.