[vtkusers] please help on using multiple scalars

david michell davidmichell at rediffmail.com
Tue Jan 27 08:58:10 EST 2004


An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20040127/15a49662/attachment.htm>
-------------- next part --------------
hello everybody,
thanks for all the help.
Iam now developing a code where iam applying sphere glyphs to point data.
Iam having two arrays of scalars.
I want to use the first scalar array to size the glyph and the second scalar array to color the glyph.
I have written a code but it is wrong.
Please correct it and help me.
Thank you for spending you time,
David Michell


the data.set file contains the coordinates of the points ie
x y z x y z x y z.......
//all the #include goes here
void main()
{
int npts=10;
int i;
FILE *fp;
float coord[3];

vtkLookupTable *ltab;

fp=fopen("data.set","r");

vtkPoints *ps=vtkPoints::New();
vtkCellArray *ca =vtkCellArray::New();
vtkUnstructuredGrid *ug=vtkUnstructuredGrid::New();
vtkFloatArray *da=vtkFloatArray::New();

ps->Allocate(npts);

ca->Allocate(ca->EstimateSize(100,100));
ca->InsertNextCell(npts);

ltab=vtkLookupTable::New();
ltab->SetNumberOfColors(npts);
ltab->SetHueRange(0.893,0.021);
ltab->Build();


for (i=0;i<npts,i++)
{
fscanf(fp,"%f%f%f",&coord[0],&coord[1],&coord[2]);
ps->InsertNextPoint(coord);
ca->InsertCellPoint(i);
da->InsertValue(i,i); //i want this to be the color scalar
}

fclose(fp);

ug->Allocate(100,100);
ug->SetPoints(ps);
i=1;
ug->SetCells(&i,ca);



vtkRenderer *rn=vtkRenderer::New();

vtkRenderWindow *win=vtkRenderWindow::New();
win->AddRenderer(rn);

vtkRenderWindowInteractor *intr=vtkRenderWindowInteractor::New();
inter->SetRenderWindow(rn);


vtkSphereSource *cst=vtkSphereSource::New();
cst->SetRadius(0.1);
cst->SetPhiResolution(6);
cst->SetThetaResolution(6);

vtkFloatArray *sz =vtkFloatArray::New();//i want this to be the glyph scaling scalar

sz->InsertValue(0,1.0);
sz->InsertValue(1,2.0);
sz->InsertValue(2,3.0);
sz->InsertValue(3,4.0);
sz->InsertValue(4,5.0);
sz->InsertValue(5,6.0);
sz->InsertValue(6,7.0);
sz->InsertValue(7,8.0);
sz->InsertValue(8,9.0);
sz->InsertValue(9,10.0);


vtkGlyph3D *g3t=vtkGlyph3D::New();
g3t->SetInput(ug);
g3t->SetSource(cst->GetOutput());
//here iam saying the unstructured grid to use sz as the scalar 
//so that glyph3d can use it for scaling
ug->GetPointData()->SetScalars(sz);
g3t->SetScaleModeToScaleByScalar();

vtkPolyDataMapper *g3map=vtkPolyDataMapper::New();

g3map->SetInput(g3t->GetOutput());
g3map->SetLookupTable(ltab);
//here iam saying the unstructured grid to use da as the scalar 
//to get the color
ug->GetPointData()->SetScalars(da);

vtkActor *g3act=vtkActor::New();
g3act->SetMapper(g3map);

rn->AddActor(g3act);

intr->Initialize();
rn->Render();
intr->Start();
}



More information about the vtkusers mailing list