File: TestSlice.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 (101 lines) | stat: -rwxr-xr-x 2,735 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python
"""
This tests VTK's use of Piston's slice operator.

"""

import sys
import vtk

from vtk.test import Testing
from PistonTestCommon import *

def widgetCallBack(obj,event):
     global plane, filter
     obj.GetPlane(plane)
     filter.Update() #TODO: Why is this necessary?

class TestSlice(Testing.vtkTest):
  def testSlice(self):
    global plane, filter, args
    writefiles = "SaveData" in args

    renderer = vtk.vtkRenderer()
    renwin = vtk.vtkRenderWindow()
    renwin.AddRenderer(renderer)
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renwin)
    renwin.Render()

    if "GPURender" in args:
        vtk.vtkPistonMapper.InitCUDAGL(renwin)

    src = vtk.vtkImageMandelbrotSource()
    src.SetWholeExtent(0,20,0,20,0,20)

    #scale and bias until piston understands origin and spacing
    src.Update()
    inputdata = src.GetOutput()
    if "Normalize" in args:
         testdata1 = inputdata.NewInstance()
         testdata1.ShallowCopy(inputdata)
         testdata1.SetSpacing(1,1,1)
         testdata1.SetOrigin(0,0,0)
         inputdata = testdata1

    bounds = inputdata.GetBounds()
    center = [(bounds[1]-bounds[0])/2+bounds[0],
              (bounds[3]-bounds[2])/2+bounds[2],
              (bounds[5]-bounds[4])/2+bounds[4]]

    d2p = vtk.vtkDataSetToPiston()
    d2p.SetInputData(inputdata)
    #d2p.SetInputConnection(src.GetOutputPort())

    plane = vtk.vtkPlane()
    plane.SetOrigin(center)
    plane.SetNormal(0,0,1)

    filter = vtk.vtkPistonSlice()
    filter.SetInputConnection(d2p.GetOutputPort())
    filter.SetClippingPlane(plane)
    filter.SetOffset(0.0)

    p2d = vtk.vtkPistonToDataSet()
    p2d.SetOutputDataSetType(vtk.VTK_POLY_DATA)
    p2d.SetInputConnection(filter.GetOutputPort())
    if writefiles:
        writeFile(p2d, "piston_slice.vtk")

    mapper = vtk.vtkPistonMapper()
    mapper.SetInputConnection(filter.GetOutputPort())
    mapper.Update() #TODO why is this necessary

    actor = vtk.vtkActor()
    actor.SetMapper(mapper)

    renderer.AddActor(actor)

    widget = vtk.vtkImplicitPlaneWidget()
    widget.PlaceWidget(bounds)
    widget.SetOrigin([plane.GetOrigin()[x] for x in 0,1,2])
    widget.SetNormal([plane.GetNormal()[x] for x in 0,1,2])
    widget.SetInteractor(iren)
    widget.AddObserver("InteractionEvent", widgetCallBack)
    widget.SetEnabled(1)
    widget.DrawPlaneOff()

    renderer.ResetCamera()
    renwin.Render()

    img_file = "TestSlice.png"
    Testing.compareImage(renwin, Testing.getAbsImagePath(img_file))

    if Testing.isInteractive():
        widget.DrawPlaneOn()
        iren.Start()

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