Overlay model with original image in slicer

G_Tom
Fri, 08 Dec 2023 21:02:26 +0000
Support

Hi, I have the following MWE code in slicer. I want to show the 3D grid of the image along with the image. I use the vtkExtractEdges and pass that to a vtkTubeFilter.
When I visualize the result, the extracted grid is much smaller than the original image? What gives ? Please see image below.

Thanks

import os

nodeName = "MyNewVolume"
imageSize = [4, 6, 4]
voxelType=vtk.VTK_UNSIGNED_CHAR
imageOrigin = [0.0, 0.0, 0.0]
imageSpacing = [13.0, 13.0, 13.0]
imageDirections = [[1,0,0], [0,1,0], [0,0,1]]
fillVoxelValue = 500

# Create an empty image volume, filled with fillVoxelValue
imageData = vtk.vtkImageData()
imageData.SetDimensions(imageSize)
imageData.AllocateScalars(voxelType, 1)
imageData.GetPointData().GetScalars().Fill(fillVoxelValue)

extractEdges = vtk.vtkExtractEdges()
extractEdges.SetInputData(imageData)

# Tube the edges
tubes = vtk.vtkTubeFilter()
tubes.SetInputConnection(extractEdges.GetOutputPort())
tubes.SetRadius(0.008)
tubes.SetNumberOfSides(32)

model = slicer.modules.models.logic().AddModel(tubes.GetOutputPort())

# Create volume node
volumeNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLScalarVolumeNode", nodeName)
volumeNode.SetOrigin(imageOrigin)
volumeNode.SetSpacing(imageSpacing)
volumeNode.SetIJKToRASDirections(imageDirections)
volumeNode.SetAndObserveImageData(imageData)
volumeNode.CreateDefaultDisplayNodes()
volumeNode.CreateDefaultStorageNode()

4 posts - 2 participants