news 2026/6/15 18:45:55

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/6/15 14:12:51

DisplacementPlot 结构动态可视化

一:主要的知识点 1、说明 本文只是教程内容的一小段,因博客字数限制,故进行拆分。主教程链接:vtk教程——逐行解析官网所有Python示例-CSDN博客 2、知识点纪要 本段代码主要涉及的有①vtkWarpVector 根据向量场对几何体进行形…

作者头像 李华
网站建设 2026/6/6 11:08:46

ExponentialCosine 复杂的二维数学函数映射为3D曲面

一:主要的知识点 1、说明 本文只是教程内容的一小段,因博客字数限制,故进行拆分。主教程链接:vtk教程——逐行解析官网所有Python示例-CSDN博客 2、知识点纪要 本段代码主要涉及的有①vtkWarpScalar根据标量值沿着发现方向进行…

作者头像 李华
网站建设 2026/6/15 14:41:34

HardwareSelector 单元网格面鼠标选择

一:主要的知识点 1、说明 本文只是教程内容的一小段,因博客字数限制,故进行拆分。主教程链接:vtk教程——逐行解析官网所有Python示例-CSDN博客 2、知识点纪要 本段代码主要涉及的有①vtkHardwareSelector网格面的UI交互选择 …

作者头像 李华
网站建设 2026/6/15 13:19:37

ResNet18实战:智能监控系统物体识别部署案例

ResNet18实战:智能监控系统物体识别部署案例 1. 引言:通用物体识别的工程价值与ResNet-18的定位 在智能监控、安防预警、行为分析等实际场景中,通用物体识别是构建视觉感知能力的基础环节。传统方案依赖人工规则或轻量级分类器,…

作者头像 李华
网站建设 2026/6/15 13:18:23

ResNet18优化实战:推理吞吐量提升

ResNet18优化实战:推理吞吐量提升 1. 背景与挑战:通用物体识别中的性能瓶颈 在AI应用落地过程中,模型的稳定性和推理效率是决定用户体验的核心因素。基于TorchVision官方实现的ResNet-18模型因其轻量、稳定、泛化能力强,广泛应用…

作者头像 李华
网站建设 2026/6/15 13:19:45

ResNet18实战教程:工业缺陷检测系统搭建指南

ResNet18实战教程:工业缺陷检测系统搭建指南 1. 引言:从通用识别到工业场景的迁移价值 1.1 通用物体识别为何能用于工业缺陷检测? 在智能制造与自动化质检领域,传统机器视觉依赖规则化图像处理(如边缘检测、模板匹配…

作者头像 李华