15 #include <vtkDecimatePro.h> 16 #include <vtkImageChangeInformation.h> 17 #include <vtkImageData.h> 18 #include <vtkLinearTransform.h> 20 #include <vtkMatrix4x4.h> 21 #include <vtkQuadricDecimation.h> 23 #include <vtkCleanPolyData.h> 24 #include <vtkPolyDataNormals.h> 25 #include <vtkSmartPointer.h> 31 m_Decimate(NoDecimation),
33 m_TargetReduction(0.95f),
34 m_SmoothIteration(50),
35 m_SmoothRelaxation(0.1)
44 vtkImageData *vtkimage,
48 vtkImageChangeInformation *indexCoordinatesImageFilter = vtkImageChangeInformation::New();
49 indexCoordinatesImageFilter->SetInputData(vtkimage);
50 indexCoordinatesImageFilter->SetOutputOrigin(0.0, 0.0, 0.0);
53 vtkSmartPointer<vtkMarchingCubes> skinExtractor = vtkSmartPointer<vtkMarchingCubes>::New();
54 skinExtractor->ComputeScalarsOff();
55 skinExtractor->SetInputConnection(indexCoordinatesImageFilter->GetOutputPort());
56 indexCoordinatesImageFilter->Delete();
57 skinExtractor->SetValue(0, threshold);
59 vtkPolyData *polydata;
60 skinExtractor->Update();
61 polydata = skinExtractor->GetOutput();
62 polydata->Register(
nullptr);
66 vtkSmoothPolyDataFilter *smoother = vtkSmoothPolyDataFilter::New();
68 smoother->SetInputConnection(skinExtractor->GetOutputPort());
71 smoother->SetFeatureAngle(60);
72 smoother->FeatureEdgeSmoothingOff();
73 smoother->BoundarySmoothingOff();
74 smoother->SetConvergence(0);
78 polydata = smoother->GetOutput();
79 polydata->Register(
nullptr);
87 vtkDecimatePro *decimate = vtkDecimatePro::New();
88 decimate->SplittingOff();
89 decimate->SetErrorIsAbsolute(5);
90 decimate->SetFeatureAngle(30);
91 decimate->PreserveTopologyOn();
92 decimate->BoundaryVertexDeletionOff();
93 decimate->SetDegree(10);
95 decimate->SetInputData(polydata);
97 decimate->SetMaximumError(0.002);
101 polydata = decimate->GetOutput();
102 polydata->Register(
nullptr);
107 vtkQuadricDecimation *decimate = vtkQuadricDecimation::New();
110 decimate->SetInputData(polydata);
113 polydata = decimate->GetOutput();
114 polydata->Register(
nullptr);
120 if (polydata->GetNumberOfPoints() > 0)
124 vtkPoints *points = polydata->GetPoints();
125 vtkMatrix4x4 *vtkmatrix = vtkMatrix4x4::New();
127 double(*matrix)[4] = vtkmatrix->Element;
130 for (i = 0; i < 3; ++i)
131 for (j = 0; j < 3; ++j)
132 matrix[i][j] /= spacing[j];
134 unsigned int n = points->GetNumberOfPoints();
137 for (i = 0; i < n; i++)
139 points->GetPoint(i, point);
141 points->SetPoint(i, point);
148 vtkSmartPointer<vtkPolyDataNormals> normalsGenerator = vtkSmartPointer<vtkPolyDataNormals>::New();
149 normalsGenerator->SetInputData(polydata);
150 normalsGenerator->FlipNormalsOn();
152 vtkSmartPointer<vtkCleanPolyData> cleanPolyDataFilter = vtkSmartPointer<vtkCleanPolyData>::New();
153 cleanPolyDataFilter->SetInputConnection(normalsGenerator->GetOutputPort());
154 cleanPolyDataFilter->PieceInvariantOff();
155 cleanPolyDataFilter->ConvertLinesToPointsOff();
156 cleanPolyDataFilter->ConvertPolysToLinesOff();
157 cleanPolyDataFilter->ConvertStripsToPolysOff();
158 cleanPolyDataFilter->PointMergingOn();
159 cleanPolyDataFilter->Update();
162 polydata->UnRegister(
nullptr);
169 if (
image ==
nullptr || !
image->IsInitialized())
170 mitkThrow() <<
"No input image set, please set an valid input image!";
174 int tstart = outputRegion.GetIndex(3);
175 int tmax = tstart + outputRegion.GetSize(3);
177 if ((tmax - tstart) > 0)
183 for (t = tstart; t < tmax; ++t)
185 vtkImageData *vtkimagedata =
image->GetVtkImageData(t);
204 this->ProcessObject::SetNthInput(0, const_cast<mitk::Image *>(image));
209 if (this->GetNumberOfInputs() < 1)
214 return static_cast<const mitk::Image *
>(this->ProcessObject::GetInput(0));
224 itkDebugMacro(<<
"GenerateOutputInformation()");
226 if (inputImage.IsNull())
void Progress(unsigned int steps=1)
Sets the current amount of progress to current progress + steps.
Class for storing surfaces (vtkPolyData).
vtkLinearTransform * GetVtkTransform() const
Get the m_IndexToWorldTransform as a vtkLinearTransform.
~ImageToSurfaceFilter() override
const mitk::Image * GetInput(void)
virtual void SetInput(const mitk::Image *image)
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 mitkVtkLinearTransformPoint(T1 matrix[4][4], T2 in[3], T3 out[3])
void SetSmoothRelaxation(float smoothRelaxation)
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)
mitk::Image::Pointer image
void AddStepsToDo(unsigned int steps)
Adds steps to totalSteps.
const mitk::Vector3D GetSpacing() const
Get the spacing (size of a pixel).
DecimationType m_Decimate
void SetSmoothIteration(int smoothIteration)
mitk::BaseGeometry * GetGeometry(int t=0) const
Return the geometry, which is a TimeGeometry, of the data as non-const pointer.