[vtkusers] ColorMapping and Scalar Data

Chris Bayley bayley at me.queensu.ca
Fri Jun 8 15:54:29 EDT 2001


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;

//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);

//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);

//Colours->Delete();
DataPoints->Delete();
DataProfile->Delete();
DataMapper->Delete();




More information about the vtkusers mailing list