news 2026/8/22 1:32:11

Bottle 一条曲线通过旋转形成一个瓶子的mesh

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
Bottle 一条曲线通过旋转形成一个瓶子的mesh

一:主要的知识点

1、说明

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

2、知识点纪要

本段代码主要涉及的有①围绕某个轴旋转进行模型生成


二:代码及注释

import vtkmodules.vtkRenderingOpenGL2 from vtkmodules.vtkCommonColor import vtkNamedColors from vtkmodules.vtkCommonCore import vtkPoints from vtkmodules.vtkCommonDataModel import vtkCellArray, vtkPolyData from vtkmodules.vtkFiltersCore import vtkStripper, vtkTubeFilter from vtkmodules.vtkFiltersModeling import vtkRotationalExtrusionFilter from vtkmodules.vtkRenderingCore import ( vtkActor, vtkPolyDataMapper, vtkRenderWindow, vtkRenderWindowInteractor, vtkRenderer ) def main(): colors = vtkNamedColors() points = vtkPoints() points.InsertPoint(0, 0.01, 0.0, 0.0) points.InsertPoint(1, 1.5, 0.0, 0.0) points.InsertPoint(2, 1.5, 0.0, 3.5) points.InsertPoint(3, 1.25, 0.0, 3.75) points.InsertPoint(4, 0.75, 0.0, 4.00) points.InsertPoint(5, 0.6, 0.0, 4.35) points.InsertPoint(6, 0.7, 0.0, 4.65) points.InsertPoint(7, 1.0, 0.0, 4.75) points.InsertPoint(8, 1.0, 0.0, 5.0) points.InsertPoint(9, 0.2, 0.0, 5.0) lines = vtkCellArray() lines.InsertNextCell(10) # 创建一个新的单元(cell),需要参数指定这个单元需要多少个点 lines.InsertCellPoint(0) # 将这个点的ID添加到当前正在构建的单元中 lines.InsertCellPoint(1) lines.InsertCellPoint(2) lines.InsertCellPoint(3) lines.InsertCellPoint(4) lines.InsertCellPoint(5) lines.InsertCellPoint(6) lines.InsertCellPoint(7) lines.InsertCellPoint(8) lines.InsertCellPoint(9) profile = vtkPolyData() profile.SetPoints(points) profile.SetLines(lines) # 根据profile绕着某个轴进行旋转,获得一个完整的mesh extrude = vtkRotationalExtrusionFilter() extrude.SetInputData(profile) """ Resolution 控制 旋转拉伸时的分段数,也就是把 360° 拆分成多少个切片。 值越大,旋转生成的 3D 表面越平滑;值越小,表面就会显得棱角分明 """ extrude.SetResolution(60) """ extrude = vtkRotationalExtrusionFilter() extrude.SetInputData(profile) extrude.SetResolution(360) # 设置旋转后的 角度分辨率(采样数) extrude.SetTranslation(6) # 在旋转的同时沿着 Z 轴平移 6 个单位长度 extrude.SetDeltaRadius(1.0) # 表示在旋转过程中半径的变化量, 也就是每转一圈,物体的半径增加1个单位 extrude.SetAngle(2160.0) # 设置旋转的总角度 """ mapper = vtkPolyDataMapper() mapper.SetInputConnection(extrude.GetOutputPort()) bottle = vtkActor() bottle.SetMapper(mapper) bottle.GetProperty().SetColor(colors.GetColor3d("Mint")) """ vtkStripper 将一个网格中独立的多边形(通常是三角形或四边形)转换为三角形带(triangle strips)和多边形带(polygon strips) 方便渲染,但是在这个例子里,有没有这个区别不大,可以视为是一个优化方法。 """ stripper = vtkStripper() stripper.SetInputData(profile) # 将这条线进行膨胀并显示 tubes = vtkTubeFilter() tubes.SetInputConnection(stripper.GetOutputPort()) """ 下面这种写法,摒弃了stripper的优化,直接使用profile这个polydata也可以 """ tubes.SetInputConnection(stripper.GetOutputPort()) tubes.SetNumberOfSides(11) tubes.SetRadius(0.05) profileMapper = vtkPolyDataMapper() profileMapper.SetInputConnection(tubes.GetOutputPort()) profileActor = vtkActor() profileActor.SetMapper(profileMapper) profileActor.GetProperty().SetColor(colors.GetColor3d('Tomato')) renderer = vtkRenderer() renWin = vtkRenderWindow() renWin.AddRenderer(renderer) iren = vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) renderer.AddActor(bottle) renderer.AddActor(profileActor) renderer.SetBackground(colors.GetColor3d('Burlywood')) renWin.SetSize(640, 480) renWin.SetWindowName('Bottle'); renWin.Render() renderer.GetActiveCamera().SetPosition(1, 0, 0) renderer.GetActiveCamera().SetFocalPoint(0, 0, 0) renderer.GetActiveCamera().SetViewUp(0, 0, 1) renderer.ResetCamera() renderer.GetActiveCamera().Azimuth(30) renderer.GetActiveCamera().Elevation(30) renWin.Render() iren.Start() if __name__ == '__main__': main()
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/8/22 16:01:45

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

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

作者头像 李华
网站建设 2026/8/22 5:06:48

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

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

作者头像 李华
网站建设 2026/8/22 18:04:45

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

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

作者头像 李华
网站建设 2026/8/21 17:43:45

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

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

作者头像 李华
网站建设 2026/8/21 16:11:09

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

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

作者头像 李华
网站建设 2026/8/22 7:41:30

Symbolic 英文单词学习

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

作者头像 李华