如何将 Z 访问上的 2 个表面连接成一个网格?

问题描述

所以我有 2 个表面(PyVista 中的 polyData)一个在另一个之上:

enter image description here

它们在 Z 访问上的形状略有不同,但只要顶部在 X、Y 平面上具有 Z 值,我们就可以确定底部具有相同的值。那么如何将两个对齐的 X、Y 曲面合并为一个实体网格?


我的尝试:

import numpy as np
import pyvista as pv

import vtk

def extruder(mesh,val_z):
    extrude = vtk.vtkLinearExtrusionFilter()
    extrude.SetInputData(mesh)
    extrude.SetVector(0,val_z)
    extrude.Update()
    extruded_mesh = pv.wrap(extrude.Getoutput())
    return extruded_mesh

# generate two sheets of input data
noise = pv.perlin_noise(2,(0.2,0.2,0.2),(0,0))
bounds_2d = (-10,10,-10,10)
dim = (40,50,1)
bottom,top = [
    pv.sample_function(noise,dim=dim,bounds=bounds_2d + (z,z)).warp_by_scalar()
    for z in [-5,5]
]
bottom = bottom.extract_surface(nonlinear_subdivision=5)
top = top.extract_surface(nonlinear_subdivision=5)

top =  extruder(top,-50).triangulate()
bottom =  extruder(bottom,50).triangulate()

intersection = bottom.boolean_cut(top)

#top = top.clip_surface(bottom,invert=False,compute_distance=True)

#top =  top.extrude([0,-50]).triangulate()
#bottom =  bottom.extrude([0,50]).triangulate()
#intersection = bottom.boolean_cut(top).triangulate()
p = pv.Plotter()
p.add_mesh(top,cmap="hot",opacity=0.15)
p.add_mesh(bottom,cmap="RdYlBu",opacity=0.15)
p.add_mesh(intersection,cmap="Dark2",opacity=1)
p.show()

我得到了什么:

enter image description here

我的预期:

enter image description here

只填中间。

解决方法

所以必须这样做:

import numpy as np
import pyvista as pv

# generate two sheets of input data
noise = pv.perlin_noise(2,(0.2,0.2,0.2),(0,0))
bounds_2d = (-10,10,-10,10)
dim = (40,50,1)
bottom,top = [
    pv.sample_function(noise,dim=dim,bounds=bounds_2d + (z,z)).warp_by_scalar()
    for z in [-5,5]
]
bottom = bottom.extract_surface()
top = top.extract_surface()

topm =  top.extrude([0,-50]).triangulate().clean()
bottomm =  bottom.extrude([0,50]).triangulate().clean()


topm = topm.clip_surface(bottom,invert=False)
bottomm = bottomm.clip_surface(top,invert=True)
intersection = topm.boolean_add(bottomm).triangulate().clean().subdivide(2).clean()

p = pv.Plotter()
#p.add_mesh(topm,cmap="hot",opacity=0.15)
#p.add_mesh(bottomm,cmap="gnuplot2",opacity=0.15)
p.add_mesh(intersection,cmap="Dark2",opacity=1)
p.show()

生成的网格非常糟糕,但它具有所需的形状并且可以在可用时间内进行计算: enter image description here

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...