Hi all,
In 3d slicer, I have a point (x,y,z) -a fiducial- into a brain 3D model (mesh). Without changing the x and y coordinates, I would like to create a new point where the z coordinate will be at the top of the mesh. Do you know how could I do that (perhaps by the different voxel value between the inside/outside of the mesh)?
Itâs relatively easy to do with some python scripting. Something like this
m=getNode('Segment_1')
mp=m.GetPolyData()
top=-10.0**11
for i in xrange(0, mp.GetNumberOfPoints()):
p=mp.GetPoint(i)
if p[2] > top:
top = p[2]
f=getNode('F')
fp=[0]*4
f.GetNthFiducialWorldCoordinates(0,fp)
fp[2] = top
f.SetNthFiducialWorldCoordinates(0,fp)
Please note that this is very simplistic (does not account for transforms on the model or the fiducial), and the code snippet is very sloppy (not dynamic, bad variable names etc), but it can be a good starting point.
To get the âtopâ point, you can also use GetBounds() method of the vtkPolyData instead of iterating through all the points (which may take long time for large meshes).
If you load the model from file using this script, then you already have the model node in the variable called âmodelâ, so you donât need to find it in the scene.
Note that the name of the model will not be the full path. If you drag&drop the model and want to know its name, Go to Data module and see the name of your model. Enter the model name instead of âfilenameâ.
A gerenal advice is that in the python interactor you can type commands one by one. After each command itâs prudent to see if the variable contains what you expect or not. The error you got happens because the value of variable âmâ will be None.