[vtkusers] coloring unstructured grid

John Platt jcplatt at dsl.pipex.com
Sun Dec 17 17:32:56 EST 2006


Hi Wolfgang,

Attach cell (or point) scalars to your UG. Use the default LUT of the
dataset mapper, your own LUT or define the scalars as actual colours
(unsigned chars) which, by default, are not mapped through the LUT. Have
a look at VTKMapper.

HTH

John.

-----Original Message-----
From: vtkusers-bounces+jcplatt=dsl.pipex.com at vtk.org
[mailto:vtkusers-bounces+jcplatt=dsl.pipex.com at vtk.org] On Behalf Of
WolfgangZillig
Sent: 17 December 2006 09:43
To: vtkusers at public.kitware.com
Subject: [vtkusers] coloring unstructured grid

Hello,

I'm quite new to VTK but I don't understand yet how to color single 
elements in a unstructured triangle grid. Coloring everything is done 
quite easily but I want different colors for the elements either by 
defining a color for the element or by defining a color in the nodes and

that I get a color ramp between.

Any help is appreciated.

Kind regards
Wolfgang Z

Here my python code to generate two triangle elements in the mesh:

#!/usr/bin/env python

import vtk

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

aTriangleGrid = vtk.vtkUnstructuredGrid()
aTriangleGrid.Allocate(2, 2)

aTriangle = vtk.vtkTriangle()
aTriangle.GetPointIds().SetId(0, 0)
aTriangle.GetPointIds().SetId(1, 1)
aTriangle.GetPointIds().SetId(2, 2)
aTriangleGrid.InsertNextCell(aTriangle.GetCellType(),aTriangle.GetPointI
ds())

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

aTriangleGrid.SetPoints(trianglePoints)


aTriangleMapper = vtk.vtkDataSetMapper()
aTriangleMapper.SetInput(aTriangleGrid)
aTriangleActor = vtk.vtkActor()
aTriangleActor.SetMapper(aTriangleMapper)
aTriangleActor.AddPosition(4, 0, 2)
aTriangleActor.GetProperty().SetDiffuseColor(.3, 1, .5)
#aTriangleActor.GetProperty().SetRepresentationToWireframe()

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

ren.SetBackground(.1, .2, .4)

ren.AddActor(aTriangleActor)


ren.ResetCamera()
ren.GetActiveCamera().Azimuth(30)
ren.GetActiveCamera().Elevation(20)
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()

_______________________________________________
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