Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | 85x 85x 85x 85x 107x 85x 1x 1x 1x 1x 84x 84x 106x 106x 22x 84x 84x 84x 84x 84x | import cache from '../cache/cache';
// import type { VolumeViewport } from '../RenderingEngine'
import { ICamera, IImageVolume, IVolumeViewport } from '../types';
import getSpacingInNormalDirection from './getSpacingInNormalDirection';
/**
* Given a volume viewport and camera, find the target volume.
* The imageVolume is retrieved from cache for the specified targetVolumeId or
* in case it is not provided, it chooses the volumeId on the viewport (there
* might be more than one in case of fusion) that has the finest resolution in the
* direction of view (normal).
*
* @param viewport - volume viewport
* @param camera - current camera
* @param targetVolumeId - If a target volumeId is given that volume
* is forced to be used.
*
* @returns An object containing the imageVolume and spacingInNormalDirection.
*
*/
export default function getTargetVolumeAndSpacingInNormalDir(
viewport: IVolumeViewport,
camera: ICamera,
targetVolumeId?: string
): {
imageVolume: IImageVolume;
spacingInNormalDirection: number;
} {
const { viewPlaneNormal } = camera;
const volumeActors = viewport.getActors();
Iif (!volumeActors || !volumeActors.length) {
return { spacingInNormalDirection: null, imageVolume: null };
}
const numVolumeActors = volumeActors.length;
const imageVolumes = volumeActors.map((va) => cache.getVolume(va.uid));
// If a volumeId is defined, set that volume as the target
if (targetVolumeId) {
const imageVolume = imageVolumes.find(
(iv) => iv.volumeId === targetVolumeId
);
const spacingInNormalDirection = getSpacingInNormalDirection(
imageVolume,
viewPlaneNormal
);
return { imageVolume, spacingInNormalDirection };
}
// Fetch volume actor with finest resolution in direction of projection.
const smallest = {
spacingInNormalDirection: Infinity,
imageVolume: null,
};
for (let i = 0; i < numVolumeActors; i++) {
const imageVolume = imageVolumes[i];
// TODO: Hacky workaround for undefined volumes created by Seg
if (!imageVolume) {
continue;
}
const spacingInNormalDirection = getSpacingInNormalDirection(
imageVolume,
viewPlaneNormal
);
Eif (spacingInNormalDirection < smallest.spacingInNormalDirection) {
smallest.spacingInNormalDirection = spacingInNormalDirection;
smallest.imageVolume = imageVolume;
}
}
return smallest;
}
|