Skip to content

Commit

Permalink
Add getOrientationFromCosines
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmartel committed Apr 25, 2024
1 parent a080f12 commit 2bf2845
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
21 changes: 3 additions & 18 deletions src/dicom/dicomElementsWrapper.js
Expand Up @@ -13,8 +13,7 @@ import {
getTagFromKey
} from './dicomTag';
import {isNativeLittleEndian} from './dataReader';
import {Vector3D} from '../math/vector';
import {Matrix33} from '../math/matrix';
import {getOrientationFromCosines} from '../math/matrix';
import {Spacing} from '../image/spacing';
import {logger} from '../utils/logger';

Expand Down Expand Up @@ -698,22 +697,8 @@ export function getOrientationMatrix(dataElements) {
// slice orientation (cosines are matrices' columns)
// http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.6.2.html#sect_C.7.6.2.1.1
if (typeof imageOrientationPatient !== 'undefined') {
const rowCosines = new Vector3D(
parseFloat(imageOrientationPatient.value[0]),
parseFloat(imageOrientationPatient.value[1]),
parseFloat(imageOrientationPatient.value[2]));
const colCosines = new Vector3D(
parseFloat(imageOrientationPatient.value[3]),
parseFloat(imageOrientationPatient.value[4]),
parseFloat(imageOrientationPatient.value[5]));
const normal = rowCosines.crossProduct(colCosines);
/* eslint-disable array-element-newline */
orientationMatrix = new Matrix33([
rowCosines.getX(), colCosines.getX(), normal.getX(),
rowCosines.getY(), colCosines.getY(), normal.getY(),
rowCosines.getZ(), colCosines.getZ(), normal.getZ()
]);
/* eslint-enable array-element-newline */
orientationMatrix =
getOrientationFromCosines(imageOrientationPatient.value);
}
return orientationMatrix;
}
Expand Down
28 changes: 28 additions & 0 deletions src/math/matrix.js
Expand Up @@ -498,4 +498,32 @@ function getVectorStringLPS(vector) {
}

return orientation;
}

/**
* Get the orientation matrix associated to the direction cosines.
* *

Check failure on line 505 in src/math/matrix.js

View workflow job for this annotation

GitHub Actions / build

Expected 1 lines after block description

Check warning on line 505 in src/math/matrix.js

View workflow job for this annotation

GitHub Actions / build

Should be no multiple asterisks on middle lines
* @param {number[]} cosines The direction cosines.
* @returns {Matrix33} The orientation matrix.
*/
export function getOrientationFromCosines(cosines) {
let orientationMatrix;
if (typeof cosines !== 'undefined' && cosines.length === 6) {
const rowCosines = new Vector3D(
parseFloat(cosines[0]),
parseFloat(cosines[1]),
parseFloat(cosines[2]));
const colCosines = new Vector3D(
parseFloat(cosines[3]),
parseFloat(cosines[4]),
parseFloat(cosines[5]));
const normal = rowCosines.crossProduct(colCosines);
/* eslint-disable array-element-newline */
orientationMatrix = new Matrix33([
rowCosines.getX(), colCosines.getX(), normal.getX(),
rowCosines.getY(), colCosines.getY(), normal.getY(),
rowCosines.getZ(), colCosines.getZ(), normal.getZ()
]);
}
return orientationMatrix;
}

0 comments on commit 2bf2845

Please sign in to comment.