def __init__(self, module_manager): # initialise our base class ModuleBase.__init__(self, module_manager) NoConfigModuleMixin.__init__(self) # these will be our markers self._inputPoints = None # we can't connect the image input directly to the masksource, # so we have to keep track of it separately. self._inputImage = None self._inputImageObserverID = None # we need to modify the mask (I) as well. The problem with a # ProgrammableFilter is that you can't request GetOutput() before # the input has been set... self._maskSource = vtk.vtkProgrammableSource() self._maskSource.SetExecuteMethod(self._maskSourceExecute) # we'll use this to synthesise a volume according to the seed points self._markerSource = vtk.vtkProgrammableSource() self._markerSource.SetExecuteMethod(self._markerSourceExecute) # second input is J (the marker) # we'll use this to change the markerImage into something we can use self._imageThreshold = vtk.vtkImageThreshold() # everything equal to or above 1.0 will be "on" self._imageThreshold.ThresholdByUpper(1.0) self._imageThresholdObserverID = self._imageThreshold.AddObserver( 'EndEvent', self._observerImageThreshold) self._viewFrame = self._createViewFrame( {'Module (self)' : self}) # we're not going to give imageErode any input... that's going to # to happen manually in the execute_module function :) self._imageErode = vtk.vtkImageContinuousErode3D() self._imageErode.SetKernelSize(3,3,3) module_utils.setup_vtk_object_progress(self, self._imageErode, 'Performing greyscale 3D erosion') self._sup = vtk.vtkImageMathematics() self._sup.SetOperationToMax() self._sup.SetInput1(self._imageErode.GetOutput()) self._sup.SetInput2(self._maskSource.GetStructuredPointsOutput()) # pass the data down to the underlying logic self.config_to_logic() # and all the way up from logic -> config -> view to make sure self.syncViewWithLogic()
def __init__(self, module_manager): # initialise our base class ModuleBase.__init__(self, module_manager) NoConfigModuleMixin.__init__(self) # these will be our markers self._inputPoints = None # we can't connect the image input directly to the masksource, # so we have to keep track of it separately. self._inputImage = None self._inputImageObserverID = None # we need to modify the mask (I) as well. The problem with a # ProgrammableFilter is that you can't request GetOutput() before # the input has been set... self._maskSource = vtk.vtkProgrammableSource() self._maskSource.SetExecuteMethod(self._maskSourceExecute) # we'll use this to synthesise a volume according to the seed points self._markerSource = vtk.vtkProgrammableSource() self._markerSource.SetExecuteMethod(self._markerSourceExecute) # second input is J (the marker) # we'll use this to change the markerImage into something we can use self._imageThreshold = vtk.vtkImageThreshold() # everything equal to or above 1.0 will be "on" self._imageThreshold.ThresholdByUpper(1.0) self._imageThresholdObserverID = self._imageThreshold.AddObserver( 'EndEvent', self._observerImageThreshold) self._viewFrame = self._createViewFrame({'Module (self)': self}) # we're not going to give imageErode any input... that's going to # to happen manually in the execute_module function :) self._imageErode = vtk.vtkImageContinuousErode3D() self._imageErode.SetKernelSize(3, 3, 3) module_utils.setup_vtk_object_progress( self, self._imageErode, 'Performing greyscale 3D erosion') self._sup = vtk.vtkImageMathematics() self._sup.SetOperationToMax() self._sup.SetInput1(self._imageErode.GetOutput()) self._sup.SetInput2(self._maskSource.GetStructuredPointsOutput()) # pass the data down to the underlying logic self.config_to_logic() # and all the way up from logic -> config -> view to make sure self.syncViewWithLogic()
def __init__(self, module_manager): # initialise our base class ModuleBase.__init__(self, module_manager) # these will be our markers self._inputPoints = None # we can't connect the image input directly to the masksource, # so we have to keep track of it separately. self._inputImage = None self._inputImageObserverID = None # we need to modify the mask (I) as well. The problem with a # ProgrammableFilter is that you can't request GetOutput() before # the input has been set... self._maskSource = vtk.vtkProgrammableSource() self._maskSource.SetExecuteMethod(self._maskSourceExecute) self._dualGreyReconstruct = vtkdevide.vtkImageGreyscaleReconstruct3D() # first input is I (the modified mask) self._dualGreyReconstruct.SetDual(1) self._dualGreyReconstruct.SetInput1( self._maskSource.GetStructuredPointsOutput()) # we'll use this to synthesise a volume according to the seed points self._markerSource = vtk.vtkProgrammableSource() self._markerSource.SetExecuteMethod(self._markerSourceExecute) # second input is J (the marker) self._dualGreyReconstruct.SetInput2( self._markerSource.GetStructuredPointsOutput()) # we'll use this to change the markerImage into something we can use self._imageThreshold = vtk.vtkImageThreshold() # everything equal to or above 1.0 will be "on" self._imageThreshold.ThresholdByUpper(1.0) self._imageThresholdObserverID = self._imageThreshold.AddObserver( 'EndEvent', self._observerImageThreshold) module_utils.setup_vtk_object_progress( self, self._dualGreyReconstruct, 'Performing dual greyscale reconstruction') NoConfigModuleMixin.__init__( self, { 'Module (self)': self, 'vtkImageGreyscaleReconstruct3D': self._dualGreyReconstruct }) self.sync_module_logic_with_config()
def __init__(self): vtk.vtkProgrammableSource(self) def genPoints(): points = vtk.vtkPoints() output = self.GetPolyDataOutput() output.SetPoints(points) # Left the points in a *. txt file , and read them from here n = 5 for i in range(n): for j in range(n): for k in range(n): points.InsertNextPoint(i, j, k) self.SetExecuteMethod(genPoints)
def SurfaceReconstruction(self): pointSource = vtk.vtkProgrammableSource() def readPoints(): output = pointSource.GetPolyDataOutput() points = vtk.vtkPoints() output.SetPoints(points) for i in IDList: p = self.pointCloud.vtkPoints.GetPoint(i) points.InsertNextPoint(p) pointSource.SetExecuteMethod(readPoints) surf = vtk.vtkSurfaceReconstructionFilter() surf.SetInputConnection(pointSource.GetOutputPort()) cf = vtk.vtkContourFilter() cf.SetInputConnection(surf.GetOutputPort()) cf.SetValue(0, 0) mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(cf.GetOutputPort()) mapper.ScalarVisibilityOff() actor = vtk.vtkActor() actor.SetMapper(mapper) actor.GetProperty().SetDiffuseColor(1, 0.3882, 0.2784) actor.GetProperty().SetSpecularColor(1, 1, 1) actor.GetProperty().SetSpecular(.4) actor.GetProperty().SetSpecularPower(50) self.renderer.AddActor(actor) self.refresh_renderer()
def trace(obj): s = vtk.vtkProgrammableSource() def execute(): global offset positions = [trajectory(obj,i) for i in range(offset)] #construct a VTK polydata object: a single poly-line 'cell' dataset = s.GetPolyDataOutput() points = vtk.vtkPoints() cells = vtk.vtkCellArray() cells.InsertNextCell(len(positions)) for p in positions: id = points.InsertNextPoint(*p) cells.InsertCellPoint(id) dataset.SetPoints(points) dataset.SetLines(cells) return dataset s.SetExecuteMethod(execute) m=vtk.vtkPolyDataMapper() m.SetInput(s.GetOutput()) a=vtk.vtkActor() a.SetMapper(m) def update(): s.Modified() return (update,a)
def trace(obj): s = vtk.vtkProgrammableSource() def execute(): global offset positions = [trajectory(obj, i) for i in range(offset)] #construct a VTK polydata object: a single poly-line 'cell' dataset = s.GetPolyDataOutput() points = vtk.vtkPoints() cells = vtk.vtkCellArray() cells.InsertNextCell(len(positions)) for p in positions: id = points.InsertNextPoint(*p) cells.InsertCellPoint(id) dataset.SetPoints(points) dataset.SetLines(cells) return dataset s.SetExecuteMethod(execute) m = vtk.vtkPolyDataMapper() m.SetInput(s.GetOutput()) a = vtk.vtkActor() a.SetMapper(m) def update(): s.Modified() return (update, a)
def surfaceRecon(self): pointSource = vtk.vtkProgrammableSource() def readPoints(): output = pointSource.GetPolyDataOutput() #points = vtk.vtkPoints() output.SetPoints(self.vtkPoints) pointSource.SetExecuteMethod(readPoints) surf = vtk.vtkSurfaceReconstructionFilter() surf.SetInputConnection(pointSource.GetOutputPort()) print(surf) contour = vtk.vtkContourFilter() contour.SetInputConnection(surf.GetOutputPort()) contour.SetValue(0, 0.0) print(contour) reverse = vtk.vtkReverseSense() reverse.SetInputConnection(contour.GetOutputPort()) reverse.ReverseCellsOn() reverse.ReverseNormalsOn() contourMapper = vtk.vtkPolyDataMapper() contourMapper.SetInputConnection(reverse.GetOutputPort()) contourMapper.ScalarVisibilityOff() print(contourMapper) contourActor = vtk.vtkActor() contourActor.SetMapper(contourMapper) print(contourActor) return contourActor
def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__( self, module_manager, vtk.vtkProgrammableSource(), 'Processing.', (), ('vtkDataSet', 'vtkDataSet', 'vtkDataSet', 'vtkDataSet', 'vtkDataSet'), replaceDoc=True, inputFunctions=None, outputFunctions=None)
def __init__(self, module_manager): # initialise our base class ModuleBase.__init__(self, module_manager) # these will be our markers self._inputPoints = None # we can't connect the image input directly to the masksource, # so we have to keep track of it separately. self._inputImage = None self._inputImageObserverID = None # we need to modify the mask (I) as well. The problem with a # ProgrammableFilter is that you can't request GetOutput() before # the input has been set... self._maskSource = vtk.vtkProgrammableSource() self._maskSource.SetExecuteMethod(self._maskSourceExecute) self._dualGreyReconstruct = vtkdevide.vtkImageGreyscaleReconstruct3D() # first input is I (the modified mask) self._dualGreyReconstruct.SetDual(1) self._dualGreyReconstruct.SetInput1(self._maskSource.GetStructuredPointsOutput()) # we'll use this to synthesise a volume according to the seed points self._markerSource = vtk.vtkProgrammableSource() self._markerSource.SetExecuteMethod(self._markerSourceExecute) # second input is J (the marker) self._dualGreyReconstruct.SetInput2(self._markerSource.GetStructuredPointsOutput()) # we'll use this to change the markerImage into something we can use self._imageThreshold = vtk.vtkImageThreshold() # everything equal to or above 1.0 will be "on" self._imageThreshold.ThresholdByUpper(1.0) self._imageThresholdObserverID = self._imageThreshold.AddObserver("EndEvent", self._observerImageThreshold) module_utils.setup_vtk_object_progress( self, self._dualGreyReconstruct, "Performing dual greyscale reconstruction" ) NoConfigModuleMixin.__init__( self, {"Module (self)": self, "vtkImageGreyscaleReconstruct3D": self._dualGreyReconstruct} ) self.sync_module_logic_with_config()
def __init__(self, data): self._data = None if data is not None: if len(data) > 0: self._data = data else: self._data = None if self._data is not None: self._time = min(self._data[:, 0]) else: self._time = 0 self._contact_source_a = vtk.vtkProgrammableSource() self._contact_source_b = vtk.vtkProgrammableSource() self._contact_source_a.SetExecuteMethod(self.method) self._contact_source_b.SetExecuteMethod(self.method)
def get_point_source(): #return MyPointSource() pointSource = vtk.vtkProgrammableSource() # Source def genPoints(): points = vtk.vtkPoints() output = pointSource.GetPolyDataOutput() output.SetPoints(points) # Left the points in a *. txt file , and read them from here n = 3 for i in range(n): for j in range(n): for k in range(n): points.InsertNextPoint(i, j, k) pointSource.SetExecuteMethod(genPoints) return pointSource
def __init__(self, path, file, write_out=True): self.path = path self.file = file # Remove ".mat" extensions from filename, for later use if (self.file.find(".mat") > -1): self.file = self.file[0:self.file.find(".mat")] self.points = vtk.vtkProgrammableSource() self.surface = vtk.vtkPolyData() # Function to read in point cloud def loadPoints(): import scipy.io data_all = scipy.io.loadmat(self.path + self.file + ".mat") self.raw_points = data_all.get(self.file) p = vtk.vtkPoints() for i in range(self.raw_points.shape[0]): for j in range(self.raw_points.shape[1]): x = self.raw_points[i, j, 0] y = self.raw_points[i, j, 1] z = self.raw_points[i, j, 2] p.InsertNextPoint(x, y, z) self.points.GetPolyDataOutput().SetPoints(p) self.points.SetExecuteMethod(loadPoints) self.surface = self.createSurface(self.points) # Write VTP file if (write_out) == True: self.writeVTP()
pcaStatistics.GetEigenvectors(eigenvectors) for idx in range(0,eigenvectors.GetNumberOfTuples()): print 'Eigenvector ' + str(idx) + ' : ' evec = [0]*eigenvectors.GetNumberOfComponents() eigenvectors.GetTuple(idx, evec) print evec if __name__ == '__main__': r = vtk.vtkEnsembleSource() aColumn = vtk.vtkIntArray() aColumn.SetName("Ensemble Index") for mem in range(1,MEMBERS+1): ps = vtk.vtkProgrammableSource() ps.GetStructuredPointsOutput() ps.GetExecutive().SetOutputData(0, vtk.vtkImageData()) ps.SetExecuteMethod(makeReadFunction(ps, mem)) r.AddMember(ps) aColumn.InsertNextValue(mem) table = vtk.vtkTable() table.SetNumberOfRows(MEMBERS) table.GetRowData().AddArray(aColumn) r.SetMetaData(table) pf = vtk.vtkProgrammableFilter() pf.SetInputConnection(r.GetOutputPort()) container = ProgrammableFilterDataContainer(pf)
def testReconstructSurface(self): # Read some points. Use a programmable filter to read them. # pointSource = vtk.vtkProgrammableSource() def readPoints(): fp = open(VTK_DATA_ROOT + "/Data/cactus.3337.pts", "r") points = vtk.vtkPoints() while True: line = fp.readline().split() if len(line) == 0: break if line[0] == "p": points.InsertNextPoint(float(line[1]), float(line[2]), float(line[3])) pointSource.GetPolyDataOutput().SetPoints(points) pointSource.SetExecuteMethod(readPoints) # Construct the surface and create isosurface # surf = vtk.vtkSurfaceReconstructionFilter() surf.SetInputConnection(pointSource.GetOutputPort()) cf = vtk.vtkContourFilter() cf.SetInputConnection(surf.GetOutputPort()) cf.SetValue(0, 0.0) reverse = vtk.vtkReverseSense() reverse.SetInputConnection(cf.GetOutputPort()) reverse.ReverseCellsOn() reverse.ReverseNormalsOn() map = vtk.vtkPolyDataMapper() map.SetInputConnection(reverse.GetOutputPort()) map.ScalarVisibilityOff() surfaceActor = vtk.vtkActor() surfaceActor.SetMapper(map) surfaceActor.GetProperty().SetDiffuseColor(1.0000, 0.3882, 0.2784) surfaceActor.GetProperty().SetSpecularColor(1, 1, 1) surfaceActor.GetProperty().SetSpecular(.4) surfaceActor.GetProperty().SetSpecularPower(50) # Create the RenderWindow, Renderer and both Actors # ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) # Add the actors to the renderer, set the background and size # ren.AddActor(surfaceActor) ren.SetBackground(1, 1, 1) renWin.SetSize(300, 300) ren.GetActiveCamera().SetFocalPoint(0, 0, 0) ren.GetActiveCamera().SetPosition(1, 0, 0) ren.GetActiveCamera().SetViewUp(0, 0, 1) ren.ResetCamera() ren.GetActiveCamera().Azimuth(20) ren.GetActiveCamera().Elevation(30) ren.GetActiveCamera().Dolly(1.2) ren.ResetCameraClippingRange() # render and interact with data iRen = vtk.vtkRenderWindowInteractor() iRen.SetRenderWindow(renWin) renWin.Render() img_file = "reconstructSurface.png" vtk.test.Testing.compareImage( iRen.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=25) vtk.test.Testing.interact()
def __init__(self): self.pts = "" self.cntr_nr = 0 self.pointSource = vtk.vtkProgrammableSource() self.pointSource.SetExecuteMethod(self.readPoints)
def testReconstructSurface(self): # Read some points. Use a programmable filter to read them. # pointSource = vtk.vtkProgrammableSource() def readPoints(): fp = open(VTK_DATA_ROOT + "/Data/cactus.3337.pts", "r") points = vtk.vtkPoints() while True: line = fp.readline().split() if len(line) == 0: break if line[0] == "p": points.InsertNextPoint(float(line[1]), float(line[2]), float(line[3])) pointSource.GetPolyDataOutput().SetPoints(points) pointSource.SetExecuteMethod(readPoints) # Construct the surface and create isosurface # surf = vtk.vtkSurfaceReconstructionFilter() surf.SetInputConnection(pointSource.GetOutputPort()) cf = vtk.vtkContourFilter() cf.SetInputConnection(surf.GetOutputPort()) cf.SetValue(0, 0.0) reverse = vtk.vtkReverseSense() reverse.SetInputConnection(cf.GetOutputPort()) reverse.ReverseCellsOn() reverse.ReverseNormalsOn() map = vtk.vtkPolyDataMapper() map.SetInputConnection(reverse.GetOutputPort()) map.ScalarVisibilityOff() surfaceActor = vtk.vtkActor() surfaceActor.SetMapper(map) surfaceActor.GetProperty().SetDiffuseColor(1.0000, 0.3882, 0.2784) surfaceActor.GetProperty().SetSpecularColor(1, 1, 1) surfaceActor.GetProperty().SetSpecular(.4) surfaceActor.GetProperty().SetSpecularPower(50) # Create the RenderWindow, Renderer and both Actors # ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) # Add the actors to the renderer, set the background and size # ren.AddActor(surfaceActor) ren.SetBackground(1, 1, 1) renWin.SetSize(300, 300) ren.GetActiveCamera().SetFocalPoint(0, 0, 0) ren.GetActiveCamera().SetPosition(1, 0, 0) ren.GetActiveCamera().SetViewUp(0, 0, 1) ren.ResetCamera() ren.GetActiveCamera().Azimuth(20) ren.GetActiveCamera().Elevation(30) ren.GetActiveCamera().Dolly(1.2) ren.ResetCameraClippingRange() # render and interact with data iRen = vtk.vtkRenderWindowInteractor() iRen.SetRenderWindow(renWin); renWin.Render() img_file = "reconstructSurface.png" vtk.test.Testing.compareImage(iRen.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=25) vtk.test.Testing.interact()
def reconstructSurface(folder): pointSource = vtk.vtkProgrammableSource() def readPoints(): output = pointSource.GetPolyDataOutput() points = vtk.vtkPoints() output.SetPoints(points) group_points = groupsToPoints(folder) for p in group_points: points.insertNextPoint(p[0],p[1],p[2]) pointSource.SetExecuteMethod(readPoints) # Construct the surface and create isosurface. surf = vtk.vtkSurfaceReconstructionFilter() surf.SetInputConnection(pointSource.GetOutputPort()) cf = vtk.vtkContourFilter() cf.SetInputConnection(surf.GetOutputPort()) cf.SetValue(0, 0.0) # Sometimes the contouring algorithm can create a volume whose gradient # vector and ordering of polygon (using the right hand rule) are # inconsistent. vtkReverseSense cures this problem. reverse = vtk.vtkReverseSense() reverse.SetInputConnection(cf.GetOutputPort()) reverse.ReverseCellsOn() reverse.ReverseNormalsOn() map = vtk.vtkPolyDataMapper() map.SetInputConnection(reverse.GetOutputPort()) map.ScalarVisibilityOff() surfaceActor = vtk.vtkActor() surfaceActor.SetMapper(map) surfaceActor.GetProperty().SetDiffuseColor(1.0000, 0.3882, 0.2784) surfaceActor.GetProperty().SetSpecularColor(1, 1, 1) surfaceActor.GetProperty().SetSpecular(.4) surfaceActor.GetProperty().SetSpecularPower(50) # Create the RenderWindow, Renderer and both Actors ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # Add the actors to the renderer, set the background and size ren.AddActor(surfaceActor) ren.SetBackground(1, 1, 1) renWin.SetSize(400, 400) ren.GetActiveCamera().SetFocalPoint(0, 0, 0) ren.GetActiveCamera().SetPosition(1, 0, 0) ren.GetActiveCamera().SetViewUp(0, 0, 1) ren.ResetCamera() ren.GetActiveCamera().Azimuth(20) ren.GetActiveCamera().Elevation(30) ren.GetActiveCamera().Dolly(1.2) ren.ResetCameraClippingRange() iren.Initialize() renWin.Render() iren.Start()
import vtk # The points to be triangulated are generated randomly in the unit # cube located at the origin. The points are then associated with a # vtkPolyData. math = vtk.vtkMath() pointSource = vtk.vtkProgrammableSource() def readPoints(): output = pointSource.GetPolyDataOutput() points = vtk.vtkPoints() output.SetPoints(points) for i in range(0, 50): x, y = math.Random(0,1), math.Random(0,1) points.InsertNextPoint(x, y, x*y+x) pointSource.SetExecuteMethod(readPoints) # Construct the surface and create isosurface. surf = vtk.vtkSurfaceReconstructionFilter() surf.SetInputConnection(pointSource.GetOutputPort()) cf = vtk.vtkContourFilter() cf.SetInputConnection(surf.GetOutputPort()) cf.SetValue(0, 0.0) # Sometimes the contouring algorithm can create a volume whose gradient # vector and ordering of polygon (using the right hand rule) are # inconsistent. vtkReverseSense cures this problem. reverse = vtk.vtkReverseSense() reverse.SetInputConnection(cf.GetOutputPort())
#surface shading. contourFilter = vtk.vtkContourFilter() contourFilter.SetInputConnection(reader.GetOutputPort()) contourFilter.SetValue(0,1) contourNormals = vtk.vtkPolyDataNormals() contourNormals.SetInputConnection(contourFilter.GetOutputPort()) contourNormals.SetFeatureAngle(60.0) dataMapper = vtk.vtkPolyDataMapper() dataMapper.SetInputConnection(contourNormals.GetOutputPort()) dataMapper.ScalarVisibilityOff() contour = vtk.vtkActor() contour.SetMapper(dataMapper) contour.GetProperty().SetOpacity(0.8) #Point sources for the streamlines pointSource1 = vtk.vtkProgrammableSource() pointSource2 = vtk.vtkProgrammableSource() def points1(): output = pointSource1.GetPolyDataOutput() points1 = vtk.vtkPoints() output.SetPoints(points1) for i in range(nPoints): x, y, z = 1.5, (.5 + random.randint(y1[0],y1[1])), (.5 + random.randint(z1[0],z1[1])) points1.InsertNextPoint(x, y, z) def points2(): output = pointSource2.GetPolyDataOutput() points2 = vtk.vtkPoints() output.SetPoints(points2)
# First we generate a volume using the # vtkSurfaceReconstructionFilter. The volume values are a distance # field. Once this is generated, the volume is countoured at a # distance value of 0.0. import os import string import vtk from vtk.util.misc import vtkGetDataRoot VTK_DATA_ROOT = vtkGetDataRoot() inFile = 'E:\\LX\\myprojects\\CORE3D\\data\\data_core3d\\crop1.xyz' outFile = 'E:\\LX\\myprojects\\CORE3D\\data\\data_core3d\\crop1_vtk.xyz' # Read some points. Use a programmable filter to read them. pointSource = vtk.vtkProgrammableSource() def readPoints(): global inFile output = pointSource.GetPolyDataOutput() points = vtk.vtkPoints() output.SetPoints(points) #file = open(os.path.normpath(os.path.join(VTK_DATA_ROOT, "Data/cactus.3337.pts"))) #file = open(os.path.normpath(r"E:\LX\myprojects\CORE3D\data\data_core3d\crop1.xyz")) file = open(inFile) line = file.readline() while line: data = line.split()
def reconstruct_surface(): """Example of constructing a surface from a point cloud https://github.com/Kitware/VTK/blob/a1a94d0ca96854fe72480cf2ec031a533b129b04/Examples/Modelling/Python/reconstructSurface.py """ pointSource = vtk.vtkProgrammableSource() def readPoints(): output = pointSource.GetPolyDataOutput() points = vtk.vtkPoints() output.SetPoints(points) fname = open('./data/point_clouds/cactus.3337.pts') line = fname.readline() while line: data = line.split() if data and data[0] == 'p': x, y, z = float(data[1]), float(data[2]), float(data[3]) points.InsertNextPoint(x, y, z) line = fname.readline() pointSource.SetExecuteMethod(readPoints) surf = vtk.vtkSurfaceReconstructionFilter() surf.SetInputConnection(pointSource.GetOutputPort()) cf = vtk.vtkContourFilter() cf.SetInputConnection(surf.GetOutputPort()) cf.SetValue(0, 0.0) reverse = vtk.vtkReverseSense() reverse.SetInputConnection(cf.GetOutputPort()) reverse.ReverseCellsOn() reverse.ReverseNormalsOn() map = vtk.vtkPolyDataMapper() map.SetInputConnection(reverse.GetOutputPort()) map.ScalarVisibilityOff() surfaceActor = vtk.vtkActor() surfaceActor.SetMapper(map) surfaceActor.GetProperty().SetDiffuseColor(1, 0.3882, 0.2784) surfaceActor.GetProperty().SetSpecularColor(1, 1, 1) surfaceActor.GetProperty().SetSpecular(0.4) surfaceActor.GetProperty().SetSpecularPower(50) ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) ren.AddActor(surfaceActor) ren.SetBackground(1, 1, 1) renWin.SetSize(400, 400) ren.GetActiveCamera().SetFocalPoint(0, 0, 0) ren.GetActiveCamera().SetPosition(1, 0, 0) ren.GetActiveCamera().SetViewUp(0, 0, 1) ren.ResetCamera() ren.GetActiveCamera().Azimuth(20) ren.GetActiveCamera().Elevation(30) ren.GetActiveCamera().Dolly(1.2) ren.ResetCameraClippingRange() iren.Initialize() renWin.Render() iren.Start()