模型3D

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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python
 
import vtk
 
 
def main():
    colors = vtk.vtkNamedColors()
 
    # Create the RenderWindow, Renderer and Interactor.
    #
    renderer = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(renderer)
 
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)
 
    # Create the bottle profile.
    #
    points = vtk.vtkPoints()
    points.InsertPoint(0, 0.01, 0.0, 0.0)
    points.InsertPoint(1, 1.5, 0.0, 0.0)
    points.InsertPoint(2, 1.5, 0.0, 3.5)
    points.InsertPoint(3, 1.25, 0.0, 3.75)
    points.InsertPoint(4, 0.75, 0.0, 4.00)
    points.InsertPoint(5, 0.6, 0.0, 4.35)
    points.InsertPoint(6, 0.7, 0.0, 4.65)
    points.InsertPoint(7, 1.0, 0.0, 4.75)
    points.InsertPoint(8, 1.0, 0.0, 5.0)
    points.InsertPoint(9, 0.2, 0.0, 5.0)
 
    lines = vtk.vtkCellArray()
    lines.InsertNextCell(10# The number of points.
    lines.InsertCellPoint(0)
    lines.InsertCellPoint(1)
    lines.InsertCellPoint(2)
    lines.InsertCellPoint(3)
    lines.InsertCellPoint(4)
    lines.InsertCellPoint(5)
    lines.InsertCellPoint(6)
    lines.InsertCellPoint(7)
    lines.InsertCellPoint(8)
    lines.InsertCellPoint(9)
 
    profile = vtk.vtkPolyData()
    profile.SetPoints(points)
    profile.SetLines(lines)
 
    # Extrude the profile to make the bottle.
    #
    extrude = vtk.vtkRotationalExtrusionFilter()
    extrude.SetInputData(profile)
    extrude.SetResolution(60)
 
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(extrude.GetOutputPort())
 
    bottle = vtk.vtkActor()
    bottle.SetMapper(mapper)
    bottle.GetProperty().SetColor(colors.GetColor3d("Mint"))
 
    # Sisplay the profile.
    stripper = vtk.vtkStripper()
    stripper.SetInputData(profile)
 
    tubes = vtk.vtkTubeFilter()
    tubes.SetInputConnection(stripper.GetOutputPort())
    tubes.SetNumberOfSides(11)
    tubes.SetRadius(.05)
 
    profileMapper = vtk.vtkPolyDataMapper()
    profileMapper.SetInputConnection(tubes.GetOutputPort())
 
    profileActor = vtk.vtkActor()
    profileActor.SetMapper(profileMapper)
    profileActor.GetProperty().SetColor(colors.GetColor3d("Tomato"))
 
    # Add the actors to the renderer, set the background and size.
    #
    renderer.AddActor(bottle)
    renderer.AddActor(profileActor)
    renderer.SetBackground(colors.GetColor3d("Burlywood"))
 
    renWin.SetSize(640, 480)
    renWin.Render()
 
    renderer.GetActiveCamera().SetPosition(1, 0, 0)
    renderer.GetActiveCamera().SetFocalPoint(0, 0, 0)
    renderer.GetActiveCamera().SetViewUp(0, 0, 1)
    renderer.ResetCamera()
    renderer.GetActiveCamera().Azimuth(30)
    renderer.GetActiveCamera().Elevation(30)
 
    # Render the image.
    #
    renWin.Render()
    iren.Start()
 
 
if __name__ == '__main__':
    main()

  

posted @   飞雪飘鸿  阅读(12)  评论(0编辑  收藏  举报
https://damo.alibaba.com/ https://tianchi.aliyun.com/course?spm=5176.21206777.J_3941670930.5.87dc17c9BZNvLL
点击右上角即可分享
微信分享提示