File: TestArrayArguments.py

package info (click to toggle)
vtk9 9.5.2%2Bdfsg3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 205,916 kB
  • sloc: cpp: 2,336,565; 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: 178; javascript: 165; objc: 153; tcl: 59
file content (144 lines) | stat: -rw-r--r-- 4,282 bytes parent folder | download | duplicates (3)
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
"""Test passing arguments of various types

Created on Sept 19, 2010 by David Gobbi
"""

import sys
from vtkmodules.vtkCommonCore import (
    vtkBitArray,
    vtkCharArray,
    vtkDoubleArray,
    vtkFloatArray,
    vtkIdTypeArray,
    vtkIntArray,
    vtkLongArray,
    vtkMath,
    vtkShortArray,
    vtkSignedCharArray,
    vtkStringArray,
    vtkTypeInt64Array,
    vtkTypeUInt64Array,
    vtkUnsignedCharArray,
    vtkUnsignedIntArray,
    vtkUnsignedLongArray,
    vtkUnsignedShortArray,
)
from vtkmodules.vtkCommonDataModel import vtkDataObject
from vtkmodules.vtkImagingSources import vtkImageGridSource
from vtkmodules.test import Testing

arrays = [
  vtkFloatArray,
  vtkDoubleArray,
  vtkSignedCharArray,
  vtkShortArray,
  vtkIntArray,
  vtkLongArray,
  vtkTypeInt64Array,
  vtkIdTypeArray,
]

unsignedArrays = [
  vtkUnsignedCharArray,
  vtkUnsignedShortArray,
  vtkUnsignedIntArray,
  vtkUnsignedLongArray,
  vtkTypeUInt64Array,
]

class TestArrayArguments(Testing.vtkTest):
    def testArrayArguments(self):
        for arrayClass in arrays:
            a = arrayClass()
            a.SetNumberOfComponents(3)
            a.SetNumberOfTuples(1)
            ti = [0, a.GetDataTypeValueMin(), a.GetDataTypeValueMax()]
            to = [0, 0, 0]
            a.SetTypedTuple(0, ti)
            a.GetTypedTuple(0, to);
            self.assertEqual(ti, to)
            d1 = a.GetTuple(0)
            d2 = [float(x) for x in ti]
            r1 = [round(x) for x in d1]
            r2 = [round(x) for x in d2]
            self.assertEqual(r1, r2)

    def testUnsignedArrayArguments(self):
        for arrayClass in unsignedArrays:
            a = arrayClass()
            a.SetNumberOfComponents(3)
            a.SetNumberOfTuples(1)
            ti = [0, a.GetDataTypeValueMin(), a.GetDataTypeValueMax()]
            to = [0, 0, 0]
            a.SetTypedTuple(0, ti)
            a.GetTypedTuple(0, to);
            self.assertEqual(ti, to)
            d1 = a.GetTuple(0)
            d2 = [float(x) for x in ti]
            r1 = [round(x) for x in d1]
            r2 = [round(x) for x in d2]
            self.assertEqual(r1, r2)

    def testCharArrayArguments(self):
        a = vtkCharArray()
        a.SetNumberOfComponents(3)
        a.SetNumberOfTuples(1)
        ti = "opn"
        a.SetTypedTuple(0, ti)
        # python strings are immutable, so this should NOT work
        #to = "***"
        #a.GetTypedTuple(0, to);
        d1 = list(a.GetTuple(0))
        d2 = [ord(x) for x in ti]
        self.assertEqual(d1, d2)

    def testBitArrayArguments(self):
        a = vtkBitArray()
        a.SetNumberOfComponents(2)
        a.SetNumberOfTuples(1)
        ti = [0,1]
        to = [0,0]
        a.SetTuple(0, ti)
        a.GetTuple(0, to);
        self.assertEqual(ti, [int(x) for x in to])

    def testNDimArrayArguments(self):
        a = [[0,0,0],[0,0,0],[0,0,0]]
        vtkMath.Identity3x3(a)
        x = [0.5, 0.2, 0.1]
        y = [0.0, 0.0, 0.0]
        vtkMath.Multiply3x3(a, x, y)
        self.assertEqual(x, y)

    def testInformationVectorKeys(self):
        a = vtkImageGridSource()
        spacing = (3.0, 2.0, 1.0)
        a.SetDataSpacing(spacing)
        a.UpdateInformation()
        info = a.GetOutputInformation(0)
        t = info.Get(vtkDataObject.SPACING())
        self.assertEqual(t, spacing)

    def testArrayIterator(self):
        # try a string array
        a = vtkStringArray()
        a.InsertNextValue("hello")
        i = a.NewIterator()
        self.assertEqual(a.GetValue(0), i.GetValue(0))
        # try the various data array subclasses
        for arrayClass in arrays:
            a = arrayClass()
            a.SetNumberOfComponents(2)
            a.SetNumberOfTuples(1)
            tupleIn = (a.GetDataTypeValueMin(), a.GetDataTypeValueMax())
            a.SetTypedTuple(0, tupleIn)
            i = a.NewIterator()
            # make sure iterator's GetTuple method is wrapped
            tupleOut = i.GetTuple(0)
            self.assertEqual(tupleIn, tupleOut)
            # make sure the GetValue method returns expected result
            self.assertEqual(tupleIn[0], i.GetValue(0))
            self.assertEqual(tupleIn[1], i.GetValue(1))

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