C++版例子:
https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/SelectVisiblePoints/
优点:
缺点
示例用法:
自定义输入资源,左键旋转,右键显示当前可见点。
import vtk
# 自定义动作
class MyInteractor(vtk.vtkInteractorStyleTrackballCamera):
def __init__(self, parent=None):
self.AddObserver("RightButtonPressEvent", self.RightButtonPressEvent)
def SetVisibleFilter(self, vis):
self.VisibleFilter = vis
def RightButtonPressEvent(self, obj, event):
self.VisibleFilter.Update()
print("number of visible points: ", self.VisibleFilter.GetOutput().GetNumberOfPoints())
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputData(self.VisibleFilter.GetOutput())
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetPointSize(2)
actor.GetProperty().SetColor(1, 0, 0)
self.GetDefaultRenderer().AddActor(actor)
self.OnRightButtonDown()
return
def CreateScene(mesh):
renWin = vtk.vtkRenderWindow()
ren = vtk.vtkRenderer()
# 设置背景颜色
ren.GradientBackgroundOn()
ren.SetBackground(0.1, 0.1, 0.1)
ren.SetBackground2(0.8, 0.8, 0.8)
# 设置窗口大小
renWin.SetSize(600, 600)
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
# 添加自定义动作
style = MyInteractor()
style.SetDefaultRenderer(ren)
iren.SetInteractorStyle(style)
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputData(mesh)
actor = vtk.vtkLODActor()
actor.SetMapper(mapper)
ren.AddActor(actor)
visPts = vtk.vtkSelectVisiblePoints()
visPts.SetInputData(mesh)
visPts.SetRenderer(ren)
style.SetVisibleFilter(visPts)
renWin.Render()
iren.Initialize()
iren.Start()
if __name__ == "__main__":
filename = "xxxx.obj"
reader = vtk.vtkOBJReader()
reader.SetFileName(filename)
reader.Update()
mesh = reader.GetOutput()
CreateScene(mesh)
手机扫一扫
移动阅读更方便
你可能感兴趣的文章