Plane Fitting with vtk

If your data is supposed to represent a functional surface ( e.g. a height map where z = f(x, y) ), then it is not a good idea to apply a rotation to your points towards the fitted plane. Why? Because you will change the (x, y) coordinates too.

What you want is tecnically not a correction but an operation called detrending. Detrending alone is an entire field of research. Assuming your data is functional, a simple and fast procedure is: a) fit a plane like you suggested; b) evaluate the slope function at each data location (z* = f(x, y)); c) then making a new z for each data point z’ = z - z*.