Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(scroll): Scrolling failed to find the volume with segmentation #470

Merged
merged 5 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common/reviews/api/core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ function getSpacingInNormalDirection(imageVolume: IImageVolume, viewPlaneNormal:
function getTargetVolumeAndSpacingInNormalDir(viewport: IVolumeViewport, camera: ICamera, targetVolumeId?: string): {
imageVolume: IImageVolume;
spacingInNormalDirection: number;
uid: string;
};

// @public (undocumented)
Expand Down
1 change: 1 addition & 0 deletions common/reviews/api/tools.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2943,6 +2943,7 @@ function jumpToSlice(element: HTMLDivElement, options?: JumpToSliceOptions): Pro
type JumpToSliceOptions = {
imageIndex: number;
debounceLoading?: boolean;
volumeId?: string;
};

// @public (undocumented)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ export default function getTargetVolumeAndSpacingInNormalDir(
): {
imageVolume: IImageVolume;
spacingInNormalDirection: number;
uid: string;
} {
const { viewPlaneNormal } = camera;
const volumeActors = viewport.getActors();

if (!volumeActors || !volumeActors.length) {
return { spacingInNormalDirection: null, imageVolume: null };
return { spacingInNormalDirection: null, imageVolume: null, uid: null };
}

const imageVolumes = volumeActors
Expand All @@ -44,26 +45,29 @@ export default function getTargetVolumeAndSpacingInNormalDir(

// If a volumeId is defined, set that volume as the target
if (targetVolumeId) {
const imageVolume = imageVolumes.find(
const imageVolumeIndex = imageVolumes.findIndex(
(iv) => iv.volumeId === targetVolumeId
);

const imageVolume = imageVolumes[imageVolumeIndex];
const { uid } = volumeActors[imageVolumeIndex];
const spacingInNormalDirection = getSpacingInNormalDirection(
imageVolume,
viewPlaneNormal
);

return { imageVolume, spacingInNormalDirection };
return { imageVolume, spacingInNormalDirection, uid };
}

if (!imageVolumes.length) {
return { spacingInNormalDirection: null, imageVolume: null };
return { spacingInNormalDirection: null, imageVolume: null, uid: null };
}

// Fetch volume actor with finest resolution in direction of projection.
const smallest = {
spacingInNormalDirection: Infinity,
imageVolume: null,
uid: null,
};

for (let i = 0; i < imageVolumes.length; i++) {
Expand All @@ -74,9 +78,12 @@ export default function getTargetVolumeAndSpacingInNormalDir(
viewPlaneNormal
);

if (spacingInNormalDirection < smallest.spacingInNormalDirection) {
// Allow for 1/1000 part larger requirement to prefer earlier volumes
// when the spacing is all essentially the same.
if (spacingInNormalDirection * 1.001 < smallest.spacingInNormalDirection) {
wayfarer3130 marked this conversation as resolved.
Show resolved Hide resolved
smallest.spacingInNormalDirection = spacingInNormalDirection;
smallest.imageVolume = imageVolume;
smallest.uid = volumeActors[i].uid;
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/tools/src/types/JumpToSliceOptions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
type JumpToSliceOptions = {
imageIndex: number;
debounceLoading?: boolean;
volumeId?: string;
};

export default JumpToSliceOptions;
3 changes: 2 additions & 1 deletion packages/tools/src/utilities/cine/playClip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function playClip(
targetImageIdIndex: viewport.getTargetImageIdIndex(),
imageIds: viewport.getImageIds(),
};

let newImageIdIndex = stackData.targetImageIdIndex;
const imageCount = stackData.imageIds.length;

Expand Down Expand Up @@ -182,6 +182,7 @@ function playClip(
*/
function stopClip(element: HTMLDivElement): void {
const enabledElement = getEnabledElement(element);
if (!enabledElement) return;
const { viewport } = enabledElement;

const cineToolData = getToolState(viewport.element);
Expand Down
9 changes: 5 additions & 4 deletions packages/tools/src/utilities/scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,20 @@ export function scrollVolume(
) {
const camera = viewport.getCamera();
const { focalPoint, viewPlaneNormal, position } = camera;
const { spacingInNormalDirection, imageVolume } =
const { spacingInNormalDirection, uid } =
csUtils.getTargetVolumeAndSpacingInNormalDir(viewport, camera, volumeId);

if (!imageVolume) {
if (!uid) {
throw new Error(
`Could not find image volume with id ${volumeId} in the viewport`
);
}

const actorEntry = viewport.getActor(imageVolume.volumeId);
const actorEntry = viewport.getActor(uid);

if (!actorEntry) {
console.warn('No actor found for with actorUID of', imageVolume.volumeId);
console.warn('No actor found for with actorUID of', uid);
return;
}

const volumeActor = actorEntry.actor as Types.VolumeActor;
Expand Down
4 changes: 2 additions & 2 deletions packages/tools/src/utilities/viewport/jumpToSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function jumpToSlice(
element: HTMLDivElement,
options = {} as JumpToSliceOptions
): Promise<void> {
const { imageIndex, debounceLoading } = options;
const { imageIndex, debounceLoading, volumeId } = options;
const enabledElement = getEnabledElement(element);

if (!enabledElement) {
Expand All @@ -40,7 +40,7 @@ async function jumpToSlice(
const imageIndexToJump = _getImageIndexToJump(numberOfSlices, imageIndex);
const delta = imageIndexToJump - currentImageIndex;

scroll(viewport, { delta, debounceLoading });
scroll(viewport, { delta, debounceLoading, volumeId });
}

function _getImageSliceData(
Expand Down