forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
imageMCAll.py
executable file
·144 lines (115 loc) · 4.87 KB
/
imageMCAll.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
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
# -*- 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 imageMCAll(vtk.test.Testing.vtkTest):
class Colors(object):
'''
Provides some wrappers for using color names.
'''
def __init__(self):
'''
Define a single instance of the NamedColors class here.
'''
self.namedColors = vtk.vtkNamedColors()
def GetRGBColor(self, colorName):
'''
Return the red, green and blue components for a
color as doubles.
'''
rgb = [0.0, 0.0, 0.0] # black
self.namedColors.GetColorRGB(colorName, rgb)
return rgb
def GetRGBAColor(self, colorName):
'''
Return the red, green, blue and alpha
components for a color as doubles.
'''
rgba = [0.0, 0.0, 0.0, 1.0] # black
self.namedColors.GetColor(colorName, rgba)
return rgba
def testimageMCAll(self):
# Create the RenderWindow, Renderer and both Actors
#
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
# create pipeline
#
slc = vtk.vtkStructuredPointsReader()
slc.SetFileName(VTK_DATA_ROOT + "/Data/ironProt.vtk")
colors = ["flesh", "banana", "grey", "pink", "carrot", "gainsboro", "tomato", "gold", "thistle", "chocolate"]
types = ["UnsignedChar", "Char", "Short", "UnsignedShort", "Int", "UnsignedInt", "Long", "UnsignedLong", "Float", "Double"]
i = 1
c = 0
clip = list()
cast = list()
iso = list()
mapper = list()
actor = list()
colorWrapper = self.Colors()
for idx, vtkType in enumerate(types):
clip.append(vtk.vtkImageClip())
clip[idx].SetInputConnection(slc.GetOutputPort())
clip[idx].SetOutputWholeExtent(-1000, 1000, -1000, 1000, i, i + 5)
i += 5
cast.append(vtk.vtkImageCast())
eval('cast[idx].SetOutputScalarTypeTo' + vtkType + '()')
cast[idx].SetInputConnection(clip[idx].GetOutputPort())
cast[idx].ClampOverflowOn()
iso.append(vtk.vtkMarchingContourFilter())
iso[idx].SetInputConnection(cast[idx].GetOutputPort())
iso[idx].GenerateValues(1, 30, 30)
mapper.append(vtk.vtkPolyDataMapper())
mapper[idx].SetInputConnection(iso[idx].GetOutputPort())
mapper[idx].ScalarVisibilityOff()
actor.append(vtk.vtkActor())
actor[idx].SetMapper(mapper[idx])
# actor[idx].Actor.GetProperty().SetDiffuseColor(lindex.colors.c.lindex.colors.c+1.lindex.colors.c+1)
actor[idx].GetProperty().SetDiffuseColor(colorWrapper.GetRGBColor(colors[c]))
actor[idx].GetProperty().SetSpecularPower(30)
actor[idx].GetProperty().SetDiffuse(.7)
actor[idx].GetProperty().SetSpecular(.5)
c += 1
ren.AddActor(actor[idx])
outline = vtk.vtkOutlineFilter()
outline.SetInputConnection(slc.GetOutputPort())
outlineMapper = vtk.vtkPolyDataMapper()
outlineMapper.SetInputConnection(outline.GetOutputPort())
outlineActor = vtk.vtkActor()
outlineActor.SetMapper(outlineMapper)
outlineActor.VisibilityOff()
# Add the actors to the renderer, set the background and size
#
ren.AddActor(outlineActor)
ren.SetBackground(0.9, .9, .9)
ren.ResetCamera()
ren.GetActiveCamera().SetViewAngle(30)
ren.GetActiveCamera().Elevation(20)
ren.GetActiveCamera().Azimuth(20)
ren.GetActiveCamera().Zoom(1.5)
ren.ResetCameraClippingRange()
renWin.SetSize(400, 400)
# render and interact with data
iRen = vtk.vtkRenderWindowInteractor()
iRen.SetRenderWindow(renWin);
renWin.Render()
img_file = "imageMCAll.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([(imageMCAll, 'test')])