@cornerstonejs/tools 5.10.5 → 5.10.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,7 +11,7 @@ import { StrategyCallbacks } from '../../enums/index.js';
11
11
  import * as LabelmapMemo from '../../utilities/segmentation/createLabelmapMemo.js';
12
12
  import { getAllAnnotations, removeAnnotation, } from '../../stateManagement/annotation/annotationState.js';
13
13
  import { filterAnnotationsForDisplay } from '../../utilities/planar/index.js';
14
- import { isPointInsidePolyline3D } from '../../utilities/math/polyline/index.js';
14
+ import { iterateContourFillVoxels } from './strategies/utils/contourVoxelSlab.js';
15
15
  import { triggerSegmentationDataModified } from '../../stateManagement/segmentation/triggerSegmentationEvents.js';
16
16
  import { fillInsideCircle } from './strategies/index.js';
17
17
  import getViewportLabelmapRenderMode from '../../stateManagement/segmentation/helpers/getViewportLabelmapRenderMode.js';
@@ -19,6 +19,7 @@ import { getOrCreateLabelmapVolume, resolveLabelmapForSegment, } from '../../sta
19
19
  import getViewportICamera from '../../utilities/getViewportICamera.js';
20
20
  import triggerAnnotationRenderForViewportIds from '../../utilities/triggerAnnotationRenderForViewportIds.js';
21
21
  import { resetElementCursor } from '../../cursors/elementCursor.js';
22
+ const { asUnitNormal } = csUtils.voxelSlab;
22
23
  class LabelmapBaseTool extends BaseTool {
23
24
  constructor(toolProps, defaultToolProps) {
24
25
  super(toolProps, defaultToolProps);
@@ -343,29 +344,20 @@ class LabelmapBaseTool extends BaseTool {
343
344
  const { memo, segmentationId } = preview;
344
345
  const previewVoxels = memo?.voxelManager;
345
346
  const segmentationVoxels = previewVoxels.sourceVoxelManager || previewVoxels;
346
- const { dimensions } = previewVoxels;
347
347
  const imageData = viewport
348
348
  .getDefaultActor()
349
349
  .actor.getMapper()
350
350
  .getInputData();
351
+ const volume = {
352
+ dimensions: imageData.getDimensions(),
353
+ direction: imageData.getDirection(),
354
+ spacing: imageData.getSpacing(),
355
+ origin: imageData.getOrigin(),
356
+ };
351
357
  for (const annotation of contourAnnotations) {
352
- const boundsIJK = [
353
- [Infinity, -Infinity],
354
- [Infinity, -Infinity],
355
- [Infinity, -Infinity],
356
- ];
357
358
  const { polyline } = annotation.data.contour;
358
- for (const point of polyline) {
359
- const indexPoint = imageData.worldToIndex(point);
360
- indexPoint.forEach((v, idx) => {
361
- boundsIJK[idx][0] = Math.min(boundsIJK[idx][0], v);
362
- boundsIJK[idx][1] = Math.max(boundsIJK[idx][1], v);
363
- });
364
- }
365
- boundsIJK.forEach((bound, idx) => {
366
- bound[0] = Math.round(Math.max(0, bound[0]));
367
- bound[1] = Math.round(Math.min(dimensions[idx] - 1, bound[1]));
368
- });
359
+ const camera = viewport.getCamera();
360
+ const viewPlaneNormal = asUnitNormal(annotation.metadata?.viewPlaneNormal ?? camera.viewPlaneNormal);
369
361
  const activeIndex = getActiveSegmentIndex(segmentationId);
370
362
  const startPoint = annotation.data.handles?.[0] || polyline[0];
371
363
  const startIndex = imageData.worldToIndex(startPoint).map(Math.round);
@@ -388,16 +380,13 @@ class LabelmapBaseTool extends BaseTool {
388
380
  : startValue === 0
389
381
  ? activeIndex
390
382
  : 0;
391
- for (let i = boundsIJK[0][0]; i <= boundsIJK[0][1]; i++) {
392
- for (let j = boundsIJK[1][0]; j <= boundsIJK[1][1]; j++) {
393
- for (let k = boundsIJK[2][0]; k <= boundsIJK[2][1]; k++) {
394
- const worldPoint = imageData.indexToWorld([i, j, k]);
395
- const isContained = isPointInsidePolyline3D(worldPoint, polyline);
396
- if (isContained) {
397
- previewVoxels.setAtIJK(i, j, k, segmentIndex);
398
- }
399
- }
400
- }
383
+ for (const ijk of iterateContourFillVoxels({
384
+ volume,
385
+ polyline,
386
+ viewPlaneNormal,
387
+ imageData,
388
+ })) {
389
+ previewVoxels.setAtIJK(ijk[0], ijk[1], ijk[2], segmentIndex);
401
390
  }
402
391
  if (removeContours) {
403
392
  removeAnnotation(annotation.annotationUID);
@@ -0,0 +1,15 @@
1
+ import type { Types } from '@cornerstonejs/core';
2
+ export declare const CONTOUR_FILL_COVERAGE: "centerInside";
3
+ export type ContourFillVolume = {
4
+ dimensions: Types.Point3;
5
+ direction: Types.Mat3;
6
+ spacing: Types.Point3;
7
+ origin: Types.Point3;
8
+ };
9
+ export interface ContourFillOptions {
10
+ volume: ContourFillVolume;
11
+ polyline: Types.Point3[];
12
+ viewPlaneNormal: Types.Point3;
13
+ imageData: any;
14
+ }
15
+ export declare function iterateContourFillVoxels({ volume, polyline, viewPlaneNormal, imageData, }: ContourFillOptions): Generator<Types.Point3>;
@@ -0,0 +1,27 @@
1
+ import { utilities as csUtils } from '@cornerstonejs/core';
2
+ import { getShapeIndexBounds } from '../../../../utilities/sampleAreaAnnotationVoxels.js';
3
+ const { createPolylineShape, getSlabHalfWidth, getVoxelThicknessAlongNormal, iterateVoxelsInShape, } = csUtils.voxelSlab;
4
+ export const CONTOUR_FILL_COVERAGE = 'centerInside';
5
+ export function* iterateContourFillVoxels({ volume, polyline, viewPlaneNormal, imageData, }) {
6
+ if (!(polyline?.length >= 3)) {
7
+ return;
8
+ }
9
+ const planePoint = polyline[0];
10
+ const voxelThickness = getVoxelThicknessAlongNormal(volume, viewPlaneNormal);
11
+ const shape = createPolylineShape({
12
+ volume,
13
+ planePoint,
14
+ viewPlaneNormal,
15
+ polyline,
16
+ });
17
+ for (const { ijk } of iterateVoxelsInShape({
18
+ volume,
19
+ planePoint,
20
+ viewPlaneNormal,
21
+ depthCoverage: CONTOUR_FILL_COVERAGE,
22
+ bounds: getShapeIndexBounds(polyline, volume, imageData, viewPlaneNormal, getSlabHalfWidth(voxelThickness, voxelThickness, CONTOUR_FILL_COVERAGE)),
23
+ getShapeRuns: shape.getRuns,
24
+ })) {
25
+ yield ijk;
26
+ }
27
+ }
@@ -42,4 +42,4 @@ export interface AreaAnnotationVoxelsOptions {
42
42
  storePointData?: boolean;
43
43
  }
44
44
  export default function sampleAreaAnnotationVoxels({ annotation, image, voxelManager, points, boundsMargin, createShape, planePoint: planePointOverride, minimumPoints, onSample, storePointData, }: AreaAnnotationVoxelsOptions): AreaAnnotationVoxel[];
45
- export declare function getShapeIndexBounds(points: Types.Point3[], volume: Pick<AreaAnnotationVolume, 'dimensions' | 'direction' | 'spacing'>, imageData: any, viewPlaneNormal: Types.Point3, halfWidth: number, margin: number): Types.BoundsIJK;
45
+ export declare function getShapeIndexBounds(points: Types.Point3[], volume: Pick<AreaAnnotationVolume, 'dimensions' | 'direction' | 'spacing'>, imageData: any, viewPlaneNormal: Types.Point3, halfWidth: number, margin?: number): Types.BoundsIJK;
@@ -46,7 +46,7 @@ function resolveAnnotationNormal(metadata) {
46
46
  ? asUnitNormal(normal)
47
47
  : undefined;
48
48
  }
49
- export function getShapeIndexBounds(points, volume, imageData, viewPlaneNormal, halfWidth, margin) {
49
+ export function getShapeIndexBounds(points, volume, imageData, viewPlaneNormal, halfWidth, margin = 0) {
50
50
  const { dimensions, direction, spacing } = volume;
51
51
  const indexPoints = points.map((point) => imageData.worldToIndex(point));
52
52
  const boundingBox = getBoundingBoxAroundShapeIJK(indexPoints);
@@ -1 +1 @@
1
- export declare const version = "5.10.5";
1
+ export declare const version = "5.10.6";
@@ -1 +1 @@
1
- export const version = '5.10.5';
1
+ export const version = '5.10.6';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/tools",
3
- "version": "5.10.5",
3
+ "version": "5.10.6",
4
4
  "description": "Cornerstone3D Tools",
5
5
  "types": "./dist/esm/index.d.ts",
6
6
  "module": "./dist/esm/index.js",
@@ -126,11 +126,11 @@
126
126
  "lodash.get": "4.4.2"
127
127
  },
128
128
  "devDependencies": {
129
- "@cornerstonejs/core": "5.10.5",
129
+ "@cornerstonejs/core": "5.10.6",
130
130
  "canvas": "3.2.0"
131
131
  },
132
132
  "peerDependencies": {
133
- "@cornerstonejs/core": "5.10.5",
133
+ "@cornerstonejs/core": "5.10.6",
134
134
  "@kitware/vtk.js": "36.4.1",
135
135
  "@types/d3-array": "3.2.1",
136
136
  "@types/d3-interpolate": "3.0.4",