File: TestTensorGlyph.py

package info (click to toggle)
vtk 5.8.0-13
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 130,524 kB
  • sloc: cpp: 1,129,256; ansic: 708,203; tcl: 48,526; python: 20,875; xml: 6,779; yacc: 4,208; perl: 3,121; java: 2,788; lex: 931; sh: 660; asm: 471; makefile: 299
file content (121 lines) | stat: -rwxr-xr-x 3,707 bytes parent folder | download | duplicates (8)
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env python

# Run this test like so:
# vtkpython TestTensorGlyph.py  -D $VTK_DATA_ROOT \
# -B $VTK_DATA_ROOT/Baseline/Graphics/

import os
import vtk
from vtk.test import Testing

class SimpleGlyph:
    """A simple class used to test vtkTensorGlyph."""
    def __init__(self, reader):
        self.reader = reader
        sg = self.src_glyph = vtk.vtkSphereSource()
        sg.SetRadius(0.5)
        sg.SetCenter(0.5, 0.0, 0.0)
        g = self.glyph = vtk.vtkTensorGlyph()        
        g.SetInputConnection(self.reader.GetOutputPort())
        g.SetSource(self.src_glyph.GetOutput())
        g.SetScaleFactor(0.25)
        
        # The normals are needed to generate the right colors and if
        # not used some of the glyphs are black.        
        self.normals = vtk.vtkPolyDataNormals()
        self.normals.SetInputConnection(g.GetOutputPort())
        self.map = vtk.vtkPolyDataMapper()
        self.map.SetInputConnection(self.normals.GetOutputPort())        
        self.act = vtk.vtkActor()
        self.act.SetMapper(self.map)

        # An outline.
        self.of = vtk.vtkOutlineFilter()
        self.of.SetInputConnection(self.reader.GetOutputPort())
        self.out_map = vtk.vtkPolyDataMapper()
        self.out_map.SetInputConnection(self.of.GetOutputPort())
        self.out_act = vtk.vtkActor()
        self.out_act.SetMapper(self.out_map)        

    def GetActors(self):
        return self.act, self.out_act

    def Update(self):
        self.glyph.Update()
        s = self.glyph.GetOutput().GetPointData().GetScalars()
        if s:
            self.map.SetScalarRange(s.GetRange())
            
    def SetPosition(self, pos):
        self.act.SetPosition(pos)
        self.out_act.SetPosition(pos)


class TestTensorGlyph(Testing.vtkTest):
    def testGlyphs(self):
        "Test if the glyphs are created nicely."
        reader = vtk.vtkDataSetReader()
        data_file = os.path.join(Testing.VTK_DATA_ROOT, "Data",
                                 "tensors.vtk")
        reader.SetFileName(data_file)

        g1 = SimpleGlyph(reader)
        g1.glyph.ColorGlyphsOff()
        g1.Update()

        g2 = SimpleGlyph(reader)
        g2.glyph.ExtractEigenvaluesOff()
        g2.Update()
        g2.SetPosition((2.0, 0.0, 0.0))

        g3 = SimpleGlyph(reader)
        g3.glyph.SetColorModeToEigenvalues()
        g3.glyph.ThreeGlyphsOn()
        g3.Update()
        g3.SetPosition((0.0, 2.0, 0.0))

        g4 = SimpleGlyph(reader)
        g4.glyph.SetColorModeToEigenvalues()
        g4.glyph.ThreeGlyphsOn()
        g4.glyph.SymmetricOn()
        g4.Update()
        g4.SetPosition((2.0, 2.0, 0.0))

        ren = vtk.vtkRenderer()
        for i in (g1, g2, g3, g4):
            for j in i.GetActors():
                ren.AddActor(j)

        ren.ResetCamera();
        cam = ren.GetActiveCamera()
        cam.Azimuth(-20)
        cam.Elevation(20)
        cam.Zoom(1.5)

        ren.SetBackground(0.5, 0.5, 0.5)
        renWin = vtk.vtkRenderWindow()
        renWin.AddRenderer(ren)
        renWin.Render()
        
        img_file = "TestTensorGlyph.png"
        Testing.compareImage(renWin, Testing.getAbsImagePath(img_file))
        Testing.interact()

    def testParse(self):
        "Test if vtkTensorGlyph is parseable"
        tg = vtk.vtkTensorGlyph()
        self._testParse(tg)

    def testGetSet(self):
        "Testing Get/Set methods of vtkTensorGlyph"
        tg = vtk.vtkTensorGlyph()
        self._testGetSet(tg)

    def testParse(self):
        "Testing Boolean methods of vtkTensorGlyph"
        tg = vtk.vtkTensorGlyph()
        self._testBoolean(tg)


if __name__ == "__main__":
    Testing.main([(TestTensorGlyph, 'test')])