news 2026/5/1 11:40:31

HighlightPickedActor 对象的选择

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
HighlightPickedActor 对象的选择

一:主要的知识点

1、说明

本文只是教程内容的一小段,因博客字数限制,故进行拆分。主教程链接:vtk教程——逐行解析官网所有Python示例-CSDN博客

2、知识点纪要

本段代码主要涉及的有①vtkPropPicker选取一个prop对象


二:代码及注释

import vtkmodules.vtkInteractionStyle import vtkmodules.vtkRenderingOpenGL2 from vtkmodules.vtkCommonColor import vtkNamedColors from vtkmodules.vtkRenderingCore import vtkRenderer, vtkActor, vtkPolyDataMapper, vtkRenderWindow, \ vtkRenderWindowInteractor, vtkPropPicker, vtkProperty from vtkmodules.vtkInteractionStyle import vtkInteractorStyleTrackballCamera from vtkmodules.vtkCommonCore import vtkMinimalStandardRandomSequence from vtkmodules.vtkFiltersSources import vtkSphereSource class MouseInteractorHighLightActor(vtkInteractorStyleTrackballCamera): def __init__(self): self.AddObserver("LeftButtonPressEvent", self.leftButtonPressEvent) self.LastPickedActor = None self.LastPickedProperty = vtkProperty() def leftButtonPressEvent(self, obj, event): colors = vtkNamedColors() clickPos = self.GetInteractor().GetEventPosition() """ vtkPropPicker 在屏幕坐标中拾取(Pick)一个 vtkProp 对象 """ picker = vtkPropPicker() picker.Pick(clickPos[0], clickPos[1], 0, self.GetDefaultRenderer()) self.NewPickedActor = picker.GetActor() if self.NewPickedActor: if self.LastPickedActor: self.LastPickedActor.GetProperty().DeepCopy(self.LastPickedProperty) self.LastPickedProperty.DeepCopy(self.NewPickedActor.GetProperty()) self.NewPickedActor.GetProperty().SetColor(colors.GetColor3d('Red')) self.NewPickedActor.GetProperty().SetDiffuse(1.0) self.NewPickedActor.GetProperty().SetSpecular(0.0) self.NewPickedActor.GetProperty().EdgeVisibilityOn() self.LastPickedActor = self.NewPickedActor self.OnLeftButtonDown() def main(): NUMBER_OF_SPHERES = 10 colors = vtkNamedColors() renderer = vtkRenderer() renderer.SetBackground(colors.GetColor3d("SteelBlue")) renwin = vtkRenderWindow() renwin.AddRenderer(renderer) renwin.SetSize(640, 480) renwin.SetWindowName('HighlightPickedActor') interactor = vtkRenderWindowInteractor() interactor.SetRenderWindow(renwin) # 自定义交互 style = MouseInteractorHighLightActor() style.SetDefaultRenderer(renderer) interactor.SetInteractorStyle(style) randomSequence = vtkMinimalStandardRandomSequence() randomSequence.SetSeed(8775070) for i in range(NUMBER_OF_SPHERES): source = vtkSphereSource() x = randomSequence.GetRangeValue(-5.0, 5.0) randomSequence.Next() y = randomSequence.GetRangeValue(-5.0, 5.0) randomSequence.Next() z = randomSequence.GetRangeValue(-5.0, 5.0) randomSequence.Next() radius = randomSequence.GetRangeValue(0.5, 1.0) randomSequence.Next() source.SetRadius(radius) source.SetCenter(x, y, z) source.SetPhiResolution(11) source.SetThetaResolution(21) mapper = vtkPolyDataMapper() mapper.SetInputConnection(source.GetOutputPort()) actor = vtkActor() actor.SetMapper(mapper) r = randomSequence.GetRangeValue(0.4, 1.0) randomSequence.Next() g = randomSequence.GetRangeValue(0.4, 1.0) randomSequence.Next() b = randomSequence.GetRangeValue(0.4, 1.0) randomSequence.Next() actor.GetProperty().SetDiffuseColor(r, g, b) actor.GetProperty().SetDiffuse(.8) actor.GetProperty().SetSpecular(.5) actor.GetProperty().SetSpecularColor(colors.GetColor3d('White')) actor.GetProperty().SetSpecularPower(30.0) renderer.AddActor(actor) interactor.Initialize() renwin.Render() interactor.Start() if __name__ == '__main__': main()
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/5/1 6:55:44

企业级WPS离线部署实战:200台电脑批量安装指南

快速体验 打开 InsCode(快马)平台 https://www.inscode.net输入框内输入如下内容: 创建一个企业级WPS Office批量部署解决方案,包含:1.制作包含所有组件的完整离线安装包 2.开发静默安装脚本(无界面自动安装) 3.局域网分发工具 4.安装进度监…

作者头像 李华
网站建设 2026/5/1 10:40:55

比CHMOD -R 777更高效:智能批量权限管理工具

快速体验 打开 InsCode(快马)平台 https://www.inscode.net输入框内输入如下内容: 开发一个智能的Linux文件权限批量管理工具,替代危险的CHMOD -R 777命令。功能包括:1) 递归分析目录结构 2) 智能识别文件类型 3) 自动应用最小必要权限 4) …

作者头像 李华
网站建设 2026/5/1 10:41:05

AI如何自动化生成DHCP检测工具?

快速体验 打开 InsCode(快马)平台 https://www.inscode.net输入框内输入如下内容: 开发一个DHCP检测工具,能够自动扫描局域网内的DHCP服务器,检测IP地址分配情况,识别IP冲突,并生成可视化报告。要求:1.支…

作者头像 李华
网站建设 2026/5/1 5:52:13

零基础玩转通义千问2.5-0.5B:树莓派AI助手实战

零基础玩转通义千问2.5-0.5B:树莓派AI助手实战 你是否想过,让一台树莓派也能运行大模型?不是“能跑就行”的玩具级体验,而是真正具备代码生成、数学推理、多语言对话、结构化输出能力的轻量级AI助手? 今天&#xff0…

作者头像 李华
网站建设 2026/5/1 8:11:24

小白必看!通义千问2.5轻量版保姆级安装教程

小白必看!通义千问2.5轻量版保姆级安装教程 你是否也想在自己的手机、树莓派甚至老旧笔记本上运行一个真正“全功能”的大模型?不是只能聊聊天的玩具模型,而是能写代码、做数学、输出 JSON、支持多语言的真实生产力工具? 今天&a…

作者头像 李华