How to use `vtkprojectPointsToPlane` to project to a 3D object to a special plane?

I want to use the vtkProjectPointsToPlane to project this object onto a specific plane, but encountered this problem:
:point_down:the 3D object in 3D Slicer:

def pd2plaPj(mod, cp= [0,0,0], norm=[0,1,0]):
    norm = norm/,norm)
    pd = Helper.getPd(mod)    
    p2plaFilter = vtk.vtkProjectPointsToPlane()
    return p2plaFilter.GetOutput()
pd2plaPj(mod) # Or norm is [1,0,0] Or [0,0,1]


It’s very good!
but …

pd2plaPj(mod, norm=[0,1,1))

got :point_down: a 3D object(red)

what’s wrong?

@lassoan 老师

I’ve never used this filter. I would simply apply a projection transform using vtkTransformPolyDataFilter.

vtkTransformPolyDataFilter? I don’t quite understand? I want to project an object (the yellow in the picture above👆🏻) to a specific plane (in green) instead of transform an object (in red) to a location.

@ lassoon. Do you mean that the projection task can be simply achieved using vtkTransformPolyDataFilter?

Projection to plane is a linear transform that can be described by a 4x4 homogenous matrix. You can construct it by concatenating 3 trivial transforms:

  1. Transforms the point coordinates from world coordinate system into the plane’s coordinate system (it is the inverse of the third transform)
  2. Apply projection transform (diag(1, 1, 0, 1))
  3. Transforms the point coordinates from the plane’s coordinate system to the world’s coordinate system (it is very easy to construct this transform: the first 3 columns of the transformation matrix are the 3 plane axes, the fourth column is the plane position; the bottom row is [0, 0, 0, 1])

The entire implementation is just few ten lines of Python code, see for example here.

@lassoan what’s wrong?

Description and implementation of the algorithm should be sufficient help, I’m sure you can figure out the rest.

Just a hint for your last question: check if your point position vectors should be in rows or columns.

Do you officially not maintain methods that are less commonly used like this👆🏻?

vtkProjectPointsToPlane was added relatively recently, so I did not have a chance to try it and also did not feel the need to use it because the more general vtkTransformPolyDataFilter was fast enough for me.

vtkProjectPointsToPlane is optimized for a single purpose and so it is (supposed to be) simpler to use and should be more efficient. So, even though its scope is very narrow it deserves to exist. Maybe it could be in a VTK remote module to keep VTK core leaner.

Attempting to convert segmen of vtkProjectPointsToPlane() into labelMap error:

A labelmap representation of this segmentation cannot be generated for some reason. I would recommend to post this question with some more details on how to reproduce the behavior to the Slicer forum.