Different colors for different parts of the glyph when using the vtkGlyph3DMapper

Hello,

I want to display each point of my point cloud as a circle with a disk as its edge. And I want the circle and the disk to have different colors. I tried vtkGlyph3DMapper with a vtkRegularPolygonSource and a vtkDiskSource combined by a vtkAppendPolyData. The glyph displayed but it always has a single color. I tried setting scalars to both sources, to the combined polydata but none of these works. Is there a way to make this work? If not, are there other alternatives?

Thanks in advance!

No, this is not currently possible because the glyph mapper can only map scalars from the input dataset’s points.

Instead, you can take a different approach. Do not append. Use the inner polygon as source for one glyph mapper and the disk for another glyph mapper. Connect both mappers to the same input point cloud. Assign the two mappers to two separate actors. Finally, set the color on each actor’s property to whatever you want.

Thanks, this saves me a lot of time. Using separate mappers sounds like a good idea, although it may make picking more complicated but I guess I will have to have a try. Another question is can I assign different colors for the front and back side of the glyph? I need a way to differentiate the front and back but for now they looks the same even when I set the normals.

If your concern is dealing with two different prop IDs in the selection callback, try adding both of those actors as parts of a vtkAssembly and add the assembly into the renderer. Then, in your picker callback, the vtkAbstractPropPicker::GetAssembly() will return the assembly instead of an individual part.

Yes, it is very easy. You can set the backface colors on the actor’s backface property. Use actor->GetBackfaceProperty(). It is also an instance of vtkProperty.

Thank you Jaswant! using an assembly for selection sounds promising.

Regarding the backface property, I tried creating a backface property with a color for the actor. But after adding that, the actor becomes invisible when looking from the back. I tried set BackfaceCullingOff but it does not work. Does the backface property work with vtkGlyph3DMapper?

Yes, that’s definitely a bug. I’ve a fix here - https://gitlab.kitware.com/vtk/vtk/-/merge_requests/11789

Works like a charm, thanks Jaswant!

1 Like