当前位置: 首页 > news >正文

CubeAxesActor 为几何体添加边框和坐标轴

一:主要的知识点

1、说明

本文只是教程内容的一小段,因博客字数限制,故进行拆分。主教程链接:vtk教程——逐行解析官网所有Python示例-CSDN博客

2、知识点纪要

本段代码主要涉及的有①vtkCubeAxesActor立方体坐标轴


二:代码及注释

import vtkmodules.vtkRenderingOpenGL2 import vtkmodules.vtkInteractionStyle from vtkmodules.vtkFiltersSources import vtkSuperquadricSource from vtkmodules.vtkRenderingAnnotation import vtkCubeAxesActor from vtkmodules.vtkCommonColor import vtkNamedColors from vtkmodules.vtkRenderingCore import ( vtkActor, vtkPolyDataMapper, vtkRenderWindow, vtkRenderWindowInteractor, vtkRenderer ) def main(): colors = vtkNamedColors() backgroundColor = colors.GetColor3d("DarkSlateGray") actorColor = colors.GetColor3d("Tomato") axis1Color = colors.GetColor3d("Salmon") axis2Color = colors.GetColor3d("PaleGreen") axis3Color = colors.GetColor3d("LightSkyBlue") superquadricSource = vtkSuperquadricSource() superquadricSource.SetPhiRoundness(3.1) superquadricSource.SetThetaRoundness(1.0) superquadricSource.Update() # needed to GetBounds later renderer = vtkRenderer() mapper = vtkPolyDataMapper() mapper.SetInputConnection(superquadricSource.GetOutputPort()) superquadricActor = vtkActor() superquadricActor.SetMapper(mapper) superquadricActor.GetProperty().SetDiffuseColor(actorColor) superquadricActor.GetProperty().SetDiffuse(.7) superquadricActor.GetProperty().SetSpecular(.7) superquadricActor.GetProperty().SetSpecularPower(50.0) """ vtkCubeAxesActor 在三维场景中绘制立方体坐标轴(带刻度、标签、标题),帮助用户理解模型的空间范围和方向 """ cubeAxesActor = vtkCubeAxesActor() cubeAxesActor.SetUseTextActor3D(1) # 使用3D文本,确保刻度标签使用3D文本 Actor 渲染,以便它们在3D空间中正确旋转和缩放 cubeAxesActor.SetBounds(superquadricSource.GetOutput().GetBounds()) cubeAxesActor.SetCamera(renderer.GetActiveCamera()) # 确保坐标轴始终围绕相机进行调整,即使相机移动,轴线框看起来仍然像是正确的3D边界 cubeAxesActor.GetTitleTextProperty(0).SetColor(axis1Color) cubeAxesActor.GetTitleTextProperty(0).SetFontSize(18) cubeAxesActor.GetLabelTextProperty(0).SetColor(axis1Color) cubeAxesActor.DrawXGridlinesOn() # 刻画刻度线 cubeAxesActor.XAxisMinorTickVisibilityOff() # 禁用X坐标轴上的次要刻度线的显示 cubeAxesActor.GetTitleTextProperty(1).SetColor(axis2Color) cubeAxesActor.GetTitleTextProperty(1).SetFontSize(18) cubeAxesActor.GetLabelTextProperty(1).SetColor(axis2Color) cubeAxesActor.DrawYGridlinesOn() cubeAxesActor.YAxisMinorTickVisibilityOff() cubeAxesActor.GetTitleTextProperty(2).SetColor(axis3Color) cubeAxesActor.GetTitleTextProperty(2).SetFontSize(18) cubeAxesActor.GetLabelTextProperty(2).SetColor(axis3Color) cubeAxesActor.DrawZGridlinesOn() cubeAxesActor.ZAxisMinorTickVisibilityOff() cubeAxesActor.SetGridLineLocation(cubeAxesActor.VTK_GRID_LINES_FURTHEST) # 设置网格线位置,这里是设置网格线位于立方体轴线框最远端 cubeAxesActor.SetFlyModeToStaticEdges() # 稳定边缘,确保坐标轴标签和刻度保持稳定,即使相机移动,轴线也不会“乱飞”或突然切换位置 renderer.AddActor(cubeAxesActor) renderer.AddActor(superquadricActor) renderer.GetActiveCamera().Azimuth(30) renderer.GetActiveCamera().Elevation(30) renderer.ResetCamera() renderer.SetBackground(backgroundColor) renderWindow = vtkRenderWindow() renderWindow.AddRenderer(renderer) renderWindow.SetSize(640, 480) renderWindow.SetWindowName('CubeAxesActor') renderWindowInteractor = vtkRenderWindowInteractor() renderWindowInteractor.SetRenderWindow(renderWindow) renderWindow.Render() renderer.GetActiveCamera().Zoom(0.8) renderWindowInteractor.Start() if __name__ == '__main__': main()
http://www.jsqmd.com/news/232051/

相关文章:

  • MOSFET基本工作原理图解:开关状态转换详解
  • ResNet18代码详解:从模型加载到推理全流程
  • ResNet18实战指南:构建智能农业监测系统
  • ResNet18部署案例:教育场景应用开发指南
  • USB_Burning_Tool批量模式下固件一致性保障方案
  • DisplacementPlot 结构动态可视化
  • ResNet18实战:5分钟搭建高精度图像分类系统
  • ExponentialCosine 复杂的二维数学函数映射为3D曲面
  • STC89C52控制蜂鸣器演奏乐曲完整指南
  • ResNet18实战:教育智能教具识别系统
  • ResNet18优化实战:量化加速推理的完整步骤
  • 通俗解释波形发生器设计中的频率控制
  • ResNet18实战:智能监控系统物体识别部署案例
  • ResNet18实战:构建高稳定性识别服务的关键
  • ResNet18应用解析:智能交通管理系统
  • ResNet18实战教程:服装分类系统开发
  • ResNet18性能测试:CPU环境下的推理速度对比
  • ResNet18应用案例:智能垃圾分类系统
  • 多层板PCB生产流程实例分析:常见缺陷及改善措施
  • ResNet18部署详解:Kubernetes集群部署方案
  • ResNet18入门指南:零代码实现物体识别WebUI
  • ResNet18应用实例:零售货架商品识别系统
  • ResNet18性能测试:批量处理能力评测
  • ResNet18性能优化:CPU推理速度提升5倍的详细步骤
  • ResNet18代码实例:Python调用图像分类API详细教程
  • 无源蜂鸣器驱动电路工作原理深度剖析
  • ResNet18物体识别详解:模型部署常见问题
  • 超详细版:并行计算加速科学仿真的实战案例
  • ResNet18优化教程:早停策略应用
  • ResNet18实战:智能家居物品识别系统