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: Segmentation slice range is wrong when nearly orthonormal as well as for segmentation volumes #511

Merged
merged 3 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions packages/core/src/loaders/volumeLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,11 @@ export function registerVolumeLoader(
volumeLoaders[scheme] = volumeLoader;
}

/** Gets the array of volume loader schemes */
export function getVolumeLoaderSchemes(): string[] {
return Object.keys(volumeLoaders);
}

/**
* Registers a new unknownVolumeLoader and returns the previous one
*
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/utilities/getSliceRange.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import vtkMatrixBuilder from '@kitware/vtk.js/Common/Core/MatrixBuilder';
import getVolumeActorCorners from './getVolumeActorCorners';
import type { VolumeActor, Point3, ActorSliceRange } from '../types';
import { EPSILON } from '../constants';

const isOne = (v) => Math.abs(v) > 0.99 && Math.abs(v) < 1.01;
const isOne = (v) => Math.abs(Math.abs(v) - 1) < EPSILON;
const isUnit = (v, off) =>
isOne(v[off]) || isOne(v[off + 1]) || isOne(v[off + 2]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,22 @@ import { EPSILON } from '../constants';
// import type { VolumeViewport } from '../RenderingEngine'
import { ICamera, IImageVolume, IVolumeViewport } from '../types';
import getSpacingInNormalDirection from './getSpacingInNormalDirection';
import { getVolumeLoaderSchemes } from '../loaders/volumeLoader';

// One EPSILON part larger multiplier
const EPSILON_PART = 1 + EPSILON;

const startsWith = (str, starts) =>
starts === str.substring(0, Math.min(str.length, starts.length));

// Check if this is a primary volume
// For now, that means it came from some sort of image loader, but
// should be specifically designated.
const isPrimaryVolume = (volume): boolean =>
!!getVolumeLoaderSchemes().find((scheme) =>
startsWith(volume.volumeId, scheme)
);

/**
* Given a volume viewport and camera, find the target volume.
* The imageVolume is retrieved from cache for the specified targetVolumeId or
Expand Down Expand Up @@ -82,9 +94,16 @@ export default function getTargetVolumeAndSpacingInNormalDir(
actorUID: null,
};

const hasPrimaryVolume = imageVolumes.find(isPrimaryVolume);

for (let i = 0; i < imageVolumes.length; i++) {
const imageVolume = imageVolumes[i];

if (hasPrimaryVolume && !isPrimaryVolume(imageVolume)) {
// Secondary volumes like segmentation don't count towards spacing
continue;
}

const spacingInNormalDirection = getSpacingInNormalDirection(
imageVolume,
viewPlaneNormal
Expand Down