[2229] | 1 | # Basic VTK pipeline |
---|
| 2 | |
---|
| 3 | from pylab import * |
---|
| 4 | from vtk import * |
---|
| 5 | |
---|
| 6 | |
---|
| 7 | # ------- a boilerplate VTK pipeline --------- |
---|
| 8 | #--- Create some LUTs |
---|
| 9 | # (default) red -> blue (lo->hi)LUT |
---|
| 10 | lutRedBlue = vtkLookupTable() |
---|
| 11 | lutRedBlue.Build() |
---|
| 12 | |
---|
| 13 | # blue -> red LUT |
---|
| 14 | lutBlueRed = vtkLookupTable() |
---|
| 15 | lutBlueRed.SetHueRange(0.667,0.0) |
---|
| 16 | lutBlueRed.Build() |
---|
| 17 | |
---|
| 18 | |
---|
| 19 | vtkRen=vtkRenderer() |
---|
| 20 | vtkRenWin=vtkRenderWindow() |
---|
| 21 | |
---|
| 22 | # TODO - allow changing window size |
---|
| 23 | global winWidth, winHeight |
---|
| 24 | winWidth = 256 |
---|
| 25 | winHeight = 256 |
---|
| 26 | vtkRenWin.SetSize(winWidth,winHeight) |
---|
| 27 | im = zeros((winWidth,winHeight,3), typecode=Float) |
---|
| 28 | |
---|
| 29 | vtkRenWin.OffScreenRenderingOn() |
---|
| 30 | vtkRenWin.AddRenderer(vtkRen) |
---|
| 31 | |
---|
| 32 | vtkRGB = vtkUnsignedCharArray() |
---|
| 33 | |
---|
| 34 | """ |
---|
| 35 | def copyVTKImage(): |
---|
| 36 | vtkRenWin.Render() |
---|
| 37 | vtkRenWin.GetPixelData(0,0,winWidth-1,winHeight-1, 1,vtkRGB) |
---|
| 38 | # vtkRGB.Squeeze() |
---|
| 39 | idx=0 |
---|
| 40 | for iy in range(winHeight-1,-1,-1): |
---|
| 41 | for ix in range(winWidth): |
---|
| 42 | im[iy,ix,0] = vtkRGB.GetValue(idx) / 255. |
---|
| 43 | im[iy,ix,1] = vtkRGB.GetValue(idx+1) / 255. |
---|
| 44 | im[iy,ix,2] = vtkRGB.GetValue(idx+2) / 255. |
---|
| 45 | idx += 3 |
---|
| 46 | |
---|
| 47 | def vtkRotX(degs): |
---|
| 48 | vtkRen.GetActiveCamera().Elevation(degs) |
---|
| 49 | |
---|
| 50 | def vtkPerspective(flag): |
---|
| 51 | if flag > 0: |
---|
| 52 | vtkRen.GetActiveCamera().ParallelProjectionOff() |
---|
| 53 | else: |
---|
| 54 | vtkRen.GetActiveCamera().ParallelProjectionOn() |
---|
| 55 | |
---|
| 56 | def vtkWinsize(w,h): |
---|
| 57 | winWidth = w |
---|
| 58 | winHeight = h |
---|
| 59 | im = zeros((winWidth,winHeight,3), typecode=Float) |
---|
| 60 | vtkRenWin.SetSize(winWidth,winHeight) |
---|
| 61 | """ |
---|
| 62 | |
---|