Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions NaviNIBS/Navigator/GUI/ViewPanels/SubjectRegistrationPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,10 @@ def _onFidTblCurrentCellChanged(self, currentRow: int, currentCol: int, previous
lookAt = None
if lookAt is not None:
self._plotter.camera.focal_point = lookAt
vec = lookAt - subReg.approxHeadCenter
self._plotter.camera.position = lookAt + vec*10
headCenter = subReg.approxHeadCenter
if headCenter is not None:
vec = lookAt - headCenter
self._plotter.camera.position = lookAt + vec*10
self._plotter.reset_camera()

def _getSelectedFiducialKeys(self):
Expand Down
2 changes: 1 addition & 1 deletion NaviNIBS/Navigator/Model/SubjectRegistration.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def approxHeadCenter(self) -> tp.Optional[np.ndarray]:
lpa = self.fiducials.get('LPA', None)
rpa = self.fiducials.get('RPA', None)
if lpa is not None and rpa is not None and lpa.plannedCoord is not None and rpa.plannedCoord is not None:
center = (lpa + rpa) / 2
center = (lpa.plannedCoord + rpa.plannedCoord) / 2
else:
logger.warning('Insufficient information for determining approximate header center')
# TODO: implement more general method of estimating center, e.g. more variety of LPA/RPA naming, name-agnostic averaging, etc.
Expand Down
29 changes: 29 additions & 0 deletions tests/test_Model/test_subjectRegistrationCalcs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
Regression tests for SubjectRegistration derived values.
"""

import numpy as np

from NaviNIBS.Navigator.Model.SubjectRegistration import SubjectRegistration, Fiducial


def test_approxHeadCenterAveragesPlannedCoords():
"""
Previously averaged the Fiducial objects themselves instead of their
planned coordinates, raising TypeError whenever LPA and RPA were planned.
"""
sr = SubjectRegistration()
sr.fiducials.addItem(Fiducial(key='LPA', plannedCoord=np.array([-80., 0., -40.])))
sr.fiducials.addItem(Fiducial(key='RPA', plannedCoord=np.array([80., 0., -40.])))

center = sr.approxHeadCenter
assert center is not None
np.testing.assert_allclose(center, np.array([0., 0., -40.]))


def test_approxHeadCenterMissingFiducials():
sr = SubjectRegistration()
assert sr.approxHeadCenter is None

sr.fiducials.addItem(Fiducial(key='LPA', plannedCoord=np.array([-80., 0., -40.])))
assert sr.approxHeadCenter is None