File: cowHair.py

package info (click to toggle)
vtk6 6.3.0%2Bdfsg2-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 118,880 kB
  • sloc: cpp: 1,442,792; ansic: 113,395; python: 72,383; tcl: 46,998; xml: 8,119; yacc: 4,525; java: 4,239; perl: 3,108; lex: 1,694; sh: 1,093; asm: 154; makefile: 103; objc: 17
file content (89 lines) | stat: -rwxr-xr-x 2,380 bytes parent folder | download | duplicates (11)
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
#!/usr/bin/env python
import vtk
from vtk.test import Testing
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()

def GetRGBColor(colorName):
    '''
        Return the red, green and blue components for a
        color as doubles.
    '''
    rgb = [0.0, 0.0, 0.0]  # black
    vtk.vtkNamedColors().GetColorRGB(colorName, rgb)
    return rgb

# Create the RenderWindow, Renderer and both Actors
#
ren1 = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren1)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

# read data
#
wavefront = vtk.vtkOBJReader()
wavefront.SetFileName(VTK_DATA_ROOT + "/Data/Viewpoint/cow.obj")
wavefront.Update()

cone = vtk.vtkConeSource()
cone.SetResolution(6)
cone.SetRadius(.1)

transform = vtk.vtkTransform()
transform.Translate(0.5, 0.0, 0.0)
transformF = vtk.vtkTransformPolyDataFilter()
transformF.SetInputConnection(cone.GetOutputPort())
transformF.SetTransform(transform)

# we just clean the normals for efficiency (keep down number of cones)
clean = vtk.vtkCleanPolyData()
clean.SetInputConnection(wavefront.GetOutputPort())

glyph = vtk.vtkHedgeHog()
glyph.SetInputConnection(clean.GetOutputPort())
glyph.SetVectorModeToUseNormal()
glyph.SetScaleFactor(0.4)

hairMapper = vtk.vtkPolyDataMapper()
hairMapper.SetInputConnection(glyph.GetOutputPort())

hair = vtk.vtkActor()
hair.SetMapper(hairMapper)

cowMapper = vtk.vtkPolyDataMapper()
cowMapper.SetInputConnection(wavefront.GetOutputPort())

cow = vtk.vtkActor()
cow.SetMapper(cowMapper)

# Add the actors to the renderer, set the background and size
#
ren1.AddActor(cow)
ren1.AddActor(hair)
ren1.ResetCamera()
ren1.GetActiveCamera().Dolly(2)
ren1.GetActiveCamera().Azimuth(30)
ren1.GetActiveCamera().Elevation(30)
ren1.ResetCameraClippingRange()

hair.GetProperty().SetDiffuseColor(GetRGBColor('saddle_brown'))
hair.GetProperty().SetAmbientColor(GetRGBColor('thistle'))
hair.GetProperty().SetAmbient(.3)

# Beige in vtk.vtkNamedColors() is compliant with
# http://en.wikipedia.org/wiki/Web_colors and is a different color.
# so we revert to the one used in colors.tcl.
# cow.GetProperty().SetDiffuseColor(GetRGBColor('beige'))
cow.GetProperty().SetDiffuseColor(163 / 255.0, 148 / 255.0, 128 / 255.0)

renWin.SetSize(320, 240)
ren1.SetBackground(.1, .2, .4)

iren.Initialize()
renWin.Render()

# render the image
#
#iren.Start()