# How to Create a zero thickness plane in 3D slicer?

**URL:** <https://discourse.slicer.org/t/how-to-create-a-zero-thickness-plane-in-3d-slicer/20743>\
**Category:** Support\
**Tags:** segmentation\
**Created:** [November 23, 2021, 8:12am UTC](https://discourse.slicer.org/t/how-to-create-a-zero-thickness-plane-in-3d-slicer/20743 "2021-11-23T08:12:53Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sliceeeeee](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sliceeeeee/32/12358_2.png) [@Sliceeeeee](https://discourse.slicer.org/u/Sliceeeeee)\
**Post date:** [November 23, 2021, 8:12am UTC](https://discourse.slicer.org/t/how-to-create-a-zero-thickness-plane-in-3d-slicer/20743/1 "2021-11-23T08:12:53Z")

</div>

Hello

I have made 3d model of nasal cavity ,now I want to add another segment in which I will create a plane surface with zero thickness , how can I do that?

---

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [November 23, 2021, 12:52pm UTC](https://discourse.slicer.org/t/how-to-create-a-zero-thickness-plane-in-3d-slicer/20743/2 "2021-11-23T12:52:13Z")

</div>

If you want a model. You can add a modelNode to the scene and set its polydata from `vtk.vtkPlaneSource()`

I’m sure you’ll find vtk examples on how to use that filter and you can use this from the [scriptRepository](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#define-edit-a-circular-region-of-interest-in-a-slice-viewer):

```auto
# Create model node and add to scene
modelsLogic = slicer.modules.models.logic()
model = modelsLogic.AddModel(sphere.GetOutput())

```

Instead of sphere it should be your plane.

---

<div class="post-metadata">

**Author:** ![Sliceeeeee](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sliceeeeee/32/12358_2.png) [@Sliceeeeee](https://discourse.slicer.org/u/Sliceeeeee)\
**Post date:** [November 23, 2021, 7:12am UTC](https://discourse.slicer.org/t/how-to-create-a-zero-thickness-plane-in-3d-slicer/20743/4 "2021-11-23T07:12:26Z")

</div>

Hello Sir

How can I make a plane of zero thickness in 3D slicer ?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 23, 2021, 3:29pm UTC](https://discourse.slicer.org/t/how-to-create-a-zero-thickness-plane-in-3d-slicer/20743/5 "2021-11-23T15:29:05Z")

</div>

Markups plane node is a plane of zero thickness.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/3/b/3b46f6ac860bbe42adfa5919de59125d9214802a.png)

---

<div class="post-metadata">

**Author:** ![Sliceeeeee](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sliceeeeee/32/12358_2.png) [@Sliceeeeee](https://discourse.slicer.org/u/Sliceeeeee)\
**Post date:** [November 23, 2021, 3:42pm UTC](https://discourse.slicer.org/t/how-to-create-a-zero-thickness-plane-in-3d-slicer/20743/6 "2021-11-23T15:42:29Z")

</div>

But can I export this plane as a STL geometry , how can I do that please help

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 23, 2021, 4:05pm UTC](https://discourse.slicer.org/t/how-to-create-a-zero-thickness-plane-in-3d-slicer/20743/7 "2021-11-23T16:05:25Z")

</div>

You can save the plane as a json file, which contains the plane position and normal, size, etc. You can also create a model node from the markup node using this code snippet that can be saved as STL, PLY, etc. file format:

```python
planeNode = getNode('P')

# Get plane geometry
import numpy as np
origin = np.array(planeNode.GetOriginWorld())
axisX = np.zeros(3)
axisY = np.zeros(3)
axisZ = np.zeros(3)
planeNode.GetAxesWorld(axisX, axisY, axisZ)
corner = origin - 0.5 * size[0]*axisX - 0.5 * size[1]*axisY
size = planeNode.GetSize()

# Create polygonal mesh model that can be saved as ply, obj, stl,... file
planeSource = vtk.vtkPlaneSource()
planeSource.SetOrigin(corner)
planeSource.SetPoint1(corner+size[0]*axisX)
planeSource.SetPoint2(corner+size[1]*axisY)
planeModel = slicer.modules.models.logic().AddModel(planeSource.GetOutputPort())

```

Why do you need this plane as an STL file?

---

<div class="post-metadata">

**Author:** ![Sliceeeeee](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sliceeeeee/32/12358_2.png) [@Sliceeeeee](https://discourse.slicer.org/u/Sliceeeeee)\
**Post date:** [November 23, 2021, 6:55pm UTC](https://discourse.slicer.org/t/how-to-create-a-zero-thickness-plane-in-3d-slicer/20743/8 "2021-11-23T18:55:56Z")

</div>

Where should I write the code? I am not getting any option

---

<div class="post-metadata">

**Author:** ![Sliceeeeee](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sliceeeeee/32/12358_2.png) [@Sliceeeeee](https://discourse.slicer.org/u/Sliceeeeee)\
**Post date:** [November 24, 2021, 5:30am UTC](https://discourse.slicer.org/t/how-to-create-a-zero-thickness-plane-in-3d-slicer/20743/9 "2021-11-24T05:30:21Z")

</div>

I need this plane because i will use this plane to select patches in my geometry for giving boundary conditions

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 24, 2021, 1:43pm UTC](https://discourse.slicer.org/t/how-to-create-a-zero-thickness-plane-in-3d-slicer/20743/10 "2021-11-24T13:43:04Z")

</div>

Your can open the Python console from the View menu.

---

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [December 22, 2022, 10:33pm UTC](https://discourse.slicer.org/t/how-to-create-a-zero-thickness-plane-in-3d-slicer/20743/11 "2022-12-22T22:33:11Z")

</div>

This code works for any [vtkMRMLMarkupsPlaneNode](https://apidocs.slicer.org/master/classvtkMRMLMarkupsPlaneNode.html) _(any sizeMode, any planeType)_:

```auto
planeNode = getNode('P')

cornerPoints = vtk.vtkPoints()
planeNode.GetPlaneCornerPoints(cornerPoints)

from vtk.util.numpy_support import vtk_to_numpy
cornerPoints_np = vtk_to_numpy(cornerPoints.GetData())

import numpy as np
def sort_points(pts):
    """Sort 4 points in a winding order"""
    pts = np.array(pts)
    centroid = np.sum(pts, axis=0) / pts.shape[0]
    vector_from_centroid = pts - centroid
    vector_angle = np.arctan2(
        vector_from_centroid[:, 1], vector_from_centroid[:, 0])
    # Find the indices that give a sorted vector_angle array
    sort_order = np.argsort(-vector_angle)
    # Apply sort_order to original pts array.
    return list(sort_order)

order = sort_points(cornerPoints_np)

# Create polygonal mesh model that can be saved as ply, obj, stl,... file
planeSource = vtk.vtkPlaneSource()
planeSource.SetOrigin(cornerPoints_np[order[0]])
planeSource.SetPoint1(cornerPoints_np[order[1]])
planeSource.SetPoint2(cornerPoints_np[order[-1]])
planeModel = slicer.modules.models.logic().AddModel(planeSource.GetOutputPort())

```

Hope it helps

---

<div class="post-metadata">

**Author:** ![VincentYu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/vincentyu/32/69793_2.png) [@VincentYu](https://discourse.slicer.org/u/VincentYu)\
**Post date:** [July 12, 2023, 2:40am UTC](https://discourse.slicer.org/t/how-to-create-a-zero-thickness-plane-in-3d-slicer/20743/12 "2023-07-12T02:40:17Z")

</div>

```auto
corner = origin - 0.5 * size[0]*axisX - 0.5 * size[1]*axisY
size = planeNode.GetSize()

```

These two lines seems have to be swapped since the variable “size” is used before defined?  
Thank you, prof. Lasso, this code is helpful !
