[vtkusers] ColorMapping and Scalar Data

Malcolm Drummond malcolm at geovision.co.za
Sun Jun 10 09:38:38 EDT 2001


Hi Chris

Does "X and Y data being indices" mean you're dealing with results on a
regular mesh? If so, you could create a vtkStructuredPoints dataset and
manually set the scalars with the z-value. You can use the "width" of the
dataset to calculate the scalar index (just like you would to obtain a point
index), so for each of your points (X,Y,Z) ...

scalars SetScalar [expr $X+($Y*$width)] $Z

This assumes zero-offset and that you've already set the number of scalars
to width*height.

Malcolm

----- Original Message -----
From: Chris Bayley <bayley at me.queensu.ca>
To: <vtkusers at public.kitware.com>
Sent: Friday, June 08, 2001 9:54 PM
Subject: [vtkusers] ColorMapping and Scalar Data


> Hello Everyone;
>
> Thanks in advance to everyone out there.
>
> I am having trouble obtaining colour mapping my data.  My data is a series
of
> X,Y,Z data points, with the X and Y data being indices and the Z the
height
> that I'm interested in.  I've looked through the Users quide and the
> Visualization toolkit book, but I can't figure out how I should be
presenting
> my datapoints to represent them as scalar quantities.  I want to the
colour
> scale to represent the magnitude of the Z component of the data.
>
> So far I taking my datapoints and passing them through vtkpoints, then
> using these points creating a mesh of VTK_Quad cells using vtkPolyData
then
> finally create mapper from the vtkPolyData.  Then I specify with the
vtkMapper
> to use a vtkColorLookupTable to represent the data.
>
> Any Suggestions as to what I'm doing wrong?
>
> Sincerely
>
> Chris Bayley
>
> My C++ code looks like this:
>
> void PowerSpectrumVTK(int *M, int *N, float *PowerSpectra)
> {
> int i,j, index, k, NN, DP, pt;
> float pts[3],max=0.0,min=0.0;
> int quad[4];
>
> vtkPoints *DataPoints = vtkPoints::New();
> DataPoints->Allocate((*N)*(*M));
>
> vtkPolyData *DataProfile = vtkPolyData::New();
> DataProfile->Allocate((*N)*(*M));
>
> k=0;
> NN=(*N)/2+1;
>
> file://Define the vtkPoints
>
> for(i=0;i<(*M);i++){
> for(j=0;j<NN;j++){
>         index = j+(NN*i);
>
> pts[0]=i;
> pts[1]=j;
> pts[2]=log(PowerSpectra[index]);
>
>         if(log(PowerSpectra[index])>max) max=log(PowerSpectra[index]);
>         if(log(PowerSpectra[index])<min) min=log(PowerSpectra[index]);
>
> DataPoints->InsertNextPoint(pts);
> k++;
> }
> }
> printf("Min %f Max %f\n",min, max);
>
> file://Define a "mesh" for the data points
> for(i=0;i<((*M)-1);i++){
> pt=0;
> DP=i*NN;
> while( pt+2 < NN )
> {
>
> quad[0]=DP;
> quad[1]=DP+1;
> quad[2]=DP+(NN+1);
>                 quad[3]= DP+(NN);
>
> DataProfile->InsertNextCell(VTK_QUAD,4,quad);
>
> DP++;
> pt++;
> }
>
> }
>
> DataProfile->SetPoints(DataPoints);
>
> vtkLookupTable *Colours = vtkLookupTable::New();
> Colours->SetNumberOfColors(256);
>         Colours->SetHueRange(0.0 ,0.667);
>         Colours->Build();
>
>
> vtkPolyDataMapper *DataMapper = vtkPolyDataMapper::New();
> DataMapper->ScalarVisibilityOn;
>         DataMapper->SetLookupTable(Colours);
>         DataMapper->SetInput(DataProfile);
>
>
> ActorArray[POWERSPECTRUMACTOR] = vtkActor::New();
> ActorArray[POWERSPECTRUMACTOR]->SetMapper(DataMapper);
>
> file://Colours->Delete();
> DataPoints->Delete();
> DataProfile->Delete();
> DataMapper->Delete();
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at:
<http://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>





More information about the vtkusers mailing list