How to draw 10000+ object?

Of course, using 2 actors will prevent you from using the “opacity trick” to hide entities.
You’ll have to deal with it in a totally different way …
Display many entities with VTK keeping decent performances is quite a long journey …

You can make some parts of an actor opauqe and other parts transparent by specifying RGBA color+opacity for points or cells (either directly or via a lookup table).

If you need to change properties that are uniform for the entire actor in current VTK actors/mappers then you can add some custom shaders for those - most likely just a few lines of code (but you need to learn about GLSL and the VTK shaders to be able to write those few lines).

VTK is not the best solution for all kinds of rendering needs, but it is actually quite capable of dealing with large visualization problems.

Yes Andras, you are right, but all that stuff is a matter of “time to spend”.

Of course you can develop your own Actor / Mapper / Shader / … but this cannot be done without a profound and clear understanding of VTK “arcanes” and “ways” to drive the graphic subsystem.
And this can be a real time sink.

On the other hand, you can search for the easiest way to deal with “standard” VTK behaviors, and find some tricks to make things append the way you want.

Obviously, VTK has been tailored to deal with a few number (order of magnitude 10) of complex geometries.
I’m repeating myself, but displaying a huge number (1k, 10k, 100k …) of simple geometries, each having its own behavior as far as color/picking/visibility/… and achieving good perfs (30 fps +) at the same time, is rather tricky.

You can make some parts of an actor opauqe and other parts transparent by specifying RGBA color+opacity for points or cells (either directly or via a lookup table).

All my tests leads to the impossibility to do that.
I you use point/cell data as RGBA & mix alpha values, as soon as at least one value has A < 1, then all the cell are drawn more or less transparent.

Please Andras, do you have a working POC of that ?

In 3D Slicer we color polydata using point and cell data and using RGBA textures and it all works well.

Coloring of a quad using textures (and changing the RGBA lookup table to add/remove transparency):

Coloring of a triangle mesh using point data (and changing the RGBA lookup table to add/remove transparency):

If an actor is not fully opaque then it is rendered using a slightly different path, but the parts where you set 1.0 opacity it should still be fully opaque. If this is not what you see on your system then maybe you are not using it right (e.g., have not enabled depth peeling) or it may be a bug in your graphics driver (it is not uncommon to have issues with transparency on Intel Graphics) or in VTK.

1 Like

Very interesting I’ll have do dig further … Thanks Andras.

1 Like

I’m talking under your control Andras :

vtkMapper, when applying colors, chooses between “texture mapping” and “vertex color”.

  • The 1rst mode is applying a whole texture above the entire polydata.
  • The 2nd mode uses graphical subsystem to apply colors (e.g. glColor()).

When the 2nd mode is used, the pipeline must do 2 passes to render opaque, then translucent geometry.
But, here is what you can find in vtkMapper.cxx line 693 :

bool vtkMapper::HasOpaqueGeometry()
{
  // by default we only return true for Opaque or Translucent
  // not both.
  return !this->HasTranslucentPolygonalGeometry();
}

So, except from deriving the vtkMapper class to tweak it, my understanding is that the default vtkMapper cannot render both opaque & translucent geometry when “vertex color” is used.

In your cases, the result is indeed correct because it uses “texture mapping”.
But in my cases, when using a RGBA cell data field to pass colors to the mapper, vtkMapper chooses explicitly “vertex color” (vtkMapper.cxx line 380+), and opacity mixing is thus forbidden.

In rgba the a compoment is opacity, so why you can’t use it? I just overviewed the problem

Hopenit helps

First image with 2 actors, each having several objects with consistant opacity (i.e. the 4 windows are inside their own actor) => display is good

Second image, all objects are inside the same unique actor => bad display

As stated in my previous post, using RGBA inside a Celldata field is perfectly fine, but only if opacity is consistant (opaque or not) inside a given actor.

Are uou sure you set up the A values roght for the sefond picture?

The Polydatas are exactly & strictly the same for both images, the sole and only difference is the actor number.

Maybe researching this function is helpful

Please chexk if this 3 lines don’t have a logix problem

bool is_opaque = (this->Property->GetOpacity() >= 1.0);

// are we using an opaque texture, if any?
is_opaque = is_opaque && (this->Texture == nullptr || this->Texture->IsTranslucent() == 0);

// are we using an opaque scalar array, if any?
is_opaque = is_opaque && (this->Mapper == nullptr || this->Mapper->HasOpaqueGeometry());

There is no logic problem, at the end the Actor asks its Mapper if it is Opaque or not, which leads to the code I’ve linked above, preventing rendering both Opaque & Translucent at the same time within only one Actor.

I would suggest you improve the code and make a pull request if you want to correct that if there is more people that find it as a bug.

@Olivier could you provide a minimal example that reproduces the error? It could be a Python script or a screen capture video using ParaView.

How to draw parts of an actor opaque and other parts transparent by specifying RGBA? Do you have an example to add custom shaders?