1
votes

Simple question, but I've tried a few things and nothing seems to work.

I want to overlay some statistics onto a 3d VTK scene, using 2D vtkTextActors. This works fine, but the text is at times difficult to see, depending on what appears behind it in the 3D scene.

For this reason, I'd like to add a 2d, semi-transparent "box" behind my text actors to provide a darker background.

Which VTK object is appropriate for this? I've tried so far:

  • vtkLegendBoxActor: Not what I want, but I can use this with no text to display a semi-transparent box on screen. I cannot size it directly and I get warnings about not initialising some of the content.
  • vtkImageData: Tried manually creating image data and adding it to the scene; I believe it was placed within the 3d scene and not used as an overlay. If that's not the case then I couldn't get it to show at all.
  • vtkCornerAnnotation: Scales with window size, is fixed to a corner and the background opacity cannot be set AFAIK.
  • vtkTextActor: Cannot set a background color or opacity

Can anyone tell me how they might achieve what I'm after in VTK?

2

2 Answers

1
votes

I've found a way to do this with vtkPolyMapper2D which seems to work okay. It seems to be a very stupid way to do this. If there is something more elegant, I'm all ears.

import vtk
extents = [[0,0],[620,0],[620,220],[0,220]]

polyPoints = vtk.vtkPoints()

for x, y in extents:
    polyPoints.InsertNextPoint(x, y, 0)

num_corners = len(extents)
polyCells = vtk.vtkCellArray()
polyCells.InsertNextCell(num_corners + 1)

for i in range(0, num_corners):
    polyCells.InsertCellPoint(i)

polyCells.InsertCellPoint(0) ## Rejoin at the end

poly_profile = vtk.vtkPolyData()
poly_profile.SetPoints(polyPoints)
poly_profile.SetPolys(polyCells) ## Goes solid

cut_triangles = vtk.vtkTriangleFilter()
cut_triangles.SetInput(poly_profile)

_poly_mapper = vtk.vtkPolyDataMapper2D()
_poly_mapper.SetInput(poly_profile)
_poly_mapper.SetInputConnection(cut_triangles.GetOutputPort())

_actor = vtk.vtkActor2D()
_actor.SetMapper(_poly_mapper)
_actor.GetProperty().SetColor([0.1,0.1,0.1])
_actor.GetProperty().SetOpacity(0.5)
#Add to renderer as normal  
0
votes

just use vtktexture, vtkimagedata & add your own image as texture background to the vtkrenderer by reducing the opacity like a watermark. thats it