Skip to content

Commit

Permalink
Make getOrientationName broader
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmartel committed Apr 25, 2024
1 parent b570424 commit 74cea12
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
22 changes: 8 additions & 14 deletions src/dicom/dicomParser.js
Expand Up @@ -14,8 +14,11 @@ import {
} from './dictionary';
import {DataReader} from './dataReader';
import {logger} from '../utils/logger';
import {arrayEquals} from '../utils/array';
import {Orientation} from '../math/orientation';
import {
getOrientationFromCosines,
getOrientationStringLPS,
getLPSGroup
} from '../math/orientation';

// doc imports
/* eslint-disable no-unused-vars */
Expand Down Expand Up @@ -197,18 +200,9 @@ export function getReverseOrientation(ori) {
* @returns {string} The orientation name: axial, coronal or sagittal.
*/
export function getOrientationName(orientation) {
const axialOrientation = [1, 0, 0, 0, 1, 0];
const coronalOrientation = [1, 0, 0, 0, 0, -1];
const sagittalOrientation = [0, 1, 0, 0, 0, -1];
let name;
if (arrayEquals(orientation, axialOrientation)) {
name = Orientation.Axial;
} else if (arrayEquals(orientation, coronalOrientation)) {
name = Orientation.Coronal;
} else if (arrayEquals(orientation, sagittalOrientation)) {
name = Orientation.Sagittal;
}
return name;
const orientMatrix = getOrientationFromCosines(orientation);
const lpsStr = getOrientationStringLPS(orientMatrix.asOneAndZeros());
return getLPSGroup(lpsStr);
}

/**
Expand Down
23 changes: 22 additions & 1 deletion src/math/orientation.js
Expand Up @@ -146,6 +146,27 @@ function getVectorStringLPS(vector) {
return orientation;
}

/**

Check warning on line 149 in src/math/orientation.js

View workflow job for this annotation

GitHub Actions / build

Missing JSDoc @param "code" declaration
* Get the LPS 'group' (axial, coronal or sagittal) from a LPS code.
*
* @param {string} lps The LPS code string.

Check failure on line 152 in src/math/orientation.js

View workflow job for this annotation

GitHub Actions / build

JSDoc '@param' tag has name 'lps', but there is no parameter with that name.

Check warning on line 152 in src/math/orientation.js

View workflow job for this annotation

GitHub Actions / build

Expected @param names to be "code". Got "lps"
* @returns {string} The group.
*/
export function getLPSGroup(code) {
let orientStr;
const axialCodes = ['LPS', 'LAI', 'RPI', 'RAS'];
const coronalCodes = ['LSA', 'LIP', 'RSP', 'RIA'];
const sagittalCodes = ['PSL', 'PIR', 'ASR', 'AIL'];
if (axialCodes.includes(code)) {
orientStr = Orientation.Axial;
} else if (coronalCodes.includes(code)) {
orientStr = Orientation.Coronal;
} else if (sagittalCodes.includes(code)) {
orientStr = Orientation.Sagittal;
}
return orientStr;
}

/**
* Get the orientation matrix associated to the direction cosines.
*
Expand All @@ -166,4 +187,4 @@ export function getOrientationFromCosines(cosines) {
]);
}
return orientationMatrix;
}
}
6 changes: 6 additions & 0 deletions tests/dicom/dicomParser.test.js
Expand Up @@ -274,10 +274,16 @@ QUnit.test('DICOMDIR parsing - #DWV-REQ-IO-02-004 Load DICOMDIR URL',
QUnit.test('getOrientationName', function (assert) {
const test00 = [1, 0, 0, 0, 1, 0];
assert.equal(getOrientationName(test00), 'axial', 'test axial #0');
const test01 = [0.99, 0.02, 0.05, -0.02, 0.99, 1.4e-08];
assert.equal(getOrientationName(test01), 'axial', 'test axial #1');

const test10 = [1, 0, 0, 0, 0, -1];
assert.equal(getOrientationName(test10), 'coronal', 'test coronal #0');
const test11 = [0.7, 0.3, 0, 0, 0.4, -0.6];
assert.equal(getOrientationName(test11), 'coronal', 'test coronal #1');

const test20 = [0, 1, 0, 0, 0, -1];
assert.equal(getOrientationName(test20), 'sagittal', 'test sagittal #0');
const test21 = [-0.01, 0.98, -0.20, 0.05, -0.19, -0.98];
assert.equal(getOrientationName(test21), 'sagittal', 'test axial #1');
});

0 comments on commit 74cea12

Please sign in to comment.