1#!/usr/bin/env python
2import vtk
3from vtk.util.misc import vtkGetDataRoot
4VTK_DATA_ROOT = vtkGetDataRoot()
5
6# Use the painter to draw using colors.
7# This is not a pipeline object.  It will support pipeline objects.
8# Please do not use this object directly.
9imageCanvas = vtk.vtkImageCanvasSource2D()
10imageCanvas.SetNumberOfScalarComponents(3)
11imageCanvas.SetScalarTypeToUnsignedChar()
12imageCanvas.SetExtent(0,320,0,320,0,0)
13imageCanvas.SetDrawColor(0,0,0)
14imageCanvas.FillBox(0,511,0,511)
15# r, g, b
16imageCanvas.SetDrawColor(255,0,0)
17imageCanvas.FillBox(0,50,0,100)
18imageCanvas.SetDrawColor(128,128,0)
19imageCanvas.FillBox(50,100,0,100)
20imageCanvas.SetDrawColor(0,255,0)
21imageCanvas.FillBox(100,150,0,100)
22imageCanvas.SetDrawColor(0,128,128)
23imageCanvas.FillBox(150,200,0,100)
24imageCanvas.SetDrawColor(0,0,255)
25imageCanvas.FillBox(200,250,0,100)
26imageCanvas.SetDrawColor(128,0,128)
27imageCanvas.FillBox(250,300,0,100)
28# intensity scale
29imageCanvas.SetDrawColor(5,5,5)
30imageCanvas.FillBox(0,50,110,210)
31imageCanvas.SetDrawColor(55,55,55)
32imageCanvas.FillBox(50,100,110,210)
33imageCanvas.SetDrawColor(105,105,105)
34imageCanvas.FillBox(100,150,110,210)
35imageCanvas.SetDrawColor(155,155,155)
36imageCanvas.FillBox(150,200,110,210)
37imageCanvas.SetDrawColor(205,205,205)
38imageCanvas.FillBox(200,250,110,210)
39imageCanvas.SetDrawColor(255,255,255)
40imageCanvas.FillBox(250,300,110,210)
41# saturation scale
42imageCanvas.SetDrawColor(245,0,0)
43imageCanvas.FillBox(0,50,220,320)
44imageCanvas.SetDrawColor(213,16,16)
45imageCanvas.FillBox(50,100,220,320)
46imageCanvas.SetDrawColor(181,32,32)
47imageCanvas.FillBox(100,150,220,320)
48imageCanvas.SetDrawColor(149,48,48)
49imageCanvas.FillBox(150,200,220,320)
50imageCanvas.SetDrawColor(117,64,64)
51imageCanvas.FillBox(200,250,220,320)
52imageCanvas.SetDrawColor(85,80,80)
53imageCanvas.FillBox(250,300,220,320)
54convert = vtk.vtkImageRGBToHSI()
55convert.SetInputConnection(imageCanvas.GetOutputPort())
56convertBack = vtk.vtkImageHSIToRGB()
57convertBack.SetInputConnection(convert.GetOutputPort())
58cast = vtk.vtkImageCast()
59cast.SetInputConnection(convertBack.GetOutputPort())
60cast.SetOutputScalarTypeToFloat()
61cast.ReleaseDataFlagOff()
62viewer = vtk.vtkImageViewer()
63viewer.SetInputConnection(convertBack.GetOutputPort())
64#viewer SetInputConnection [imageCanvas GetOutputPort]
65viewer.SetColorWindow(256)
66viewer.SetColorLevel(127.5)
67viewer.SetSize(320,320)
68viewer.Render()
69# --- end of script --
70