Scale bars in vtk python

Dear VTK team,

I’m looking for a way to add scale bars to the render window both in python and js. An example picture is attached.


I used vtkLineSource and vtkVectorText but depending on the image size I render this doesn’t work sometimes, so I need some universal solution so that the scale bar line and text always look ok.

Could you please advise something concerning this problem?

Best wishes,
Olga.

I only know of vtkLegendScaleActor, but I guess because of perspective it might be a bit misleading, eg.

from vedo import *
c = Cylinder()
x0,x1,y0,y1,z0,z1 = c.bounds()
r = Ruler([x1+.1,y0,z0], [x1+.1,y1,z0], units='\mum')
show(c, r, axes=13) # 13=vtkLegendScaleActor

Screenshot from 2020-08-29 12-53-10

I would not even allow displaying a ruler if you use perspective projection, but should work well for parallel projection. You can even display it as a 2D actor - see how it is done in C++ here.

…true, it doesn’t make much sense. Indeed it works well in parallel projection

image