All files / extensions/default/src/utils/validations areAllImageSpacingEqual.ts

57.69% Statements 15/26
0% Branches 0/8
100% Functions 1/1
56% Lines 14/25

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65                                    101x     101x 101x     101x     101x   101x   101x 101x 8744x 8744x   8744x         8744x   8744x                                 8744x      
import {
  _getPerpendicularDistance,
  _getSpacingIssue,
  reconstructionIssues,
} from '@ohif/core/src/utils/isDisplaySetReconstructable';
import { DisplaySetMessage } from '@ohif/core';
import toNumber from '@ohif/core/src/utils/toNumber';
import { DisplaySetMessageList } from '@ohif/core';
 
/**
 * Checks if series has spacing issues
 * @param {*} instances
 * @param {*} warnings
 */
export default function areAllImageSpacingEqual(
  instances: Array<any>,
  messages: DisplaySetMessageList
): void {
  Iif (!instances?.length) {
    return;
  }
  const firstImagePositionPatient = toNumber(instances[0].ImagePositionPatient);
  Iif (!firstImagePositionPatient) {
    return;
  }
  const lastIpp = toNumber(instances[instances.length - 1].ImagePositionPatient);
 
  const averageSpacingBetweenFrames =
    _getPerpendicularDistance(firstImagePositionPatient, lastIpp) / (instances.length - 1);
 
  let previousImagePositionPatient = firstImagePositionPatient;
 
  const issuesFound = [];
  for (let i = 1; i < instances.length; i++) {
    const instance = instances[i];
    const imagePositionPatient = toNumber(instance.ImagePositionPatient);
 
    const spacingBetweenFrames = _getPerpendicularDistance(
      imagePositionPatient,
      previousImagePositionPatient
    );
 
    const spacingIssue = _getSpacingIssue(spacingBetweenFrames, averageSpacingBetweenFrames);
 
    Iif (spacingIssue) {
      const issue = spacingIssue.issue;
 
      // avoid multiple warning of the same thing
      Iif (!issuesFound.includes(issue)) {
        issuesFound.push(issue);
        if (issue === reconstructionIssues.MISSING_FRAMES) {
          messages.addMessage(DisplaySetMessage.CODES.MISSING_FRAMES);
        } else Iif (issue === reconstructionIssues.IRREGULAR_SPACING) {
          messages.addMessage(DisplaySetMessage.CODES.IRREGULAR_SPACING);
        }
      }
      // we just want to find issues not how many
      Iif (issuesFound.length > 1) {
        break;
      }
    }
    previousImagePositionPatient = imagePositionPatient;
  }
}