Skip to main content
 首页 » 编程设计

python之沿任意表面探针采样数据量

2025年05月04日10soundcode

在 numpy 中,用 m 维探针 (m

o = [0, 0, 0] # origin 
v1 = [1, 0, 0]; l1=1 # First vector and length 
v2 = [0, 1, 0]; l2=1 # Second vector and length 
 
ds1,ds2 = 10,10 # samples per direction 
 
l1x,l1y,l1z = np.linspace(o[0],v1[0]*l1,ds1),np.linspace(o[1],v1[1]*l1,ds1),np.linspace(o[2],v1[2]*l1,ds1) 
l2x,l2y,l2z = np.linspace(o[0],v2[0]*l2,ds2),np.linspace(o[1],v2[1]*l2,ds2),np.linspace(o[2],v1[2]*l2,ds2) 
llx, lly, llz = l1x, l1y, l1z 
 
# shift points in direction of 2nd vector and append  
for i in range(1,ds2): 
  llx = np.hstack((llx,l1x+l2x[i])) 
  lly = np.hstack((lly,l1y+l2y[i])) 
  llz = np.hstack((llz,l1z+l2z[i])) 
 
ptcoords = np.vstack((llx,lly,llz)).T  

编辑: 我找到了一种更简洁的方式来表达这个:使用 l 的 pxn 数组列表(例如 p=3、n=10、10 个 3D 点的数组或线性探针),其中 m 是固定的在整个列表中,但 n 可以因元素而异,此代码将构建整个探测数组:

base = l[0] # if l[0] is the only one 
for ll in l[1:]: 
  n = ll.shape[0] 
  nb = base.shape[0] 
  base = np.repeat(ll,nb,0) + np.vstack(np.hsplit(np.tile(base,n),n)) 

不过,我认为循环和大量数组操作是可以避免的!我已经在一些 3D 配置上对其进行了测试,这是屏幕截图。让我知道您是否可以改进或找到错误。

请您参考如下方法:

对于 3D 数据和 2D 剪辑,我一直在使用 Mayavi。非常粗略地说,您需要执行以下步骤:加载数据、添加 delaunay 三角剖分过滤器、可视化体积、添加标量剖切面、定位并读出数据。