PVGeo 离散点集连接成线(最短路径)
PVGeo.filters.AddCellConnToPoints
用VTK_LINE
和VTK_POLYLINE
把离散的点集联通起来。可以按照点的索引顺序连接也可以按照邻近的距离。按照邻近距离进行连接是最合理恰当的。
"""
Add Cell Connectivity To Points
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Example for :class:`PVGeo.filters.AddCellConnToPoints`This filter will add **linear** cell connectivity between scattered points.
You have the option to add ``VTK_LINE`` or ``VTK_POLYLINE`` connectivity.
``VTK_LINE`` connectivity makes a straight line between the points in order
(either in the order by index or using a nearest neighbor calculation).
The ``VTK_POLYLINE`` adds polyline connectivity between all points as one
spline (either in the order by index or using a nearest neighbor calculation)."""
import numpy as np
import pyvista
from PVGeo import points_to_poly_data
from PVGeo.filters import AddCellConnToPoints# 首先,产生一些离散的点
def path1(y):"""Equation: x = a(y-h)^2 + k"""a = - 110.0 / 160.0**2x = a*y**2 + 110.0idxs = np.argwhere(x>0)return x[idxs][:,0], y[idxs][:,0]x, y = path1(np.arange(0.0, 200.0, 25.0))
zo = np.linspace(9.0, 11.0, num=len(y))
coords = np.vstack((x,y,zo)).T
# 打乱点集的顺序
np.random.shuffle(coords)# Make a VTK data object for the filter to use
vtkPoints = points_to_poly_data(coords)###############################################################################
# Apply the Filter
# ++++++++++++++++
#
# Now that you have the points generated, lets go ahead and apply
# the **Add Cell Connectivity To Points** filter from
# *Filters->PVGeo: General Filters->Add Cell Connectivity To Points*.
# The output data should look really wacky and incorrectly built like the image
# below; this is good.
line = AddCellConnToPoints().apply(vtkPoints)p = pyvista.Plotter()
p.add_mesh(line, line_width=5, point_size=10)
p.show()
按照索引顺序连接,看起来杂乱无章。
# Use the filter: Here is vtkPolyData containing the connected line:
line_o = AddCellConnToPoints(nearest_nbr=True).apply(vtkPoints)
p = pyvista.Plotter()
p.add_mesh(line_o, line_width=5, point_size=10)
p.show()
按照点集的邻近距离进行连通。
如何寻找最短邻近距离的点:即寻找一个最短的路径,遍历每一个点找出K个最近的点组成一条路径,通过“打擂”的方式找出最短路径。
def _find_min_path(points):try:# sklearn's KDTree is faster: use it if availablefrom sklearn.neighbors import KDTree as Treeexcept ImportError:from scipy.spatial import cKDTree as Tree_compute_dist = lambda pt0, pt1: np.linalg.norm(pt0-pt1)ind, min_dist = None, np.inftree = Tree(points)for pt in points:cur_ind = tree.query([pt], k=len(points))[1].ravel()dist = 0.for i in range(len(cur_ind)-1):dist += _compute_dist(points[cur_ind[i]], points[cur_ind[i+1]])if dist < min_dist:ind = cur_indmin_dist = distreturn ind.ravel()
PVGeo 离散点集连接成线(最短路径)相关推荐
- R语言ggplot2可视化交互作用图(Interaction Plot):可视化不同分组(分类变量1)在不同剂量下(分类变量2)的箱图(box plot)、均值计算并连接成线图(line plot)
R语言ggplot2可视化交互作用图(Interaction Plot):可视化不同分组(分类变量1)在不同剂量下(分类变量2)的箱图(box plot).均值计算并连接成线图(line plot) ...
- matlab中怎样画出散点图,将这些散点连接成线
https://www.cnblogs.com/yuzhuwei/p/4459415.html https://www.cnblogs.com/yuzhuwei/p/4459535.html
- cad连接不同线段的端点_【CAD图形】】为什么CAD连续的图形无法连接成完整的多段线...
为什么 CAD 连续的图形无法连接成完整的多段线 在使用 CAD 软件绘图的时候, 有时候出于绘图需要, 设计师需要将连续的 CAD 图形连接成 完整的额多段线, 但是很多人总是无法成功操作, 这是怎 ...
- ArcGIS基础:某字段属性相同的点集数据转换成面数据
需求:将地籍号相同的(DJH)点集数据转成同一个宗地(也就是点转面). PS:实验数据来自于闫磊老师书中数据. 如果你的excel表格数据无法直接使用ArcGIS加载,可以先使用[Excel转表]工具 ...
- [学习]07 连点成线背书法
连点成线背书法 今天要跟大家分享的是,大段文字的记忆方法:怎么记,以及怎么才能不忘记,做到信手拈来地引用.--是记,不是背. 既然要记,肯定是要考试.一个重要前提:考试对这段文字/章节的要求是,记 ...
- 设有n个正整数,将他们连接成一排,组成一个最大的多位整数
题目描述: 设有n个正整数,将他们连接成一排,组成一个最大的多位整数. 如:n=3时,3个整数13,312,343,连成的最大整数为34331213. 如:n=4时,4个整数7,13,4,246连接成 ...
- arcgis导入坐标点转面_ArcGIS问题:如何将坐标点或者点文件转换成线、面文件
ArcGIS 问题:如何将坐标点或者点文件转换成线.面文件 工作过程中,如果获得了一批点坐标信息(如通过 GPS 获得的点位坐标) ,如何将这些坐标信息直接转换 成 Arcmap 下面的点呢?或者说就 ...
- 有没有能把excel表弄成线上多人填报的办法?
把Excel表弄成线上多人填报,最省时省力的方法就是使用在线协作的文档,现在普通的本地Office已经无法满足办公人员移动办公的需求,永中优云这款协作办公工具就能将Excel协作分享至社交群,让多个成 ...
- ps如何将图片转化成线稿 简单版
学习目标: 用到Adobe Photoshop CC 2018 图片转化成线稿 学习内容: 1. 下载ps 2. 安装ps 3. 导入图片 4. 开始操作 学习时间: 1. 周一至周五晚上 7 点-晚 ...
最新文章
- JavaScript系列----面向对象的JavaScript(2)
- 第14章 SpringBoot静态资源处理
- 人工智能技术为大脑制作地图 前沿
- Tableau可视化分析实战系列Tableau基础概念全解析 (一)-数据结构及字段
- maven国内镜像(maven下载慢的解决方法)
- mysql中ifnull和hive中if函数的转换
- python设计个人简历_python软件工程师 个人简历模板
- Linux安全 chage sudo授权 selinux安全上下文 gpg加密 aide入侵检测系统 audit 审计
- 利用.NET绘图技术制作水晶按钮控件(转)
- poj 1273 最大流
- C++11中using 的使用
- mysql数据脱敏_数据脱敏|静态脱敏|动态脱敏—数据库脱敏_产品
- Spy++ —— 窗口、消息查看分析利器
- BZOJ 1069 最大土地面积(旋转卡壳求最大四边形)
- 估计很多人不知道:在PowerPoint中插入图片的三种方式用法和解析
- Android 5.1 添加下拉通知栏数据流量开关快捷图标
- 探索的动机: 爱因斯坦于1918年4月的讲话
- 计算机网络交换机无法ping,无法Ping通路由器交换机提示request time out修复方法
- uni-app 在mac电脑连接安卓手机进行真机调试
- Xneomai 简介