19 #include <vtkDecimatePro.h>
20 #include <vtkImageChangeInformation.h>
21 #include <vtkImageData.h>
22 #include <vtkLinearTransform.h>
24 #include <vtkMatrix4x4.h>
25 #include <vtkQuadricDecimation.h>
27 #include <vtkCleanPolyData.h>
28 #include <vtkPolyDataNormals.h>
29 #include <vtkSmartPointer.h>
35 m_Decimate(NoDecimation),
37 m_TargetReduction(0.95f),
38 m_SmoothIteration(50),
39 m_SmoothRelaxation(0.1)
48 vtkImageData *vtkimage,
53 indexCoordinatesImageFilter->SetInputData(vtkimage);
54 indexCoordinatesImageFilter->SetOutputOrigin(0.0, 0.0, 0.0);
58 skinExtractor->ComputeScalarsOff();
59 skinExtractor->SetInputConnection(indexCoordinatesImageFilter->GetOutputPort());
60 indexCoordinatesImageFilter->Delete();
61 skinExtractor->SetValue(0, threshold);
63 vtkPolyData *polydata;
64 skinExtractor->Update();
65 polydata = skinExtractor->GetOutput();
66 polydata->Register(
nullptr);
72 smoother->SetInputConnection(skinExtractor->GetOutputPort());
73 smoother->SetNumberOfIterations(m_SmoothIteration);
74 smoother->SetRelaxationFactor(m_SmoothRelaxation);
75 smoother->SetFeatureAngle(60);
76 smoother->FeatureEdgeSmoothingOff();
77 smoother->BoundarySmoothingOff();
78 smoother->SetConvergence(0);
82 polydata = smoother->GetOutput();
83 polydata->Register(
nullptr);
89 if (m_Decimate == DecimatePro)
92 decimate->SplittingOff();
93 decimate->SetErrorIsAbsolute(5);
94 decimate->SetFeatureAngle(30);
95 decimate->PreserveTopologyOn();
96 decimate->BoundaryVertexDeletionOff();
97 decimate->SetDegree(10);
99 decimate->SetInputData(polydata);
100 decimate->SetTargetReduction(m_TargetReduction);
101 decimate->SetMaximumError(0.002);
105 polydata = decimate->GetOutput();
106 polydata->Register(
nullptr);
109 else if (m_Decimate == QuadricDecimation)
112 decimate->SetTargetReduction(m_TargetReduction);
114 decimate->SetInputData(polydata);
117 polydata = decimate->GetOutput();
118 polydata->Register(
nullptr);
124 if (polydata->GetNumberOfPoints() > 0)
126 mitk::Vector3D spacing = GetInput()->GetGeometry(time)->GetSpacing();
128 vtkPoints *points = polydata->GetPoints();
130 GetInput()->GetGeometry(time)->GetVtkTransform()->GetMatrix(vtkmatrix);
131 double(*matrix)[4] = vtkmatrix->Element;
134 for (i = 0; i < 3; ++i)
135 for (j = 0; j < 3; ++j)
136 matrix[i][j] /= spacing[j];
138 unsigned int n = points->GetNumberOfPoints();
141 for (i = 0; i < n; i++)
143 points->GetPoint(i, point);
144 mitkVtkLinearTransformPoint(matrix, point, point);
145 points->SetPoint(i, point);
153 normalsGenerator->SetInputData(polydata);
154 normalsGenerator->FlipNormalsOn();
157 cleanPolyDataFilter->SetInputConnection(normalsGenerator->GetOutputPort());
158 cleanPolyDataFilter->PieceInvariantOff();
159 cleanPolyDataFilter->ConvertLinesToPointsOff();
160 cleanPolyDataFilter->ConvertPolysToLinesOff();
161 cleanPolyDataFilter->ConvertStripsToPolysOff();
162 cleanPolyDataFilter->PointMergingOn();
163 cleanPolyDataFilter->Update();
166 polydata->UnRegister(
nullptr);
174 mitkThrow() <<
"No input image set, please set an valid input image!";
178 int tstart = outputRegion.GetIndex(3);
179 int tmax = tstart + outputRegion.GetSize(3);
181 if ((tmax - tstart) > 0)
187 for (t = tstart; t < tmax; ++t)
190 CreateSurface(t, vtkimagedata, surface, m_Threshold);
197 m_SmoothIteration = smoothIteration;
202 m_SmoothRelaxation = smoothRelaxation;
208 this->ProcessObject::SetNthInput(0, const_cast<mitk::Image *>(image));
213 if (this->GetNumberOfInputs() < 1)
218 return static_cast<const mitk::Image *
>(this->ProcessObject::GetInput(0));
228 itkDebugMacro(<<
"GenerateOutputInformation()");
230 if (inputImage.IsNull())
void Progress(unsigned int steps=1)
Sets the current amount of progress to current progress + steps.
Class for storing surfaces (vtkPolyData).
virtual const RegionType & GetRequestedRegion() const
virtual ~ImageToSurfaceFilter()
const mitk::Image * GetInput(void)
virtual void SetInput(const mitk::Image *image)
virtual vtkImageData * GetVtkImageData(int t=0, int n=0)
Get a volume at a specific time t of channel n as a vtkImageData.
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 SetSmoothRelaxation(float smoothRelaxation)
virtual void GenerateOutputInformation() override
itk::ImageRegion< RegionDimension > RegionType
Image class for storing images.
void CreateSurface(int time, vtkImageData *vtkimage, mitk::Surface *surface, const ScalarType threshold)
virtual void SetVtkPolyData(vtkPolyData *polydata, unsigned int t=0)
void AddStepsToDo(unsigned int steps)
Adds steps to totalSteps.
virtual bool IsInitialized() const
Check whether the data has been initialized, i.e., at least the Geometry and other header data has be...
void SetSmoothIteration(int smoothIteration)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.