news 2026/4/16 19:46: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/4/16 13:02:17

ResNet18技术解析:ImageNet预训练模型的应用

ResNet18技术解析:ImageNet预训练模型的应用 1. 通用物体识别中的ResNet18:从理论到落地 1.1 深度学习时代的图像分类演进 在计算机视觉的发展历程中,图像分类是最早被深度神经网络攻克的核心任务之一。2012年AlexNet的横空出世标志着卷积…

作者头像 李华
网站建设 2026/4/16 11:16:01

ResNet18实战指南:构建智能农业监测系统

ResNet18实战指南:构建智能农业监测系统 1. 引言:通用物体识别在智能农业中的价值 随着人工智能技术的普及,通用物体识别正成为智能农业系统的核心能力之一。从田间作物生长状态监测、病虫害识别,到农机设备自动巡检、牲畜行为分…

作者头像 李华
网站建设 2026/4/16 15:33:38

ResNet18实战案例:打造稳定物体识别服务

ResNet18实战案例:打造稳定物体识别服务 1. 引言:通用物体识别中的ResNet18价值 在当前AI应用快速落地的背景下,通用物体识别已成为智能监控、内容审核、辅助交互等场景的核心能力。然而,许多开发者面临模型依赖外部API、响应延…

作者头像 李华
网站建设 2026/4/15 15:23:19

嵌入式Linux中ioctl接口的完整指南

嵌入式Linux中ioctl接口的实战解析:从入门到避坑 你有没有遇到过这样的场景?想通过程序设置串口波特率,却发现 write() 函数无能为力;或者要读取一个传感器的状态寄存器,但 read() 只能返回原始数据流。这时候&…

作者头像 李华
网站建设 2026/4/16 12:21:49

三极管开关模式详解:超详细版硬件设计指南

三极管开关设计实战指南:从原理到避坑全解析在嵌入式和电源系统中,你可能已经用过无数个MOSFET、DC-DC芯片甚至智能栅极驱动器。但当你翻开发烧友的电路板或拆开一台老式家电时,总会发现那个熟悉的身影——一个小小的三极管,正默默…

作者头像 李华
网站建设 2026/4/16 11:08:01

ResNet18应用场景:从日用品到自然风景识别

ResNet18应用场景:从日用品到自然风景识别 1. 引言:通用物体识别中的ResNet18价值 在计算机视觉领域,图像分类是基础且关键的任务之一。无论是智能相册自动打标签、电商平台商品识别,还是安防系统中的异常物品检测,背…

作者头像 李华