[Paraview] Setting the colour/scale palete used for glyphs

Moreland, Kenneth kmorel at sandia.gov
Tue Nov 20 11:28:05 EST 2012


Under certain circumstances ParaView will treat a vector field as colors.
Specifically, IF the field is of type unsigned char with 3 or 4 components
AND IF the field is set as the scalars in the data set, then the values in
that field will be treated directly as colors rather than interpolated in
a color map.(What actually happens is that in this circumstance, ParaView
will turn off the "Map Scalars" display parameter.)


So, I don't think there is any way for your filter to force or suggest a
color map for its scalar values. However, if you instead directly create
the colors you want in the filter, store them in a vtkUnsignedCharArray of
3 or 4 components, then add that array to your data set using SetScalars,
you should get the desired result.

Here is a quick Python script that can be executed in the Programmable
Filter that I wrote up to demonstrate how to do this.  (Try applying it to
the output from the Box source.)


input = self.GetPolyDataInput()
output = self.GetPolyDataOutput()

output.ShallowCopy(input)
numPoints = output.GetNumberOfPoints()

colors = vtk.vtkUnsignedCharArray()
colors.SetName("Colors")
colors.SetNumberOfComponents(3)
colors.SetNumberOfTuples(numPoints)

for pointIndex in range(0, numPoints):
    coord = output.GetPoint(pointIndex)
    r = 255 * (coord[0] + 0.5)
    g = 255 * (coord[1] + 0.5)
    b = 255 * (coord[2] + 0.5)
    colors.SetTuple3(pointIndex, r, g, b)

output.GetPointData().SetScalars(colors)


Hope that helps.

-Ken



On 11/20/12 1:53 AM, "Kit Chambers" <kit.chambers.kc at gmail.com> wrote:

>Thanks David,  ideally I'd like to have something in the plugin so that
>when the user applies the filter and the default display is the 2 color
>option for this object. Rather than them having to go through a series
>of clicks on the GUI inorder to get to the discrete color pallete.
>
>The field values are just +1 and -1, and I would like them to be plotted
>as either black or white accordingly by default.
>
>Kit
>
>On 20/11/2012 05:09, David Thompson wrote:
>> Hi Kit,
>>
>>> ... I would like to ensure that field is coloured (by default) using a
>>>specific colour palette. More specifically I want to it to use 2
>>>discrete colours, rather than the rainbow scale. Is this possible?
>> You can set the number of colors in the lookup table by
>> + clicking on the color scale editor button in the toolbar,
>> + ensuring that the "Use Discrete Colors" checkbox is ON, and
>> + changing the "Resolution" slider to 2.
>>
>> As long as the field values are uniformly spaced, you can handle more
>>than 2 colors by changing the resolution appropriately (but note that
>>you may wish to use the "Rescale Range" button to keep color band edges
>>from falling on special values).
>>
>> 	David
>
>_______________________________________________
>Powered by www.kitware.com
>
>Visit other Kitware open-source projects at
>http://www.kitware.com/opensource/opensource.html
>
>Please keep messages on-topic and check the ParaView Wiki at:
>http://paraview.org/Wiki/ParaView
>
>Follow this link to subscribe/unsubscribe:
>http://www.paraview.org/mailman/listinfo/paraview
>




More information about the ParaView mailing list