Skip to content

Commit

Permalink
fix: NM is reconstructable false
Browse files Browse the repository at this point in the history
  • Loading branch information
wayfarer3130 committed Nov 29, 2024
1 parent 63281e4 commit 5bbdbba
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
43 changes: 23 additions & 20 deletions platform/core/src/utils/combineFrameInstance.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { vec3 } from 'gl-matrix';
import { dicomSplit } from './dicomSplit';

/**
* Combine the Per instance frame data, the shared frame data
Expand All @@ -16,23 +17,13 @@ const combineFrameInstance = (frame, instance) => {
SharedFunctionalGroupsSequence,
NumberOfFrames,
SpacingBetweenSlices,
ImageType,
} = instance;

instance.ImageType = dicomSplit(ImageType);

if (PerFrameFunctionalGroupsSequence || NumberOfFrames > 1) {
const frameNumber = Number.parseInt(frame || 1);
const shared = SharedFunctionalGroupsSequence
? Object.values(SharedFunctionalGroupsSequence[0])
.filter(Boolean)
.map(it => it[0])
.filter(it => typeof it === 'object')
: [];

const perFrame = PerFrameFunctionalGroupsSequence
? Object.values(PerFrameFunctionalGroupsSequence[frameNumber - 1])
.filter(Boolean)
.map(it => it[0])
.filter(it => typeof it === 'object')
: [];

// this is to fix NM multiframe datasets with position and orientation
// information inside DetectorInformationSequence
Expand Down Expand Up @@ -73,8 +64,11 @@ const combineFrameInstance = (frame, instance) => {
ImagePositionPatientToUse = [position[0], position[1], position[2]];
}
}
const sharedInstance = createCombinedValue(instance, shared);
const newInstance = createCombinedValue(sharedInstance, perFrame);
const sharedInstance = createCombinedValue(instance, SharedFunctionalGroupsSequence?.[0]);
const newInstance = createCombinedValue(
sharedInstance,
PerFrameFunctionalGroupsSequence?.[frameNumber]
);
newInstance.ImagePositionPatient = ImagePositionPatientToUse ??
newInstance.ImagePositionPatient ?? [0, 0, frameNumber];
newInstance.frameNumber = frameNumber;
Expand All @@ -84,11 +78,20 @@ const combineFrameInstance = (frame, instance) => {
}
};

function createCombinedValue(parent, shared) {
if (shared._sharedValue) {
return shared._sharedValue;
}
function createCombinedValue(parent, functionalGroups) {
const newInstance = Object.create(parent);
if (!functionalGroups) {
return newInstance;
}
if (functionalGroups._sharedValue) {
return functionalGroups._sharedValue;
}
const shared = functionalGroups
? Object.values(functionalGroups)
.filter(Boolean)
.map(it => it[0])
.filter(it => typeof it === 'object')
: [];

// merge the shared first then the per frame to override
[...shared].forEach(item => {
Expand All @@ -100,7 +103,7 @@ function createCombinedValue(parent, shared) {
newInstance[key] = value;
});
});
Object.defineProperty(shared, '_sharedValue', {
Object.defineProperty(functionalGroups, '_sharedValue', {
value: newInstance,
writable: false,
enumerable: false,
Expand Down
5 changes: 5 additions & 0 deletions platform/core/src/utils/dicomSplit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function dicomSplit(value) {
return (
(Array.isArray(value) && value) || (typeof value === 'string' && value.split('\\')) || value
);
}

0 comments on commit 5bbdbba

Please sign in to comment.