[vtkusers] coloring unstructured grid
WolfgangZillig
wollez at gmx.net
Sun Dec 17 04:42:39 EST 2006
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.GetPointIds())
aTriangle.GetPointIds().SetId(0, 0)
aTriangle.GetPointIds().SetId(1, 2)
aTriangle.GetPointIds().SetId(2, 3)
aTriangleGrid.InsertNextCell(aTriangle.GetCellType(),aTriangle.GetPointIds())
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()
More information about the vtkusers
mailing list