[vtkusers] Re: Colorscale Problem

WolfgangZillig wollez at gmx.net
Wed Jan 31 03:39:23 EST 2007


Hello,

has nobody an idea why I get this strange color mapping with my 
colorTransferFunction? Why can't I have a color transition from blue 
over yellow to red in one element of my unstructured grid.

Kind regards
WolfgangZillig



WolfgangZillig schrieb:
> 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
> 
> 
> 
> ------------------------------------------------------------------------
> 
> 
> ------------------------------------------------------------------------
> 
> 
> ------------------------------------------------------------------------
> 
> #!/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()
> 
> 
> ------------------------------------------------------------------------
> 
> 
> ------------------------------------------------------------------------
> 
> 
> ------------------------------------------------------------------------
> 
> #!/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()
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> 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