news 2026/4/23 15:29:59

FilledPolygon切割一个三维模型并用颜色填充其横截面

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
FilledPolygon切割一个三维模型并用颜色填充其横截面

一:主要的知识点

1、说明

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

2、知识点纪要

本段代码主要涉及的有①切割模型并用颜色填充横截面


二:代码及注释

import vtkmodules.vtkRenderingOpenGL2 from vtkmodules.vtkCommonColor import vtkNamedColors from vtkmodules.vtkCommonDataModel import vtkPlane, vtkPolyData from vtkmodules.vtkFiltersSources import vtkSphereSource from vtkmodules.vtkFiltersCore import vtkCutter, vtkFeatureEdges, vtkStripper from vtkmodules.vtkRenderingCore import ( vtkActor, vtkPolyDataMapper, vtkProperty, vtkRenderWindow, vtkRenderWindowInteractor, vtkRenderer ) def main(): colors = vtkNamedColors() sphere = vtkSphereSource() sphere.SetRadius(50) sphere.SetThetaResolution(100) sphere.SetPhiResolution(100) # cubeMapper = vtkPolyDataMapper() # cubeMapper.SetInputConnection(cube.GetOutputPort()) plane = vtkPlane() plane.SetOrigin(20, 0, 0) plane.SetNormal(1, 0, 0) cutter = vtkCutter() cutter.SetCutFunction(plane) cutter.SetInputConnection(sphere.GetOutputPort()) cutter.Update() # FeatureEdges = vtkFeatureEdges() # FeatureEdges.SetInputConnection(cutter.GetOutputPort()) # FeatureEdges.BoundaryEdgesOn() # FeatureEdges.FeatureEdgesOff() # FeatureEdges.ManifoldEdgesOff() # FeatureEdges.NonManifoldEdgesOff() # FeatureEdges.Update() cutStrips = vtkStripper() cutStrips.SetInputConnection(cutter.GetOutputPort()) cutStrips.Update() cutPoly = vtkPolyData() cutPoly.SetPoints(cutStrips.GetOutput().GetPoints()) cutPoly.SetPolys(cutStrips.GetOutput().GetLines()) cutMapper = vtkPolyDataMapper() cutMapper.SetInputData(cutPoly) backface = vtkProperty() backface.SetColor(colors.GetColor3d('Gold')) cutActor = vtkActor() cutActor.SetMapper(cutMapper) cutActor.GetProperty().SetColor(colors.GetColor3d('Yellow')) cutActor.GetProperty().SetEdgeColor(colors.GetColor3d('Red')) cutActor.GetProperty().SetLineWidth(2) cutActor.GetProperty().EdgeVisibilityOn() # cutActor.GetProperty().SetOpacity(0.7) cutActor.SetBackfaceProperty(backface) ren = vtkRenderer() ren.AddActor(cutActor) # Add renderer to renderwindow and render renWin = vtkRenderWindow() renWin.AddRenderer(ren) renWin.SetSize(600, 400) renWin.SetWindowName('FilledPolygon') iren = vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) ren.SetBackground(colors.GetColor3d('DarkSlateGray')) ren.GetActiveCamera().SetPosition(223, -122, -91) renWin.Render() camera = ren.GetActiveCamera() camera.SetPosition(151.519511, 12.795117, -223.586044) camera.SetFocalPoint(12.518283, 1.963242, 7.618042) camera.SetViewUp(0.740690, -0.523767, 0.420769) camera.SetDistance(269.988889) camera.SetClippingRange(175.347580, 366.490816) camera.Zoom(1.5) iren.Start() if __name__ == '__main__': main()
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/23 13:00:13

自动售货机:西门子 S7 - 1200 与 TP700 触摸屏联机程序大揭秘

自动售货机西门子S7-1200和TP700触摸屏联机程序11,博途V15,带注释和IO表设计要求最近我在搞自动售货机相关的项目,用的是西门子 S7 - 1200 和 TP700 触摸屏,搭配博途 V15 软件。今天就来和大家分享下这个项目里的程序设计&#xf…

作者头像 李华
网站建设 2026/4/23 14:33:38

开启HFSS仿真文献建模复现之旅

HFSS仿真,文献建模复现最近在做电磁仿真相关的研究,其中HFSS仿真那可是相当重要。今天就跟大家聊聊我在进行HFSS仿真文献建模复现过程中的那些事儿,这里面有很多值得说道的地方,也穿插着一些代码和我对代码的简单分析,…

作者头像 李华
网站建设 2026/4/23 14:33:44

“1”背后的数学浪漫:从暴力扫描到位数拆解,聊聊 Number of Digit One

“1”背后的数学浪漫:从暴力扫描到位数拆解,聊聊 Number of Digit One ——Echo_Wish 🧩 开篇:你以为是数 1,其实是数复杂度 很多朋友第一次看到这个题目: 统计从 1 到 n 所有整数里,数字 “1” 出现了多少次? 感觉这不就是循环一遍吗? 比如输入 13,输出 6(1、10…

作者头像 李华
网站建设 2026/4/22 6:17:47

用极狐 CodeRider-Kilo 开发俄罗斯方块:AI 辅助编程的沉浸式体验

前言:AI 编程时代的到来 在当今信息爆炸与技术飞速迭代的今天,编程已不再是开发者独有的技能壁垒。随着 AI 辅助编程工具的崛起,开发效率得到了质的飞跃。作为一名编程爱好者,我最近体验了极狐 GitLab 推出的 AI 编程助手 ——Cod…

作者头像 李华
网站建设 2026/4/23 14:17:11

在大数据中如何做好数据质量监控

随着企业数字化转型的深入,大数据已成为驱动业务决策、智能运营和自动化服务的核心引擎。然而,数据的价值不仅取决于其“量”,更取决于其“质”。在复杂的大数据生态系统中,数据从采集、传输、存储到处理和分析,经历多…

作者头像 李华
网站建设 2026/4/23 13:52:34

GraniStudio零代码开发,一站式设备控制与可视化开发平台

苏州格拉尼视觉科技有限公司推出GraniStudio零代码工控软件开发平台,是集数据采集、运动控制、机器视觉、HMI 等功能于一体的工业级工控软件开发平台。集设计、开发、调试、运行于一体,是一款类似 Labview软件,且侧重于自动化设备工控软件开发…

作者头像 李华