VTK平面通过3D点

问题描述 投票:0回答:1

我有一组3D点,需要拟合最佳拟合平面,我正在用下面的代码(在stackoverflow上找到的)。

points = np.reshape(points, (np.shape(points)[0], -1))
assert points.shape[0] <= points.shape[1], "There are only {} points in {} dimensions.".format(points.shape[1], points.shape[0])

ctr = points.mean(axis=1)
x = points - ctr[:, np.newaxis]
M = np.dot(x, x.T)
return ctr, svd(M)[0][:,-1] # return point and normal vector

之后我想用VTK显示这个平面。问题是我必须缩放平面,但当我这样做时,平面也被翻译。我怎样才能防止这种情况发生呢?

def create_vtk_plane_actor(point, normal_vector):
 print("\n Display plane with point: %s and vector: %s" % (point, normal_vector))

 plane_source = vtk.vtkPlaneSource()
 plane_source.SetOrigin(point[0], point[1], point[2])
 plane_source.SetNormal(normal_vector[0], normal_vector[1], normal_vector[2])
 plane_source.Update()

 transform = vtk.vtkTransform()
 transform.Scale(1.5, 1.5, 1.0)

 transform_filter = vtk.vtkTransformFilter()
 transform_filter.SetInputConnection(plane_source.GetOutputPort())
 transform_filter.SetTransform(transform)

 actor = vtk.vtkActor()

 mapper = vtk.vtkPolyDataMapper()
 mapper.SetInputConnection(transform_filter.GetOutputPort())
vector vtk plane
1个回答
0
投票

比例尺不是应用在你的计划的局部坐标上,而是应用在你设置的坐标上。所以确实,中心会移动。如果你想让它移动,你需要在你的计划中设置一个 Translate 在您的变换上。


0
投票

适应平面是一个内置的功能在 vtkplotter缩放是用 mesh.scale():

from vtkplotter import *
from vtkplotter import datadir
from vtkplotter.pyplot import histogram

plt = Plotter()

apple = load(datadir+"apple.ply").subdivide().addGaussNoise(1)
plt += apple.alpha(0.1)

variances = []
for i, p in enumerate(apple.points()):
    pts = apple.closestPoint(p, N=12) # find the N closest points to p
    plane = fitPlane(pts)             # find the fitting plane and scale
    variances.append(plane.variance)
    if i % 400: continue
    print(i, plane.variance)
    plt += plane.scale(2)
    plt += Points(pts)              
    plt += Arrow(plane.center, plane.center+plane.normal/10)

plt += histogram(variances).scale(6).pos(1.2,.2,-1)
plt.show()

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.