/
getVolumeSliceRangeInfo.ts
60 lines (53 loc) · 1.57 KB
/
getVolumeSliceRangeInfo.ts
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
import getSliceRange from './getSliceRange';
import getTargetVolumeAndSpacingInNormalDir from './getTargetVolumeAndSpacingInNormalDir';
import {
ActorSliceRange,
IVolumeViewport,
ICamera,
VolumeActor,
} from '../types';
/**
* Calculates the slice range for the given volume based on its orientation
* @param viewport - Volume viewport
* @param volumeId - Id of one of the volumes loaded on the given viewport
* @param useSlabThickness - If true, the slice range will be calculated
* based on the slab thickness instead of the spacing in the normal direction
* @returns slice range information
*/
function getVolumeSliceRangeInfo(
viewport: IVolumeViewport,
volumeId: string,
useSlabThickness = false
): {
sliceRange: ActorSliceRange;
spacingInNormalDirection: number;
camera: ICamera;
} {
const camera = viewport.getCamera();
const { focalPoint, viewPlaneNormal } = camera;
const { spacingInNormalDirection, actorUID } =
getTargetVolumeAndSpacingInNormalDir(
viewport,
camera,
volumeId,
useSlabThickness
);
if (!actorUID) {
throw new Error(
`Could not find image volume with id ${volumeId} in the viewport`
);
}
const actorEntry = viewport.getActor(actorUID);
if (!actorEntry) {
console.warn('No actor found for with actorUID of', actorUID);
return null;
}
const volumeActor = actorEntry.actor as VolumeActor;
const sliceRange = getSliceRange(volumeActor, viewPlaneNormal, focalPoint);
return {
sliceRange,
spacingInNormalDirection,
camera,
};
}
export default getVolumeSliceRangeInfo;