def Execute(self): if self.Surface == None: self.PrintError('Error: No input surface.') curvatureFilter = vtk.vtkCurvatures() curvatureFilter.SetInput(self.Surface) if self.CurvatureType == 'mean': curvatureFilter.SetCurvatureTypeToMean() elif self.CurvatureType == 'gaussian': curvatureFilter.SetCurvatureTypeToGaussian() elif self.CurvatureType == 'maximum': curvatureFilter.SetCurvatureTypeToMaximum() elif self.CurvatureType == 'minimum': curvatureFilter.SetCurvatureTypeToMinimum() curvatureFilter.Update() activeScalars = curvatureFilter.GetOutput().GetPointData().GetScalars() activeScalars.SetName('Curvature') if self.AbsoluteCurvature: for i in range(activeScalars.GetNumberOfTuples()): value = activeScalars.GetTuple1(i) activeScalars.SetTuple1(i, abs(value)) neighborhoods = None if not self.CurvatureOnBoundaries or self.MedianFiltering: neighborhoods = vtkvmtk.vtkvmtkNeighborhoods() neighborhoods.SetNeighborhoodTypeToPolyDataManifoldNeighborhood() neighborhoods.SetDataSet(self.Surface) neighborhoods.Build() if not self.CurvatureOnBoundaries: boundaryExtractor = vtkvmtk.vtkvmtkPolyDataBoundaryExtractor() boundaryExtractor.SetInput(self.Surface) boundaryExtractor.Update() boundaryIdsArray = vtk.vtkIdTypeArray.SafeDownCast( boundaryExtractor.GetOutput().GetPointData().GetScalars()) boundaryIds = vtk.vtkIdList() boundaryIds.SetNumberOfIds(boundaryIdsArray.GetNumberOfTuples()) for i in range(boundaryIdsArray.GetNumberOfTuples()): boundaryIds.SetId(i, boundaryIdsArray.GetValue(i)) self.Surface.BuildLinks() for i in range(boundaryIds.GetNumberOfIds()): pointId = boundaryIds.GetId(i) neighborhood = neighborhoods.GetNeighborhood(pointId) values = [] for j in range(neighborhood.GetNumberOfPoints()): neighborId = neighborhood.GetPointId(j) if boundaryIds.IsId(neighborId) != -1: continue value = activeScalars.GetTuple1(neighborId) values.append(value) values.sort() if not values: continue medianValue = values[(len(values) - 1) / 2] activeScalars.SetTuple1(pointId, medianValue) if self.MedianFiltering: for i in range(neighborhoods.GetNumberOfNeighborhoods()): neighborhood = neighborhoods.GetNeighborhood(i) values = [] for j in range(neighborhood.GetNumberOfPoints()): neighborId = neighborhood.GetPointId(j) value = activeScalars.GetTuple1(neighborId) values.append(value) values.sort() if not values: continue medianValue = values[(len(values) - 1) / 2] activeScalars.SetTuple1(i, medianValue) if self.BoundedReciprocal: for i in range(activeScalars.GetNumberOfTuples()): value = activeScalars.GetTuple1(i) reciprocalValue = 1.0 / (self.Epsilon + value) activeScalars.SetTuple1(i, reciprocalValue) if self.Offset: for i in range(activeScalars.GetNumberOfTuples()): value = activeScalars.GetTuple1(i) activeScalars.SetTuple1(i, value + self.Offset) if self.ReferenceSurface == None: self.Surface.GetPointData().AddArray(activeScalars) else: self.ReferenceSurface.GetPointData().AddArray(activeScalars) self.Surface = self.ReferenceSurface
def Execute(self): if self.Surface == None: self.PrintError('Error: No input surface.') # cleaner = vtk.vtkCleanPolyData() # cleaner.SetInput(self.Surface) # cleaner.Update() # # triangleFilter = vtk.vtkTriangleFilter() # triangleFilter.SetInput(cleaner.GetOutput()) # triangleFilter.Update() # # self.Surface = triangleFilter.GetOutput() boundaryIds = vtk.vtkIdList() if self.Interactive: if not self.vmtkRenderer: import vmtkrenderer self.vmtkRenderer = vmtkrenderer.vmtkRenderer() self.vmtkRenderer.Initialize() self.OwnRenderer = 1 self.vmtkRenderer.RegisterScript(self) boundaryExtractor = vtkvmtk.vtkvmtkPolyDataBoundaryExtractor() boundaryExtractor.SetInputData(self.Surface) boundaryExtractor.Update() boundaries = boundaryExtractor.GetOutput() numberOfBoundaries = boundaries.GetNumberOfCells() seedPoints = vtk.vtkPoints() for i in range(numberOfBoundaries): barycenter = [0.0, 0.0, 0.0] vtkvmtk.vtkvmtkBoundaryReferenceSystems.ComputeBoundaryBarycenter(boundaries.GetCell(i).GetPoints(),barycenter) seedPoints.InsertNextPoint(barycenter) seedPolyData = vtk.vtkPolyData() seedPolyData.SetPoints(seedPoints) labelsMapper = vtk.vtkLabeledDataMapper(); labelsMapper.SetInputData(seedPolyData) labelsMapper.SetLabelModeToLabelIds() labelsActor = vtk.vtkActor2D() labelsActor.SetMapper(labelsMapper) self.vmtkRenderer.Renderer.AddActor(labelsActor) surfaceMapper = vtk.vtkPolyDataMapper() surfaceMapper.SetInputData(self.Surface) surfaceMapper.ScalarVisibilityOff() surfaceActor = vtk.vtkActor() surfaceActor.SetMapper(surfaceMapper) surfaceActor.GetProperty().SetOpacity(0.25) self.vmtkRenderer.Renderer.AddActor(surfaceActor) #self.vmtkRenderer.Render() #self.vmtkRenderer.Renderer.RemoveActor(labelsActor) #self.vmtkRenderer.Renderer.RemoveActor(surfaceActor) ok = False while not ok: labelString = self.InputText("Please input boundary ids: ",self.LabelValidator) labels = [int(label) for label in labelString.split()] ok = True for label in labels: if label not in range(numberOfBoundaries): ok = False for label in labels: boundaryIds.InsertNextId(label) if self.Method == 'simple': capper = vtkvmtk.vtkvmtkSimpleCapPolyData() capper.SetInputData(self.Surface) elif self.Method == 'centerpoint': capper = vtkvmtk.vtkvmtkCapPolyData() capper.SetInputData(self.Surface) capper.SetDisplacement(0.0) capper.SetInPlaneDisplacement(0.0) elif self.Method == 'smooth': triangle = vtk.vtkTriangleFilter() triangle.SetInputData(self.Surface) triangle.PassLinesOff() triangle.PassVertsOff() triangle.Update() capper = vtkvmtk.vtkvmtkSmoothCapPolyData() capper.SetInputConnection(triangle.GetOutputPort()) capper.SetConstraintFactor(self.ConstraintFactor) capper.SetNumberOfRings(self.NumberOfRings) elif self.Method == 'annular': capper = vtkvmtk.vtkvmtkAnnularCapPolyData() capper.SetInputData(self.Surface) elif self.Method == 'concaveannular': import vtkvmtkcontrib capper = vtkvmtkcontrib.vtkvmtkConcaveAnnularCapPolyData() capper.SetInputData(self.Surface) if self.Interactive: capper.SetBoundaryIds(boundaryIds) capper.SetCellEntityIdsArrayName(self.CellEntityIdsArrayName) capper.SetCellEntityIdOffset(self.CellEntityIdOffset) capper.Update() self.Surface = capper.GetOutput() if self.TriangleOutput == 1: triangle = vtk.vtkTriangleFilter() triangle.SetInputData(self.Surface) triangle.PassLinesOff() triangle.PassVertsOff() triangle.Update() self.Surface = triangle.GetOutput() normals = vtk.vtkPolyDataNormals() normals.SetInputData(self.Surface) normals.AutoOrientNormalsOn() normals.SplittingOff() normals.ConsistencyOn() normals.Update() self.Surface = normals.GetOutput()
def Execute(self): if self.Surface == None: self.PrintError('Error: No input surface.') if self.ExtensionMode == "centerlinedirection" and self.Centerlines == None: self.PrintError('Error: No input centerlines.') boundaryIds = vtk.vtkIdList() if self.Interactive: if not self.vmtkRenderer: import vmtkrenderer self.vmtkRenderer = vmtkrenderer.vmtkRenderer() self.vmtkRenderer.Initialize() self.OwnRenderer = 1 boundaryExtractor = vtkvmtk.vtkvmtkPolyDataBoundaryExtractor() boundaryExtractor.SetInput(self.Surface) boundaryExtractor.Update() boundaries = boundaryExtractor.GetOutput() numberOfBoundaries = boundaries.GetNumberOfCells() seedPoints = vtk.vtkPoints() for i in range(numberOfBoundaries): barycenter = [0.0, 0.0, 0.0] vtkvmtk.vtkvmtkBoundaryReferenceSystems.ComputeBoundaryBarycenter(boundaries.GetCell(i).GetPoints(),barycenter) seedPoints.InsertNextPoint(barycenter) seedPolyData = vtk.vtkPolyData() seedPolyData.SetPoints(seedPoints) seedPolyData.Update() labelsMapper = vtk.vtkLabeledDataMapper(); labelsMapper.SetInput(seedPolyData) labelsMapper.SetLabelModeToLabelIds() labelsActor = vtk.vtkActor2D() labelsActor.SetMapper(labelsMapper) self.vmtkRenderer.Renderer.AddActor(labelsActor) surfaceMapper = vtk.vtkPolyDataMapper() surfaceMapper.SetInput(self.Surface) surfaceMapper.ScalarVisibilityOff() surfaceActor = vtk.vtkActor() surfaceActor.SetMapper(surfaceMapper) surfaceActor.GetProperty().SetOpacity(0.25) self.vmtkRenderer.Renderer.AddActor(surfaceActor) self.vmtkRenderer.Render() self.vmtkRenderer.Renderer.RemoveActor(labelsActor) self.vmtkRenderer.Renderer.RemoveActor(surfaceActor) ok = False while not ok: labelString = self.InputText("Please input boundary ids: ",self.LabelValidator) labels = [int(label) for label in labelString.split()] ok = True for label in labels: if label not in range(numberOfBoundaries): ok = False for label in labels: boundaryIds.InsertNextId(label) flowExtensionsFilter = vtkvmtk.vtkvmtkPolyDataFlowExtensionsFilter() flowExtensionsFilter.SetInput(self.Surface) flowExtensionsFilter.SetCenterlines(self.Centerlines) flowExtensionsFilter.SetSigma(self.Sigma) flowExtensionsFilter.SetAdaptiveExtensionLength(self.AdaptiveExtensionLength) flowExtensionsFilter.SetAdaptiveExtensionRadius(self.AdaptiveExtensionRadius) flowExtensionsFilter.SetAdaptiveNumberOfBoundaryPoints(self.AdaptiveNumberOfBoundaryPoints) flowExtensionsFilter.SetExtensionLength(self.ExtensionLength) flowExtensionsFilter.SetExtensionRatio(self.ExtensionRatio) flowExtensionsFilter.SetExtensionRadius(self.ExtensionRadius) flowExtensionsFilter.SetTransitionRatio(self.TransitionRatio) flowExtensionsFilter.SetCenterlineNormalEstimationDistanceRatio(self.CenterlineNormalEstimationDistanceRatio) flowExtensionsFilter.SetNumberOfBoundaryPoints(self.TargetNumberOfBoundaryPoints) if self.ExtensionMode == "centerlinedirection": flowExtensionsFilter.SetExtensionModeToUseCenterlineDirection() elif self.ExtensionMode == "boundarynormal": flowExtensionsFilter.SetExtensionModeToUseNormalToBoundary() if self.InterpolationMode == "linear": flowExtensionsFilter.SetInterpolationModeToLinear() elif self.InterpolationMode == "thinplatespline": flowExtensionsFilter.SetInterpolationModeToThinPlateSpline() if self.Interactive: flowExtensionsFilter.SetBoundaryIds(boundaryIds) flowExtensionsFilter.Update() self.Surface = flowExtensionsFilter.GetOutput() if self.Surface.GetSource(): self.Surface.GetSource().UnRegisterAllOutputs()
def Execute(self): if self.Surface == None: self.PrintError('Error: No input surface.') curvatureFilter = vtk.vtkCurvatures() curvatureFilter.SetInput(self.Surface) if self.CurvatureType == 'mean': curvatureFilter.SetCurvatureTypeToMean() elif self.CurvatureType == 'gaussian': curvatureFilter.SetCurvatureTypeToGaussian() elif self.CurvatureType == 'maximum': curvatureFilter.SetCurvatureTypeToMaximum() elif self.CurvatureType == 'minimum': curvatureFilter.SetCurvatureTypeToMinimum() curvatureFilter.Update() activeScalars = curvatureFilter.GetOutput().GetPointData().GetScalars() activeScalars.SetName('Curvature') if self.AbsoluteCurvature: for i in range(activeScalars.GetNumberOfTuples()): value = activeScalars.GetTuple1(i) activeScalars.SetTuple1(i,abs(value)) neighborhoods = None if not self.CurvatureOnBoundaries or self.MedianFiltering: neighborhoods = vtkvmtk.vtkvmtkNeighborhoods() neighborhoods.SetNeighborhoodTypeToPolyDataManifoldNeighborhood() neighborhoods.SetDataSet(self.Surface) neighborhoods.Build() if not self.CurvatureOnBoundaries: boundaryExtractor = vtkvmtk.vtkvmtkPolyDataBoundaryExtractor() boundaryExtractor.SetInput(self.Surface) boundaryExtractor.Update() boundaryIdsArray = vtk.vtkIdTypeArray.SafeDownCast(boundaryExtractor.GetOutput().GetPointData().GetScalars()) boundaryIds = vtk.vtkIdList() boundaryIds.SetNumberOfIds(boundaryIdsArray.GetNumberOfTuples()) for i in range(boundaryIdsArray.GetNumberOfTuples()): boundaryIds.SetId(i,boundaryIdsArray.GetValue(i)) self.Surface.BuildLinks() for i in range(boundaryIds.GetNumberOfIds()): pointId = boundaryIds.GetId(i) neighborhood = neighborhoods.GetNeighborhood(pointId) values = [] for j in range(neighborhood.GetNumberOfPoints()): neighborId = neighborhood.GetPointId(j) if boundaryIds.IsId(neighborId) != -1: continue value = activeScalars.GetTuple1(neighborId) values.append(value) values.sort() if not values: continue medianValue = values[(len(values) - 1)/2] activeScalars.SetTuple1(pointId,medianValue) if self.MedianFiltering: for i in range(neighborhoods.GetNumberOfNeighborhoods()): neighborhood = neighborhoods.GetNeighborhood(i) values = [] for j in range(neighborhood.GetNumberOfPoints()): neighborId = neighborhood.GetPointId(j) value = activeScalars.GetTuple1(neighborId) values.append(value) values.sort() if not values: continue medianValue = values[(len(values) - 1)/2] activeScalars.SetTuple1(i,medianValue) if self.BoundedReciprocal: for i in range(activeScalars.GetNumberOfTuples()): value = activeScalars.GetTuple1(i) reciprocalValue = 1.0 / (self.Epsilon + value) activeScalars.SetTuple1(i,reciprocalValue) if self.Offset: for i in range(activeScalars.GetNumberOfTuples()): value = activeScalars.GetTuple1(i) activeScalars.SetTuple1(i,value + self.Offset) if self.ReferenceSurface == None: self.Surface.GetPointData().AddArray(activeScalars) else: self.ReferenceSurface.GetPointData().AddArray(activeScalars) self.Surface = self.ReferenceSurface