# Rendering a scene with cubes \> 5000 ?

**URL:** https://discourse.vtk.org/t/rendering-a-scene-with-cubes-5000/8992
**Category:** Support
**Created:** [July 22, 2022, 12:01am UTC](https://discourse.vtk.org/t/rendering-a-scene-with-cubes-5000/8992 "2022-07-22T00:01:57Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![ujjwala](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/u/7feea3/32.png) [@ujjwala](https://discourse.vtk.org/u/ujjwala)
#### Post date: [July 22, 2022, 12:01am UTC](https://discourse.vtk.org/t/rendering-a-scene-with-cubes-5000/8992/1 "2022-07-22T00:01:57Z")

</div>

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

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [July 23, 2022, 8:34am UTC](https://discourse.vtk.org/t/rendering-a-scene-with-cubes-5000/8992/2 "2022-07-23T08:34:33Z")

</div>

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](https://kitware.github.io/vtk-examples/site/).

---

<div class="post-metadata">

### Author: ![ujjwala](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/u/7feea3/32.png) [@ujjwala](https://discourse.vtk.org/u/ujjwala)
#### Post date: [July 23, 2022, 5:52pm UTC](https://discourse.vtk.org/t/rendering-a-scene-with-cubes-5000/8992/3 "2022-07-23T17:52:45Z")

</div>

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

---

<div class="post-metadata">

### Author: ![guaje](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/g/85f322/32.png) [@guaje](https://discourse.vtk.org/u/guaje)
#### Post date: [July 28, 2022, 6:41pm UTC](https://discourse.vtk.org/t/rendering-a-scene-with-cubes-5000/8992/4 "2022-07-28T18:41:06Z")

</div>

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](https://fury.gl/latest/auto_tutorials/01_introductory/viz_selection.html#sphx-glr-auto-tutorials-01-introductory-viz-selection-py)

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [August 1, 2022, 10:30pm UTC](https://discourse.vtk.org/t/rendering-a-scene-with-cubes-5000/8992/5 "2022-08-01T22:30:14Z")

</div>

> [@ujjwala](#):
>
> I saw that for me to use VtkTextMapper, I need to create a corresponding vtkTextactor. I’m afraid that will not scale well.

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

> [@ujjwala](#):
>
> 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.

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/](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).

---

<div class="post-metadata">

### Author: ![ujjwala](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/u/7feea3/32.png) [@ujjwala](https://discourse.vtk.org/u/ujjwala)
#### Post date: [August 1, 2022, 10:39pm UTC](https://discourse.vtk.org/t/rendering-a-scene-with-cubes-5000/8992/6 "2022-08-01T22:39:55Z")

</div>

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](https://stackoverflow.com/questions/42934716/how-to-visualize-cell-attributes-as-labels)) which is what I’m trying right now. Thanks again for your response ! I truly appreciate it.
