extensions/xnat/src/utils/IO/classes/NIFTIReader.js
/**
   * _compareSliceOrientation - Checks the orientation of the NIFTI slices in
   *                            relation to the scan data.
   *
   * @param  {object} imagePositionPatient  The imagePositionPatient of the
   *                                        first image in the series.
   * @param  {object} firstVoxelInDicomPCSFrame The position of the the first
   *                                            voxel of the NIFTI in the PCS.
   * @param  {number} tol                       The tolerance.
   * @returns {string}  A string that indicates if the NIFTI slices are in the
   *                    same orienation as the DICOM or if they are flipped.
   */
Checks the orientation of the NIFTI slices in
relation to the scan data.

@param  {object} imagePositionPatient  The imagePositionPatient of the
first image in the series.
@param  {object} firstVoxelInDicomPCSFrame The position of the the first
voxel of the NIFTI in the PCS.
@param  {number} tol                       The tolerance.
@returns {string}  A string that indicates if the NIFTI slices are in the
same orienation as the DICOM or if they are flipped.
Checks the orientation of the NIFTI slices in relation to the scan data . @param { object } imagePositionPatient The imagePositionPatient of the first image in the series . @param { object } firstVoxelInDicomPCSFrame The position of the the first voxel of the NIFTI in the PCS . @param { number } tol The tolerance . @returns { string } A string that indicates if the NIFTI slices are in the same orienation as the DICOM or if they are flipped .
_compareSliceOrientation(
    imagePositionPatient,
    firstVoxelInDicomPCSFrame,
    tol
  ) {
    if (
      Math.abs(imagePositionPatient.x) -
        Math.abs(firstVoxelInDicomPCSFrame[0]) <
        tol &&
      Math.abs(imagePositionPatient.y) -
        Math.abs(firstVoxelInDicomPCSFrame[1]) <
        tol
    ) {
      if (
        Math.sign(imagePositionPatient.x) ===
        Math.sign(firstVoxelInDicomPCSFrame[0])
      ) {
        return 'same';
      }
      return 'reverse';
    }
    throw new Error(
      `x-y plane does not coincide with DICOM, Either these images have totally
      different frame of references or we need to implement more clever method to map NIFTI.`
    );
  }
_compareSliceOrientation ( imagePositionPatient , firstVoxelInDicomPCSFrame , tol ) { if ( Math . abs ( imagePositionPatient . x ) - Math . abs ( firstVoxelInDicomPCSFrame [ 0 ] ) < tol && Math . abs ( imagePositionPatient . y ) - Math . abs ( firstVoxelInDicomPCSFrame [ 1 ] ) < tol ) { if ( Math . sign ( imagePositionPatient . x ) === Math . sign ( firstVoxelInDicomPCSFrame [ 0 ] ) ) { return 'same' ; } return 'reverse' ; } throw new Error ( ` ` ) ; }
_compareSliceOrientation - Checks the orientation of the NIFTI slices in
                            relation to the scan data.
_compareSliceOrientation - Checks the orientation of the NIFTI slices in relation to the scan data .
// TODO -> This isn't exhaustive yet, just the most common eventualities between NIFTI <--> DICOM. // Close, are the images flipped? // Same direction, each slice has same X-Y mapping. // TODO -> Maybe only one direction is flipped? You'd assume either it was in Radialogical or // Neurological frame of reference, but perhaps we could get some ugly half way house? // Assume flipped in x and y per slice.