Exporting a model to STL with markups

I have a model and have a point list of markups on the model, How do i export this model to STL with the control points?

You could use a Python snippet like this

fiducialNode = getNode('F')
import numpy as np
sphereSource = vtk.vtkSphereSource()
for i in range(fiducialNode.GetNumberOfControlPoints()):
  p = np.zeros(3)
  fiducialNode.GetNthControlPointPosition(i, p)
  fiducialModel = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLModelNode', f'Model_{fiducialNode.GetName()}_{i}')
  polyData = vtk.vtkPolyData()

Please note you’ll need to replace the name of your fiducial node (in my example it is F) and set the sphere radius as desired.

Once you have the model nodes you can append them together in Dynamic Modeler module’s Append feature, then export to STL.


Alternatively, you can use a glyph filter like this:

markup = getNode('F')
glyph = vtk.vtkSphereSource()
glypher = vtk.vtkGlyph3D()
model = slicer.modules.models.logic().AddModel(glypher.GetOutputPort())
slicer.util.saveNode(model, "c:/tmp/something.stl")

Both of the above mentioned solutions work perfectly, i can now export a model that has all the points on it. Thank You.
Would it be possible to have the points and the model to be in different colors? When i use the Append feature in Dynamic Modeler the final Model is of all the same color, i would prefer if the points and my model where of different colours.

Can this be extended to a curve? If my markups are in the form of a curve, can that be exported to an STL?

Yes, it works exactly the same way for curves, just replace the glyph filter by tube filter.

1 Like