[vtkusers] Change Contour Colors

Derek Gaston friedmud at gmail.com
Sun Jul 8 01:22:41 EDT 2012


Just in case someone else hits this thread later... all I needed for a
blue-to-red rainbow lookuptable was:

    lut = vtk.vtkLookupTable()
    lut.SetHueRange(0.667, 0.0)
    lut.SetNumberOfColors(256)
    lut.Build()

Now... since Andrew pointed me to that great paper by Ken let's discuss
colormaps a bit!  Firstly, that was a great paper... definitely well done.
 Unfortunately, I can't agree completely with the conclusions.

If every person on earth was a scientist or engineer... then we should all
take Ken's advice and use Blue-to-Red Diverging for our colormaps.
 Unfortunately, that's not the case!  So while a diverging colormap might
convey detail better to a scientist or engineer who is familiar with the
domain... many times visualizations are shown to people who have no real
background on the material... and in those cases they want to see
_color_... and I don't just mean a bit of red and a bit of blue with some
grey in between... they want to see a LOT of color.

The people I'm talking about here are the program managers and senators and
bosses and even customers.... the people we depend on to give us money so
we can continue to do science!  When those people are in the room I want to
catch their eye with over saturated rainbows of color... even if a bit of
detail is lost in the green areas ;-)

Only after catching their eye can I even attempt to explain the science
behind what they're seeing and convince them to give me more money to study
it further.  If they're turned off by boring colors from the start I might
never get the chance....

Just my 2 cents ;-)

Derek

On Mon, Jul 2, 2012 at 4:37 PM, Andrew Maclean <andrew.amaclean at gmail.com>wrote:

>  Hi Derek,
>    You might like to look at:
> http://www.vtk.org/Wiki/VTK/Examples/Python/CurvaturesDemo
> This shows you how to use a diverging colour space very nicely!
> To choose other colour spaces and to extend this look at the C++ code
> referred to in the document
> http://www.cs.unm.edu/~kmorel/documents/ColorMaps/ColorMapsExpanded.pdf by Kenneth Moreland,
> this is a very good article.
>
> Regards
>    Andrew
>
>
> ---------- Forwarded message ----------
>> From: Derek Gaston <friedmud at gmail.com>
>> To: vtkusers at vtk.org
>> Cc:
>> Date: Sun, 1 Jul 2012 15:15:53 -0600
>> Subject: [vtkusers] Change Contour Colors
>> 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()
>>
>>
>
> --
> ___________________________________________
> Andrew J. P. Maclean
>
> ___________________________________________
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120707/dfc20997/attachment.htm>


More information about the vtkusers mailing list