Get normal vector of a model mesh at fiducial marker

Hi everyone!
I´d like to get the normal vector of a model surface at a marked point with a fiducial.
Is there any example in the script repository for this task?

Thanks on advance…

Here is the code:

fiducial = getNode('F')
model = getNode('Model')

point = [0,0,0]
fiducial.GetNthFiducialPosition(0,point)

normalsOfModel = slicer.util.arrayFromModelPointData(model, 'Normals')

modelMesh = model.GetMesh()

pointID = modelMesh.FindPoint(point)

normalAtPointID = normalsOfModel[pointID]

It gives the normal of the nearest-model-point to the fiducial-point

3 Likes

It gives me some kind of problem @mau_igna_06 :

AppData\Local\NA-MIC\Slicer 4.13.0-2021-02-16\bin\Python\slicer\util.py", line 1505, in _vtkArrayFromModelData
location, arrayName, “', '”.join(availableArrayNames)))
ValueError: Input modelNode does not contain point data array ‘Normals’. Available array names: ‘RegionId’

It look like modelNode hasn´t normals info…

You can compute normals using Surface Toolbox module.

1 Like