1

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

在此处输入图像描述

它们在 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, 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, 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, 0, -50]).triangulate()
#bottom =  bottom.extrude([0, 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()

我能得到什么: 在此处输入图像描述

我所期望的: 在此处输入图像描述 只有中间被填充。

4

1 回答 1

1

所以不得不这样做:

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, 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, 0, -50]).triangulate().clean()
bottomm =  bottom.extrude([0, 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()

生成的网格非常糟糕,但它具有所需的形状并且可以在可用时间内计算: 在此处输入图像描述

于 2021-07-03T14:56:07.440 回答