-
Notifications
You must be signed in to change notification settings - Fork 0
/
makevolume.py
64 lines (50 loc) · 2.05 KB
/
makevolume.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
#! python 2
import vtk
class makevolume:
def __init__(self):
self.volumecolorTransferFunction = vtk.vtkColorTransferFunction()
self.isocolorTransferFunction = vtk.vtkColorTransferFunction()
self.opacityTransferFunction = vtk.vtkPiecewiseFunction()
self.isocolor = vtk.vtkColorTransferFunction()
self.volumeProperty = vtk.vtkVolumeProperty()
self.volume = vtk.vtkVolume()
self.volumeMapper = vtk.vtkGPUVolumeRayCastMapper()
self.actor = vtk.vtkActor()
self.isomapperlist = []
def volumeopacity(self, valuelist, opacitylist):
ops = zip(valuelist, opacitylist)
for each in ops:
self.opacityTransferFunction.AddPoint(each[0], each[1])
def volumecolortransfer(self, value, rgbtuple):
colors = zip(value, rgbtuple)
for each in colors:
rgb = each[1]
self.volumecolorTransferFunction.AddRGBPoint(each[0], rgb[0]/255.0, rgb[1]/255.0, rgb[2]/255.0)
def isocolortransfer(self, value, rgbtuple):
colors = zip(value, rgbtuple)
for each in colors:
rgb = each[1]
self.isocolorTransferFunction.AddRGBPoint(each[0], rgb[0]/255.0, rgb[1]/255.0, rgb[2]/255.0)
def createvolumeproperties(self, ambient, diffuse, specular):
self.volumeProperty.SetScalarOpacity(self.opacityTransferFunction)
self.volumeProperty.SetColor(self.volumecolorTransferFunction)
self.volumeProperty.ShadeOn()
self.volumeProperty.SetInterpolationTypeToLinear()
self.volumeProperty.SetAmbient(0.4)
self.volumeProperty.SetDiffuse(0.6)
self.volumeProperty.SetSpecular(0.2)
def generateisosurface(self, value, opacity, dataport):
contour = vtk.vtkContourFilter()
contour.SetInputConnection(dataport)
contour.SetValue(0, value)
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(contour.GetOutputPort())
mapper.SetLookupTable(self.isocolorTransferFunction)
self.actor.SetMapper(mapper)
self.actor.GetProperty().SetOpacity(opacity)
return self.actor
def mapvolume(self, dataport):
self.volumeMapper.SetInputConnection(dataport)
self.volume.SetMapper(self.volumeMapper)
self.volume.SetProperty(self.volumeProperty)
return self.volume