news 2026/5/12 22:16:41

ConstrainedDelaunay2D 顺逆时针限制三角剖分

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
ConstrainedDelaunay2D 顺逆时针限制三角剖分

一:主要的知识点

1、说明

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

2、知识点纪要

本段代码主要涉及的有①平面生成Delaunay2D注意事项,②如何生成一个带空洞的平面


二:代码及注释

import vtkmodules.vtkInteractionStyle import vtkmodules.vtkRenderingOpenGL2 from vtkmodules.vtkCommonColor import vtkNamedColors from vtkmodules.vtkCommonCore import ( vtkMinimalStandardRandomSequence, vtkPoints ) from vtkmodules.vtkCommonDataModel import ( vtkCellArray, vtkPolyData, vtkPolygon ) from vtkmodules.vtkFiltersCore import vtkDelaunay2D from vtkmodules.vtkRenderingCore import ( vtkActor, vtkPolyDataMapper, vtkRenderWindow, vtkRenderWindowInteractor, vtkRenderer ) def main(): colors = vtkNamedColors() rng = vtkMinimalStandardRandomSequence() rng.SetSeed(0) gridSize = 10 points = vtkPoints() for x in range(gridSize): for y in range(gridSize): d1 = rng.GetValue() / 2.0 - 0.25 rng.Next() d2 = rng.GetValue() / 2.0 - 0.25 rng.Next() points.InsertNextPoint(x+d1, y+d2, 0) aPolyData = vtkPolyData() aPolyData.SetPoints(points) aCellArray = vtkCellArray() # vtkPolyGon 多边形单元 aPolygon = vtkPolygon() """ 下面索引的顺序是顺时针的 顺时针定义的内部多边形被视为孔洞,剖分会避开此区域,源代码写法是这样的 aPolygon.GetPointIds().InsertNextId(22) aPolygon.GetPointIds().InsertNextId(23) aPolygon.GetPointIds().InsertNextId(24) aPolygon.GetPointIds().InsertNextId(25) aPolygon.GetPointIds().InsertNextId(35) aPolygon.GetPointIds().InsertNextId(45) aPolygon.GetPointIds().InsertNextId(44) aPolygon.GetPointIds().InsertNextId(43) aPolygon.GetPointIds().InsertNextId(42) aPolygon.GetPointIds().InsertNextId(32) """ aPolygon.GetPointIds().SetNumberOfIds(10) aPolygon.GetPointIds().SetId(0, 22) aPolygon.GetPointIds().SetId(1, 23) aPolygon.GetPointIds().SetId(2, 24) aPolygon.GetPointIds().SetId(3, 25) aPolygon.GetPointIds().SetId(4, 35) aPolygon.GetPointIds().SetId(5, 45) aPolygon.GetPointIds().SetId(6, 44) aPolygon.GetPointIds().SetId(7, 43) aPolygon.GetPointIds().SetId(8, 42) aPolygon.GetPointIds().SetId(9, 32) """ 下面的索引的顺序是逆时针的 逆时针定义的外部多边形会被视为外部边界,只在这里面发生三角剖分 aPolygon.GetPointIds().InsertNextId(32) aPolygon.GetPointIds().InsertNextId(42) aPolygon.GetPointIds().InsertNextId(43) aPolygon.GetPointIds().InsertNextId(44) aPolygon.GetPointIds().InsertNextId(45) aPolygon.GetPointIds().InsertNextId(35) aPolygon.GetPointIds().InsertNextId(25) aPolygon.GetPointIds().InsertNextId(24) aPolygon.GetPointIds().InsertNextId(23) aPolygon.GetPointIds().InsertNextId(22) """ aCellArray.InsertNextCell(aPolygon) boundary = vtkPolyData() boundary.SetPoints(points) boundary.SetPolys(aCellArray) delaunay = vtkDelaunay2D() delaunay.SetInputData(aPolyData) # 提供待剖分的100个点 delaunay.SetSourceData(boundary) # 提供了约束信息,根据约束信息的顺逆时针决定是不剖分还是只剖分这个不分 # Visualize meshMapper = vtkPolyDataMapper() meshMapper.SetInputConnection(delaunay.GetOutputPort()) meshActor = vtkActor() meshActor.SetMapper(meshMapper) meshActor.GetProperty().EdgeVisibilityOn() meshActor.GetProperty().SetEdgeColor(colors.GetColor3d('Peacock')) meshActor.GetProperty().SetInterpolationToFlat() boundaryMapper = vtkPolyDataMapper() boundaryMapper.SetInputData(boundary) boundaryActor = vtkActor() boundaryActor.SetMapper(boundaryMapper) boundaryActor.GetProperty().SetColor(colors.GetColor3d('Raspberry')) boundaryActor.GetProperty().SetLineWidth(3) boundaryActor.GetProperty().EdgeVisibilityOn() boundaryActor.GetProperty().SetEdgeColor(colors.GetColor3d('Red')) boundaryActor.GetProperty().SetRepresentationToWireframe() # 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(meshActor) renderer.AddActor(boundaryActor) renderer.SetBackground(colors.GetColor3d('Mint')) # Render and interact renderWindow.SetSize(640, 480) renderWindow.SetWindowName('ConstrainedDelaunay2D') renderWindow.Render() renderWindowInteractor.Start() if __name__ == '__main__': main()
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/5/9 7:40:16

Docker中配置Stable Diffusion WebUI与TensorRT

Docker中配置Stable Diffusion WebUI与TensorRT 在AIGC应用从实验走向生产的今天,如何高效部署一个既能稳定运行又能快速响应图像生成请求的服务,成为系统工程师面临的核心挑战。尤其是在电商设计、内容平台自动化出图等高并发场景下,单纯的…

作者头像 李华
网站建设 2026/5/10 1:06:23

小模型在昇腾上如何比英伟达更快?一次实战告诉你答案

小模型迁移到昇腾怎么才能比 NVIDIA 更快?一次真实踩坑复盘告诉你答案 小模型迁移到昇腾,可能遇到速度变慢的情况,一般会以为是硬件差异导致的,尤其是和 NVIDIA 的 4090、A100 这种 GPU 比。此次迁移一个不到 1B 的小模型后&…

作者头像 李华
网站建设 2026/5/12 8:32:57

PyTorch多GPU训练全解析:从单卡到分布式

PyTorch多GPU训练全解析:从单卡到分布式 在深度学习项目中,当模型越来越大、数据越来越多时,单张 GPU 往往难以支撑训练任务。显存不足、训练周期过长,已成为许多开发者面临的现实瓶颈。幸运的是,PyTorch 提供了强大而…

作者头像 李华
网站建设 2026/5/9 10:53:39

PyTorch使用GPU的常见坑与解决方案

PyTorch使用GPU的常见坑与解决方案 在深度学习项目中,从本地笔记本到云端集群,PyTorch 已成为最主流的框架之一。随着模型越来越大,GPU 加速不再是“锦上添花”,而是训练能否进行的关键。然而,即便是经验丰富的开发者&…

作者头像 李华
网站建设 2026/5/9 15:46:20

YOLOv3中build_targets函数详解

YOLOv3中build_targets函数详解 在目标检测领域,YOLO系列模型因其“一次前向传播即可完成检测”的高效特性而广受青睐。尽管从YOLOv1到如今的YOLOv8,架构不断演进,但其训练过程中一个核心环节始终未变:如何将真实标注框&#xff0…

作者头像 李华
网站建设 2026/5/9 7:40:31

PyTorch实现Mask R-CNN实例分割实战指南

PyTorch实现Mask R-CNN实例分割实战指南 在自动驾驶感知系统中,不仅要识别出“前方有一辆车”,更要精确知道这辆车占据的每一个像素区域——这种对图像中每个独立目标进行检测并逐像素分割的任务,正是实例分割(Instance Segmentat…

作者头像 李华