[vtkusers] Colour iso-surface by another variable

Kevin Wright krw at viz-solutions.com
Fri May 3 12:34:30 EDT 2002


At 10:29 AM 5/3/2002 +0100, you wrote:
>but once I have the isosurface I want to colour it by another variable. I am
>presently doing this using
>
>   vtkProbeFilter *probe = vtkProbeFilter::New();
>   probe->SetInput(iso->GetOutput() );
>   probe->SetSource(ProCol->GetOutput() );
>   vtkCastToConcrete *cast2 = vtkCastToConcrete::New();
>   cast2->SetInput(probe->GetOutput() );
>
>My data is an unstructured grid with point data. I am told that there is a
>better way to do this using AddArray but can find no examples of such. Is
>there anyone who can shed some light on this?

If you're using VTK 3, I believe the way you're doing it is correct.  If 
you're using VTK 4, then you can try something a little more efficient:

If you have two scalar fields:

vtkFloatArray *scalar1
scalar1->SetName("IsoScalar");
vtkFloatArray *scalar2;
scalar2->SetName("MapScalar");

If you want to create an isosurface based on scalar1, and map with scalar2 
you can create your original grid like this:

vtkUnstructuredGrid *uns = vtkUnstructuredGrid::New();
...
uns->GetPointData()->SetScalars(scalar1);
uns->GetPointData()->AddArray(scalar2);

Then once this grid is passed through the contouring filter, there should 
be values of scalar2 for each point of the iso-surface.  You can then set 
the mapper to map that field instead of the scalar field:

Mapper->ColorByArrayComponent("MapScalar",0);
Mapper->SetScalarModeToUsePointFieldData();

And that should be it.

Hope that helps,
Kevin.





More information about the vtkusers mailing list