[vtkusers] ConfigScalarLegend from python interpreter

Paul Cochrane paultcochrane at gmail.com
Mon Dec 5 02:58:51 EST 2005


Hi James,

I'm assuming that you're interested in driving vtk from python rather
than driving mayavi from python, so hopefully this will be of some
help to you.

To reverse the LUT the only way I've found to do it is to explicitly
create a lookup table in the opposite order and assign it to the
relevant object (i.e. the mapper and the scalar bar):

# get the vtk stuff
import vtk

# reverse the order of the colourmap
lut = vtk.vtkLookupTable()
refLut = vtk.vtkLookupTable()
lut.Build()
refLut.Build()
for i in range(256):
    lut.SetTableValue(i, refLut.GetTableValue(255-i))

When you configure the scalar legend in mayavi I believe all you are
doing is adding a vtkScalarBarActor object.  Consequently, what you
need to do to show the legend is create a vtkScalarBarActor object and
add it to the renderer. i.e.

# add a scalar bar
scalarBar = vtk.vtkScalarBarActor()
scalarBar.SetLookupTable(lut)  # use predefined LUT
scalarBar.SetWidth(0.1)  # 0.1 of the width of the viewport
scalarBar.SetHeight(0.8)  # 0.8 of the height of the viewport
scalarBar.SetPosition(0.9, 0.15)  # a location in units of the viewport
scalarBar.SetTitle("scalar bar")

# add the actor to the renderer
ren.AddActor(scalarBar)  # assuming that you've already defined the renderer

To get the Shadow Legend working, you need to set up a text property
object, make sure that you set ShadowOn() (I've added other bits and
pieces here), and then ShallowCopy it into the scalar bar's text
property.

# text properties
textProp = vtk.vtkTextProperty()
textProp.SetFontSize(14)
textProp.SetFontFamilyToArial()
textProp.BoldOff()
textProp.ItalicOff()
textProp.ShadowOn()

# set up the label text properties
scalarBarTextProp = scalarBar.GetTitleTextProperty()
scalarBarTextProp.ShallowCopy(textProp)

All this basically shows you is that there's a fair bit of code going
on behind the checkboxes in mayavi :-)

I hope this has helped a bit.

Paul

On 12/4/05, jck103 at soton.ac.uk <jck103 at soton.ac.uk> wrote:
> In MayaVi there is a button titled "ConfigScalarLegend", from the window
> that pops up one can reverse the look up table with a check box "Reverse
> LUT" and can select "Show Legend" and "Shadow Legened".
>
> Is it possible to select any of these using commands from a Python
> interpreter, say IPython.
>
>   Thanks,       James.
>
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>


More information about the vtkusers mailing list