[vtkusers] Re: vtkGlyph - how to apply color

Roger Blum roger_blum at swissonline.ch
Wed Nov 8 16:10:02 EST 2006


Hello Barbara,

I had the same problem a couple of months ago. I can explain my solution 
with Tcl which should be easy to translate to C++

With vtkGlyph3D you can have different glyphs and different colors, 
orientations and scales for each glyph. This is how it works for me:

  # Create points and polydata
  vtkPoints P
  vtkPolyData PolyD
  PolyD SetPoints P
  # Get point data from poly data object
  set PD [PolyD GetPointData]

  # For every transformation you need the corresponding data in a data 
array.
  # Scalar data for glyph  types
  vtkIntArray IA1
  IA1 SetName "types"
  # Scalar data for colors
  vtkIntArray IA2
  IA2 SetName "colors"
  # Vector data for directions
  vtkFloatArray FA1
  FA1 SetName "directions"
  FA1 SetNumberOfComponents 3

  # Add the data arrays to the point data
  PD SetScalars IA1
  PD AddArray IA2
  PD SetVectors FA1
  PD CopyAllOn

  # For every glyph (point of your data) add the corresponding data
  P InsertNextPoint $x $y $z
  IA1 InsertNextValue $type
  IA2 InsertNextValue $color
  FA1 InsertNextTupel3 $dx $dy $dz

  # Create and configure the glyph filter
  vtkGlyph3D G3D
  G3D SetInput PolyD
  # different glyph types
  G3D SetSource $i $glyph_i; # For all glyph types (i = 0..n)
  G3D SetIndexModeToScalar
  G3D SetRange 0 n
  G3D SetInputArrayToProcess 0 0 0 0 "types"
  # Different colors
  G3D SetColorModeToColorByScalar
  G3D SetInputArrayToProcess 3 0 0 0 "colors"
  # Different directions
  G3D OrientOn
  G3D SetInputArrayToProcess 1 0 0 0 "directions"

  # To color the glyphs we need a lookup table
  vtkLookupTable LUT
  ...

  # Create and configure the mapper
  vtkPolyDataMapper PDM
  PDM SetInput [G3D GetOutput]
  PDM SetLookupTable LUT
  PDM SetColorModeToMapScalars
  PDM ScalarVisibilityOn
  PDM SelectColorArray "colors"
  PDM SetScalarRange 0 $maxColor
  PDM SetScalarModeToUsePointData

  # Create the actor
  vtkActor A
  A SetMapper PDM

HTH,
Roger

"Barbara Okupna" <barbaraokupna at yahoo.com> schrieb im Newsbeitrag 
news:20061105015037.784.qmail at web54702.mail.yahoo.com...
I create a sphere, and then pass the sphere to the glyph object as a source,
the Input of the Glyph is array of x,y, z coordinates for the sphere.

How would I apply color to the sphere.
Sphere at each location (x,y,z) has different color.

points = vtkPoints::New();
for(int i=0;i<1097;i++)
{
double x1 = map[i].x;
double y1 = map[i].y;
points->InsertPoint(i,x1,y1,0);

double color = map[i].col;   -   How would I specify the color of sphere at 
x,y,z point

}
data = vtkPolyData::New();
data->SetPoints(points);

sphere = vtkSphereSource::New();

sphereGlyph = vtkGlyph3D::New();
sphereGlyph->SetInput(data);
sphereGlyph->SetSource(sphere->GetOutput());

Thank you,


Check out the New Yahoo! Mail - Fire up a more powerful email and get things 
done faster.



_______________________________________________
This is the private VTK discussion list.
Please keep messages on-topic. Check the FAQ at: 
http://www.vtk.org/Wiki/VTK_FAQ
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers 






More information about the vtkusers mailing list