Operating system: macOS
Slicer version: 4.3 & 4.7
Hi everyone,
While I was building a tractography display, Slicer allows me to export it as a *.obj file, however, it fails to export the labels file. Thus, when I try to open that *.obj file in any 3D modeler, it does not have the colors associated with the tractography analysis.
I already read the thread Export a tractography display as a 3D file, but the code provided by James and Steve does not seem to work on Slicer 4.3 nor Slicer 4.7.
Can anyone help me out with this? Is is possible to merge the label files with the object/model file?
I used the following source-code:
Slicer 4.3
plyFilePath = “/tmp/fibers.ply”
lineDisplayNode = getNode(“LineDisplay”)
tuber = vtk.vtkTubeFilter()
tuber.SetInput(lineDisplayNode.GetOutputPolyData())
tubes = tuber.GetOutput()
tubes.Update()
scalars = tubes.GetPointData().GetArray(0)
scalars.SetName(“scalars”)
triangles = vtk.vtkTriangleFilter()
triangles.SetInput(tubes)
colorNode = lineDisplayNode.GetColorNode()
lookupTable = vtk.vtkLookupTable()
lookupTable.DeepCopy(colorNode.GetLookupTable())
lookupTable.SetTableRange(0,1)
plyWriter = vtk.vtkPLYWriter()
plyWriter.SetInput(triangles.GetOutput())
plyWriter.SetLookupTable(lookupTable)
plyWriter.SetArrayName(“scalars”)
plyWriter.SetFileName(plyFilePath)
plyWriter.Write()
Slicer 4.7 (James mentioned it was untested and it does not effectively work)
plyFilePath = “/tmp/fibers.ply”
lineDisplayNode = getNode(“LineDisplay”)
tuber = vtk.vtkTubeFilter()
tuber.SetInputData(lineDisplayNode.GetOutputPolyData())
tubes = tuber.GetOutputData()
tubes.Update()
scalars = tubes.GetPointData().GetArray(0)
scalars.SetName(“scalars”)
triangles = vtk.vtkTriangleFilter()
triangles.SetInputConnection(tubes)
colorNode = lineDisplayNode.GetColorNode()
lookupTable = vtk.vtkLookupTable()
lookupTable.DeepCopy(colorNode.GetLookupTable())
lookupTable.SetTableRange(0,1)
plyWriter = vtk.vtkPLYWriter()
plyWriter.SetInputConnection(triangles.GetOutputPort())
plyWriter.SetLookupTable(lookupTable)
plyWriter.SetArrayName(“scalars”)
plyWriter.SetFileName(plyFilePath)
plyWriter.Write()
Thanks in advance,
Vasco Pontinha