news 2026/8/7 23:22:39

AppendFilter使用AppendFilter合并两个不同的数据并展示

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
AppendFilter使用AppendFilter合并两个不同的数据并展示

一:主要的知识点

1、说明

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

2、知识点纪要

本段代码主要涉及的有①vtkUnstructuredGrid无法显示点的原因,②使用appendfilter合并不同数据


二:代码及注释

#!/usr/bin/env python # noinspection PyUnresolvedReferences import vtkmodules.vtkInteractionStyle # noinspection PyUnresolvedReferences import vtkmodules.vtkRenderingOpenGL2 from vtkmodules.vtkCommonColor import vtkNamedColors from vtkmodules.vtkCommonCore import vtkPoints from vtkmodules.vtkCommonDataModel import ( vtkPolyData, vtkUnstructuredGrid,vtkVertex ) from vtkmodules.vtkFiltersCore import vtkAppendFilter from vtkmodules.vtkFiltersSources import ( vtkPointSource, vtkSphereSource ) from vtkmodules.vtkRenderingCore import ( vtkActor, vtkDataSetMapper, vtkGlyph3DMapper, vtkRenderWindow, vtkRenderWindowInteractor, vtkRenderer ) def main(): colors = vtkNamedColors() # Create 5 points (vtkPolyData) """ vtkPointSource 快速生成一个包含随机点的 vtkPolyData 对象,以方便测试和演示 会自动在默认的坐标范围内(一个以原点为中心,半径为 0.5 的球体内部)随机生成点 """ pointSource = vtkPointSource() pointSource.SetNumberOfPoints(5) pointSource.Update() polydata = pointSource.GetOutput() print('There are', polydata.GetNumberOfPoints(), 'points in the polydata.') # Create 2 points in a vtkUnstructuredGrid points = vtkPoints() points.InsertNextPoint(0, 0, 0) points.InsertNextPoint(0, 0, 1) ug = vtkUnstructuredGrid() ug.SetPoints(points) print('There are', ug.GetNumberOfPoints(), 'points in the unstructured.') """ vtkDataSetMapper 默认会画出 几何单元 (cells),而不是裸的点 ug里面的点,并没有创建默认的vertex单元。所以当下面的 renderer.AddActor(sphereActor) 这一行代码被注释掉,就只能看到5个点 要想看看到完整的7个点,就要给ug中的各个点创建vertex单元 for i in range(points.GetNumberOfPoints()): vertex = vtkVertex() vertex.GetPointIds().SetId(0, i) ug.InsertNextCell(vertex.GetCellType(), vertex.GetPointIds()) """ # Combine the two data sets appendFilter = vtkAppendFilter() appendFilter.AddInputData(polydata) appendFilter.AddInputData(ug) appendFilter.Update() # combined = vtkUnstructuredGrid() combined = appendFilter.GetOutput() print('There are', combined.GetNumberOfPoints(), 'points combined.') # Create a mapper and actor mapper = vtkDataSetMapper() mapper.SetInputConnection(appendFilter.GetOutputPort()) actor = vtkActor() actor.SetMapper(mapper) actor.GetProperty().SetPointSize(5) # Map the points to spheres sphereActor = point_to_glyph(appendFilter.GetOutput().GetPoints(), 0.05) sphereActor.GetProperty().SetColor(colors.GetColor3d("Gold")) # Create a renderer, render window, and interactor renderer = vtkRenderer() renderWindow = vtkRenderWindow() renderWindow.AddRenderer(renderer) renderWindowInteractor = vtkRenderWindowInteractor() renderWindowInteractor.SetRenderWindow(renderWindow) # Add the actor to the scene renderer.AddActor(actor) renderer.AddActor(sphereActor) renderer.SetBackground(colors.GetColor3d('RoyalBlue')) # Render and interact renderWindow.SetWindowName('AppendFilter') renderWindow.Render() renderWindowInteractor.Start() def point_to_glyph(points, scale): """ Convert points to glyphs. :param points: The points to glyph. :param scale: The scale, used to determine the size of the glyph representing the point, expressed as a fraction of the largest side of the bounding box surrounding the points. e.g. 0.05 :return: The actor. """ bounds = points.GetBounds() max_len = 0.0 for i in range(0, 3): max_len = max(bounds[i + 1] - bounds[i], max_len) sphere_source = vtkSphereSource() sphere_source.SetRadius(scale * max_len) pd = vtkPolyData() pd.SetPoints(points) mapper = vtkGlyph3DMapper() mapper.SetInputData(pd) mapper.SetSourceConnection(sphere_source.GetOutputPort()) mapper.ScalarVisibilityOff() mapper.ScalingOff() actor = vtkActor() actor.SetMapper(mapper) return actor if __name__ == '__main__': main()
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/8/7 20:37:15

Happy LLM:Github爆火!手把手教你从0手搓个大模型!

最近刷 GitHub 时刷到一个挺有意思的开源项目:Happy LLM它在GitHub上十分火热,已经收获13.8k⭐。 它是 Datawhale 出品的,教你从0搭建一个215M的大模型!这套 LLM 学习材料啊,是从自然语言处理的基础知识开始讲的。之后…

作者头像 李华
网站建设 2026/8/7 19:21:13

SSM线上学习系统8e88w(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面

系统程序文件列表系统项目功能:学院,课程,教师,学生,课程信息,学习记录SSM线上学习系统开题报告一、课题背景与意义1.1 课题背景在“互联网教育”政策推动下,线上学习已成为教育模式的重要组成部分。然而当前部分线上学习工具存在功能单一、数据割裂等问…

作者头像 李华
网站建设 2026/8/7 2:47:15

深度解析:MindsDB与ChromaDB向量数据库集成的高效实战指南

深度解析:MindsDB与ChromaDB向量数据库集成的高效实战指南 【免费下载链接】mindsdb mindsdb/mindsdb: 是一个基于 SQLite 数据库的分布式数据库管理系统,它支持多种数据存储方式,包括 SQL 和 NoSQL。适合用于构建分布式数据库管理系统&#…

作者头像 李华
网站建设 2026/8/7 21:29:08

32、深入了解Samba与Linux安全策略

深入了解Samba与Linux安全策略 在当今复杂的网络环境中,无论是实现不同操作系统间的资源共享,还是保障系统的安全性,都是至关重要的任务。Samba作为实现Linux与Windows系统资源共享的关键工具,以及Linux系统安全策略的制定与实施,对于系统的稳定运行和数据安全起着举足轻…

作者头像 李华
网站建设 2026/8/7 10:52:56

26、调试 Shell 程序的实用方法

调试 Shell 程序的实用方法 在编程过程中,调试是不可或缺的环节。对于使用 bash 进行 UNIX 编程的开发者来说,虽然 bash 具备丰富的特性和控制结构,但缺乏像 C 和 C++ 那样强大且集成的编程支持工具。不过,bash 自身也提供了一些实用的调试功能,下面将详细介绍。 基本调…

作者头像 李华
网站建设 2026/8/7 18:57:13

Symbolic 英文单词学习

1️、基本信息单词:symbolic词性:形容词发音: 🇺🇸 /sɪmˈbɑː.lɪk/🇬🇧 /sɪmˈbɒl.ɪk/词源: 来自希腊语 symbolikos(象征的、符号的),由 s…

作者头像 李华