fn qform_for(affine: &[f64; 16], pixdim: (f64, f64, f64)) -> Option<QForm>Expand description
The qform to write alongside an sform, or None when no quaternion reproduces the affine.
Every file this crate writes carries an sform, and for a long time that was all it carried:
qform_code and the quaternion fields were left at zero. That is spec-legal — a reader is
meant to fall back to method 1, the bare pixdim scaling — but it is not what readers
actually show. fslhd and friends print a qto_xyz derived from the all-zero quaternion
regardless, so every output looked as though it had been silently reoriented to a canonical
axial frame with no translation, disagreeing with the sform beside it (QSMxT#240). Writing a
real qform is what those tools want, so that is what we do.
pixdim has to be the voxel size as written to the header, because method 2 scales the
quaternion’s rotation by it. An affine whose column norms disagree with pixdim therefore
cannot be expressed as a qform even when its rotation is exact, and that is one of two ways
the attempt can fail; shear is the other. Both are caught the same way — rebuild the affine a
reader would derive and compare — so a qform is only ever advertised when it is the sform.