-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvtkDelaunay3d.py
78 lines (59 loc) · 1.88 KB
/
vtkDelaunay3d.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# -*- coding: utf-8 -*-
"""
Created on Thu May 08 14:04:19 2014
@author: adminGH
"""
# This example shows how to use Delaunay3D with alpha shapes.
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()
points = vtk.vtkPoints()
filename = 'PZFlex.csv'
data = loadtxt(filename, delimiter=',')
# Read positional data
X = data[:,0]; Y = data[:,1]; Z = data[:,2]
# Read velocity data
Xv = data[:,3]; Yv = data[:,4]; Zv = data[:,5]
Np = len(data)
for i in range(0, Np):
points.InsertPoint(i, X[i], Y[i], Z[i])
profile = vtk.vtkPolyData()
profile.SetPoints(points)
# Delaunay3D is used to triangulate the points. The Tolerance is the
# distance that nearly coincident points are merged
# together. (Delaunay does better if points are well spaced.) The
# alpha value is the radius of circumcircles, circumspheres. Any mesh
# entity whose circumcircle is smaller than this value is output.
delny = vtk.vtkDelaunay3D()
delny.SetInput(profile)
delny.SetTolerance(0.001)
delny.SetAlpha(0.02)
delny.BoundingTriangulationOn()
print 'done'
# Shrink the result to help see it better.
shrink = vtk.vtkShrinkFilter()
shrink.SetInputConnection(delny.GetOutputPort())
shrink.SetShrinkFactor(0.9)
map = vtk.vtkDataSetMapper()
map.SetInputConnection(shrink.GetOutputPort())
triangulation = vtk.vtkActor()
triangulation.SetMapper(map)
triangulation.GetProperty().SetColor(1, 0, 0)
# Create graphics stuff
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(triangulation)
ren.SetBackground(1, 1, 1)
renWin.SetSize(250, 250)
renWin.Render()
cam1 = ren.GetActiveCamera()
cam1.Zoom(1.5)
iren.Initialize()
renWin.Render()
iren.Start()