[vtkusers] Adding colors to grid based on grid points

Satheesh Maheswaran smaheswa at gmail.com
Sat Jan 6 14:52:31 EST 2007


Hi,

I am trying to generate a regular 3-D grid.  I would like to be able
to pick a point, say (1,1,1) and change the color of it or even draw
the outside edges of the cube in a different color.
I have managed to do this by actually defining each cube point as a
vtkHexahedron, and then adding individual actors to the scene and
changing their colors etc, however since I would want to update my
scene (3-D grid) in an iterative manner, this would be inefficient and
slow.

Another way, I have managed to do is as follows, but I am unable to
choose a point here and add some color to it, can some one please
point me in the direction of how to go about it ?

I assume here that I want a 3-D grid of 10*10*10 points.

vtkPoints *points = vtkPoints::New();
  for(int i=0;i<10;i++){
  for(int j=0;j<10;j++){
  for(int k=0;k<10;k++){
  points->InsertNextPoint(i,j,k);
  }
  }
  }
  vtkStructuredGrid *sgrid = vtkStructuredGrid::New();
  sgrid->SetDimensions(10,10,10);
  sgrid->SetPoints(points);

  vtkCellDataToPointData *Cell2Point = vtkCellDataToPointData::New();
  Cell2Point->SetInput(sgrid);
  Cell2Point->PassCellDataOn();

  vtkDataSetMapper *mapper = vtkDataSetMapper::New();
  mapper->SetInput(Cell2Point->GetStructuredGridOutput());

  vtkActor *actor = vtkActor::New();
  actor->SetMapper(mapper);

  vtkRenderer *renderer = vtkRenderer::New();
  vtkRenderWindow *renWin = vtkRenderWindow::New();
  renWin->AddRenderer(renderer);

Thanks,

-- 
Satheesh



More information about the vtkusers mailing list