[vtkusers] Change Contour Colors

Derek Gaston friedmud at gmail.com
Sun Jul 1 17:15:53 EDT 2012


Hello all.

I'm writing a bit of custom Python with Qt and VTK to add some
visualization to a small PyQt GUI we have.

I need to read ExodusII and just do some simple contour plotting of what's
in there with a color scale/legend (I also draw the edges so you can see
the mesh).  I have it basically working at this point (although hardcoded
to a specific variable name... but I'll change that later). But I'm hung up
at trying to change the colors of the contours.

All I want is very simple.  Right now it generates from Red to Blue (low to
high)... all I need is for it to go from Blue to Red (BTW - why the heck is
Red to Blue the default... shouldn't Blue to Red be the default?  I think
most people associate Red with a high color... especially if you are
plotting temperature... but that's beside the point).

I've looked at vtkLookupTable and vtkColorTransferFunction... but I can't
seem to come up with the right magic.  Basically, what I want is just the
simple Blue to Red HSV color bar that you can get in Paraview by choosing
that preset.  Any help would be awesome!

Here is my current code (it's in a Python class that inherits from QWidget
and uses a QVTKWidget2 that is initialized elsewhere):



    self.file_name = file_name
    reader = vtk.vtkExodusIIReader()
    reader.SetFileName(self.file_name)
    reader.UpdateInformation()
    reader.SetAllArrayStatus(vtk.vtkExodusIIReader.NODAL, 1)
    reader.SetAllArrayStatus(vtk.vtkExodusIIReader.NODAL_TEMPORAL, 1)
    reader.SetTimeStep(1)
    reader.Update()

    cdp = vtk.vtkCompositeDataPipeline()
    vtk.vtkAlgorithm.SetDefaultExecutivePrototype(cdp)

    geom = vtk.vtkCompositeDataGeometryFilter()
    geom.SetInputConnection(0,reader.GetOutputPort(0));
    geom.Update()

    data = geom.GetOutput()
    data.GetPointData().SetScalars(data.GetPointData().GetArray("u"))
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInput(data)
    mapper.ScalarVisibilityOn()
    mapper.SetColorModeToMapScalars()
    mapper.SetColorMode(2)
    mapper.SetScalarRange(0,1.0)

    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    self.renderer.AddActor(actor)

    edge_geom = vtk.vtkCompositeDataGeometryFilter()
    edge_geom.SetInputConnection(0,reader.GetOutputPort(0));
    edge_geom.Update()

    edges = vtk.vtkExtractEdges()
    edges.SetInput(edge_geom.GetOutput())
    edge_mapper = vtk.vtkPolyDataMapper()
    edge_mapper.SetInput(edges.GetOutput())

    edge_actor = vtk.vtkActor()
    edge_actor.SetMapper(edge_mapper)
    edge_actor.GetProperty().SetColor(0,0,0)

    self.renderer.AddActor(edge_actor)

    scalar_bar = vtk.vtkScalarBarActor()
    scalar_bar.SetLookupTable(mapper.GetLookupTable())
    scalar_bar.SetTitle("u")
    scalar_bar.SetNumberOfLabels(4)

    self.renderer.AddActor2D(scalar_bar)

    # Avoid z-buffer fighting
    vtk.vtkPolyDataMapper().SetResolveCoincidentTopologyToPolygonOffset()


    self.renderer.ResetCamera()
    self.vtkwidget.updateGL()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120701/1bdc9f2a/attachment.htm>


More information about the vtkusers mailing list