File: TestStyleBase.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 (118 lines) | stat: -rwxr-xr-x 4,139 bytes parent folder | download | duplicates (7)
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
#!/usr/bin/env python

import vtk


class TestStyleBase(object):

    def __init__(self, ren):
        self.ren1 = ren

        # Get random numbers
        self.math = vtk.vtkMath()
        self.math.RandomSeed(1)


    def randint(self, min, max):
        f = self.math.Random(min, max)
        return int(f)


    # Main testing proc

    def test_style(self, style):

        # Event state to test

        buttons = ["Left", "Middle", "Right"]
        ctrls = [0, 1]
        shifts = [0, 1]

        # I do not trust timers while testing (since they trigger asynchronous
        # rendering/interaction)

        use_timers = style.GetUseTimers()
        style.UseTimersOff()
        style.AutoAdjustCameraClippingRangeOn()

        print "Testing: " + style.GetClassName()

        iren = style.GetInteractor()
        renwin = iren.GetRenderWindow()

        renwin.Render()

        # Get renwin size and center

        win_size = renwin.GetSize()
        win_center_x = win_size[0] / (2.0)
        win_center_y = win_size[1] / (2.0)

        pick = vtk.vtkPropPicker()

        radius = 5 * (1 + use_timers)

        for ctrl in ctrls:
            for shift in shifts:
                print " - ctrl: " + str(ctrl) + " shift: " + str(shift) + " " + "button: ",
                for button in buttons:
                    print button,
                    # First try to find a starting position where an actor
                    # can be picked (not mandatory for trackball modes).
                    # Search in increasingly big area, until we reach win size
                    # in that case actors might not be on screen, so reset cam

                    search = radius
                    while True:
                        start_x = self.randint(win_center_x - search, win_center_x + search)
                        start_y = self.randint(win_center_x - search, win_center_x + search)
                        if pick.PickProp(start_x, start_y, self.ren1):
                            break
                        else:
                            if search > win_center_x or search > win_center_y:
                                print "   (resetting camera)",
                                self.ren1.ResetCamera()
                                search = radius
                            else:
                                search += 5

                    # Start by pressing the button

                    iren.SetEventInformationFlipY(start_x, start_y, ctrl, shift, '', 0, '')
                    eval('iren.InvokeEvent("' + button + 'ButtonPressEvent")')
                    pos = iren.GetEventPosition()
                    #print " - Starting: " + str(pos)

                    # Now move around (alternating left and right around
                    # the window center in order to compensate somehow).

                    sign = 1
                    for i in range(0, 2 + use_timers):
                        sign *= -1
                        x = self.randint(win_center_x + radius * 2 * sign, win_center_y + radius * sign)
                        y = self.randint(win_center_y + radius * 2 * sign, win_center_y + radius * sign)
                        iren.SetEventInformationFlipY(x, y, ctrl, shift, '', 0, '')
                        #pos = iren.GetEventPosition()
                        #lastPos = iren.GetLastEventPosition()
                        #print " - Moving:   " + str(pos) + " " + str(ctrl) + " " + str(shift) + " (was " + str(lastPos) + ")"
                        iren.InvokeEvent("MouseMoveEvent")

                        # If this style uses timers, run OnTimer multiple times

                        if use_timers:
                            for j in range(0, 10):
                                iren.InvokeEvent("TimerEvent")

                        renwin.Render()


                    # End by releasing the button

                    iren.SetEventInformationFlipY(x, y, ctrl, shift, '', 0, '')
                    eval('iren.InvokeEvent("' + button + 'ButtonReleaseEvent")')

                print "."

        style.SetUseTimers(use_timers)

        renwin.Render()