# Rendering multiple solids with only one Actor, yet retaining RGBA and Picking

**URL:** <https://discourse.vtk.org/t/rendering-multiple-solids-with-only-one-actor-yet-retaining-rgba-and-picking/7021>\
**Category:** Support\
**Created:** [October 29, 2021, 5:13pm UTC](https://discourse.vtk.org/t/rendering-multiple-solids-with-only-one-actor-yet-retaining-rgba-and-picking/7021 "2021-10-29T17:13:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Olivier](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/o/d2c977/32.png) [@Olivier](https://discourse.vtk.org/u/Olivier)\
**Post date:** [October 29, 2021, 5:13pm UTC](https://discourse.vtk.org/t/rendering-multiple-solids-with-only-one-actor-yet-retaining-rgba-and-picking/7021/1 "2021-10-29T17:13:58Z")

</div>

Hi dear friends,

I’ve post an issue where I was facing bad overall framerate with a scene containing 500+ actors.

Thanks to many useful answers, I’ve changed my code to create each solid as a vtkPolydata, then merging them thanks to vtkAppendPolyData, and finally display them with a unique Actor.

Overral performance gain is spectacular, but obviously I’m losing several thing :

- Per solid RGBA color.
- Per solid picking.

The picking problem is quite simple to solve by using a vtkCellPicker associated with a lookup table between vtkPolydata’s cells and original solids.

The RGBA problem should have been easy to solve too, but I’m facing an issue :  
To assign a different color to each of the vtkPolydata’s cells, I’m using

```auto
double argb[4] = { R, G, B, A }; //where R...A are in [0..255]
vtkNew<vtkUnsignedCharArray> vtkcolors;
vtkcolors->SetNumberOfComponents(4);
vtkcolors->SetNumberOfTuples(mesh->GetNumberOfCells());
for (int i=0; i<poly->GetNumberOfCells(); i++) vtkcolors->InsertTuple(i, argb);
poly->GetCellData()->SetScalars(vtkcolors);

```

In my scene I have opaque solids and transparent ones.  
Displayed colors are OK, except that the whole Actor becomes transparent as soon as there is at least one transparent solid in the batch.  
I would have expected cell’s transparency being OK according to scalar map …

My question :

- Is it a normal behavior (i.e. an Actor is totally transparent or not)
- Will have I to separate my solids into as many actors as I have Alpha value ?

Thanks !

---

<div class="post-metadata">

**Author:** ![Olivier](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/o/d2c977/32.png) [@Olivier](https://discourse.vtk.org/u/Olivier)\
**Post date:** [October 29, 2021, 6:38pm UTC](https://discourse.vtk.org/t/rendering-multiple-solids-with-only-one-actor-yet-retaining-rgba-and-picking/7021/2 "2021-10-29T18:38:43Z")

</div>

Ok, my bad.  
By using a vtkMultiBlockDataSet + vtkCompositePolyDataMapper, transparency issue has gone.

---

<div class="post-metadata">

**Author:** ![ugis](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ugis/32/6790_2.png) [@ugis](https://discourse.vtk.org/u/ugis)\
**Post date:** [September 12, 2022, 7:57am UTC](https://discourse.vtk.org/t/rendering-multiple-solids-with-only-one-actor-yet-retaining-rgba-and-picking/7021/3 "2022-09-12T07:57:03Z")

</div>

Hi Olivier,

could you explain a bit more how you used vtkMultiBlockDataSet and vtkCompositePolyDataMapper to solve your transparency issue? Did you have to use a separate block for transparent / non-transparent parts?

Best,  
Ugis

---

<div class="post-metadata">

**Author:** ![Olivier](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/o/d2c977/32.png) [@Olivier](https://discourse.vtk.org/u/Olivier)\
**Post date:** [September 12, 2022, 8:13am UTC](https://discourse.vtk.org/t/rendering-multiple-solids-with-only-one-actor-yet-retaining-rgba-and-picking/7021/4 "2022-09-12T08:13:49Z")

</div>

Hi Ugis,

Sorry for late answer …  
Using vtkMultiBlockDataSet is a dead end, because it is a performance trap.

I think I have tested almost all ways to have the same behavior/capabilities as for 1 actor per object, but with good performances with thousands of objects.

My conclusion is that you have to split your objects into several batches, according to a specific criterion (eg. Opacity) and then assign each batch to a specific Actor (after having merged them by any means).  
You will end up with not so many actors, maybe 1-10, holding each many objects.  
Performances will be pretty good, and you will keep having the possibility to customize the display as if you had 1 actor per object (almost).

---

<div class="post-metadata">

**Author:** ![ugis](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ugis/32/6790_2.png) [@ugis](https://discourse.vtk.org/u/ugis)\
**Post date:** [September 12, 2022, 8:18am UTC](https://discourse.vtk.org/t/rendering-multiple-solids-with-only-one-actor-yet-retaining-rgba-and-picking/7021/5 "2022-09-12T08:18:17Z")

</div>

I see, interesting. Then indeed I should not try to merge differently transparent objects into same actor.

Thanks a lot for sharing your experience! This will certainly save me time trying to improve performance at our side.

Best,  
Ugis

---

<div class="post-metadata">

**Author:** ![Olivier](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/o/d2c977/32.png) [@Olivier](https://discourse.vtk.org/u/Olivier)\
**Post date:** [September 12, 2022, 8:22am UTC](https://discourse.vtk.org/t/rendering-multiple-solids-with-only-one-actor-yet-retaining-rgba-and-picking/7021/6 "2022-09-12T08:22:41Z")

</div>

If your only concern is opacity, you can theoretically achieve a good display with only one actor, and mixing opacities.  
For that you’ll have to :

- Use RGBA colors assigned to point data (not cell), or use a custom lookup table
- Set the actor as SetForceTranslucent

---

<div class="post-metadata">

**Author:** ![ugis](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ugis/32/6790_2.png) [@ugis](https://discourse.vtk.org/u/ugis)\
**Post date:** [September 12, 2022, 8:28am UTC](https://discourse.vtk.org/t/rendering-multiple-solids-with-only-one-actor-yet-retaining-rgba-and-picking/7021/7 "2022-09-12T08:28:26Z")

</div>

Cool, I will try that! Thanks.

/Ugis
