Skip to content

Commit

Permalink
Extract getOrientation from factory
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmartel committed Apr 25, 2024
1 parent 1c64c5f commit a080f12
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 26 deletions.
35 changes: 34 additions & 1 deletion src/dicom/dicomElementsWrapper.js
Expand Up @@ -13,14 +13,15 @@ import {
getTagFromKey
} from './dicomTag';
import {isNativeLittleEndian} from './dataReader';
import {Vector3D} from '../math/vector';
import {Matrix33} from '../math/matrix';
import {Spacing} from '../image/spacing';
import {logger} from '../utils/logger';

// doc imports
/* eslint-disable no-unused-vars */
import {Tag} from './dicomTag';
import {DataElement} from './dataElement';
import {Matrix33} from '../math/matrix';
/* eslint-enable no-unused-vars */

/**
Expand Down Expand Up @@ -685,6 +686,38 @@ export function getSpacingFromMeasure(dataElements) {
return new Spacing(spacingValues);
}

/**
* Get an orientation matrix from a dicom orientation element.
*
* @param {DataElements} dataElements The dicom element.
* @returns {Matrix33|undefined} The orientation matrix.
*/
export function getOrientationMatrix(dataElements) {
const imageOrientationPatient = dataElements['00200037'];
let orientationMatrix;
// 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 */
}
return orientationMatrix;
}

/**
* Get a dicom item from a measure sequence.
*
Expand Down
29 changes: 4 additions & 25 deletions src/image/imageFactory.js
Expand Up @@ -14,10 +14,9 @@ import {
getPixelSpacing,
getPixelUnit,
TagValueExtractor,
getSuvFactor
getSuvFactor,
getOrientationMatrix
} from '../dicom/dicomElementsWrapper';
import {Vector3D} from '../math/vector';
import {Matrix33} from '../math/matrix';
import {Point3D} from '../math/point';
import {logger} from '../utils/logger';

Expand Down Expand Up @@ -132,28 +131,8 @@ export class ImageFactory {
];
}

// 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
const imageOrientationPatient = dataElements['00200037'];
let orientationMatrix;
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 */
}
// Image orientation patient
const orientationMatrix = getOrientationMatrix(dataElements);

// geometry
const origin = new Point3D(
Expand Down

0 comments on commit a080f12

Please sign in to comment.