# Display model in slice viewer

**URL:** <https://discourse.slicer.org/t/display-model-in-slice-viewer/208>\
**Category:** Development\
**Created:** [April 27, 2017, 11:28am UTC](https://discourse.slicer.org/t/display-model-in-slice-viewer/208 "2017-04-27T11:28:36Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mag](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@mag](https://discourse.slicer.org/u/mag)\
**Post date:** [April 27, 2017, 11:28am UTC](https://discourse.slicer.org/t/display-model-in-slice-viewer/208/1 "2017-04-27T11:28:36Z")

</div>

Hi, I am trying to draw a polygon on the axial viewer given the coordinates of some fiducial points. I am using a model created from a polydata object so I can easily export it for my analysis.  
I used this code in a scripted module and the polygon is correctly displayed in the 3D view but I don’t know how to display it in the red view as well, which is what I need. Is that possible?  
I’ve attached a screenshot at the end.

fidList = slicer.util.getNode(‘F’)  
if not fidList:  
print “No points found”  
return  
numFids = fidList.GetNumberOfFiducials()

points = vtk.vtkPoints()  
polygon = vtk.vtkPolygon()  
polygon.GetPointIds().SetNumberOfIds(numFids)

points\_coords =   
for i in range(numFids):  
fid\_ras\_coord = [0, 0, 0]  
fidList.GetNthFiducialPosition(i, fid\_ras\_coord)  
points.InsertNextPoint(fid\_ras\_coord)  
polygon.GetPointIds().SetId(i, i)  
points\_coords.append(fid\_ras\_coord)

polygons = vtk.vtkCellArray()  
polygons.InsertNextCell(polygon)  
polygonPolyData = vtk.vtkPolyData()  
polygonPolyData.SetPoints(points)  
polygonPolyData.SetPolys(polygons)

model = slicer.vtkMRMLModelNode()  
model.SetAndObservePolyData(polygonPolyData)  
modelDisplay = slicer.vtkMRMLModelDisplayNode()

modelDisplay.SetColor(1, 1, 0)  
modelDisplay.BackfaceCullingOff()  
modelDisplay.SetOpacity(0.5)  
modelDisplay.SetPointSize(3)

modelDisplay.SetSliceIntersectionVisibility(True)  
modelDisplay.SetVisibility(True)  
slicer.mrmlScene.AddNode(modelDisplay)  
model.SetAndObserveDisplayNodeID(modelDisplay.GetID())  
modelDisplay.SetInputPolyDataConnection(model.GetPolyDataConnection())  
slicer.mrmlScene.AddNode(model)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/c/8cb7526feec9be95dfdbc9682abed55f679d5b17.jpeg)

---

<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:** [April 27, 2017, 12:29pm UTC](https://discourse.slicer.org/t/display-model-in-slice-viewer/208/2 "2017-04-27T12:29:43Z")

</div>

You can only see the intersection of the polydata with a slice, so the polydata has to be a 3D surface (theoretically it could be possible to have a 2D surface that is exactly aligned with the slice viewer, but in practice perfect alignment is often impossible to achieve).  
Fortunately, the `Markups to model` module in SlicerIGT extension does extactly that. It has several options for generating closed surface from a set of markups. It can do simple convex hull or smoothed contour with various options for making it more robust or accurate.

Simple quasi-planar surface generation:

 ![](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/1X/d145e35e9961e306dc31b7ff1753f2118627283e.jpg)

Smooth 3D surface generation:

 ![](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/1X/f0df0ce5445878118e78fe55c6e4b443275d89ab.jpg)

To generate the contours from your own module, you just need to add a vtkMRMLMarkupsToModelNode in your scene and set up its inputs and outputs. At minimum, call SetAndObserveMarkupsNodeID and SetAndObserveModelNodeID. See all methods and options at:  
[https://github.com/SlicerIGT/SlicerIGT/blob/master/MarkupsToModel/MRML/vtkMRMLMarkupsToModelNode.h](https://github.com/SlicerIGT/SlicerIGT/blob/master/MarkupsToModel/MRML/vtkMRMLMarkupsToModelNode.h)

---

<div class="post-metadata">

**Author:** ![mag](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@mag](https://discourse.slicer.org/u/mag)\
**Post date:** [April 28, 2017, 9:59am UTC](https://discourse.slicer.org/t/display-model-in-slice-viewer/208/3 "2017-04-28T09:59:42Z")

</div>

Thanks a lot for the reply.  
Now I can show the polygon in all the viewers using the IGT extension.  
However I could not figure out how to use vtkMRMLMarkupsToModelNode in my module. How do I set input and output?

Marta

---

<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:** [April 28, 2017, 8:30pm UTC](https://discourse.slicer.org/t/display-model-in-slice-viewer/208/4 "2017-04-28T20:30:35Z")

</div>

Example: drop a few fiducials and run this code

```
inputMarkups = getNode('F')

outputModel = slicer.mrmlScene.AddNode(slicer.vtkMRMLModelNode())
outputModel.CreateDefaultDisplayNodes()
outputModel.GetDisplayNode().SetSliceIntersectionVisibility(True)
outputModel.GetDisplayNode().SetColor(1,0,0)

markupsToModel = slicer.mrmlScene.AddNode(slicer.vtkMRMLMarkupsToModelNode())
markupsToModel.SetAutoUpdateOutput(True)
markupsToModel.SetAndObserveModelNodeID(outputModel.GetID())
markupsToModel.SetAndObserveMarkupsNodeID(inputMarkups.GetID())
```

---

<div class="post-metadata">

**Author:** ![labixin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/labixin/32/1965_2.png) [@labixin](https://discourse.slicer.org/u/labixin)\
**Post date:** [February 15, 2021, 3:15pm UTC](https://discourse.slicer.org/t/display-model-in-slice-viewer/208/5 "2021-02-15T15:15:27Z")

</div>

Thank you. I am creating a model (closed surface) based on points using Markups to Model module. The results are satisfactory. Is there any related literatures I could refer to? (for reference when describing algorithms in the scientific paper). Hope for some suggestions. Your help is highly appreciated!

Crayon

---

<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:** [February 15, 2021, 4:32pm UTC](https://discourse.slicer.org/t/display-model-in-slice-viewer/208/6 "2021-02-15T16:32:09Z")

</div>

Please cite [3D Slicer](https://slicer.readthedocs.io/en/latest/user_guide/about.html#how-to-cite) and in addition you can cite:

- [3D Slicer’s Markups to model extension](https://github.com/SlicerIGT/SlicerMarkupsToModel)
- [VTK library](https://vtk.org/vtk-textbook/)
- [Butterfly subdivision method](https://dl.acm.org/doi/pdf/10.1145/237170.237254)

---

<div class="post-metadata">

**Author:** ![slicer365](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/slicer365/32/67549_2.png) [@slicer365](https://discourse.slicer.org/u/slicer365)\
**Post date:** [February 21, 2025, 1:17pm UTC](https://discourse.slicer.org/t/display-model-in-slice-viewer/208/7 "2025-02-21T13:17:58Z")

</div>

Based on this, how to set the model’s radius?

MarkupsToModel.SetTubeRadius(5) like this ,it does not work

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [February 21, 2025, 1:30pm UTC](https://discourse.slicer.org/t/display-model-in-slice-viewer/208/8 "2025-02-21T13:30:41Z")

</div>

That function works, but only in curve mode

```auto
markupsToModel.SetModelType(slicer.vtkMRMLMarkupsToModelNode.Curve)

```
