news 2026/7/14 21:35:55

HighlightWithSilhouette 选择对象进行轮廓线高亮

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
HighlightWithSilhouette 选择对象进行轮廓线高亮

一:主要的知识点

1、说明

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

2、知识点纪要

本段代码主要涉及的有①选择对象并高亮显示


二:代码及注释

import vtkmodules.vtkInteractionStyle import vtkmodules.vtkRenderingOpenGL2 from vtkmodules.vtkCommonColor import vtkNamedColors from vtkmodules.vtkCommonCore import vtkMinimalStandardRandomSequence from vtkmodules.vtkRenderingCore import vtkActor, vtkRenderer, vtkRenderWindow, vtkRenderWindowInteractor, \ vtkPropPicker, vtkPolyDataMapper from vtkmodules.vtkFiltersHybrid import vtkPolyDataSilhouette from vtkmodules.vtkFiltersSources import vtkSphereSource from vtkmodules.vtkInteractionStyle import vtkInteractorStyleTrackballCamera class MouseInteractorHighLightActor(vtkInteractorStyleTrackballCamera): def __init__(self, silhouette=None, silhouetteActor=None): self.AddObserver("LeftButtonPressEvent", self.onLeftButtonDown) self.LastPickedActor = None self.Silhouette = silhouette self.SilhouetteActor = silhouetteActor def onLeftButtonDown(self, obj, event): clickPos = self.GetInteractor().GetEventPosition() picker = vtkPropPicker() picker.Pick(clickPos[0], clickPos[1], 0, self.GetDefaultRenderer()) self.LastPickedActor = picker.GetActor() if self.LastPickedActor: self.GetDefaultRenderer().RemoveActor(self.SilhouetteActor) # 清除渲染器中当前显示的轮廓线 self.Silhouette.SetInputData(self.LastPickedActor.GetMapper().GetInput()) self.GetDefaultRenderer().AddActor(self.SilhouetteActor) self.OnLeftButtonDown() def main(): numberOfSpheres = 10 colors = vtkNamedColors() renderer = vtkRenderer() renderer.SetBackground(colors.GetColor3d('SteelBlue')) renderWindow = vtkRenderWindow() renderWindow.SetSize(640, 480) renderWindow.AddRenderer(renderer) interactor = vtkRenderWindowInteractor() interactor.SetRenderWindow(renderWindow) randomSequence = vtkMinimalStandardRandomSequence() randomSequence.SetSeed(8775070) for i in range(numberOfSpheres): source = vtkSphereSource() # random position and radius 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(0.8) actor.GetProperty().SetSpecular(0.5) actor.GetProperty().SetSpecularColor(colors.GetColor3d('White')) actor.GetProperty().SetSpecularPower(30.0) renderer.AddActor(actor) renderWindow.Render() """ vtkPolyDataSilhouette 是一个几何特征可视化类,用来生成并显示一个模型的轮廓线 即——从某个视点或光源方向看去,模型边缘的可见轮廓线 """ silhouette = vtkPolyDataSilhouette() silhouette.SetCamera(renderer.GetActiveCamera()) # 指定相机,用来计算哪些属于轮廓 silhouetteMapper = vtkPolyDataMapper() silhouetteMapper.SetInputConnection(silhouette.GetOutputPort()) silhouetteActor = vtkActor() silhouetteActor.SetMapper(silhouetteMapper) silhouetteActor.GetProperty().SetColor(colors.GetColor3d("Tomato")) silhouetteActor.GetProperty().SetLineWidth(5) style = MouseInteractorHighLightActor(silhouette, silhouetteActor) style.SetDefaultRenderer(renderer) interactor.Initialize() interactor.SetInteractorStyle(style) renderWindow.SetWindowName('HighlightWithSilhouette') renderWindow.Render() interactor.Start() if __name__ == '__main__': main()
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/7/14 20:52:41

多视角骨骼融合方案:4路视频同步处理技巧

多视角骨骼融合方案:4路视频同步处理技巧 引言 在三维重建和人机交互领域,多视角人体骨骼关键点检测是一个基础但极具挑战性的任务。想象一下,当我们需要分析舞蹈演员的动作或运动员的训练姿势时,单摄像头视角会存在遮挡和视角局…

作者头像 李华
网站建设 2026/7/1 17:26:15

服装尺寸推荐AI:3D骨骼点+身材预测镜像,电商整合方案

服装尺寸推荐AI:3D骨骼点身材预测镜像,电商整合方案 引言:为什么电商需要智能尺码推荐? 网购服装最大的痛点是什么?相信很多人都有过这样的经历:明明按照尺码表选择了合适的号码,收到货却发现…

作者头像 李华
网站建设 2026/6/26 9:09:51

用通义千问2.5-0.5B打造智能客服:轻量级AI实战应用

用通义千问2.5-0.5B打造智能客服:轻量级AI实战应用 随着大模型技术的普及,越来越多企业希望将AI能力集成到客户服务系统中。然而,传统大模型往往依赖高性能GPU和大量算力资源,难以在边缘设备或低配服务器上稳定运行。本文聚焦阿里…

作者头像 李华
网站建设 2026/7/1 18:01:48

JSON处理神器:用通义千问2.5-0.5B打造轻量级Agent后端

JSON处理神器:用通义千问2.5-0.5B打造轻量级Agent后端 在边缘计算与本地化AI部署日益普及的今天,如何在资源受限设备上实现高效、结构化的自然语言处理成为开发者关注的核心问题。本文将深入探讨如何利用 Qwen2.5-0.5B-Instruct 这一超轻量级大模型&…

作者头像 李华
网站建设 2026/7/7 18:19:43

AI手势识别与追踪快速上手:10分钟完成环境部署

AI手势识别与追踪快速上手:10分钟完成环境部署 1. 引言:AI 手势识别与追踪的现实价值 随着人机交互技术的不断演进,非接触式控制正逐步成为智能设备的重要输入方式。从智能家居到虚拟现实,从远程会议到无障碍交互,手…

作者头像 李华
网站建设 2026/6/25 19:42:38

MelonLoader终极指南:5步掌握Unity游戏模组加载技巧

MelonLoader终极指南:5步掌握Unity游戏模组加载技巧 【免费下载链接】MelonLoader The Worlds First Universal Mod Loader for Unity Games compatible with both Il2Cpp and Mono 项目地址: https://gitcode.com/gh_mirrors/me/MelonLoader 想要为你的Unit…

作者头像 李华