File: TestTemplates.py

package info (click to toggle)
vtk9 9.5.2%2Bdfsg3-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 205,984 kB
  • sloc: cpp: 2,336,570; ansic: 327,116; python: 111,200; yacc: 4,104; java: 3,977; sh: 3,032; xml: 2,771; perl: 2,189; lex: 1,787; makefile: 181; javascript: 165; objc: 153; tcl: 59
file content (144 lines) | stat: -rwxr-xr-x 4,853 bytes parent folder | download | duplicates (4)
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env python
"""Test template support in VTK-Python

VTK-python decides which template specializations
to wrap according to which ones are used in typedefs
and which ones appear as superclasses of other classes.
In addition, the wrappers are hard-coded to wrap the
vtkDenseArray and vtkSparseArray classes over a broad
range of types.

Created on May 29, 2011 by David Gobbi
"""

import sys
from vtkmodules.vtkCommonCore import (
    VTK_DOUBLE,
    vtkArray,
    vtkArrayCoordinates,
    vtkDenseArray,
    vtkSparseArray,
    vtkVariant,
)
from vtkmodules.vtkCommonDataModel import (
    vtkColor4ub,
    vtkRectf,
    vtkVector,
    vtkVector3,
)
from vtkmodules.test import Testing

arrayTypes = ['char', 'int8', 'uint8', 'int16', 'uint16',
              'int32', 'uint32', int, 'uint', 'int64', 'uint64',
              'float32', float, str, vtkVariant]

arrayCodes = ['c', 'b', 'B', 'h', 'H',
              'i', 'I', 'l', 'L', 'q', 'Q',
              'f', 'd']

# create a unicode string
francois = 'Fran\xe7ois'

class TestTemplates(Testing.vtkTest):

    def testDenseArray(self):
        """Test vtkDenseArray template"""
        for t in (arrayTypes + arrayCodes):
            a = vtkDenseArray[t]()
            a.Resize(1)
            i = vtkArrayCoordinates(0)
            if t in ['bool', '?']:
                value = 1
                a.SetValue(i, value)
                result = a.GetValue(i)
                self.assertEqual(value, result)
            elif t in ['float32', 'float64', 'float', 'f', 'd']:
                value = 3.125
                a.SetValue(i, value)
                result = a.GetValue(i)
                self.assertEqual(value, result)
            elif t in ['char', 'c']:
                value = 'c'
                a.SetValue(i, value)
                result = a.GetValue(i)
                self.assertEqual(value, result)
            elif t in [str, 'str']:
                value = "hello"
                a.SetValue(i, value)
                result = a.GetValue(i)
                self.assertEqual(value, result)
                value = francois
                a.SetValue(i, value)
                result = a.GetValue(i)
                self.assertEqual(value, result)
            elif t in ['vtkVariant', vtkVariant]:
                value = vtkVariant("world")
                a.SetValue(i, value)
                result = a.GetValue(i)
                self.assertEqual(value, result)
            else:
                value = 12
                a.SetValue(i, value)
                result = a.GetValue(i)
                self.assertEqual(value, result)

    def testSparseArray(self):
        """Test vtkSparseArray template"""
        for t in (arrayTypes + arrayCodes):
            a = vtkSparseArray[t]()
            a.Resize(1)
            i = vtkArrayCoordinates(0)
            if t in ['bool', '?']:
                value = 0
                a.SetValue(i, value)
                result = a.GetValue(i)
                self.assertEqual(value, result)
            elif t in ['float32', 'float64', 'float', 'f', 'd']:
                value = 3.125
                a.SetValue(i, value)
                result = a.GetValue(i)
                self.assertEqual(value, result)
            elif t in ['char', 'c']:
                value = 'c'
                a.SetValue(i, value)
                result = a.GetValue(i)
                self.assertEqual(value, result)
            elif t in [str, 'str']:
                value = "hello"
                a.SetValue(i, value)
                result = a.GetValue(i)
                self.assertEqual(value, result)
                value = francois
                a.SetValue(i, value)
                result = a.GetValue(i)
                self.assertEqual(value, result)
            elif t in ['vtkVariant', vtkVariant]:
                value = vtkVariant("world")
                a.SetValue(i, value)
                result = a.GetValue(i)
                self.assertEqual(value, result)
            else:
                value = 12
                a.SetValue(i, value)
                result = a.GetValue(i)
                self.assertEqual(value, result)

    def testArray(self):
        """Test array CreateArray"""
        o = vtkArray.CreateArray(vtkArray.DENSE, VTK_DOUBLE)
        self.assertEqual(o.__class__, vtkDenseArray[float])

    def testVector(self):
        """Test vector templates"""
        # make sure Rect inherits operators
        r = vtkRectf(0, 0, 2, 2)
        self.assertEqual(r[2], 2.0)
        c = vtkColor4ub(0, 0, 0)
        self.assertEqual(list(c), [0, 0, 0, 255])
        e = vtkVector['float32', 3]([0.0, 1.0, 2.0])
        self.assertEqual(list(e), [0.0, 1.0, 2.0])
        i = vtkVector3['i'](0)
        self.assertEqual(list(i), [0, 0, 0])

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