news 2026/4/15 13:14:46

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

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
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()
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/3/17 18:20:51

多层板PCB生产流程实例分析:常见缺陷及改善措施

多层板PCB生产全流程实战解析:从缺陷溯源到工艺优化你有没有遇到过这样的情况?一块设计完美的16层服务器主板,在回流焊后突然出现间歇性通信故障。FA(失效分析)拆解发现,问题竟出在第8层一个不起眼的微孔—…

作者头像 李华
网站建设 2026/4/13 3:37:48

通俗解释波形发生器设计中的频率控制

波形发生器设计中的频率控制:从原理到实战你有没有想过,当你按下函数发生器上的“1kHz正弦波”按钮时,它是如何精准地输出一个稳定、干净的信号?背后其实是一套精密的数字控制系统在默默工作。而其中最关键的一环,就是…

作者头像 李华
网站建设 2026/4/14 15:43:29

ResNet18实战:智能相册自动分类系统开发

ResNet18实战:智能相册自动分类系统开发 1. 引言:通用物体识别的现实需求与ResNet-18的价值 在数字影像爆炸式增长的今天,个人和企业用户积累了海量的照片数据。无论是家庭相册、电商商品图库,还是安防监控截图,如何…

作者头像 李华
网站建设 2026/3/27 11:06:03

ResNet18入门指南:零代码实现物体识别WebUI

ResNet18入门指南:零代码实现物体识别WebUI 1. 引言:走进通用图像分类的基石——ResNet18 在计算机视觉领域,图像分类是许多高级任务(如目标检测、图像描述生成)的基础。而 ResNet18 作为深度残差网络家族中最轻量级…

作者头像 李华
网站建设 2026/4/3 8:19:48

ResNet18性能优化:提升吞吐量的关键技术

ResNet18性能优化:提升吞吐量的关键技术 1. 背景与挑战:通用物体识别中的效率瓶颈 在当前AI应用广泛落地的背景下,通用物体识别已成为智能监控、内容审核、辅助驾驶等多个场景的基础能力。其中,ResNet-18作为轻量级深度残差网络…

作者头像 李华
网站建设 2026/4/8 11:32:51

深入理解文件上传下载的原理及实现逻辑(3)

文件上传的是根据 http 协议的规范和定义,完成请求消息体的封装和消息体的解析,然后将二进制内容保存到文件。在上传一个文件时,需要把 form 标签的enctype设置为multipart/form-data,同时method必须为post方法。multipart/form-d…

作者头像 李华