def applyFilters(self, state): surface = state.inputModelNode.GetPolyData() if state.decimation: triangle = vtk.vtkTriangleFilter() triangle.SetInput(surface) decimation = vtk.vtkDecimatePro() decimation.SetInput(triangle.GetOutput()) decimation.SetTargetReduction(state.reduction) decimation.SetBoundaryVertexDeletion(state.boundaryDeletion) decimation.PreserveTopologyOn() decimation.Update() surface = decimation.GetOutput() if state.smoothing: if state.smoothingMethod == "Laplace": smoothing = vtk.vtkSmoothPolyDataFilter() smoothing.SetInput(surface) smoothing.SetBoundarySmoothing(state.boundarySmoothing) smoothing.SetNumberOfIterations(state.laplaceIterations) smoothing.SetRelaxationFactor(state.laplaceRelaxation) smoothing.Update() surface = smoothing.GetOutput() elif state.smoothingMethod == "Taubin": smoothing = vtk.vtkWindowedSincPolyDataFilter() smoothing.SetInput(surface) smoothing.SetBoundarySmoothing(state.boundarySmoothing) smoothing.SetNumberOfIterations(state.taubinIterations) smoothing.SetPassBand(state.taubinPassBand) smoothing.Update() surface = smoothing.GetOutput() if state.normals: normals = vtk.vtkPolyDataNormals() normals.SetInput(surface) normals.AutoOrientNormalsOn() normals.SetFlipNormals(state.flipNormals) normals.SetSplitting(state.splitting) normals.SetFeatureAngle(state.featureAngle) normals.ConsistencyOn() normals.Update() surface = normals.GetOutput() if state.cleaner: cleaner = vtk.vtkCleanPolyData() cleaner.SetInput(surface) cleaner.Update() surface = cleaner.GetOutput() if state.connectivity: connectivity = vtk.vtkPolyDataConnectivityFilter() connectivity.SetInput(surface) connectivity.SetExtractionModeToLargestRegion() connectivity.Update() surface = connectivity.GetOutput() state.outputModelNode.SetAndObservePolyData(surface) return True
def prepareModel( self, polyData ): ''' ''' # import the vmtk libraries try: #from libvtkvmtkComputationalGeometryPython import * #from libvtkvmtkMiscPython import * import libvtkvmtkComputationalGeometryPython as cg import libvtkvmtkMiscPython as m except ImportError: print "FAILURE: Unable to import the SlicerVmtk libraries!" capDisplacement = 0.0 surfaceCleaner = vtk.vtkCleanPolyData() surfaceCleaner.SetInput( polyData ) surfaceCleaner.Update() surfaceTriangulator = vtk.vtkTriangleFilter() surfaceTriangulator.SetInput( surfaceCleaner.GetOutput() ) surfaceTriangulator.PassLinesOff() surfaceTriangulator.PassVertsOff() surfaceTriangulator.Update() # new steps for preparation to avoid problems because of slim models (f.e. at stenosis) subdiv = vtk.vtkLinearSubdivisionFilter() subdiv.SetInput( surfaceTriangulator.GetOutput() ) subdiv.SetNumberOfSubdivisions( 1 ) subdiv.Update() smooth = vtk.vtkWindowedSincPolyDataFilter() smooth.SetInput( subdiv.GetOutput() ) smooth.SetNumberOfIterations( 20 ) smooth.SetPassBand( 0.1 ) smooth.SetBoundarySmoothing( 1 ) smooth.Update() normals = vtk.vtkPolyDataNormals() normals.SetInput( smooth.GetOutput() ) normals.SetAutoOrientNormals( 1 ) normals.SetFlipNormals( 0 ) normals.SetConsistency( 1 ) normals.SplittingOff() normals.Update() surfaceCapper = m.vtkvmtkCapPolyData() surfaceCapper.SetInput( normals.GetOutput() ) surfaceCapper.SetDisplacement( capDisplacement ) surfaceCapper.SetInPlaneDisplacement( capDisplacement ) surfaceCapper.Update() outPolyData = vtk.vtkPolyData() outPolyData.DeepCopy( surfaceCapper.GetOutput() ) outPolyData.Update() return outPolyData