2013-07-04 105 views
1

簡單的問題,但我已經嘗試了幾件事情,似乎沒有任何工作。半透明2D VTK文字背景

我想覆蓋一些統計數據到3D VTK場景,使用二維vtkTextActor秒。這工作正常,但有時很難看到文本,具體取決於它在3D場景中顯示的內容。

因此,我想在我的文字演員背後添加一個2d半透明「框」,以提供較暗的背景。

這VTK對象是適當的呢?到目前爲止,我已經試過:

  • vtkLegendBoxActor:不是我想要的,但我可以用這個沒有文字在屏幕上顯示一個半透明的盒子。我無法直接調整它的大小,我收到有關未初始化某些內容的警告。
  • vtkImageData:嘗試手動創建的圖像數據並將其添加到現場;我相信它被放置在3D場景中,而不是用作疊加層。如果情況並非如此,那麼我根本無法展示它。
  • vtkCornerAnnotation:具有窗口大小的比例尺固定到一個角落,背景不透明度不能設置AFAIK。
  • vtkTextActor:不能設置背景顏色或透明度

誰能告訴我怎樣可以實現我在VTK後我?

回答

1

我找到了一種方法來做到這一點vtkPolyMapper2D這似乎工作正常。這似乎是一個非常愚蠢的做法。如果有更優雅的東西,我全是耳朵。

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

只使用vtktexture,vtkimagedata &通過減少像水印的不透明度紋理背景添加自己的形象給vtkrenderer。多數民衆贊成在

+1

你可能包括一個小例子解釋如何去完成這個? – EWit