File: TestConversion.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 (86 lines) | stat: -rwxr-xr-x 3,049 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
#!/usr/bin/env python
"""
This tests the ability to send data back and forth between the CPU and GPU.

"""

import sys
import vtk

from vtk.test import Testing
from PistonTestCommon import *

class TestConversion(Testing.vtkTest):
  def testConversion(self):
    global args
    writefiles = "SaveData" in args

    src = vtk.vtkImageMandelbrotSource()
    src2 = vtk.vtkSphereSource()
    d2p = vtk.vtkDataSetToPiston()
    p2d = vtk.vtkPistonToDataSet()

    #test sending imagedata to the card and getting it back
    src.SetWholeExtent(0,10,0,10,0,10)
    d2p.SetInputConnection(src.GetOutputPort())
    p2d.SetOutputDataSetType(vtk.VTK_IMAGE_DATA)
    p2d.SetInputConnection(d2p.GetOutputPort())
    p2d.Update()

    printDS("INPUT IMAGE DATA", src.GetOutput())
    printTDO("GPU VERSION", d2p.GetPistonDataObjectOutput(0))
    printDS("OUTPUT IMAGE DATA", p2d.GetDataSetOutput(0))

    if writefiles:
        writeFile(p2d, "piston_imagedata.vtk")
    inDS = src.GetOutput()
    outDS = p2d.GetDataSetOutput(0)
    if inDS.GetBounds() != outDS.GetBounds():
        self.fail("Problem: bounds were not preserved.")
    if inDS.GetNumberOfCells() != outDS.GetNumberOfCells():
        self.fail("Problem: cells were not preserved.")
    if inDS.GetPointData().GetArray(0).GetName() != outDS.GetPointData().GetArray(0).GetName():
        self.fail("Problem: arrays were not preserved.")

    #test sending polydata to the card and getting it back
    #test a pipeline that works on poly data

    #below doesn't work in vtk6, gets null output for p2d
    #since data type AND upstream pipeline changes
    #workaround until that is fixes
    #d2p.SetInputConnection(src2.GetOutputPort())
    #p2d.SetOutputDataSetType(vtk.VTK_POLY_DATA)
    #p2d.Update()
    #printDS("INPUT POLYDATA", src2.GetOutput())
    #printTDO("GPU VERSION", d2p.GetPistonDataObjectOutput(0))
    #printDS("OUTPUT POLYDATA", p2d.GetDataSetOutput(0))
    #if writefiles:
    #    writeFile(p2d, "piston_polydata.vtk")
    #
    #so use this instead
    d2p2 = vtk.vtkDataSetToPiston()
    p2d2 = vtk.vtkPistonToDataSet()
    d2p2.SetInputConnection(src2.GetOutputPort())
    p2d2.SetOutputDataSetType(vtk.VTK_POLY_DATA)
    p2d2.SetInputConnection(d2p2.GetOutputPort())
    p2d2.Update()
    printDS("INPUT POLYDATA", src2.GetOutput())
    printTDO("GPU VERSION", d2p2.GetPistonDataObjectOutput(0))
    printDS("OUTPUT POLYDATA", p2d2.GetDataSetOutput(0))
    if writefiles:
        writeFile(p2d2, "piston_polydata.vtk")

    inDS = src2.GetOutput()
    outDS = p2d2.GetDataSetOutput(0)
    if inDS.GetBounds() != outDS.GetBounds():
        self.fail("Problem: bounds were not preserved.")
    if inDS.GetNumberOfCells() != outDS.GetNumberOfCells():
        self.fail("Problem: cells were not preserved.")
    if inDS.GetPointData().GetArray(0).GetName() != outDS.GetPointData().GetArray(0).GetName():
        self.fail("Problem: arrays were not preserved.")


if __name__ == "__main__":
    global args
    args = parseArgs()
    Testing.main([(TestConversion, 'test')])