def Execute(self): if (self.Surface == 0): self.PrintError('NonManifoldSurfaceChecker error: Surface not set') return self.NonManifoldEdgesFound = 0 self.Report = '' self.NonManifoldEdgePointIds.Initialize() neighborhoods = vtkvmtk.vtkvmtkNeighborhoods() neighborhoods.SetNeighborhoodTypeToPolyDataManifoldNeighborhood() neighborhoods.SetDataSet(self.Surface) neighborhoods.Build() neighborCellIds = vtk.vtkIdList() cellPointIds = vtk.vtkIdList() self.Surface.BuildCells() self.Surface.BuildLinks(0) numberOfNonManifoldEdges = 0 for i in range(neighborhoods.GetNumberOfNeighborhoods()): neighborhood = neighborhoods.GetNeighborhood(i) for j in range(neighborhood.GetNumberOfPoints()): neighborId = neighborhood.GetPointId(j) if (i < neighborId): neighborCellIds.Initialize() self.Surface.GetCellEdgeNeighbors(-1, i, neighborId, neighborCellIds) if (neighborCellIds.GetNumberOfIds() > 2): numberOfNonManifoldEdges = numberOfNonManifoldEdges + 1 self.Report = self.Report + "Non-manifold edge found" + str( i) + ' ' + str(neighborId) + '.\n' self.NonManifoldEdgePointIds.InsertNextId(i) self.NonManifoldEdgePointIds.InsertNextId(neighborId)
def Execute(self): if (self.Surface == 0): self.PrintError('NonManifoldSurfaceChecker error: Surface not set') return self.NonManifoldEdgesFound = 0 self.Report = '' self.NonManifoldEdgePointIds.Initialize() neighborhoods = vtkvmtk.vtkvmtkNeighborhoods() neighborhoods.SetNeighborhoodTypeToPolyDataManifoldNeighborhood() neighborhoods.SetDataSet(self.Surface) neighborhoods.Build() neighborCellIds = vtk.vtkIdList() cellPointIds = vtk.vtkIdList() self.Surface.BuildCells() self.Surface.BuildLinks(0) numberOfNonManifoldEdges = 0 for i in range(neighborhoods.GetNumberOfNeighborhoods()): neighborhood = neighborhoods.GetNeighborhood(i) for j in range(neighborhood.GetNumberOfPoints()): neighborId = neighborhood.GetPointId(j) if (i<neighborId): neighborCellIds.Initialize() self.Surface.GetCellEdgeNeighbors(-1,i,neighborId,neighborCellIds) if (neighborCellIds.GetNumberOfIds()>2): numberOfNonManifoldEdges = numberOfNonManifoldEdges + 1 self.Report = self.Report + "Non-manifold edge found" + str(i) + ' ' + str(neighborId) + '.\n' self.NonManifoldEdgePointIds.InsertNextId(i) self.NonManifoldEdgePointIds.InsertNextId(neighborId)
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.') 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