-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into issue-3595
- Loading branch information
Showing
57 changed files
with
1,234 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
b55518e08ec9c9ab23e74aa4987927d8d75ae909 | ||
5302e5b62be22eb503d4fe067b435f7934284c39 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import sortInstancesByPosition from '@ohif/core/src/utils/sortInstancesByPosition'; | ||
import { constructableModalities } from '@ohif/core/src/utils/isDisplaySetReconstructable'; | ||
import { DisplaySetMessage, DisplaySetMessageList } from '@ohif/core'; | ||
import checkMultiFrame from './utils/validations/checkMultiframe'; | ||
import checkSingleFrames from './utils/validations/checkSingleFrames'; | ||
/** | ||
* Checks if a series is reconstructable to a 3D volume. | ||
* | ||
* @param {Object[]} instances An array of `OHIFInstanceMetadata` objects. | ||
*/ | ||
export default function getDisplaySetMessages( | ||
instances: Array<any>, | ||
isReconstructable: boolean | ||
): DisplaySetMessageList { | ||
const messages = new DisplaySetMessageList(); | ||
if (!instances.length) { | ||
messages.addMessage(DisplaySetMessage.CODES.NO_VALID_INSTANCES); | ||
} | ||
|
||
const firstInstance = instances[0]; | ||
// Due to current requirements, LOCALIZER series doesn't have any messages | ||
if (firstInstance.ImageType.includes('LOCALIZER')) { | ||
return messages; | ||
} | ||
|
||
const Modality = firstInstance.Modality; | ||
if (!constructableModalities.includes(Modality)) { | ||
return messages; | ||
} | ||
|
||
const isMultiframe = firstInstance.NumberOfFrames > 1; | ||
// Can't reconstruct if all instances don't have the ImagePositionPatient. | ||
if ( | ||
!isMultiframe && | ||
!instances.every(instance => instance.ImagePositionPatient) | ||
) { | ||
messages.addMessage(DisplaySetMessage.CODES.NO_POSITION_INFORMATION); | ||
} | ||
|
||
const sortedInstances = sortInstancesByPosition(instances); | ||
|
||
isMultiframe | ||
? checkMultiFrame(sortedInstances[0], messages) | ||
: checkSingleFrames(sortedInstances, messages); | ||
|
||
if (!isReconstructable) { | ||
messages.addMessage(DisplaySetMessage.CODES.NOT_RECONSTRUCTABLE); | ||
} | ||
return messages; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { vec3 } from 'gl-matrix'; | ||
|
||
/** | ||
* Calculates the scanAxisNormal based on a image orientation vector extract from a frame | ||
* @param {*} imageOrientation | ||
* @returns | ||
*/ | ||
export default function calculateScanAxisNormal(imageOrientation) { | ||
const rowCosineVec = vec3.fromValues( | ||
imageOrientation[0], | ||
imageOrientation[1], | ||
imageOrientation[2] | ||
); | ||
const colCosineVec = vec3.fromValues( | ||
imageOrientation[3], | ||
imageOrientation[4], | ||
imageOrientation[5] | ||
); | ||
return vec3.cross(vec3.create(), rowCosineVec, colCosineVec); | ||
} |
26 changes: 26 additions & 0 deletions
26
extensions/default/src/utils/validations/areAllImageComponentsEqual.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import toNumber from '@ohif/core/src/utils/toNumber'; | ||
|
||
/** | ||
* Check if all voxels in series images has same number of components (samplesPerPixel) | ||
* @param {*} instances | ||
* @returns | ||
*/ | ||
export default function areAllImageComponentsEqual( | ||
instances: Array<any> | ||
): boolean { | ||
if (!instances?.length) { | ||
return false; | ||
} | ||
const firstImage = instances[0]; | ||
const firstImageSamplesPerPixel = toNumber(firstImage.SamplesPerPixel); | ||
|
||
for (let i = 1; i < instances.length; i++) { | ||
const instance = instances[i]; | ||
const { SamplesPerPixel } = instance; | ||
|
||
if (SamplesPerPixel !== firstImageSamplesPerPixel) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} |
27 changes: 27 additions & 0 deletions
27
extensions/default/src/utils/validations/areAllImageDimensionsEqual.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import toNumber from '@ohif/core/src/utils/toNumber'; | ||
|
||
/** | ||
* Check if the frames in a series has different dimensions | ||
* @param {*} instances | ||
* @returns | ||
*/ | ||
export default function areAllImageDimensionsEqual( | ||
instances: Array<any> | ||
): boolean { | ||
if (!instances?.length) { | ||
return false; | ||
} | ||
const firstImage = instances[0]; | ||
const firstImageRows = toNumber(firstImage.Rows); | ||
const firstImageColumns = toNumber(firstImage.Columns); | ||
|
||
for (let i = 1; i < instances.length; i++) { | ||
const instance = instances[i]; | ||
const { Rows, Columns } = instance; | ||
|
||
if (Rows !== firstImageRows || Columns !== firstImageColumns) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} |
31 changes: 31 additions & 0 deletions
31
extensions/default/src/utils/validations/areAllImageOrientationsEqual.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import toNumber from '@ohif/core/src/utils/toNumber'; | ||
import { _isSameOrientation } from '@ohif/core/src/utils/isDisplaySetReconstructable'; | ||
|
||
/** | ||
* Check is the series has frames with different orientations | ||
* @param {*} instances | ||
* @returns | ||
*/ | ||
export default function areAllImageOrientationsEqual( | ||
instances: Array<any> | ||
): boolean { | ||
if (!instances?.length) { | ||
return false; | ||
} | ||
const firstImage = instances[0]; | ||
const firstImageOrientationPatient = toNumber( | ||
firstImage.ImageOrientationPatient | ||
); | ||
|
||
for (let i = 1; i < instances.length; i++) { | ||
const instance = instances[i]; | ||
const imageOrientationPatient = toNumber(instance.ImageOrientationPatient); | ||
|
||
if ( | ||
!_isSameOrientation(imageOrientationPatient, firstImageOrientationPatient) | ||
) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} |
76 changes: 76 additions & 0 deletions
76
extensions/default/src/utils/validations/areAllImagePositionsEqual.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { vec3 } from 'gl-matrix'; | ||
import toNumber from '@ohif/core/src/utils/toNumber'; | ||
import { _getPerpendicularDistance } from '@ohif/core/src/utils/isDisplaySetReconstructable'; | ||
import calculateScanAxisNormal from '../calculateScanAxisNormal'; | ||
|
||
/** | ||
* Checks if there is a position shift between consecutive frames | ||
* @param {*} previousPosition | ||
* @param {*} actualPosition | ||
* @param {*} scanAxisNormal | ||
* @param {*} averageSpacingBetweenFrames | ||
* @returns | ||
*/ | ||
function _checkSeriesPositionShift( | ||
previousPosition, | ||
actualPosition, | ||
scanAxisNormal, | ||
averageSpacingBetweenFrames | ||
) { | ||
// predicted position should be the previous position added by the multiplication | ||
// of the scanAxisNormal and the average spacing between frames | ||
const predictedPosition = vec3.scaleAndAdd( | ||
vec3.create(), | ||
previousPosition, | ||
scanAxisNormal, | ||
averageSpacingBetweenFrames | ||
); | ||
return ( | ||
vec3.distance(actualPosition, predictedPosition) > | ||
averageSpacingBetweenFrames | ||
); | ||
} | ||
|
||
/** | ||
* Checks if a series has position shifts between consecutive frames | ||
* @param {*} instances | ||
* @returns | ||
*/ | ||
export default function areAllImagePositionsEqual( | ||
instances: Array<any> | ||
): boolean { | ||
if (!instances?.length) { | ||
return false; | ||
} | ||
const firstImageOrientationPatient = toNumber( | ||
instances[0].ImageOrientationPatient | ||
); | ||
const scanAxisNormal = calculateScanAxisNormal(firstImageOrientationPatient); | ||
const firstImagePositionPatient = toNumber(instances[0].ImagePositionPatient); | ||
const lastIpp = toNumber( | ||
instances[instances.length - 1].ImagePositionPatient | ||
); | ||
|
||
const averageSpacingBetweenFrames = | ||
_getPerpendicularDistance(firstImagePositionPatient, lastIpp) / | ||
(instances.length - 1); | ||
|
||
let previousImagePositionPatient = firstImagePositionPatient; | ||
for (let i = 1; i < instances.length; i++) { | ||
const instance = instances[i]; | ||
const imagePositionPatient = toNumber(instance.ImagePositionPatient); | ||
|
||
if ( | ||
_checkSeriesPositionShift( | ||
previousImagePositionPatient, | ||
imagePositionPatient, | ||
scanAxisNormal, | ||
averageSpacingBetweenFrames | ||
) | ||
) { | ||
return false; | ||
} | ||
previousImagePositionPatient = imagePositionPatient; | ||
} | ||
return true; | ||
} |
Oops, something went wrong.