news 2026/11/3 2:06:37

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/11/2 3:35:43

ResNet18技术揭秘:为什么它能精准识别1000类物体

ResNet18技术揭秘:为什么它能精准识别1000类物体 1. 引言:通用物体识别中的ResNet-18 在当今人工智能应用中,图像分类是计算机视觉最基础也最关键的一步。从智能相册自动打标签,到自动驾驶系统感知环境,背后都离不开…

作者头像 李华
网站建设 2026/11/2 3:35:43

ResNet18性能对比:CPU与GPU推理速度测试报告

ResNet18性能对比:CPU与GPU推理速度测试报告 1. 背景与测试目标 随着深度学习在通用物体识别领域的广泛应用,ResNet系列模型因其出色的精度与效率平衡,成为工业界和学术界的首选之一。其中,ResNet-18 作为轻量级代表&#xff0c…

作者头像 李华
网站建设 2026/11/1 23:43:39

ResNet18应用实例:零售货架商品识别系统

ResNet18应用实例:零售货架商品识别系统 1. 引言:通用物体识别与ResNet-18的工程价值 在智能零售、自动化巡检和视觉监控等场景中,快速、稳定、低成本的通用物体识别能力是实现智能化升级的关键基础。传统方案依赖云API调用或复杂部署流程&…

作者头像 李华
网站建设 2026/11/2 3:35:16

ResNet18性能优化:CPU推理速度提升5倍的详细步骤

ResNet18性能优化:CPU推理速度提升5倍的详细步骤 1. 背景与挑战:通用物体识别中的效率瓶颈 在边缘计算和本地化部署场景中,深度学习模型的推理效率直接决定了用户体验和系统可用性。尽管ResNet-18作为轻量级图像分类模型被广泛使用&#xf…

作者头像 李华
网站建设 2026/11/2 3:51:31

ResNet18技术详解:深度学习在CV中的应用

ResNet18技术详解:深度学习在CV中的应用 1. 引言:通用物体识别中的ResNet18 在计算机视觉(Computer Vision, CV)领域,图像分类是基础且关键的任务之一。从早期的SIFT特征分类器方法,到如今基于深度神经网…

作者头像 李华
网站建设 2026/11/2 3:50:15

ResNet18部署优化:提升服务稳定性的策略

ResNet18部署优化:提升服务稳定性的策略 1. 背景与挑战:通用物体识别中的稳定性需求 在AI服务落地过程中,模型推理的稳定性往往比精度更直接影响用户体验。尤其是在边缘设备或资源受限环境中,一个“看似准确”的模型若频繁崩溃、…

作者头像 李华