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
|
#!/usr/bin/env python
from vtkmodules.vtkCommonCore import vtkPoints
from vtkmodules.vtkIOImage import vtkPNGReader
from vtkmodules.vtkImagingCore import vtkImageShiftScale
from vtkmodules.vtkImagingStencil import (
vtkImageStencil,
vtkLassoStencilSource,
)
from vtkmodules.vtkRenderingCore import (
vtkActor2D,
vtkImageMapper,
vtkRenderWindow,
vtkRenderer,
)
import vtkmodules.vtkRenderingFreeType
import vtkmodules.vtkRenderingOpenGL2
from vtkmodules.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
# A script to test the vtkLassoStencilSource
reader = vtkPNGReader()
reader.SetDataSpacing(0.8,0.8,1.5)
reader.SetDataOrigin(0.0,0.0,0.0)
reader.SetFileName(VTK_DATA_ROOT + "/Data/fullhead15.png")
reader.Update()
shiftScale = vtkImageShiftScale()
shiftScale.SetInputConnection(reader.GetOutputPort())
shiftScale.SetScale(0.2)
shiftScale.Update()
points1 = vtkPoints()
points1.InsertNextPoint(80,50,0)
points1.InsertNextPoint(100,90,0)
points1.InsertNextPoint(200,50,0)
points1.InsertNextPoint(230,100,0)
points1.InsertNextPoint(150,170,0)
points1.InsertNextPoint(110,170,0)
points1.InsertNextPoint(80,50,0)
points2 = vtkPoints()
points2.InsertNextPoint(80,50,0)
points2.InsertNextPoint(100,90,0)
points2.InsertNextPoint(200,50,0)
points2.InsertNextPoint(230,100,0)
points2.InsertNextPoint(150,170,0)
points2.InsertNextPoint(110,170,0)
roiStencil1 = vtkLassoStencilSource()
roiStencil1.SetShapeToPolygon()
roiStencil1.SetSlicePoints(0,points1)
roiStencil1.SetInformationInput(reader.GetOutput())
roiStencil2 = vtkLassoStencilSource()
roiStencil2.SetShapeToPolygon()
roiStencil2.SetPoints(points2)
roiStencil2.SetInformationInput(reader.GetOutput())
roiStencil3 = vtkLassoStencilSource()
roiStencil3.SetShapeToSpline()
roiStencil3.SetPoints(points1)
roiStencil3.SetInformationInput(reader.GetOutput())
roiStencil4 = vtkLassoStencilSource()
roiStencil4.SetShapeToSpline()
roiStencil4.SetSlicePoints(0,points2)
roiStencil4.SetInformationInput(reader.GetOutput())
roiStencil4.Update()
stencil1 = vtkImageStencil()
stencil1.SetInputConnection(reader.GetOutputPort())
stencil1.SetBackgroundInputData(shiftScale.GetOutput())
stencil1.SetStencilConnection(roiStencil1.GetOutputPort())
stencil2 = vtkImageStencil()
stencil2.SetInputConnection(reader.GetOutputPort())
stencil2.SetBackgroundInputData(shiftScale.GetOutput())
stencil2.SetStencilConnection(roiStencil2.GetOutputPort())
stencil3 = vtkImageStencil()
stencil3.SetInputConnection(reader.GetOutputPort())
stencil3.SetBackgroundInputData(shiftScale.GetOutput())
stencil3.SetStencilConnection(roiStencil3.GetOutputPort())
stencil4 = vtkImageStencil()
stencil4.SetInputConnection(reader.GetOutputPort())
stencil4.SetBackgroundInputData(shiftScale.GetOutput())
stencil4.SetStencilConnection(roiStencil4.GetOutputPort())
mapper1 = vtkImageMapper()
mapper1.SetInputConnection(stencil1.GetOutputPort())
mapper1.SetColorWindow(2000)
mapper1.SetColorLevel(1000)
mapper1.SetZSlice(0)
mapper2 = vtkImageMapper()
mapper2.SetInputConnection(stencil2.GetOutputPort())
mapper2.SetColorWindow(2000)
mapper2.SetColorLevel(1000)
mapper2.SetZSlice(0)
mapper3 = vtkImageMapper()
mapper3.SetInputConnection(stencil3.GetOutputPort())
mapper3.SetColorWindow(2000)
mapper3.SetColorLevel(1000)
mapper3.SetZSlice(0)
mapper4 = vtkImageMapper()
mapper4.SetInputConnection(stencil4.GetOutputPort())
mapper4.SetColorWindow(2000)
mapper4.SetColorLevel(1000)
mapper4.SetZSlice(0)
actor1 = vtkActor2D()
actor1.SetMapper(mapper1)
actor2 = vtkActor2D()
actor2.SetMapper(mapper2)
actor3 = vtkActor2D()
actor3.SetMapper(mapper3)
actor4 = vtkActor2D()
actor4.SetMapper(mapper4)
imager1 = vtkRenderer()
imager1.AddViewProp(actor1)
imager1.SetViewport(0.5,0.0,1.0,0.5)
imager2 = vtkRenderer()
imager2.AddViewProp(actor2)
imager2.SetViewport(0.0,0.0,0.5,0.5)
imager3 = vtkRenderer()
imager3.AddViewProp(actor3)
imager3.SetViewport(0.5,0.5,1.0,1.0)
imager4 = vtkRenderer()
imager4.AddViewProp(actor4)
imager4.SetViewport(0.0,0.5,0.5,1.0)
imgWin = vtkRenderWindow()
imgWin.AddRenderer(imager1)
imgWin.AddRenderer(imager2)
imgWin.AddRenderer(imager3)
imgWin.AddRenderer(imager4)
imgWin.SetSize(512,512)
imgWin.Render()
# --- end of script --
|