[vtkusers] Polydata and mapping RGB and A to RGBA: ways use two colour arrays

Meister, Martin MM (E F CI C5 5) martin.meister at siemens.com
Tue Feb 26 08:17:47 EST 2013


Hello people,
investigating how to render two scalars into one representation. Natural solution seems to use array1=Alpha and array2=RGB. This way, I can show two scalars at once. Works well, if alpha array is i.e. the void fraction, indicating, how vanishing the values of a field actually are. This way, I can blend a field out when it is not there, or only fractionally.

What I am stumbling over is how to tell this to the mapper:
1) internally you most probably have array1 and array2 as floatarray
2) there are tutorials who basically setup an array of RGBA as the data array to be rendered.
3) this means a "conversion" of array1 and array2 into array3 (RGBA format, unsigned char)

This approach is very inflexible since changing the colourmap means a re-setup of this data array, array3, needed for rendering.

Do different ways exist?
Thanks a million,
Martin
############# pythoncode, runnable with vtkpython, looks nice ############
#!/usr/bin/python
import os, sys
from math import *
import struct
import array
import numpy as Numeric
import random
import vtk
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
renWin.AddRenderer(ren)
renWin.SetSize(500, 500)
v_lut = vtk.vtkLookupTable()
v_lut.SetTableRange([-1.0, 1.0])
v_lut.SetRange([-1.0, 1.0])
v_lut.SetHueRange(0.66,0);
v_lut.Build()
# build some initial geometry
pS = vtk.vtkSphereSource()
pS.SetThetaResolution(100)
pS.SetPhiResolution(100)
pS.Modified()
pS.Update()
pD = pS.GetOutput()
numP = pD.GetNumberOfPoints()
# ##############################################################
# initial data array
arr1 = vtk.vtkFloatArray()
arr2 = vtk.vtkFloatArray()
for i in range(numP):
 arr1.InsertNextTuple([1.0-i/(float(numP))])
 #arr1.InsertNextTuple([cos(i/8.0)])
 arr2.InsertNextTuple([sin(i/110.0)])
# fill the colours array
arr3 = vtk.vtkUnsignedCharArray()
arr3.SetName("colors")
arr3.SetNumberOfComponents(4)
for i in range(numP):
 alpha    = arr1.GetValue(i)
 rgbindex = arr2.GetValue(i)
 col      = [0,0,0]
 v_lut.GetColor(rgbindex,col)
 rgba     = [col[0]*255,col[1]*255,col[2]*255, arr1.GetValue(i)*255]
 arr3.InsertNextTuple(rgba)
# set the data to the geometry
pD.GetPointData().SetScalars(arr3)
# ---> I would prefer to set the two arrays to a mapper using it as RGBA <---
pD.GetPointData().SetActiveScalars("colors")
# mapper
pSM = vtk.vtkPolyDataMapper()
pSM.SetInput(pD)
pSM.ScalarVisibilityOn()
pSM.SetScalarModeToDefault()
# actors
pSA = vtk.vtkActor()
pSA.SetMapper(pSM)
v_scalActor = vtk.vtkScalarBarActor();
v_scalActor.SetLookupTable(v_lut);
ren.AddActor(v_scalActor)
ren.AddActor(pSA)
# ########################
style = vtk.vtkInteractorStyleTrackballCamera()
iren.SetInteractorStyle(style)
ren.ResetCamera()
ren.GradientBackgroundOn()
ren.SetBackground(0.365, .365, 0.375)
ren.SetBackground2(0.795, .7995, 0.795)
iren.Initialize()
renWin.Render()
iren.Start()

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130226/43865311/attachment.htm>


More information about the vtkusers mailing list