-
Notifications
You must be signed in to change notification settings - Fork 0
/
filtro.py
52 lines (43 loc) · 1.45 KB
/
filtro.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import vtk
import sys
def ApplySmoothFilter(polydata, iterations, relaxation_factor):
smoother = vtk.vtkSmoothPolyDataFilter()
smoother.SetInputData(polydata)
smoother.SetNumberOfIterations(iterations)
smoother.SetRelaxationFactor(relaxation_factor)
smoother.FeatureEdgeSmoothingOn()
smoother.BoundarySmoothingOn()
smoother.Update()
normal = vtk.vtkPolyDataNormals()
normal.SetInputData(smoother.GetOutput())
normal.ComputePointNormalsOn()
normal.ComputeCellNormalsOn()
normal.Update()
return normal.GetOutput()
reader = vtk.vtkOBJReader()
reader.SetFileName(sys.argv[1])
reader.Update()
poly_data = reader.GetOutput()
poly_data = ApplySmoothFilter(poly_data,15,0.1)
#print(type(poly_data))
# Create a mapper and actor for initial dataset
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputData(poly_data)
actor = vtk.vtkActor()
actor.SetMapper(mapper)
# Visualise
renderer = vtk.vtkRenderer()
renderWindow = vtk.vtkRenderWindow()
renderWindow.AddRenderer(renderer)
renderWindowInteractor = vtk.vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renderWindow)
# Add actors and render
renderer.AddActor(actor)
renderer.SetBackground(0, 0, 0) # Background color white
renderWindow.SetSize(800, 800)
#renderWindow.Render()
#renderWindowInteractor.Start()
exporter = vtk.vtkOBJExporter()
exporter.SetRenderWindow( renderWindow )
exporter.SetFilePrefix( sys.argv[2] ) #create mtl and obj file.
exporter.Write()