Hello, I need to fit a vtkPlane to a PolyData, but I do not understand how to use the method ComputeBestFittingPlane().
The vtkPlane.ComputeBestFittingPlane() documentation says “Given a set of points calculate the best-fitting origin and normal for the plane. The origin will be the centroid of the points. The normal is determined by using the covariance matrix of the points relative to the centroid. Returns true if successful. If not successful the origin will still contain the centroid and the normal will point into z-direction.”
What I understand from your answer is that the origin and normal should be dummy objects that will be filled with actual values after the ComputeBestFittingPlane method runs.
I created the reference objects and now I get an enigmatic crash that does not rise any specific error in the PyCharm debugger.
from vtk import (...) reference
my_plane = Plane()
my_origin = reference(0.)
my_normal = reference(0.)
my_plane.ComputeBestFittingPlane(my_polydata.GetOutput().GetPoints(), my_plane, my_normal)
>>> Process finished with exit code -1073741819 (0xC0000005)
Both the origin and normal should be double, so it seems OK. I also tried with [0., 0., 0.], thinking that they should be vectors actually, but this does not work.
I also tried using my_plane.GetOrigin() and my_plane.GetNormal(), and reference(my_plane.GetOrigin()) and reference(my_plane.GetNormal()).
Getorigin() and GetNormal() actually output a tuple, e.g. (0.0, 0.0, 1.0), but in the end ComputeBestFittingPlane always results in the error TypeError: ComputeBestFittingPlane argument %Id: %V.