[vtkusers] Glyph coloring

Gib Bogle g.bogle at auckland.ac.nz
Thu Nov 25 18:42:48 EST 2010


I've been trying to follow David Gobbi's suggestion about coloring the glyphs 
that I am now using to render my squares with.  The hints he provided were not 
enough for me to get it working, so I hunted around and found the wiki example
http://www.itk.org/Wiki/VTK/Examples/Cxx/Visualization/ColorGlyphs
This works fine, so I thought I could just follow the same path.  It doesn't 
work for me, and I'm guessing that it's because I'm using a vtkPolyData that 
contains both vtkPoints and vtkCellArray.  David advised me to use
input->GetPointData()->AddArray(...)
but I couldn't see how to implement this.  My code is shown below.  What am I 
missing?  (This code doesn't display the squares at all, unless I comment out 
input->GetPointData()->SetScalars(colors).)
I apologize for the ignorance I'm displaying - I don't understand why it's 
necessary to use the vtkCellArray, for example.

points = vtkSmartPointer<vtkPoints>::New();
vtkSmartPointer<vtkCellArray> dummycells = vtkSmartPointer<vtkCellArray>::New();
points->SetNumberOfPoints(npos);   // number of squares
dummycells->InsertNextCell(npos);
colors = vtkSmartPointer<vtkUnsignedCharArray>::New();
colors->SetName("colors");
colors->SetNumberOfComponents(3);
unsigned char g[3] = {0,255,0};
for (int ipos=0; ipos<npos; ipos++) {
     points->SetPoint(ipos, x, y, z);
     dummycells->InsertCellPoint(ipos);
     colors->InsertNextTupleValue(g);
}
input = vtkSmartPointer<vtkPolyData>::New();
input->SetPoints(points);
input->SetVerts(dummycells);
input->GetPointData()->SetScalars(colors);
glypher = vtkSmartPointer<vtkGlyph3D>::New();
glypher->SetInput(input);
glypher->SetSource(polygonPolyData);
glypher->SetScaleFactor(1.0);
glypher->SetColorModeToColorByScalar();
// glypher->SetInputArrayToProcess(3, 0, 0, 0, "colors");
glypher->Update();
squareMapper = vtkPolyDataMapper::New();
squareMapper->SetInputConnection(glypher->GetOutputPort());
glactor = vtkActor::New();
glactor->SetMapper(squareMapper);
glactor->GetProperty()->SetAmbient(0.5);
glactor->GetProperty()->SetDiffuse(0.2);
glactor->GetProperty()->SetSpecular(0.5);
ren->AddActor(glactor);



More information about the vtkusers mailing list