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(SegmentationStateManager): fix loading in segmentation labelmaps #1871

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -438,32 +438,39 @@ export default class SegmentationStateManager {

/**
* Helper function to update labelmap segmentation image references.
* @param {string} segmentationId - The ID of the segmentation representation.
* @param {Types.IViewport} viewport - The viewport.
* @param {string[]} labelmapImageIds - The labelmap image IDs.
* @param {Function} updateCallback - A callback to update the reference map.
* @param segmentationInfo - The segmentation info of the desired segment.
* @param viewport - The viewport.
* @param labelmapImageIds - The labelmap image IDs.
* @param updateCallback - A callback to update the reference map.
* @returns {string | undefined} The labelmap imageId reference for the current imageId rendered on the viewport.
*/
_updateLabelmapSegmentationReferences(
segmentationId,
viewport,
labelmapImageIds,
updateCallback
segmentationInfo: Segmentation,
viewport: Types.IStackViewport,
labelmapImageIds: string[],
updateCallback: (
viewport: Types.IStackViewport,
segmentationId: string,
labelmapImageIds: string[]
) => void
): string | undefined {
const currentImageId = viewport.getCurrentImageId();
const currentImageIndex = viewport.getCurrentImageIdIndex();
const segmentationId = segmentationInfo.segmentationId;

let viewableLabelmapImageIdFound = false;
for (const labelmapImageId of labelmapImageIds) {
const labelForImageIndex = labelmapImageIds[currentImageIndex];
if (labelForImageIndex) {
Comment on lines +462 to +463
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i always wondered why we don't do this instead of looping over the labelmapImageIds and finding the match.

const viewableImageId = viewport.isReferenceViewable(
{ referencedImageId: labelmapImageId },
{ referencedImageId: labelForImageIndex },
{ asOverlay: true }
);

if (viewableImageId) {
viewableLabelmapImageIdFound = true;
this._stackLabelmapImageIdReferenceMap
.get(segmentationId)
.set(currentImageId, labelmapImageId);
.set(currentImageId, labelForImageIndex);
}
}

Expand Down Expand Up @@ -504,7 +511,7 @@ export default class SegmentationStateManager {
const stackViewport = enabledElement.viewport as Types.IStackViewport;

return this._updateLabelmapSegmentationReferences(
segmentationId,
segmentation,
stackViewport,
labelmapImageIds,
null
Expand Down Expand Up @@ -537,7 +544,7 @@ export default class SegmentationStateManager {
const stackViewport = enabledElement.viewport as Types.IStackViewport;

this._updateLabelmapSegmentationReferences(
segmentationId,
segmentation,
stackViewport,
labelmapImageIds,
(stackViewport, segmentationId, labelmapImageIds) => {
Expand Down