Changing Color on Glyphs with Scalar Array

Hi,

I am currently creating multiple cubes with vtkGlyph3D to ensure a good performance.
As i am doing this in VR multiple Actors are not possible. But now i want to color them independently. As they are one Actor i can’t do it by setting a color for the actor. Thats why i have to color them by setting scalars. But to highlight a certain cube i would need to color additionaly its edges or make a hatching pattern over the color, or even set a texture.

The creation and coloring works like this:

Generating multiple Cubes:

vtkSmartPointer cubeSource = vtkSmartPointer::New();

Adding them to the Glyph:

vtkSmartPointer glyph3D = vtkSmartPointer::New();
glyph3D->GeneratePointIdsOn();
glyph3D->SetSourceConnection(cubeSource->GetOutputPort());
glyph3D->SetInputData(m_cubePolyData);
glyph3D->SetColorModeToColorByScalar();
glyph3D->SetScaleModeToDataScalingOff();
glyph3D->Update();

Create a mapper and actor:

vtkSmartPointer glyphMapper = vtkSmartPointer::New();
glyphMapper->SetInputConnection(glyph3D->GetOutputPort());
m_actor->SetMapper(glyphMapper);
Now i color them:
currentColorArr = vtkSmartPointer::New();
currentColorArr->SetName(“colors”);
currentColorArr->SetNumberOfComponents(4);
currentColorArr->InsertNextTuple4(r,g,b,a); // Loop over all cubes to color

BUT how do i now set a edge coloring or some technique to highlight a selected cube?

I am glad about every help / idea!

1 Like

In 3D Slicer, we solved this by creating a second actor that contains all the “active” glyphs. When the user grabs an object with a controller then we remove it from the normal glyphs actor and add it to the active glyphs actor.

2 Likes

Thanks @lassoan, one question, when you say remove here, you mean changing the scalar array associated to that point to opacity 0? Or something else?

In Slicer, we store the list of control points in a different object (MRML node), so when a glyph becomes active then we simply remove the corresponding point from vtkPoints object of the “Unselected” actor and add it to the vtkPoints of the “Active” actor. But using a masking/selection/thresholding filter or changing opacity could be a good solution, too, especially if you don’t maintain a separate point list in another object.

1 Like