VTK OrientationMarker 方向 三维坐标系 相机坐标轴 自定义坐标轴

news2024/10/3 21:29:26

本文 以 Python 语言开发

我们在做三维软件开发时,经常会用到相机坐标轴,来指示当前空间位置;

坐标轴效果:

相机方向坐标轴

 Cube 正方体坐标轴

 自定义坐标轴:

Code:

Axes
def main():
    colors = vtkNamedColors()

    # create a Sphere
    sphereSource = vtkSphereSource()
    sphereSource.SetCenter(0.0, 0.0, 0.0)
    sphereSource.SetRadius(0.5)

    # create a mapper
    sphereMapper = vtkPolyDataMapper()
    sphereMapper.SetInputConnection(sphereSource.GetOutputPort())

    # create an actor
    sphereActor = vtkActor()
    sphereActor.SetMapper(sphereMapper)

    # a renderer and render window
    renderer = vtkRenderer()
    renderWindow = vtkRenderWindow()
    renderWindow.SetWindowName('Axes')
    renderWindow.AddRenderer(renderer)

    # an interactor
    renderWindowInteractor = vtkRenderWindowInteractor()
    renderWindowInteractor.SetRenderWindow(renderWindow)

    # add the actors to the scene
    renderer.AddActor(sphereActor)
    renderer.SetBackground(colors.GetColor3d('SlateGray'))

    transform = vtkTransform()
    transform.Translate(1.0, 0.0, 0.0)

    axes = vtkAxesActor()
    #  The axes are positioned with a user transform
    axes.SetUserTransform(transform)

    # properties of the axes labels can be set as follows
    # this sets the x axis label to red
    axes.GetXAxisCaptionActor2D().GetCaptionTextProperty().SetColor(colors.GetColor3d('Red'));

    # the actual text of the axis label can be changed:
    axes.SetXAxisLabelText('test')
    renderer.AddActor(axes)
    renderer.GetActiveCamera().Azimuth(50)
    renderer.GetActiveCamera().Elevation(-30)

    renderer.ResetCamera()
    renderWindow.SetWindowName('Axes')
    renderWindow.Render()

    # begin mouse interaction
    renderWindowInteractor.Start()


if __name__ == '__main__':
    main()
CameraOrientationWidget
def main():
    colors = vtkNamedColors()

    renderer = vtkRenderer()
    ren_win = vtkRenderWindow()
    interactor = vtkRenderWindowInteractor()

    sphere_source = vtkSphereSource()
    sphere_source.SetRadius(10.0)

    mapper = vtkPolyDataMapper()
    mapper.SetInputConnection(sphere_source.GetOutputPort())

    actor = vtkActor()
    actor.GetProperty().SetColor(colors.GetColor3d('Beige'))
    actor.SetMapper(mapper)

    renderer.AddActor(actor)
    renderer.SetBackground(colors.GetColor3d('DimGray'))

    ren_win.AddRenderer(renderer)
    ren_win.SetSize(600, 600)
    ren_win.SetWindowName('CameraOrientationWidget')

    # Important: The interactor must be set prior to enabling the widget.
    interactor.SetRenderWindow(ren_win)

    cam_orient_manipulator = vtkCameraOrientationWidget()
    cam_orient_manipulator.SetParentRenderer(renderer)
    # Enable the widget.
    cam_orient_manipulator.On()

    ren_win.Render()
    interactor.Initialize()
    interactor.Start()


if __name__ == "__main__":
    main()
OrientationMarkerWidget
   colors = vtkNamedColors()
    # create a rendering window and renderer
    ren = vtkRenderer()
    ren_win = vtkRenderWindow()
    ren_win.AddRenderer(ren)
    ren_win.SetWindowName('OrientationMarkerWidget')

    # create a renderwindowinteractor
    iren = vtkRenderWindowInteractor()
    iren.SetRenderWindow(ren_win)

    cube = vtkCubeSource()
    cube.SetXLength(200)
    cube.SetYLength(200)
    cube.SetZLength(200)
    cube.Update()
    cm = vtkPolyDataMapper()
    cm.SetInputConnection(cube.GetOutputPort())
    ca = vtkActor()
    ca.SetMapper(cm)
    ca.GetProperty().SetColor(colors.GetColor3d("BurlyWood"))
    ca.GetProperty().EdgeVisibilityOn()
    ca.GetProperty().SetEdgeColor(colors.GetColor3d("Red"))

    # assign actor to the renderer
    ren.AddActor(ca)
    ren.SetBackground(colors.GetColor3d('CornflowerBlue'))

    axes_actor = vtkAnnotatedCubeActor()
    axes_actor.SetXPlusFaceText('L')
    axes_actor.SetXMinusFaceText('R')
    axes_actor.SetYMinusFaceText('I')
    axes_actor.SetYPlusFaceText('S')
    axes_actor.SetZMinusFaceText('P')
    axes_actor.SetZPlusFaceText('A')
    axes_actor.GetTextEdgesProperty().SetColor(colors.GetColor3d("Yellow"))
    axes_actor.GetTextEdgesProperty().SetLineWidth(2)
    axes_actor.GetCubeProperty().SetColor(colors.GetColor3d("Blue"))
    axes = vtkOrientationMarkerWidget()
    axes.SetOrientationMarker(axes_actor)
    axes.SetInteractor(iren)
    axes.EnabledOn()
    axes.InteractiveOn()
    ren.ResetCamera()

    # enable user interface interactor
    iren.Initialize()
    ren_win.Render()
    ren.GetActiveCamera().Azimuth(45)
    ren.GetActiveCamera().Elevation(30)
    ren_win.Render()
    iren.Start()
custom OrientationMarker
    colors = vtkNamedColors()

    reader = vtkXMLPolyDataReader()
    reader.SetFileName("./Human.vtp")

    icon_mapper = vtkDataSetMapper()
    icon_mapper.SetInputConnection(reader.GetOutputPort())

    icon_actor = vtkActor()
    icon_actor.SetMapper(icon_mapper)
    icon_actor.GetProperty().SetColor(colors.GetColor3d('Silver'))

    # Set up the renderer, window, and interactor
    renderer = vtkRenderer()
    renderer.SetBackground(colors.GetColor3d('SlateGray'))

    ren_win = vtkRenderWindow()
    ren_win.AddRenderer(renderer)
    ren_win.SetSize(400, 400)
    ren_win.SetWindowName('OrientationMarkerWidget1')

    iren = vtkRenderWindowInteractor()
    iren.SetRenderWindow(ren_win)

    rgb = [0.0, 0.0, 0.0]
    colors.GetColorRGB('Wheat', rgb)
    # Set up the widget
    widget = vtkOrientationMarkerWidget()
    widget.SetOrientationMarker(icon_actor)
    widget.SetInteractor(iren)
    widget.SetViewport(0.0, 0.0, 0.3, 0.3)
    widget.SetOutlineColor(*rgb)
    widget.SetEnabled(1)
    widget.InteractiveOn()

    # Create a superquadric
    superquadric_source = vtkSuperquadricSource()
    superquadric_source.SetPhiRoundness(.001)
    superquadric_source.SetThetaRoundness(.04)

    # Create a mapper and actor
    superquadric_mapper = vtkPolyDataMapper()
    superquadric_mapper.SetInputConnection(superquadric_source.GetOutputPort())

    superquadric_actor = vtkActor()
    superquadric_actor.SetMapper(superquadric_mapper)
    superquadric_actor.GetProperty().SetInterpolationToFlat()
    superquadric_actor.GetProperty().SetDiffuseColor(colors.GetColor3d('Carrot'))
    superquadric_actor.GetProperty().SetSpecularColor(colors.GetColor3d('White'))
    superquadric_actor.GetProperty().SetDiffuse(0.6)
    superquadric_actor.GetProperty().SetSpecular(0.5)
    superquadric_actor.GetProperty().SetSpecularPower(5.0)

    renderer.AddActor(superquadric_actor)
    renderer.ResetCamera()

    ren_win.Render()

    iren.Initialize()

    iren.Start()

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1140871.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

以太网通讯与485通讯哪个好?

随着工业自动化、物联网和信息技术的快速发展,数据传输成为了各个领域越来越关注的问题。在众多通讯技术中,以太网通讯和485通讯被广泛应用于各种场景。那么,这两种通讯技术究竟哪个更好呢?接下来,小编就来为大家一一讲…

使用Terraform管理已经存在的kubernates和默认的节点池

背景: 通过terraform resource "alicloud_cs_managed_kubernetes" "k8s" {...}创建集群时,会产生一个默认的节点池default-nodepool,但是如何去修改这个默认节点池的信息呢? 解决思路: 因为Ter…

LLM系列-大模型技术汇总

LLM系列-大模型技术汇总 1. 大模型技术汇总-参数高效迁移学习方法2. 千亿模型并行训练技术2.1. 数据并行(Data Parallelism,DP)2.2. 模型并行(Model Parallelism,MP)2.2.1. 流水线并行(Pipeline…

Ubuntu16.04 python matplotlib 输出轴标签出现中文乱码

问题:坐标轴打印中文时,显示会乱码 import matplotlib.pyplot as plt plt.ylabel(时间刻度)原因:matplotlib里面没有中文字体解决方法:下载SimHei字体,快捷方法是使用everything直接在windows搜索simhei.ttf&#xff…

【0230】PG内核底层事务(transaction)实现原理之基础篇

1. 事务上层 事务是如何工作? 接下来让我们通过gdb方式来跟踪一下PG内核中事务的底层工作原理。 (1)psql登录PG服务(2)psql登录界面输入:begin(3)gdb跟踪backend进程读取用户的输入,并进入exec_simple_query()函数函数exec_simple_query()的实现如下: static void …

JAVA实现学生日常行为评分管理系统 开源项目

目录 一、摘要1.1 项目介绍1.2 项目录屏 二、系统设计2.1 功能模块设计2.2.1 登录注册模块2.2.2 用户管理模块2.2.3 评分项目模块2.2.4 评分数据模块2.2.5 数据字典模块 2.3 可行性设计2.4 用例设计2.5 数据库设计2.5.1 整体 E-R 图2.5.2 用户2.5.3 评分项目2.5.4 评分数据2.5.…

PyTorch入门教学——torchvision中数据集的使用

1、torchvision.datasets datasets是torchvision工具集中的一个工具。可以理解为调用官方数据集的一种方式,其中有很多开源的数据集,可供我们学习使用。datasets官网:Datasets — Torchvision 0.16 documentation (pytorch.org) 2、使用 …

【漏洞复现】用友OA用户信息泄露

漏洞描述 通过该接口可下载oa用户信息文件 免责声明 技术文章仅供参考,任何个人和组织使用网络应当遵守宪法法律,遵守公共秩序,尊重社会公德,不得利用网络从事危害国家安全、荣誉和利益,未经授权请勿利用文章中的技…

链游风暴再起?MBOX即将再度起飞

近期链游再次进入了我们的视野,Play To Earn在21年大放异彩之后经过了2年沉寂近期终于有了再度爆发的征兆,不管是前段时间爆拉7倍的YGG,还是近期一路高歌猛进的MC都已经吹响了链游板块即将冲锋的信号,那么近期还有哪些值得关注的链…

element form中input使用@keyup.enter.native回车页面刷新问题

当form中只有一个文本框的时候,使用keyup.enter.native会自动触发form的submit提交事件 地址栏会多出来一个? 解决方案: 在form中添加 submit.native.prevent ,阻止form提交默认事件

什么c++流行造轮子而不是调包侠?

什么c流行造轮子而不是调包侠? 因为在c(和c)中,你造的轮子是真的可以跟官方的轮子拼性能的,只要你的算法足够优秀,实现足够小心。 最近很多小伙伴找我,说想要一些c资料,然后我根据自…

大语言模型(LLM)综述(四):如何适应预训练后的大语言模型

A Survey of Large Language Models 前言5. ADAPTATION OF LLMS5.1 指导调优5.1.1 格式化实例构建5.1.2 指导调优策略5.1.3 指导调优的效果5.1.4 指导调优的实证分析 5.2 对齐调优5.2.1 Alignment的背景和标准5.2.2 收集人类反馈5.2.3 根据人类反馈进行强化学习5.2.4 无需 RLHF…

禅道项目管理系统 - 导出、导入zentao数据库

1. 导出zentao数据库 导出 - 保存(输出) - SQL(格式) 已导出zentao.sql 2. 导入zentao数据库 数据库zentao - 导入 选择sql文件 - 执行 导入成功

FindMy技术智能防丢物品

随着科技的进步,人们越来越关注物品的追踪技术。苹果公司在早先发布的AirTag让人们对于物品追踪技术有了新的认识。作为一项基于蓝牙的追踪技术,苹果的Find My功能不仅能够追踪苹果设备,还可以与第三方设备合作,打造一个更加完善的…

世微 宽电压降压 DC-DC 电源管理芯片 以太网平衡车工业控制电源驱动12V6A AP8854

1,产品描述 AP8854 一款宽电压范围降压型 DC-D 电源管理芯片,内部集成使能开关控制、基 准电源、误差放大器、过热保护、限流保 护、短路保护等功能,非常适合宽电压输 入降压使用。 AP8854 带使能控制,可以大大节省外 围器件&…

机器学习实验七:决策树-基于信贷数据集,使用sklearn中相关库实现决策树的构造

决策树-基于信贷数据集,使用sklearn中相关库实现决策树的构造 如下图数据集,住房 (1表示拥有住房,0表示没有住房) ;婚姻 (0表示单身1表示已婚,2表示离异) ;年收入一栏中单位为1000元; (拖欠贷款一栏0表示不拖欠,1表示…

将CSDN或Confluence文章转为微信公众号格式

最近在更公众号文章,苦于排版和格式,就找了一个比较方便的方法,简单易用,排版也不错。 文章提取 有的文章是已经发布在其它平台了,比如CSDN或Confluence,可以使用飞书剪存方便的将文章提取出来&#xff0…

JavaScript在IE和标准浏览器下的兼容性处理

目录 ​编辑 前言 1. 事件对象的获取 2. 获取浏览器窗口的宽度和高度 3. 获取事件的目标元素 4. 阻止事件的默认行为 5. 阻止事件冒泡 6. 设置和获取元素的属性 7. 类名的操作 8. AJAX的兼容性处理 9. DOM元素的操作 10. 样式的获取和设置 总结 前言 在Web开发中…

VSCode安装使用(含插件保姆级教程)

前言 工欲善其事,必先利其器 对于我们每一位软件工程师来说,都要有自己顺手的 IDE 开发工具,它就是我们的武器。 一个好用的 IDE 不仅能提升我们的开发效率,还能让我们保持愉悦的心情,这样才是非常 Nice 的状态 &…

喜讯 | 同立海源CGT核心原料CD28单抗完成FDA DMF备案

喜 讯 GOOD NEWS 近日,北京同立海源生物科技有限公司(简称“同立海源”)的CGT核心原料CD28单抗成功获得美国FDA DMF备案,DMF备案号:038820。 您的细胞治疗研究项目在进行临床申请或新药注册的文件中可直接引用DMF备…