def warp_surface(args): print("warp the surface ") reader = vmtkscripts.vmtkSurfaceReader() reader.InputFileName = args.surface reader.Execute() Surface = reader.Surface boundaries = vtkvmtk.vtkvmtkPolyDataBoundaryExtractor() boundaries.SetInputData(Surface) boundaries.Update() boundaryReferenceSystems = vtkvmtk.vtkvmtkBoundaryReferenceSystems() boundaryReferenceSystems.SetInputData(Surface) boundaryReferenceSystems.SetBoundaryRadiusArrayName('BoundaryRadius') boundaryReferenceSystems.SetBoundaryNormalsArrayName('BoundaryNormals') boundaryReferenceSystems.SetPoint1ArrayName('Point1') boundaryReferenceSystems.SetPoint2ArrayName('Point2') boundaryReferenceSystems.Update() ReferenceSystems = boundaryReferenceSystems.GetOutput() writer = vmtkscripts.vmtkSurfaceWriter() writer.OutputFileName = args.file_out writer.Input = warp.GetOutput() writer.Execute()
def _Execute(self, *args): assert isinstance(self.Value, int) assert isinstance(self.Iolet, Iolet) input = self.GetPolyDataInput() clipped = self._Clip(input) clipped.BuildLinks(0) newPoints = vtkPoints() newPoints.DeepCopy(clipped.GetPoints()) newPolys = vtkCellArray() newPolys.DeepCopy(clipped.GetPolys()) newData = vtkIntArray() newData.DeepCopy(clipped.GetCellData().GetScalars()) boundaryExtractor = vtkvmtkPolyDataBoundaryExtractor() boundaryExtractor.SetInputData(clipped) boundaryExtractor.Update() boundaries = boundaryExtractor.GetOutput() boundariesPointIdMap = boundaries.GetPointData().GetScalars() for i in xrange(boundaries.GetNumberOfCells()): boundary = vtkPolyLine.SafeDownCast(boundaries.GetCell(i)) barycentre = [0., 0., 0.] vtkvmtkBoundaryReferenceSystems.ComputeBoundaryBarycenter( boundary.GetPoints(), barycentre) barycentreId = newPoints.InsertNextPoint(barycentre) numberOfBoundaryPoints = boundary.GetNumberOfPoints() trianglePoints = vtkIdList() trianglePoints.SetNumberOfIds(3) for j in xrange(numberOfBoundaryPoints): trianglePoints.SetId(0, boundariesPointIdMap.GetValue(boundary.GetPointId(j))) trianglePoints.SetId(1, barycentreId) trianglePoints.SetId(2, boundariesPointIdMap.GetValue(boundary.GetPointId((j + 1) % numberOfBoundaryPoints)) ) newPolys.InsertNextCell(trianglePoints) newData.InsertNextValue(self.Value) continue continue output = self.GetPolyDataOutput() output.SetPoints(newPoints) output.SetPolys(newPolys) output.GetCellData().SetScalars(newData) return
def _Execute(self, *args): assert isinstance(self.Value, int) assert isinstance(self.Iolet, Iolet) input = self.GetPolyDataInput() clipped = self._Clip(input) clipped.BuildLinks(0) newPoints = vtkPoints() newPoints.DeepCopy(clipped.GetPoints()) newPolys = vtkCellArray() newPolys.DeepCopy(clipped.GetPolys()) newData = vtkIntArray() newData.DeepCopy(clipped.GetCellData().GetScalars()) boundaryExtractor = vtkvmtkPolyDataBoundaryExtractor() boundaryExtractor.SetInputData(clipped) boundaryExtractor.Update() boundaries = boundaryExtractor.GetOutput() boundariesPointIdMap = boundaries.GetPointData().GetScalars() for i in xrange(boundaries.GetNumberOfCells()): boundary = vtkPolyLine.SafeDownCast(boundaries.GetCell(i)) barycentre = [0., 0., 0.] vtkvmtkBoundaryReferenceSystems.ComputeBoundaryBarycenter( boundary.GetPoints(), barycentre) barycentreId = newPoints.InsertNextPoint(barycentre) numberOfBoundaryPoints = boundary.GetNumberOfPoints() trianglePoints = vtkIdList() trianglePoints.SetNumberOfIds(3) for j in xrange(numberOfBoundaryPoints): trianglePoints.SetId( 0, boundariesPointIdMap.GetValue(boundary.GetPointId(j))) trianglePoints.SetId(1, barycentreId) trianglePoints.SetId( 2, boundariesPointIdMap.GetValue( boundary.GetPointId((j + 1) % numberOfBoundaryPoints))) newPolys.InsertNextCell(trianglePoints) newData.InsertNextValue(self.Value) continue continue output = self.GetPolyDataOutput() output.SetPoints(newPoints) output.SetPolys(newPolys) output.GetCellData().SetScalars(newData) return
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: from vmtk 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 list(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': from vmtk 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: 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: if (self.Exclude): labelString = self.InputText( "Please input boundary ids to exclude: ", self.LabelValidator) else: 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 list(range(numberOfBoundaries)): ok = False if (self.Exclude): for label in list(range(numberOfBoundaries)): if label not in labels: boundaryIds.InsertNextId(label) else: for label in labels: boundaryIds.InsertNextId(label) flowExtensionsFilter = vtkvmtk.vtkvmtkPolyDataFlowExtensionsFilter() flowExtensionsFilter.SetInputData(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()
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: 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: if(self.Exclude): labelString = self.InputText("Please input boundary ids to exclude: ",self.LabelValidator) else: 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 list(range(numberOfBoundaries)): ok = False if(self.Exclude): for label in list(range(numberOfBoundaries)): if label not in labels: boundaryIds.InsertNextId(label) else: for label in labels: boundaryIds.InsertNextId(label) flowExtensionsFilter = vtkvmtk.vtkvmtkPolyDataFlowExtensionsFilter() flowExtensionsFilter.SetInputData(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()
def Execute(self): if self.Surface == None: self.PrintError('Error: No input surface.') curvatureFilter = vtk.vtkCurvatures() curvatureFilter.SetInputData(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.SetInputData(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: from vmtk 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 list(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': from vmtk 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.') curvatureFilter = vtk.vtkCurvatures() curvatureFilter.SetInputData(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.SetInputData(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