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

**URL:** <https://discourse.vtk.org/t/how-to-use-vtkprojectpointstoplane-to-project-to-a-3d-object-to-a-special-plane/11221>\
**Category:** Development\
**Tags:** python, code\
**Created:** [April 16, 2023, 5:28pm UTC](https://discourse.vtk.org/t/how-to-use-vtkprojectpointstoplane-to-project-to-a-3d-object-to-a-special-plane/11221 "2023-04-16T17:28:10Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![jumbojing](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jumbojing/32/5578_2.png) [@jumbojing](https://discourse.vtk.org/u/jumbojing)\
**Post date:** [April 16, 2023, 5:28pm UTC](https://discourse.vtk.org/t/how-to-use-vtkprojectpointstoplane-to-project-to-a-3d-object-to-a-special-plane/11221/1 "2023-04-16T17:28:10Z")

</div>

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

 ![image](https://discourse.vtk.org/uploads/default/original/2X/4/4015dc76b310a2a3bba77358407b0e2ee5abf334.png)

```python
def pd2plaPj(mod, cp= [0,0,0], norm=[0,1,0]):
    norm = norm/np.dot(norm,norm)
    pd = Helper.getPd(mod)    
    p2plaFilter = vtk.vtkProjectPointsToPlane()
    p2plaFilter.SetInputData(pd)
    p2plaFilter.SetProjectionTypeToSpecifiedPlane()
    p2plaFilter.SetOrigin(cp)
    p2plaFilter.SetNormal(norm)
    p2plaFilter.Update()
    return p2plaFilter.GetOutput()

```

```auto
pd2plaPj(mod) # Or norm is [1,0,0] Or [0,0,1]

```

get👇:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/9/98e5d3b45ecf3625d9234c134ac01a1f3fb8cc8a.png)

It’s very good!  
but …

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

```

got 👇 a 3D object(red)

 ![image](https://discourse.vtk.org/uploads/default/original/2X/4/4f563323719ed1c5f58852c71df42bfc13a975fa.png)

what’s wrong?

---

<div class="post-metadata">

**Author:** ![jumbojing](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jumbojing/32/5578_2.png) [@jumbojing](https://discourse.vtk.org/u/jumbojing)\
**Post date:** [April 16, 2023, 5:33pm UTC](https://discourse.vtk.org/t/how-to-use-vtkprojectpointstoplane-to-project-to-a-3d-object-to-a-special-plane/11221/2 "2023-04-16T17:33:02Z")

</div>

@lassoan 老师

---

<div class="post-metadata">

**Author:** ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)\
**Post date:** [April 16, 2023, 6:06pm UTC](https://discourse.vtk.org/t/how-to-use-vtkprojectpointstoplane-to-project-to-a-3d-object-to-a-special-plane/11221/3 "2023-04-16T18:06:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jumbojing](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jumbojing/32/5578_2.png) [@jumbojing](https://discourse.vtk.org/u/jumbojing)\
**Post date:** [April 16, 2023, 10:11pm UTC](https://discourse.vtk.org/t/how-to-use-vtkprojectpointstoplane-to-project-to-a-3d-object-to-a-special-plane/11221/4 "2023-04-16T22:11:49Z")

</div>

![image](https://discourse.vtk.org/uploads/default/original/2X/7/759bcbacfbced94885cb287770892e4205b0282f.png)

> [@lassoan](#):
>
> 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`?

---

<div class="post-metadata">

**Author:** ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)\
**Post date:** [April 16, 2023, 11:38pm UTC](https://discourse.vtk.org/t/how-to-use-vtkprojectpointstoplane-to-project-to-a-3d-object-to-a-special-plane/11221/5 "2023-04-16T23:38:54Z")

</div>

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](https://github.com/SlicerHeart/SlicerHeart/blob/bb7a14a48f52dad67142ff14339e23761e1829aa/ValveAnnulusAnalysis/HeartValveLib/ValveModel.py#L1438-L1509).

---

<div class="post-metadata">

**Author:** ![jumbojing](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jumbojing/32/5578_2.png) [@jumbojing](https://discourse.vtk.org/u/jumbojing)\
**Post date:** [April 17, 2023, 12:01am UTC](https://discourse.vtk.org/t/how-to-use-vtkprojectpointstoplane-to-project-to-a-3d-object-to-a-special-plane/11221/6 "2023-04-17T00:01:01Z")

</div>

![image](https://discourse.vtk.org/uploads/default/original/2X/5/5921efc7882313d55b57f084765bcec5988a6d75.png)  
@lassoan what’s wrong?

---

<div class="post-metadata">

**Author:** ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)\
**Post date:** [April 17, 2023, 12:26am UTC](https://discourse.vtk.org/t/how-to-use-vtkprojectpointstoplane-to-project-to-a-3d-object-to-a-special-plane/11221/7 "2023-04-17T00:26:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jumbojing](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jumbojing/32/5578_2.png) [@jumbojing](https://discourse.vtk.org/u/jumbojing)\
**Post date:** [April 17, 2023, 9:50am UTC](https://discourse.vtk.org/t/how-to-use-vtkprojectpointstoplane-to-project-to-a-3d-object-to-a-special-plane/11221/8 "2023-04-17T09:50:44Z")

</div>

> [@jumbojing](#):
>
> vtkProjectPointsToPlane

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

---

<div class="post-metadata">

**Author:** ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)\
**Post date:** [April 17, 2023, 11:20am UTC](https://discourse.vtk.org/t/how-to-use-vtkprojectpointstoplane-to-project-to-a-3d-object-to-a-special-plane/11221/9 "2023-04-17T11:20:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jumbojing](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jumbojing/32/5578_2.png) [@jumbojing](https://discourse.vtk.org/u/jumbojing)\
**Post date:** [November 27, 2023, 11:48am UTC](https://discourse.vtk.org/t/how-to-use-vtkprojectpointstoplane-to-project-to-a-3d-object-to-a-special-plane/11221/10 "2023-11-27T11:48:34Z")

</div>

![image](https://discourse.vtk.org/uploads/default/original/2X/5/58ae077d3f28bb203057fc4f5192e2d903f0d261.png)

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

---

<div class="post-metadata">

**Author:** ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)\
**Post date:** [December 15, 2023, 2:54pm UTC](https://discourse.vtk.org/t/how-to-use-vtkprojectpointstoplane-to-project-to-a-3d-object-to-a-special-plane/11221/11 "2023-12-15T14:54:27Z")

</div>

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](https://discourse.slicer.org/).
