[vtkusers] mapping indpenent scalars to opacity and color

bryan cole bryan.cole at teraview.com
Fri Dec 5 07:22:42 EST 2003


Thanks Vladan. This explanation helped a *lot*. I was unaware of the
vtkScalarToColor::SetVectorComponent() and other vector-related methods
because I'm using v4.1 version documentation. The Vector mapping stuff
seems to be a more recent addition. I'm downloading the up-to-date docs
now...

In fact, I've achieved the results I wanted an alternative way -

I'm using the vtkMapper::SetColorModeToDefault() and
SetScalarModeToUsePointFieldData() to pass a 4-component RGBA unisgned
char array as the active scalars. This bypasses any color-mapping by the
mapper and uses the RGBA array directly.

I created the RGBA array from my two original scalar-arrays using a
separate vtkLookUpTable instance and calling MapScalars() explicitly to
create RGBA arrays. I then copying the forth component (the alpha
values) directly from one vtkDataArray into the other using
vtkDataArray::CopyComponent().

Right now this process doesn't use true pipeline execution, but this is
OK for now. I could build it all into a vtkProgramableFilter() for
integration into a pipeline. 100% python, no C++ required. hurrah!

cheers,
Bryan


On Fri, 2003-12-05 at 08:56, Vladan Bato wrote:
> bryan cole wrote:
> > I can't see how to set a vtkMapper to use vector data. Does this happen
> > automatically in the absence of any Scalars? Creating a custom
> > vtkScalarsToColors doesn't seem like to much work for me. 
> 
> The problem is that the term "Scalars" is used in vtk for different things:
> - actual scalars, i.e. numbers
> - a data array of any dimensionality associated with your geometry.
> 
> What the mapper does is map a data array to colors.
> First you choose what data (cell, point, etc.) to map with 
> SetScalarMode(), then you can choose the actual data array (if there is 
> more than one) with SelectColorArray().
> 
> This array can have more than one component.
> 
> The mapper will pass this array to its LookupTable (a descendant of 
> vtkScalarsToColors) to convert the data to colors.
> 
> In vtkScalarsToColors, you can choose how to map multicomponent data 
> (still called scalars) by calling SetVectorMode.
> 
> The colors are mapped through
> 
> vtkUnsignedCharArray *vtkScalarsToColors::MapScalars(
>                       vtkDataArray *scalars, int colorMode, int comp)
> 
> The mapper can either choose a component to map (but this is considered 
> obsolete), or leave it to the lookup table. If comp is -1, 
> vtkScalarsToColors uses its VectorMode to select how to map vectors 
> (multiple components).
> 
> MapScalars() in turn calls MapScalarsThroughTable2() which is a pure 
> virtual method that is implemented in descendant classes.
> 
> This is the method that should be reimplemented to map the vectors in a 
> custom way by, for example, using a normal vtkLookupTable to map one 
> component, and then using another component to change the alpha.
> 
> The only problem is that you need to have both components in a single 
> multi-component attribute (vtkDataArray) of your data set. If you have 
> them as separate attributes you need to combine them somehow.
> 
> Now a disclaimer: I have never used vector data myself. What I wrote 
> above is based on reading the docs and the source code, but I could be 
> wrong.
> 
> I hope this clarifies a bit what I wrote yesterday.
-- 
Bryan Cole
Teraview Ltd., 302-304 Cambridge Science Park, Milton Road, Cambridge CB4 0WG, United Kingdom.
tel: +44 (1223) 435380 / 435386 (direct-dial) fax: +44 (1223) 435382




More information about the vtkusers mailing list