news 2026/4/16 18:11:47

ImplicitPolyDataDistance 隐式距离显示

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
ImplicitPolyDataDistance 隐式距离显示

一:主要的知识点

1、说明

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

2、知识点纪要

本段代码主要涉及的有①vtkImplicitPolyDataDistance计算任意点到几何体表面的符号距离


二:代码及注释

import numpy as np import vtkmodules.vtkRenderingOpenGL2 import vtkmodules.vtkInteractionStyle from vtkmodules.vtkCommonColor import vtkNamedColors from vtkmodules.vtkCommonCore import vtkFloatArray, vtkPoints from vtkmodules.vtkFiltersSources import vtkSphereSource from vtkmodules.vtkFiltersCore import vtkImplicitPolyDataDistance from vtkmodules.vtkCommonDataModel import vtkPolyData from vtkmodules.vtkFiltersGeneral import vtkVertexGlyphFilter from vtkmodules.vtkRenderingCore import ( vtkActor, vtkPolyDataMapper, vtkRenderWindow, vtkRenderWindowInteractor, vtkRenderer ) def main(): colors = vtkNamedColors() sphereSource = vtkSphereSource() sphereSource.SetCenter(0, 0, 0) sphereSource.SetRadius(1.0) sphereSource.Update() sphereMapper = vtkPolyDataMapper() sphereMapper.SetInputConnection(sphereSource.GetOutputPort()) sphereMapper.ScalarVisibilityOff() sphereActor = vtkActor() sphereActor.SetMapper(sphereMapper) # SetOpacity 设置模型是否透明,1完全不透明,0完全透明 sphereActor.GetProperty().SetOpacity(0.3) sphereActor.GetProperty().SetColor(1, 0, 0) """ vtkImplicitPolyDataDistance 计算空间中任意一点到这个多边形几何体表面的符号距离 """ implicitPolyDataDistance = vtkImplicitPolyDataDistance() implicitPolyDataDistance.SetInput(sphereSource.GetOutput()) # 设置隐式距离函数 points = vtkPoints() step = 0.1 for x in np.arange(-2, 2, step): for y in np.arange(-2, 2, step): for z in np.arange(-2, 2, step): points.InsertNextPoint(x, y, z) signedDistance = vtkFloatArray() signedDistance.SetNumberOfComponents(1) signedDistance.SetName("") for pointId in range(points.GetNumberOfPoints()): p = points.GetPoint(pointId) dist_ = implicitPolyDataDistance.EvaluateFunction(p) signedDistance.InsertNextValue(dist_) polyData = vtkPolyData() polyData.SetPoints(points) polyData.GetPointData().SetScalars(signedDistance) """ vtkVertexGlyphFilter 把点集转换成可渲染的几何体 """ vertexGlyphFilter = vtkVertexGlyphFilter() vertexGlyphFilter.SetInputData(polyData) vertexGlyphFilter.Update() signedDistanceMapper = vtkPolyDataMapper() signedDistanceMapper.SetInputConnection(vertexGlyphFilter.GetOutputPort()) signedDistanceMapper.ScalarVisibilityOn() # 根据标量进行着色 signedDistanceActor = vtkActor() signedDistanceActor.SetMapper(signedDistanceMapper) renderer = vtkRenderer() renderer.AddViewProp(sphereActor) renderer.AddViewProp(signedDistanceActor) renderer.SetBackground(colors.GetColor3d('SlateGray')) renderWindow = vtkRenderWindow() renderWindow.AddRenderer(renderer) renderWindow.SetWindowName('ImplicitPolyDataDistance') renWinInteractor = vtkRenderWindowInteractor() renWinInteractor.SetRenderWindow(renderWindow) renderWindow.Render() renWinInteractor.Start() if __name__ == '__main__': main()
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/16 11:02:10

Piper开发调试实战指南:3大核心技巧加速游戏设备配置开发

Piper开发调试实战指南:3大核心技巧加速游戏设备配置开发 【免费下载链接】piper GTK application to configure gaming devices 项目地址: https://gitcode.com/gh_mirrors/pip/piper Piper作为专业的游戏设备配置GTK应用程序,为开发者提供了高效…

作者头像 李华
网站建设 2026/4/16 11:01:26

jQuery-Cookie到JS Cookie技术迁移完整指南:高效版本升级最佳实践

jQuery-Cookie到JS Cookie技术迁移完整指南:高效版本升级最佳实践 【免费下载链接】jquery-cookie No longer maintained, superseded by JS Cookie: 项目地址: https://gitcode.com/gh_mirrors/jq/jquery-cookie 在当前前端技术快速迭代的背景下&#xff0c…

作者头像 李华
网站建设 2026/4/16 11:01:19

【2024最新】Zalando RESTful API设计准则深度解析与实战指南

【2024最新】Zalando RESTful API设计准则深度解析与实战指南 【免费下载链接】restful-api-guidelines A model set of guidelines for RESTful APIs and Events, created by Zalando 项目地址: https://gitcode.com/gh_mirrors/re/restful-api-guidelines 在微服务架构…

作者头像 李华
网站建设 2026/4/16 12:52:58

Keploy Serverless测试:零代码自动化测试的革命性突破

Keploy Serverless测试:零代码自动化测试的革命性突破 【免费下载链接】keploy Test generation for Developers. Generate tests and stubs for your application that actually work! 项目地址: https://gitcode.com/GitHub_Trending/ke/keploy 我们发现&a…

作者头像 李华
网站建设 2026/4/16 1:20:32

JAX多精度计算实战:3大技巧提升深度学习模型性能

在深度学习模型部署过程中,你是否面临这样的困境:高精度模型推理缓慢,低精度模型准确性堪忧?JAX框架的多精度计算能力正是解决这一痛点的利器。本文将带你深入了解JAX数值类型系统的特性,掌握3大核心优化技巧&#xff…

作者头像 李华
网站建设 2026/4/16 13:45:35

告别Vim碎片化搜索:Unite.vim统一界面全攻略

告别Vim碎片化搜索:Unite.vim统一界面全攻略 【免费下载链接】unite.vim :dragon: Unite and create user interfaces 项目地址: https://gitcode.com/gh_mirrors/un/unite.vim 还在为Vim中各种搜索命令记不住而烦恼吗?Unite.vim就是你的救星&…

作者头像 李华