[vtkusers] Glyphing vtkImageData scalars (3D) as arrows

David Doria daviddoria at gmail.com
Tue Oct 5 11:55:36 EDT 2010


I have an image with 3d scalars:

  // Create an image
  vtkSmartPointer<vtkImageData> image1 =
    vtkSmartPointer<vtkImageData>::New();
  image1->SetExtent(0, 1, 0, 1, 0, 0);
  image1->SetNumberOfScalarComponents(3);
  image1->SetScalarTypeToFloat();

  int coord[3]; float* pixel;

  // Fill the image with vectors
  coord[0] = 0; coord[1] = 0; coord[2] = 0;
  pixel = static_cast<float*>(image1->GetScalarPointer(coord));
  pixel[0] = 1.0; pixel[1] = 0.0; pixel[2] = 0.0;

... fill the rest of the image


Now I want to glyph arrows to show the vectors:

I tried this:

  vtkSmartPointer<vtkArrowSource> arrowSource =
    vtkSmartPointer<vtkArrowSource>::New();

  vtkSmartPointer<vtkGlyph3DMapper> glyph3Dmapper1 =
    vtkSmartPointer<vtkGlyph3DMapper>::New();
  glyph3Dmapper1->SetSourceConnection(arrowSource->GetOutputPort());
  glyph3Dmapper1->SetInputConnection(image1->GetProducerPort());
  glyph3Dmapper1->Update();

  vtkSmartPointer<vtkActor> actor1 =
    vtkSmartPointer<vtkActor>::New();
  actor1->SetMapper(glyph3Dmapper1);

but it colors the arrows rather than orients them. It looks like
vtkGlyph3DMapper wants to use the Vectors attribute to orient the
glyphs, but my ImageData doesn't have a Vectors since everything is in
the Scalars (but they are not scalars, because they are 3d).

So I guess two things would solve it:
1) How do you set the vectors of an imageData to be its scalars?
2) How could I tell vtkGlyph3DMapper to orient the arrows by the image scalars?

Thanks,

David



More information about the vtkusers mailing list