How can I use the module of "Markups to Model" in command line?

Hi
Dear developers and users

How can I use the module of “Markups to Model” in command line?
I noticed that I can create a tube model around of centerline using the module of “Markups to Model” . At now, I want create this tube using this module in the command line. How can I do it?
Is it another module to create the tube around centerline?

Please guide me.
Shahrokh

Hi shahrokh,

You mean through python interactor?

There is no public function in the module yet to do this, but I can add one. In the meantime you can use vtk.vtkTubeFilter (https://www.vtk.org/doc/nightly/html/classvtkTubeFilter.html) to create tube poly data around the points. Something like this (note I haven’t personally tried running this so you may need to tweak it):

  numPoints = pointsToConnect.GetNumberOfPoints()
  lineCellArray = vtk.vtkCellArray()
  lineCellArray.InsertNextCell( numPoints )

  for i in xrange(0,numPoints)
  {
    lineCellArray.InsertCellPoint( i )
  }

  linePolyData = vtk.vtkPolyData()
  linePolyData.SetPoints( pointsToConnect )
  linePolyData.SetLines( lineCellArray )

  tubeSegmentFilter = vtk.vtkTubeFilter()
  tubeSegmentFilter.SetInputData( linePolyData )
  tubeSegmentFilter.SetRadius( tubeRadius ) #INSERT VALUE
  tubeSegmentFilter.SetNumberOfSides( tubeNumberOfSides ) #INSERT VALUE
  tubeSegmentFilter.CappingOn()
  tubeSegmentFilter.Update()

  # Access poly data by calling tubeSegmentFilter.GetOutput()

If you want to assign it to a vtkMRMLModelNode you’ll need to do:

  modelNode.SetAndObservePolyData( tubeSegmentFilter.GetOutput() )
  modelNode.CreateDefaultDisplayNodes()

I hope that helps. If it doesn’t answer your question please let me know.

Thomas

Hello
Dear Thomas,

Thanks a lot for your guidance. At now, I want to create tube poly data around the points in my vtp centerline file according with your commands.
I have some problems to do it.
I enter the following commands in python interactor of Slicer.

import vtk
filename = “~/centerlineRodCT001.vtp”
reader = vtk.vtkXMLPolyDataReader()
reader.SetFileName(filename)
reader.Update()
numPoints = reader.GetNumberOfPoints()
lineCellArray = vtk.vtkCellArray()
lineCellArray.InsertNextCell(numPoints)
for i in range(0,numPoints):
lineCellArray.InsertCellPoint( i )
linePolyData = vtk.vtkPolyData()
linePolyData.SetPoints(reader)

At this moment, I get the following error.
Traceback (most recent call last):
File “”, line 1, in
TypeError: SetPoints argument 1: method requires a vtkPoints, a vtkXMLPolyDataReader was provided.

Please guide me. How can I get vtkPoints argument?
Best regards,
Shahrokh

Excuse me. Unfortunately I can not find any python code example about reading centelines vtp file and applying vtktubefilter to it. Please let me know where I wrong it.
Thanks a lot.
Shahrokh

Assuming that the points saved in the file are already in the correct order…

This should get you a vtkPolyData object:
polydata = reader.GetOutput()

This should get you a vtkPoints object from the vtkPolyData object:
points = polydata.GetPoints()

Dear Thomas
Thanks a lot for your guidance. I’m sure this solves my problem.
Best regards.

Dear Thomas

Thanks a lot for your guidance. Finally, I can create a tube around the centerline vtp file with the following lines:

import vtk

filename = “/home/sn/centerlineRodCT001.vtp”
reader = vtk.vtkXMLPolyDataReader()
reader.SetFileName(filename)
reader.Update()
polydata = reader.GetOutput()
points = polydata.GetPoints()
numPoints = reader.GetNumberOfPoints()
lineCellArray = vtk.vtkCellArray()
lineCellArray.InsertNextCell(numPoints)
for i in range(0,numPoints):
lineCellArray.InsertCellPoint( i )
linePolyData = vtk.vtkPolyData()
linePolyData.SetPoints(points)
linePolyData.SetLines( lineCellArray )
tubeSegmentFilter = vtk.vtkTubeFilter()
tubeSegmentFilter.SetInputData( linePolyData )
tubeSegmentFilter.SetRadius(2)
tubeSegmentFilter.SetNumberOfSides(10)
tubeSegmentFilter.SetOutputPointsPrecision(1)
tubeSegmentFilter.CappingOn()
tubeSegmentFilter.Update()
tubeSegmentFilter.GetOutput()
writer = vtk.vtkXMLPolyDataWriter()
writer.SetFileName(“tube.vtp”)
writer.SetInputDataObject(tubeSegmentFilter.GetOutput())
writer.Write()

Best regards,
Shahrokh