使用在 vedo 中变形的薄板变形体积网格

Warping a volumetric mesh using thin plates morphing in vedo

我正在尝试使用 vedo 的薄板变形功能来扭曲体积网格。但我没有成功。我什至尝试使用表面网格进行调试,但这也没有用。下面是vedo提供的原始例子。

"""Warp the tip of a mesh using Thin Plate Splines.
Red points stay fixed while a single point in space
moves as the arrow indicates. """
from vedo import *


mesh = Mesh(dataurl+"man.vtk").color('w').lineWidth(0.1)

# a heavily decimated copy
meshdec = mesh.clone().triangulate().decimate(N=200)

sources = [[0.9, 0.0, 0.2]]  # this point moves
targets = [[1.2, 0.0, 0.4]]  # to this.
arrow = Arrow(sources[0], targets[0])

for pt in meshdec.points():
    if pt[0] < 0.3:          # these pts don't move
        sources.append(pt)   # source = target
        targets.append(pt)   #

warp = mesh.clone().thinPlateSpline(sources, targets)
warp.c("blue",0.3).lineWidth(0)

apts = Points(sources).c("red")

show(mesh, arrow, warp, apts, __doc__, viewup="z", axes=1)

以下是我进行的一些试译。这些已针对表面和体积网格进行了尝试。

试用 1using decimated mesh

from vedo import *
import numpy as np
import scipy.io
import os
import sys
import csv

meshfile = "C:\..\MyVirtMean.vtk";
sourcefile = "C:\..\MyVirtMean_meanSurfNodes.csv";
targetfile = "C:\..\virtShapeGeneration.mat";
matvariable = "newShape";
Sources = []
Targets = []

mesh = Mesh(meshfile).color('w').lineWidth(0.1) # This is the mean volumetric mesh

# a heavily decimated copy
meshdec = mesh.clone().triangulate().decimate(N=200)

# Collecting mean surface point data from csv file
with open(sourcefile) as csvDataFile:
    csvReader = csv.reader(csvDataFile)
    for row in csvReader:
        Sources.append(row)
Sources = np.array(Sources)
Sources = Sources.astype(np.float)
length = int(np.size(Sources)/3)
Sources = list(Sources.reshape(length,3)) # ?x3 array

# Collecting virtual subjects point data from .mat file
Targets = scipy.io.loadmat(targetfile)[matvariable][0]
length = int(np.size(Targets)/3)
Targets = list(Targets.reshape(length,3)) # ?x3 array
    
# 
arrow = Arrow(Sources[0], Targets[0])

for pt in meshdec.points():
    if pt[0] < 0.3:          # these pts don't move
        Sources.append(pt)   # source = target
        Targets.append(pt)   #

warp = mesh.clone().thinPlateSpline(Sources, Targets) 
warp.c("blue",0.3).lineWidth(0)

apts = Points(Sources).c("red")

show(mesh, arrow, warp, apts, __doc__, viewup="z", axes=1)

试用 2using the full mesh

from vedo import *
import numpy as np
import scipy.io
import os
import sys
import csv

meshfile = "C:\..\MyVirtMean.vtk"
sourcefile = "C:\..\MyVirtMean_meanSurfNodes.csv"
targetfile = "C:\..\virtShapeGeneration.mat"
matvariable = "newShape";
Sources = []
Targets = []

mesh = Mesh(meshfile).color('w').lineWidth(0.1)
with open(sourcefile) as csvDataFile:
    csvReader = csv.reader(csvDataFile)
    for row in csvReader:
        Sources.append(row)
Sources = np.array(Sources)
Sources = Sources.astype(np.float)
length = int(np.size(Sources)/3)
Sources = list(Sources.reshape(length,3)) # ?x3 array

# Collecting virtual subjects point data from .mat file
Targets = scipy.io.loadmat(targetfile)[matvariable][0]
length = int(np.size(Targets)/3)
Targets = list(Targets.reshape(length,3)) # ?x3 array
    
# 
arrow = Arrow(Sources[0], Targets[0])

for pt in mesh.points():
    if pt[0] < 0.3:          # these pts don't move
        Sources.append(pt)   # source = target
        Targets.append(pt)   #

warp = mesh.clone().thinPlateSpline(Sources, Targets) 
warp.c("blue",0.3).lineWidth(0)

apts = Points(Sources).c("red")

show(mesh, arrow, warp, apts, __doc__, viewup="z", axes=1)

主要是内核在 warp 命令处冻结。在某些情况下,我还遇到过内核死机并重新启动的情况。我怀疑我在定义源和目标时做错了什么,但我不确定。
I'm using Python 3.7.3 64-bit in Spyder 4.1.5 (Windows 10).

我的代码有两个问题。正如预期的那样,问题出在源和目标的定义方式上。

  1. 必须使用 .tolist() 方法创建源和目标。

  2. 必须使用

    使用类似 Fortran 的索引顺序对从 ( .mat ) 文件导入的 Targets 数组进行重塑

    Targets = (Targets.reshape((length,3), order='F'))
    Targets = Targets.tolist()

另一点是我不得不使用数量减少的源和目标
for x in range(0, len(Targets), 50):
targets.append(Targets[x])

可以查到结果through this link.