[Paraview] Using a programmable filter to apply custom rgb colors to a ExodusII data set

Mark Messner mmessne2 at illinois.edu
Tue Mar 5 12:49:14 EST 2013


Hello David,

Thank you.  That code works when modified for what I'm trying to do.  And
you cleared up my confusion on the ExodusIIReader.

Mark


Mark Messner
Ph.D. Candidate
Department of Civil and Environmental Engineering
University of Illinois at Urbana-Champaign


On Mon, Mar 4, 2013 at 8:40 PM, David Thompson
<david.thompson at kitware.com>wrote:

> Hi Mark,
>
> > I'm trying to use a programmable filter to apply colors to an ExodusII
> data set.  ... From that what I assume I have to do is create a
> vtkUnsignedCharArray with length equal to the number of cells in the model,
> assign my colors, and then display.
>
> Yes, you are correct.
>
> > 1) I understand the ExodusIIReader is, well, a reader -- it will
> generate the data blocks, it's not actually representing the data.
>
> I'm not sure what you mean by "not actually representing the data." It
> *does* represent the data, segregated into a series of blocks (which is how
> it is stored on disk). The blocks are arranged into a 2-level hierarchy.
> The first level determines what the blocks represent (elements, faces,
> edges, or subsets thereof). The second level contains the actual data.
>
> >  But I don't get how to access at the generated data.  Say I have a
> single block of elements called 'hexes' with cell data 'stresses', how do I
> access that cell data in the programmable filter?
>
> I've put a script below that colors the first element block in the can.ex2
> dataset (available from the ParaViewData git repo:
> http://www.paraview.org/gitweb?p=ParaViewData.git;a=blob;f=Data/can.ex2;hb=HEAD). It shows how you can add a color array to one block (in the example
> below, ids.GetBlock(0).GetBlock(0) is the first "leaf" node of the tree
> containing the Exodus data). In reality, you probably want to loop over all
> leaf nodes in the dataset. You can use GetNumberOfBlocks() to set up a loop
> that calls GetBlock with each valid index.
>
>         David
>
> ids = self.GetInput()
> ods = self.GetOutput()
>
> ods.ShallowCopy(ids)
>
> cellData = ids.GetBlock(0).GetBlock(0).GetCellData()
> eqps = cellData.GetArray('EQPS')
> nt = eqps.GetNumberOfTuples()
>
> color = vtk.vtkUnsignedCharArray()
> color.SetName('Color')
> color.SetNumberOfComponents(3)
> color.SetNumberOfTuples(nt)
> for i in range(nt):
>    ival = eqps.GetTuple1(i)
>    red = 255.0 * ival
>    green = 255.0 * (1 - ival)
>    blue= 255.0
>    color.SetTuple3(i, red, green, blue)
>
> cellData.SetScalars(color)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.paraview.org/pipermail/paraview/attachments/20130305/116da1f6/attachment.htm>


More information about the ParaView mailing list