forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestAllShrinks.py
executable file
·100 lines (76 loc) · 3.35 KB
/
TestAllShrinks.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
=========================================================================
Program: Visualization Toolkit
Module: TestNamedColorsIntegration.py
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================
'''
import vtk
import vtk.test.Testing
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
class TestAllShrinks(vtk.test.Testing.vtkTest):
def testAllShrinks(self):
prefix = VTK_DATA_ROOT + "/Data/headsq/quarter"
renWin = vtk.vtkRenderWindow()
# Image pipeline
reader = vtk.vtkImageReader()
reader.SetDataExtent(0, 63, 0, 63, 1, 93)
reader.SetFilePrefix(prefix)
reader.SetDataByteOrderToLittleEndian()
reader.SetDataMask(0x7fff)
factor = 4
magFactor = 8
ops = ["Minimum", "Maximum", "Mean", "Median", "NoOp"]
shrink = dict()
mag = dict()
mapper = dict()
actor = dict()
imager = dict()
for operator in ops:
shrink.update({operator:vtk.vtkImageShrink3D()})
shrink[operator].SetMean(0)
if operator != "NoOp":
eval('shrink[operator].' + operator + 'On()')
shrink[operator].SetShrinkFactors(factor, factor, factor)
shrink[operator].SetInputConnection(reader.GetOutputPort())
mag.update({operator:vtk.vtkImageMagnify()})
mag[operator].SetMagnificationFactors(magFactor, magFactor, magFactor)
mag[operator].InterpolateOff()
mag[operator].SetInputConnection(shrink[operator].GetOutputPort())
mapper.update({operator:vtk.vtkImageMapper()})
mapper[operator].SetInputConnection(mag[operator].GetOutputPort())
mapper[operator].SetColorWindow(2000)
mapper[operator].SetColorLevel(1000)
mapper[operator].SetZSlice(45)
actor.update({operator:vtk.vtkActor2D()})
actor[operator].SetMapper(mapper[operator])
imager.update({operator:vtk.vtkRenderer()})
imager[operator].AddActor2D(actor[operator])
renWin.AddRenderer(imager[operator])
shrink["Minimum"].Update
shrink["Maximum"].Update
shrink["Mean"].Update
shrink["Median"].Update
imager["Minimum"].SetViewport(0, 0, .5, .33)
imager["Maximum"].SetViewport(0, .33, .5, .667)
imager["Mean"].SetViewport(.5, 0, 1, .33)
imager["Median"].SetViewport(.5, .33, 1, .667)
imager["NoOp"].SetViewport(0, .667, 1, 1)
renWin.SetSize(256, 384)
# render and interact with data
iRen = vtk.vtkRenderWindowInteractor()
iRen.SetRenderWindow(renWin);
renWin.Render()
img_file = "TestAllShrinks.png"
vtk.test.Testing.compareImage(iRen.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=25)
vtk.test.Testing.interact()
if __name__ == "__main__":
vtk.test.Testing.main([(TestAllShrinks, 'test')])