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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
#!/usr/bin/env python
## Program: VMTK
## Module: $RCSfile: vmtkcenterlineviewer.py,v $
## Language: Python
## Date: $Date: 2006/05/26 12:35:13 $
## Version: $Revision: 1.3 $
## Copyright (c) Luca Antiga, David Steinman. All rights reserved.
## See LICENCE file 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 notices for more information.
import vtk
import sys
import vtkvmtk
import vmtkrenderer
import pypes
vmtkcenterlineviewer = 'vmtkCenterlineViewer'
class vmtkCenterlineViewer(pypes.pypeScript):
def __init__(self):
pypes.pypeScript.__init__(self)
self.Centerlines = None
self.PointDataArrayName = ''
self.CellDataArrayName = ''
self.Display = 1
self.Legend = 1
self.ColorMap = 'cooltowarm'
self.NumberOfColors = 256
self.vmtkRenderer = None
self.OwnRenderer = 0
self.SetScriptName('vmtkcenterlineviewer')
self.SetScriptDoc('')
self.SetInputMembers([
['Centerlines','i','vtkPolyData',1,'','the input surface','vmtksurfacereader'],
['PointDataArrayName','pointarray','str',1,''],
['CellDataArrayName','cellarray','str',1,''],
['Legend','legend','bool',1,''],
['ColorMap','colormap','str',1,'["rainbow","blackbody","cooltowarm","grayscale"]','choose the color map'],
['NumberOfColors','numberofcolors','int',1,'','number of colors in the color map'],
['vmtkRenderer','renderer','vmtkRenderer',1,'','external renderer']])
self.SetOutputMembers([
['Centerlines','o','vtkPolyData',1,'','the output centerlines','vmtksurfacewriter']])
def Execute(self):
if not self.Centerlines:
self.PrintError('Error: No input centerlines.')
return
if not self.vmtkRenderer:
self.vmtkRenderer = vmtkrenderer.vmtkRenderer()
self.vmtkRenderer.Initialize()
self.OwnRenderer = 1
self.vmtkRenderer.RegisterScript(self)
if self.CellDataArrayName:
cellCenters = vtk.vtkCellCenters()
cellCenters.SetInputData(self.Centerlines)
cellCenters.Update()
cellCenters.GetOutput().GetPointData().SetActiveScalars(self.CellDataArrayName)
labelsMapper = vtk.vtkLabeledDataMapper();
labelsMapper.SetInputConnection(cellCenters.GetOutputPort())
labelsMapper.SetLabelModeToLabelScalars()
labelsActor = vtk.vtkActor2D()
labelsActor.SetMapper(labelsMapper)
self.vmtkRenderer.Renderer.AddActor(labelsActor)
centerlineMapper = vtk.vtkPolyDataMapper()
centerlineMapper.SetInputData(self.Centerlines)
if self.CellDataArrayName and not self.PointDataArrayName:
centerlineMapper.ScalarVisibilityOn()
centerlineMapper.SetScalarModeToUseCellData()
self.Centerlines.GetCellData().SetActiveScalars(self.CellDataArrayName)
centerlineMapper.SetScalarRange(self.Centerlines.GetCellData().GetScalars().GetRange(0))
elif self.PointDataArrayName:
centerlineMapper.ScalarVisibilityOn()
centerlineMapper.SetScalarModeToUsePointData()
self.Centerlines.GetPointData().SetActiveScalars(self.PointDataArrayName)
centerlineMapper.SetScalarRange(self.Centerlines.GetPointData().GetScalars().GetRange(0))
else:
centerlineMapper.ScalarVisibilityOff()
if self.ColorMap == 'grayscale':
lut = centerlineMapper.GetLookupTable()
lut.SetNumberOfTableValues(self.NumberOfColors)
lut.SetValueRange(0.0,1.0)
lut.SetSaturationRange(0.0,0.0)
lut.Build()
centerlineMapper.SetLookupTable(lut)
if self.ColorMap == 'rainbow':
lut = centerlineMapper.GetLookupTable()
lut.SetHueRange(0.666667,0.0)
lut.SetSaturationRange(0.75,0.75)
lut.SetValueRange(1.0,1.0)
lut.SetAlphaRange(1.0,1.0)
lut.SetNumberOfColors(self.NumberOfColors)
lut.Build()
centerlineMapper.SetLookupTable(lut)
if self.ColorMap == 'blackbody':
lut = centerlineMapper.GetLookupTable()
lut.SetNumberOfTableValues(self.NumberOfColors)
colorTransferFunction = vtk.vtkColorTransferFunction()
colorTransferFunction.SetColorSpaceToRGB()
colorTransferFunction.AddRGBPoint(0,0.0,0.0,0.0)
colorTransferFunction.AddRGBPoint(0.4,0.901961,0.0,0.0)
colorTransferFunction.AddRGBPoint(0.8,0.901961,0.901961,0.0)
colorTransferFunction.AddRGBPoint(1.0,1.0,1.0,1.0)
for ii,ss in enumerate([float(xx)/float(self.NumberOfColors) for xx in range(self.NumberOfColors)]):
cc = colorTransferFunction.GetColor(ss)
lut.SetTableValue(ii,cc[0],cc[1],cc[2],1.0)
lut.Build()
centerlineMapper.SetLookupTable(lut)
if self.ColorMap == 'cooltowarm':
lut = centerlineMapper.GetLookupTable()
lut.SetNumberOfTableValues(self.NumberOfColors)
colorTransferFunction = vtk.vtkColorTransferFunction()
colorTransferFunction.SetColorSpaceToDiverging()
colorTransferFunction.AddRGBPoint(0,0.231373,0.298039,0.752941)
colorTransferFunction.AddRGBPoint(0.5,0.865003,0.865003,0.865003)
colorTransferFunction.AddRGBPoint(1.0,0.705882,0.0156863,0.14902)
for ii,ss in enumerate([float(xx)/float(self.NumberOfColors) for xx in range(self.NumberOfColors)]):
cc = colorTransferFunction.GetColor(ss)
lut.SetTableValue(ii,cc[0],cc[1],cc[2],1.0)
lut.Build()
centerlineMapper.SetLookupTable(lut)
centerlineActor = vtk.vtkActor()
centerlineActor.SetMapper(centerlineMapper)
self.vmtkRenderer.Renderer.AddActor(centerlineActor)
scalarBarActor = None
if self.Legend and centerlineActor and self.PointDataArrayName:
scalarBarActor = vtk.vtkScalarBarActor()
scalarBarActor.SetLookupTable(centerlineActor.GetMapper().GetLookupTable())
scalarBarActor.GetLabelTextProperty().ItalicOff()
scalarBarActor.GetLabelTextProperty().BoldOff()
scalarBarActor.GetLabelTextProperty().ShadowOff()
scalarBarActor.SetLabelFormat('%.2f')
scalarBarActor.SetTitle(self.PointDataArrayName)
self.vmtkRenderer.Renderer.AddActor(scalarBarActor)
if self.Display:
self.vmtkRenderer.Render()
if self.OwnRenderer:
self.vmtkRenderer.Deallocate()
# if self.CellDataArrayName:
# self.vmtkRenderer.Renderer.RemoveActor(labelsActor)
#
# if self.Legend and centerlineActor:
# self.vmtkRenderer.Renderer.RemoveActor(scalarBarActor)
#
# self.vmtkRenderer.Renderer.RemoveActor(centerlineActor)
if __name__=='__main__':
main = pypes.pypeMain()
main.Arguments = sys.argv
main.Execute()
|