[vtkusers] Colorscale Problem

WolfgangZillig wollez at gmx.net
Tue Jan 23 08:51:05 EST 2007


Hello,

I want to generate some grapfics from results from a finite element 
calculation. It works quite well but when I tried to generate a scalebar 
(out of a manually entered grid) I got some strange results. I want to 
have the color rangeing from red over yellow to blue. I've defined this 
range by:

	min=0.50
	max=0.80
	avg=(min+max)/2.0

	aTriangleMapper.SetInput(aTriangleGrid)
	colorTransferFunction = vtk.vtkColorTransferFunction()
	colorTransferFunction.AddRGBPoint(min, 0.0, 0.0, 1.0)
	colorTransferFunction.AddRGBPoint(avg, 1.0, 1.0, 0.0)
	colorTransferFunction.AddRGBPoint(max, 1.0, 0.0, 0.0)
	aTriangleMapper.SetLookupTable(colorTransferFunction)


It looks for me that this range can not be drawn in one element of my 
grid. In the output from my calculations this is not a problem as there 
is not a that huge difference over one single element but in the mesh of 
my scalbar I got strange results. See included pictures.

So my question is: is this a limitation of vtk or do I do something wrong?

Kind regards
Wolfgang Zillig


-------------- next part --------------
A non-text attachment was scrubbed...
Name: colorscale_right_grid.png
Type: image/png
Size: 5178 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/vtkusers/attachments/20070123/85d3612a/colorscale_right_grid.png
-------------- next part --------------
A non-text attachment was scrubbed...
Name: colorscale_false.png
Type: image/png
Size: 1295 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/vtkusers/attachments/20070123/85d3612a/colorscale_false.png
-------------- next part --------------
#!/usr/bin/env python

import vtk,copy
from vtk.util.colors import *
scalars = vtk.vtkFloatArray()
scalars.InsertNextValue(0.8)
scalars.InsertNextValue(0.8)
scalars.InsertNextValue(0.5)
scalars.InsertNextValue(0.5)


trianglePoints = vtk.vtkPoints()
trianglePoints.InsertPoint(0, 0, 0, 0)
trianglePoints.InsertPoint(1, 1, 0, 0)
trianglePoints.InsertPoint(2, 0, 1, 0)
trianglePoints.InsertPoint(3, 1, 1, 0)

aTriangleGrid = vtk.vtkUnstructuredGrid()

aTriangle = vtk.vtkTriangle()
aTriangle.GetPointIds().SetId(0, 0)
aTriangle.GetPointIds().SetId(1, 1)
aTriangle.GetPointIds().SetId(2, 2)

aTriangleGrid.InsertNextCell(aTriangle.GetCellType(),aTriangle.GetPointIds())

aTriangle.GetPointIds().SetId(0, 1)
aTriangle.GetPointIds().SetId(1, 3)
aTriangle.GetPointIds().SetId(2, 2)
aTriangleGrid.InsertNextCell(aTriangle.GetCellType(),aTriangle.GetPointIds())


aTriangleGrid.SetPoints(trianglePoints)
aTriangleGrid.GetPointData().SetScalars(scalars)

aTriangleMapper = vtk.vtkDataSetMapper()

# colorTransferFunction
min=0.50
max=0.80
avg=(min+max)/2.0

aTriangleMapper.SetInput(aTriangleGrid)
colorTransferFunction = vtk.vtkColorTransferFunction()
colorTransferFunction.AddRGBPoint(min, 0.0, 0.0, 1.0)
colorTransferFunction.AddRGBPoint(avg, 1.0, 1.0, 0.0)
colorTransferFunction.AddRGBPoint(max, 1.0, 0.0, 0.0)
aTriangleMapper.SetLookupTable(colorTransferFunction)

aTriangleActor = vtk.vtkActor()
aTriangleActor.SetMapper(aTriangleMapper)
aTriangleActor.AddPosition(0, 0, 0)

# aTriangleActor.GetProperty().SetRepresentationToWireframe()

# Create the usual rendering stuff.
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
renWin.SetSize(300, 300)
iren = vtk.vtkRenderWindowInteractor()
interactor=vtk.vtkInteractorStyleTerrain()
iren.SetInteractorStyle(interactor)
iren.SetRenderWindow(renWin)

ren.SetBackground(1, 1, 1)
ren.AddActor(aTriangleActor)


ren.ResetCamera()
ren.GetActiveCamera().Azimuth(0)
ren.GetActiveCamera().Elevation(0)
# ren.GetActiveCamera().Dolly(2.8)
ren.ResetCameraClippingRange()

# Render the scene and start interaction.
iren.Initialize()
interactor=vtk.vtkInteractorStyleTerrain()
iren.SetInteractorStyle(interactor)

renWin.Render()
iren.Start()

renderLarge = vtk.vtkRenderLargeImage()
renderLarge.SetInput(ren)
renderLarge.SetMagnification(1)

# We write out the image which causes the rendering to occur. If you
# watch your screen you might see the pieces being rendered right
# after one another.
writer = vtk.vtkPNGWriter()
writer.SetInputConnection(renderLarge.GetOutputPort())
writer.SetFileName("colorscale_false.png")
writer.Write()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: colorscale_false_grid.png
Type: image/png
Size: 3968 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/vtkusers/attachments/20070123/85d3612a/colorscale_false_grid.png
-------------- next part --------------
A non-text attachment was scrubbed...
Name: colorscale_right.png
Type: image/png
Size: 1466 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/vtkusers/attachments/20070123/85d3612a/colorscale_right.png
-------------- next part --------------
#!/usr/bin/env python

import vtk,copy
from vtk.util.colors import *
scalars = vtk.vtkFloatArray()
scalars.InsertNextValue(0.8)
scalars.InsertNextValue(0.8)
scalars.InsertNextValue(0.5)
scalars.InsertNextValue(0.5)
scalars.InsertNextValue(0.65)
scalars.InsertNextValue(0.65)

trianglePoints = vtk.vtkPoints()
trianglePoints.InsertPoint(0, 0, 0, 0)
trianglePoints.InsertPoint(1, 1, 0, 0)
trianglePoints.InsertPoint(2, 0, 1, 0)
trianglePoints.InsertPoint(3, 1, 1, 0)
trianglePoints.InsertPoint(4, 0, 0.5, 0)
trianglePoints.InsertPoint(5, 1, 0.5, 0)

aTriangleGrid = vtk.vtkUnstructuredGrid()

aTriangle = vtk.vtkTriangle()
aTriangle.GetPointIds().SetId(0, 0)
aTriangle.GetPointIds().SetId(1, 1)
aTriangle.GetPointIds().SetId(2, 4)

aTriangleGrid.InsertNextCell(aTriangle.GetCellType(),aTriangle.GetPointIds())

aTriangle.GetPointIds().SetId(0, 1)
aTriangle.GetPointIds().SetId(1, 5)
aTriangle.GetPointIds().SetId(2, 4)
aTriangleGrid.InsertNextCell(aTriangle.GetCellType(),aTriangle.GetPointIds())

aTriangle.GetPointIds().SetId(0, 4)
aTriangle.GetPointIds().SetId(1, 5)
aTriangle.GetPointIds().SetId(2, 2)
aTriangleGrid.InsertNextCell(aTriangle.GetCellType(),aTriangle.GetPointIds())

aTriangle.GetPointIds().SetId(0, 5)
aTriangle.GetPointIds().SetId(1, 3)
aTriangle.GetPointIds().SetId(2, 2)
aTriangleGrid.InsertNextCell(aTriangle.GetCellType(),aTriangle.GetPointIds())


aTriangleGrid.SetPoints(trianglePoints)
aTriangleGrid.GetPointData().SetScalars(scalars)

aTriangleMapper = vtk.vtkDataSetMapper()


min=0.50
max=0.80
avg=(min+max)/2.0

aTriangleMapper.SetInput(aTriangleGrid)
colorTransferFunction = vtk.vtkColorTransferFunction()
colorTransferFunction.AddRGBPoint(min, 0.0, 0.0, 1.0)
colorTransferFunction.AddRGBPoint(avg, 1.0, 1.0, 0.0)
colorTransferFunction.AddRGBPoint(max, 1.0, 0.0, 0.0)
aTriangleMapper.SetLookupTable(colorTransferFunction)

aTriangleActor = vtk.vtkActor()
aTriangleActor.SetMapper(aTriangleMapper)
aTriangleActor.AddPosition(0, 0, 0)

# aTriangleActor.GetProperty().SetRepresentationToWireframe()


# Create the usual rendering stuff.
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
renWin.SetSize(300, 300)
iren = vtk.vtkRenderWindowInteractor()
interactor=vtk.vtkInteractorStyleTerrain()
iren.SetInteractorStyle(interactor)
iren.SetRenderWindow(renWin)

ren.SetBackground(1, 1, 1)
ren.AddActor(aTriangleActor)


ren.ResetCamera()
ren.GetActiveCamera().Azimuth(0)
ren.GetActiveCamera().Elevation(0)
# ren.GetActiveCamera().Dolly(2.8)
ren.ResetCameraClippingRange()

# Render the scene and start interaction.
iren.Initialize()
interactor=vtk.vtkInteractorStyleTerrain()
iren.SetInteractorStyle(interactor)

renWin.Render()
iren.Start()

renderLarge = vtk.vtkRenderLargeImage()
renderLarge.SetInput(ren)
renderLarge.SetMagnification(1)

# We write out the image which causes the rendering to occur. If you
# watch your screen you might see the pieces being rendered right
# after one another.
writer = vtk.vtkPNGWriter()
writer.SetInputConnection(renderLarge.GetOutputPort())
writer.SetFileName("colorscale_right.png")
writer.Write()


More information about the vtkusers mailing list