1 Star 0 Fork 2

chenyp401/CAM

forked from zzthfut/CAM 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
VtkAdaptor.py 2.30 KB
一键复制 编辑 原始数据 按行查看 历史
zzthfut 提交于 2023-07-23 19:53 . 4-8
import vtk
from Polyline import Polyline
class VtkAdaptor:
def __init__(self, bgClr=(0.95, 0.95, 0.95)):
self.renderer = vtk.vtkRenderer()
self.renderer.SetBackground(bgClr)
self.window = vtk.vtkRenderWindow()
self.window.AddRenderer(self.renderer)
self.window.SetSize(900, 600)
self.interactor = vtk.vtkRenderWindowInteractor()
self.interactor.SetRenderWindow(self.window)
self.interactor.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
self.interactor.Initialize()
def display(self):
self.interactor.Start()
def SetBackgroundColor(self, r, g, b):
return self.renderer.SetBackground(r, g, b)
def drawAxes(self, length=100.0, shaftType=0, cylinderRadius=0.01, coneRadius=0.2):
axes = vtk.vtkAxesActor()
axes.SetTotalLength(length, length, length)
axes.SetShaftType(shaftType)
axes.SetCylinderRadius(cylinderRadius)
axes.SetConeRadius(coneRadius)
axes.SetAxisLabels(0)
self.renderer.AddActor(axes)
return axes
def drawActor(self, actor):
self.renderer.AddActor(actor)
return actor
def drawPdSrc(self, pdSrc):
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(pdSrc.GetOutputPort())
actor = vtk.vtkActor()
actor.SetMapper(mapper)
return self.drawActor(actor)
def drawStlModel(self, stlFilePath):
reader = vtk.vtkSTLReader()
reader.SetFileName(stlFilePath)
return self.drawPdSrc(reader)
def removeActor(self, actor):
self.renderer.removeActor(actor)
def drawPoint(self, point, radius=2.0):
src = vtk.vtkSphereSource()
src.SetCenter(point.x, point.y, point.z)
src.SetRadius(radius)
return self.drawPdSrc(src)
def drawSegment(self, seg):
src = vtk.vtkLineSource()
src.SetPoint1(seg.A.x, seg.A.y, seg.A.z)
src.SetPoint2(seg.B.x, seg.B.y, seg.B.z)
return self.drawPdSrc(src)
def drawPolyline(self, polyline: Polyline):
src = vtk.vtkLineSource()
points = vtk.vtkPoints()
for i in range(polyline.count()):
pt = polyline.point(i)
points.InsertNextPoint((pt.x, pt.y, pt.z))
src.SetPoints(points)
return self.drawPdSrc(src)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/chenyp401/cam.git
git@gitee.com:chenyp401/cam.git
chenyp401
cam
CAM
master

搜索帮助