-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathObjProcessing.py
executable file
·35 lines (32 loc) · 1.08 KB
/
ObjProcessing.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
import vtk
def resize_poly_data(data, resize):
" resize the poly data"
pDecimate = vtk.vtkDecimatePro()
pDecimate.SetInputData(data)
pDecimate.SetTargetReduction(1-resize)
pDecimate.PreserveTopologyOff()
pDecimate.SplittingOn()
pDecimate.BoundaryVertexDeletionOn()
pDecimate.SetMaximumError(vtk.VTK_DOUBLE_MAX)
pDecimate.Update()
return pDecimate.GetOutput()
def read_color_from_ffd(filename):
colors = []
with open(filename, "r") as f:
for lines in f:
values = lines.strip().split(" ")
if values[0] == "v" and len(values) == 7:
colors.append((int(float(values[4])*255), int(float(values[5])*255), int(float(values[6])*255)))
else:
continue
return colors
def color_on_points(data, colors=[]):
" put color on points"
Colors = vtk.vtkUnsignedCharArray()
Colors.SetNumberOfComponents(3)
Colors.SetName("Colors")
for r,g,b in colors:
Colors.InsertNextTuple3(r, g, b)
data.GetPointData().SetScalars(Colors)
data.Modified()
return data