Rendering a scene with cubes > 5000 ?

I’m new to VTK and I’m trying to render a scene with a bunch of stacked cubes. My initial approach was to add a cubesource with a corresponding actor and add to the renderer, Unfortunately this approach does not scale well and I have found out that the amount of cubes I have to render are upwards of 5000. I tried to use a a Glyph3D but I also need the cubes to have different colors and cannot seem to achieve that. IS there a better solution to this problem ? I also need to all the cubes to have a label on their “X” faces.

Can you anybody suggest a solution and possibly a pseudo code snippet ? Any help/suggestion will be greatly appreciated !

Thanks,
Ujjwala

You can specify the color in a point data array and glyph filters use that to color the output. There should be at least a few examples and tests for it in the VTK repository and in VTK examples.

Thank you so much Andras !

I was wondering if you could also give me a hint to how to label the “X+” faces of each individual cube ? I saw that for me to use VtkTextMapper, I need to create a corresponding vtkTextactor. I’m afraid that will not scale well.

I have also seen that instead of vtk3DGlyph I can use vtkUnstructuredGrid with vtkHexahedrons. But with either approach I cannot seem to figure out how to label each cube/hexahedron with different labels.

Any ideas/suggestions will be greatly appreciated ! Thanks again for your response !

Thanks,
Ujjwala

Ujjwala, if you’re working with python, this tutorial might be of your interest:

https://fury.gl/latest/auto_tutorials/01_introductory/viz_selection.html#sphx-glr-auto-tutorials-01-introductory-viz-selection-py

Adding 3 vtkTextActors per cube would not scale well at all - it would be really slow for more than 100 or so cubes.

You can construct a glyph source (3D polydata) by appending the cube and labels. You can render the labels into a polydata polydata slightly away from the cube sides using vtkTextSource and make sure there is some contrast between the cube and the text by using different colors (see https://kitware.github.io/vtk-examples/site/Cxx/Remote/FrenetSerretFrame/) or enabling screen-space ambient occlusion (SSAO, which could add shadow between the text and the cube if the scale is set right; it would also make the rendering more photorealistic).

Thanks so much @lassoan ! I will give this a try for sure. I also saw examples of using a lookup table and setting annotations in LUT using cell attributes ( c++ - How to visualize cell attributes as labels - Stack Overflow) which is what I’m trying right now. Thanks again for your response ! I truly appreciate it.