'Smoothing surface in vtk (Python)
I'm new to the vtk and would like to smooth a surface that I'm loading in before doing some data processing.
I've been trying lots of different ways to feed this into either vtkQuadricClustering() or vtkSmoothPolyDataFilter() but not sure where my code is wrong?
This is what it currently looks like:
surf_reader = vtk.vtkMNIObjectReader()
surf_reader.SetFileName('surface.obj')
surf_reader.Update()
gmwm_surf = surf_reader.GetOutputDataObject(0)
# smooth_surface=vtk.vtkQuadricClustering()
# smooth_surface.SetInput(gmwm_surf)
# smooth_surface.Update()
# gmwm_surf_smooth=smooth_surface.GetOutputDataObject(0)
smoothingFilter= vtk.vtkSmoothPolyDataFilter()
smoothingFilter.SetInputDataObject(surf_reader.GetOutput())
smoothingFilter.SetNumberOfIterations(10)
smoothingFilter.Update()
gmwm_surf_smooth=smoothingFilter.GetOutput()
Can anyone spot what I'm doing wrong? How would I go about displaying this data to visualise smoothing output?
surf_mapper = vtk.vtkPolyDataMapper()
surf_mapper.SetInputConnection(surf_reader)
window = vtk.vtkRenderWindow()
window.SetSize(500, 500)
interactor = vtk.vtkRenderWindowInteractor()
interactor.SetRenderWindow(window)
renderer = vtk.vtkRenderer()
window.AddRenderer(renderer)
renderer.AddActor(surf_mapper)
# Setting the background to blue.
renderer.SetBackground(0.1, 0.1, 0.4)
window.Render()
interactor.Start()
I've tried the above but it's also currently not working, I get this error:
TypeError: SetInputConnection argument 1: method requires a vtkAlgorithmOutput, a vtkMNIObjectReader was provided.
Solution 1:[1]
This line is incorrect:
surf_mapper.SetInputConnection(surf_reader)
I believe it should be:
surf_mapper.SetInputConnection(surf_reader.GetOutputPort())
Update for new error:
AddActor is expecting a vtkActor, and you're passing it a vtkMapper. I think you can create an actor, and assign your mapper to it. It should be something like this:
actor = vtk.vtkActor()
actor.SetMapper(surf_mapper)
renderer.AddActor(actor)
In both these errors, you need to figure out what type of object each method is expecting. Check the VTK documentation for that.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
