@cornerstonejs/tools 0.56.7 → 0.57.1

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.
Files changed (101) hide show
  1. package/dist/cjs/stateManagement/segmentation/SegmentationStateManager.d.ts +1 -1
  2. package/dist/cjs/stateManagement/segmentation/SegmentationStateManager.js +5 -2
  3. package/dist/cjs/stateManagement/segmentation/SegmentationStateManager.js.map +1 -1
  4. package/dist/cjs/stateManagement/segmentation/config/segmentationColor.js.map +1 -1
  5. package/dist/cjs/stateManagement/segmentation/config/segmentationVisibility.js +23 -5
  6. package/dist/cjs/stateManagement/segmentation/config/segmentationVisibility.js.map +1 -1
  7. package/dist/cjs/stateManagement/segmentation/segmentationState.js +0 -10
  8. package/dist/cjs/stateManagement/segmentation/segmentationState.js.map +1 -1
  9. package/dist/cjs/tools/displayTools/Contour/addContourSetsToElement.d.ts +3 -0
  10. package/dist/cjs/tools/displayTools/Contour/addContourSetsToElement.js +70 -0
  11. package/dist/cjs/tools/displayTools/Contour/addContourSetsToElement.js.map +1 -0
  12. package/dist/cjs/tools/displayTools/Contour/addOrUpdateContourSets.d.ts +3 -0
  13. package/dist/cjs/tools/displayTools/Contour/addOrUpdateContourSets.js +14 -0
  14. package/dist/cjs/tools/displayTools/Contour/addOrUpdateContourSets.js.map +1 -0
  15. package/dist/cjs/tools/displayTools/Contour/contourConfig.d.ts +3 -0
  16. package/dist/cjs/tools/displayTools/Contour/contourConfig.js +14 -0
  17. package/dist/cjs/tools/displayTools/Contour/contourConfig.js.map +1 -0
  18. package/dist/cjs/tools/displayTools/Contour/contourConfigCache.d.ts +9 -0
  19. package/dist/cjs/tools/displayTools/Contour/contourConfigCache.js +17 -0
  20. package/dist/cjs/tools/displayTools/Contour/contourConfigCache.js.map +1 -0
  21. package/dist/cjs/tools/displayTools/Contour/contourDisplay.d.ts +1 -1
  22. package/dist/cjs/tools/displayTools/Contour/contourDisplay.js +4 -52
  23. package/dist/cjs/tools/displayTools/Contour/contourDisplay.js.map +1 -1
  24. package/dist/cjs/tools/displayTools/Contour/updateContourSets.d.ts +3 -0
  25. package/dist/cjs/tools/displayTools/Contour/updateContourSets.js +78 -0
  26. package/dist/cjs/tools/displayTools/Contour/updateContourSets.js.map +1 -0
  27. package/dist/cjs/tools/displayTools/Contour/utils.d.ts +6 -0
  28. package/dist/cjs/tools/displayTools/Contour/utils.js +63 -0
  29. package/dist/cjs/tools/displayTools/Contour/utils.js.map +1 -0
  30. package/dist/cjs/tools/displayTools/Labelmap/labelmapDisplay.js.map +1 -1
  31. package/dist/cjs/types/ContourTypes.d.ts +1 -0
  32. package/dist/cjs/types/SegmentationStateTypes.d.ts +4 -4
  33. package/dist/cjs/types/index.d.ts +2 -2
  34. package/dist/cjs/utilities/cine/playClip.js +0 -1
  35. package/dist/cjs/utilities/cine/playClip.js.map +1 -1
  36. package/dist/cjs/utilities/planar/filterAnnotationsWithinSlice.js +10 -1
  37. package/dist/cjs/utilities/planar/filterAnnotationsWithinSlice.js.map +1 -1
  38. package/dist/esm/stateManagement/segmentation/SegmentationStateManager.d.ts +1 -1
  39. package/dist/esm/stateManagement/segmentation/SegmentationStateManager.js +5 -2
  40. package/dist/esm/stateManagement/segmentation/SegmentationStateManager.js.map +1 -1
  41. package/dist/esm/stateManagement/segmentation/config/segmentationColor.js.map +1 -1
  42. package/dist/esm/stateManagement/segmentation/config/segmentationVisibility.js +19 -5
  43. package/dist/esm/stateManagement/segmentation/config/segmentationVisibility.js.map +1 -1
  44. package/dist/esm/stateManagement/segmentation/segmentationState.js +1 -11
  45. package/dist/esm/stateManagement/segmentation/segmentationState.js.map +1 -1
  46. package/dist/esm/tools/displayTools/Contour/addContourSetsToElement.d.ts +3 -0
  47. package/dist/esm/tools/displayTools/Contour/addContourSetsToElement.js +63 -0
  48. package/dist/esm/tools/displayTools/Contour/addContourSetsToElement.js.map +1 -0
  49. package/dist/esm/tools/displayTools/Contour/addOrUpdateContourSets.d.ts +3 -0
  50. package/dist/esm/tools/displayTools/Contour/addOrUpdateContourSets.js +10 -0
  51. package/dist/esm/tools/displayTools/Contour/addOrUpdateContourSets.js.map +1 -0
  52. package/dist/esm/tools/displayTools/Contour/contourConfig.d.ts +3 -0
  53. package/dist/esm/tools/displayTools/Contour/contourConfig.js +12 -0
  54. package/dist/esm/tools/displayTools/Contour/contourConfig.js.map +1 -0
  55. package/dist/esm/tools/displayTools/Contour/contourConfigCache.d.ts +9 -0
  56. package/dist/esm/tools/displayTools/Contour/contourConfigCache.js +11 -0
  57. package/dist/esm/tools/displayTools/Contour/contourConfigCache.js.map +1 -0
  58. package/dist/esm/tools/displayTools/Contour/contourDisplay.d.ts +1 -1
  59. package/dist/esm/tools/displayTools/Contour/contourDisplay.js +6 -54
  60. package/dist/esm/tools/displayTools/Contour/contourDisplay.js.map +1 -1
  61. package/dist/esm/tools/displayTools/Contour/updateContourSets.d.ts +3 -0
  62. package/dist/esm/tools/displayTools/Contour/updateContourSets.js +71 -0
  63. package/dist/esm/tools/displayTools/Contour/updateContourSets.js.map +1 -0
  64. package/dist/esm/tools/displayTools/Contour/utils.d.ts +6 -0
  65. package/dist/esm/tools/displayTools/Contour/utils.js +53 -0
  66. package/dist/esm/tools/displayTools/Contour/utils.js.map +1 -0
  67. package/dist/esm/tools/displayTools/Labelmap/labelmapDisplay.js.map +1 -1
  68. package/dist/esm/types/ContourTypes.d.ts +1 -0
  69. package/dist/esm/types/SegmentationStateTypes.d.ts +4 -4
  70. package/dist/esm/types/index.d.ts +2 -2
  71. package/dist/esm/utilities/cine/playClip.js +0 -1
  72. package/dist/esm/utilities/cine/playClip.js.map +1 -1
  73. package/dist/esm/utilities/planar/filterAnnotationsWithinSlice.js +11 -2
  74. package/dist/esm/utilities/planar/filterAnnotationsWithinSlice.js.map +1 -1
  75. package/dist/umd/index.js +1 -1
  76. package/dist/umd/index.js.map +1 -1
  77. package/package.json +3 -3
  78. package/src/stateManagement/segmentation/SegmentationStateManager.ts +10 -7
  79. package/src/stateManagement/segmentation/config/segmentationColor.ts +1 -0
  80. package/src/stateManagement/segmentation/config/segmentationVisibility.ts +25 -7
  81. package/src/stateManagement/segmentation/segmentationState.ts +7 -23
  82. package/src/tools/displayTools/Contour/addContourSetsToElement.ts +110 -0
  83. package/src/tools/displayTools/Contour/addOrUpdateContourSets.ts +28 -0
  84. package/src/tools/displayTools/Contour/contourConfig.ts +15 -0
  85. package/src/tools/displayTools/Contour/contourConfigCache.ts +37 -0
  86. package/src/tools/displayTools/Contour/contourDisplay.ts +11 -91
  87. package/src/tools/displayTools/Contour/updateContourSets.ts +111 -0
  88. package/src/tools/displayTools/Contour/utils.ts +117 -0
  89. package/src/tools/displayTools/Labelmap/labelmapDisplay.ts +5 -2
  90. package/src/types/ContourTypes.ts +2 -0
  91. package/src/types/SegmentationStateTypes.ts +22 -8
  92. package/src/types/index.ts +2 -0
  93. package/src/utilities/cine/playClip.ts +2 -1
  94. package/src/utilities/planar/filterAnnotationsWithinSlice.ts +29 -3
  95. package/dist/cjs/tools/displayTools/Contour/addContourToElement.d.ts +0 -4
  96. package/dist/cjs/tools/displayTools/Contour/addContourToElement.js +0 -87
  97. package/dist/cjs/tools/displayTools/Contour/addContourToElement.js.map +0 -1
  98. package/dist/esm/tools/displayTools/Contour/addContourToElement.d.ts +0 -4
  99. package/dist/esm/tools/displayTools/Contour/addContourToElement.js +0 -80
  100. package/dist/esm/tools/displayTools/Contour/addContourToElement.js.map +0 -1
  101. package/src/tools/displayTools/Contour/addContourToElement.ts +0 -135
@@ -0,0 +1,117 @@
1
+ import { Enums, Types } from '@cornerstonejs/core';
2
+ import vtkCellArray from '@kitware/vtk.js/Common/Core/CellArray';
3
+ import vtkDataArray from '@kitware/vtk.js/Common/Core/DataArray';
4
+ import vtkPoints from '@kitware/vtk.js/Common/Core/Points';
5
+ import vtkPolyData from '@kitware/vtk.js/Common/DataModel/PolyData';
6
+ import { ToolGroupSpecificContourRepresentation } from '../../../types';
7
+
8
+ /**
9
+ * If the segment specific config exists for the given segment id, it returns
10
+ * the segment specific config. Otherwise, it looks for the segment specific
11
+ * config for the given index. If it doesn't exist, it returns null.
12
+ *
13
+ * @param contourRepresentation - The representation object that is passed
14
+ * to the tool.
15
+ * @param segmentId - The id of the segment.
16
+ * @param index - The index of the segment in the list of segments.
17
+ * @returns the segment specific config for the given segment id.
18
+ *
19
+ */
20
+ export function getSegmentSpecificConfig(
21
+ contourRepresentation: ToolGroupSpecificContourRepresentation,
22
+ segmentId: string,
23
+ index: number
24
+ ) {
25
+ let segmentSpecificConfig =
26
+ contourRepresentation.segmentSpecificConfig?.[segmentId];
27
+
28
+ if (!segmentSpecificConfig) {
29
+ // try the index
30
+ segmentSpecificConfig =
31
+ contourRepresentation.segmentSpecificConfig?.[index];
32
+ }
33
+
34
+ if (!segmentSpecificConfig) {
35
+ return null;
36
+ }
37
+
38
+ return segmentSpecificConfig.CONTOUR;
39
+ }
40
+
41
+ /**
42
+ * takes a geometry object as an argument
43
+ * and throws an error if the geometry object is not a contour
44
+ * @param geometry - The geometry object to be rendered.
45
+ */
46
+ export function validateGeometry(geometry: Types.IGeometry): void {
47
+ if (!geometry) {
48
+ throw new Error(`No contours found for geometryId ${geometry.id}`);
49
+ }
50
+
51
+ const geometryId = geometry.id;
52
+
53
+ if (geometry.type !== Enums.GeometryType.CONTOUR) {
54
+ throw new Error(
55
+ `Geometry type ${geometry.type} not supported for rendering.`
56
+ );
57
+ }
58
+
59
+ if (!geometry.data) {
60
+ console.warn(
61
+ `No contours found for geometryId ${geometryId}. Skipping render.`
62
+ );
63
+ return;
64
+ }
65
+ }
66
+
67
+ /**
68
+ * It takes a contourSet and returns a vtkPolyData for that contourSet. A contour set
69
+ * is a collection of contours. Each contour is a collection of points. Each point
70
+ * is x,y,z in the world coordinate system.
71
+ *
72
+ * @param contourSet - the contour set that you want to convert to polyData
73
+ * @returns A vtkPolyData object
74
+ */
75
+ export function getPolyData(contourSet: Types.IContourSet) {
76
+ const pointArray = [];
77
+
78
+ const points = vtkPoints.newInstance();
79
+ const lines = vtkCellArray.newInstance();
80
+
81
+ // this variable will indicate the index of the first point in the current line
82
+ // so we can correctly generate the point index list to add in the cellArray
83
+ let pointIndex = 0;
84
+ contourSet.getContours().forEach((contour: Types.IContour) => {
85
+ const pointList = contour.getPoints();
86
+ const flatPoints = contour.getFlatPointsArray();
87
+ const type = contour.getType();
88
+
89
+ // creating a point index list that defines a line
90
+ const pointIndexes = pointList.map(
91
+ (_, pointListIndex) => pointListIndex + pointIndex
92
+ );
93
+
94
+ // if close planar, add the first point index to the list
95
+ if (type === Enums.ContourType.CLOSED_PLANAR) {
96
+ pointIndexes.push(pointIndexes[0]);
97
+ }
98
+
99
+ const linePoints = Float32Array.from(flatPoints);
100
+ // add the current points into the point list
101
+ pointArray.push(...linePoints);
102
+ // add the point indexes into the cell array
103
+ lines.insertNextCell([...pointIndexes]);
104
+ // update the first point index
105
+ pointIndex = pointIndex + pointList.length;
106
+ });
107
+
108
+ // converts the pointArray into vtkPoints
109
+ points.setData(pointArray, 3);
110
+
111
+ // creates the polyData
112
+ const polygon = vtkPolyData.newInstance();
113
+ polygon.setPoints(points);
114
+ polygon.setLines(lines);
115
+
116
+ return polygon;
117
+ }
@@ -12,7 +12,10 @@ import Representations from '../../../enums/SegmentationRepresentations';
12
12
  import * as SegmentationConfig from '../../../stateManagement/segmentation/config/segmentationConfig';
13
13
  import * as SegmentationState from '../../../stateManagement/segmentation/segmentationState';
14
14
  import { getToolGroup } from '../../../store/ToolGroupManager';
15
- import type { LabelmapConfig } from '../../../types/LabelmapTypes';
15
+ import type {
16
+ LabelmapConfig,
17
+ LabelmapRenderingConfig,
18
+ } from '../../../types/LabelmapTypes';
16
19
  import {
17
20
  RepresentationPublicInput,
18
21
  SegmentationRepresentationConfig,
@@ -179,7 +182,7 @@ async function render(
179
182
  actorEntry = viewport.getActor(segmentationRepresentationUID);
180
183
  }
181
184
 
182
- const { cfun, ofun } = renderingConfig;
185
+ const { cfun, ofun } = renderingConfig as LabelmapRenderingConfig;
183
186
 
184
187
  const renderInactiveSegmentations =
185
188
  toolGroupConfig.renderInactiveSegmentations;
@@ -10,6 +10,8 @@ export type ContourConfig = {
10
10
  outlineOpacity?: number;
11
11
  /** alpha of outline for inactive segmentation */
12
12
  outlineOpacityInactive?: number;
13
+ /** outline visibility */
14
+ renderOutline?: boolean;
13
15
  };
14
16
 
15
17
  /**
@@ -1,5 +1,9 @@
1
1
  import * as Enums from '../enums';
2
- import { ContourConfig, ContourSegmentationData } from './ContourTypes';
2
+ import {
3
+ ContourConfig,
4
+ ContourRenderingConfig,
5
+ ContourSegmentationData,
6
+ } from './ContourTypes';
3
7
  import type {
4
8
  LabelmapConfig,
5
9
  LabelmapRenderingConfig,
@@ -18,11 +22,8 @@ export type Color = [number, number, number, number];
18
22
  export type ColorLUT = Array<Color>;
19
23
 
20
24
  export type SegmentSpecificRepresentationConfig = {
21
- [key: number]: RepresentationConfig;
25
+ [key: number | string]: RepresentationConfig;
22
26
  };
23
- /**
24
- * Segmentation Config
25
- */
26
27
 
27
28
  export type RepresentationConfig = {
28
29
  /** labelmap configuration */
@@ -126,13 +127,14 @@ export type ToolGroupSpecificLabelmapRepresentation =
126
127
 
127
128
  export type ToolGroupSpecificContourRepresentation =
128
129
  ToolGroupSpecificRepresentationState & {
129
- config: LabelmapRenderingConfig;
130
+ config: ContourRenderingConfig;
130
131
  segmentationRepresentationSpecificConfig?: RepresentationConfig;
131
132
  segmentSpecificConfig?: SegmentSpecificRepresentationConfig;
132
133
  };
133
134
 
134
135
  export type ToolGroupSpecificRepresentation =
135
- ToolGroupSpecificLabelmapRepresentation; // | other ones
136
+ | ToolGroupSpecificLabelmapRepresentation
137
+ | ToolGroupSpecificContourRepresentation;
136
138
 
137
139
  export type ToolGroupSpecificRepresentations =
138
140
  Array<ToolGroupSpecificRepresentation>;
@@ -194,11 +196,23 @@ export type ToolGroupSpecificRepresentations =
194
196
  * colorLUTIndex: 0,
195
197
  * visibility: true,
196
198
  * segmentsHidden: Set(),
197
- * // LabelmapRenderingConfig
199
+ * // rendering config
198
200
  * config: {
199
201
  * "cfun",
200
202
  * "ofun",
201
203
  * },
204
+ * // segmentation representation specific config, has priority over the one in the outer scope
205
+ * segmentationRepresentationSpecificConfig: {
206
+ * LABELMAP: {
207
+ * renderFill: true,
208
+ * }
209
+ * }
210
+ * // segment specific config
211
+ * segmentSpecificConfig: {
212
+ * 1: {
213
+ * renderFill: false,
214
+ * }
215
+ * },
202
216
  * },
203
217
  * ],
204
218
  * config: {
@@ -36,6 +36,7 @@ import type {
36
36
  SegmentationRepresentationData,
37
37
  Segmentation,
38
38
  ToolGroupSpecificRepresentationState,
39
+ ToolGroupSpecificContourRepresentation,
39
40
  ToolGroupSpecificLabelmapRepresentation,
40
41
  ToolGroupSpecificRepresentation,
41
42
  SegmentationState,
@@ -91,6 +92,7 @@ export type {
91
92
  SegmentationRepresentationConfig,
92
93
  RepresentationConfig,
93
94
  ToolGroupSpecificRepresentationState,
95
+ ToolGroupSpecificContourRepresentation,
94
96
  ToolGroupSpecificLabelmapRepresentation,
95
97
  ToolGroupSpecificRepresentation,
96
98
  RepresentationPublicInput,
@@ -5,6 +5,7 @@ import {
5
5
  StackViewport,
6
6
  VolumeViewport,
7
7
  cache,
8
+ BaseVolumeViewport,
8
9
  } from '@cornerstonejs/core';
9
10
 
10
11
  import { Types } from '@cornerstonejs/core';
@@ -301,7 +302,7 @@ function _getVolumeFromViewport(viewport): Types.IImageVolume {
301
302
  const actorEntry = viewport.getDefaultActor();
302
303
 
303
304
  if (!actorEntry) {
304
- console.warn('No actor found');
305
+ // This can happen during setup/teardown of viewports.
305
306
  return;
306
307
  }
307
308
 
@@ -1,7 +1,8 @@
1
1
  import { vec3 } from 'gl-matrix';
2
- import { CONSTANTS } from '@cornerstonejs/core';
2
+ import { CONSTANTS, metaData } from '@cornerstonejs/core';
3
3
  import type { Types } from '@cornerstonejs/core';
4
4
  import { Annotations, Annotation } from '../../types';
5
+ import { debug } from 'console';
5
6
 
6
7
  const { EPSILON } = CONSTANTS;
7
8
 
@@ -33,8 +34,33 @@ export default function filterAnnotationsWithinSlice(
33
34
  // logic down below.
34
35
  const annotationsWithParallelNormals = annotations.filter(
35
36
  (td: Annotation) => {
36
- const annotationViewPlaneNormal = td.metadata.viewPlaneNormal;
37
-
37
+ let annotationViewPlaneNormal = td.metadata.viewPlaneNormal;
38
+
39
+ if (!annotationViewPlaneNormal) {
40
+ // This code is run to set the annotation view plane normal
41
+ // for historical data which was saved without the normal.
42
+ const { referencedImageId } = td.metadata;
43
+ const { imageOrientationPatient } = metaData.get(
44
+ 'imagePlaneModule',
45
+ referencedImageId
46
+ );
47
+ const rowCosineVec = vec3.fromValues(
48
+ imageOrientationPatient[0],
49
+ imageOrientationPatient[1],
50
+ imageOrientationPatient[2]
51
+ );
52
+
53
+ const colCosineVec = vec3.fromValues(
54
+ imageOrientationPatient[3],
55
+ imageOrientationPatient[4],
56
+ imageOrientationPatient[5]
57
+ );
58
+
59
+ annotationViewPlaneNormal = vec3.create() as Types.Point3;
60
+
61
+ vec3.cross(annotationViewPlaneNormal, rowCosineVec, colCosineVec);
62
+ td.metadata.viewPlaneNormal = annotationViewPlaneNormal;
63
+ }
38
64
  const isParallel =
39
65
  Math.abs(vec3.dot(viewPlaneNormal, annotationViewPlaneNormal)) >
40
66
  PARALLEL_THRESHOLD;
@@ -1,4 +0,0 @@
1
- import { Types } from '@cornerstonejs/core';
2
- declare function addContourToElement(element: HTMLDivElement, contour: Types.IContour, actorUID: string): void;
3
- declare function addContourSetToElement(element: HTMLDivElement, contourSet: Types.IContourSet, actorUID: string): void;
4
- export { addContourToElement, addContourSetToElement };
@@ -1,87 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.addContourSetToElement = exports.addContourToElement = void 0;
7
- const core_1 = require("@cornerstonejs/core");
8
- const PolyData_1 = __importDefault(require("@kitware/vtk.js/Common/DataModel/PolyData"));
9
- const CellArray_1 = __importDefault(require("@kitware/vtk.js/Common/Core/CellArray"));
10
- const Points_1 = __importDefault(require("@kitware/vtk.js/Common/Core/Points"));
11
- const Mapper_1 = __importDefault(require("@kitware/vtk.js/Rendering/Core/Mapper"));
12
- const Actor_1 = __importDefault(require("@kitware/vtk.js/Rendering/Core/Actor"));
13
- function addContourToElement(element, contour, actorUID) {
14
- const enabledElement = (0, core_1.getEnabledElement)(element);
15
- const { renderingEngine, viewport } = enabledElement;
16
- const { id: viewportId } = viewport;
17
- const visibility = true;
18
- const immediateRender = false;
19
- const suppressEvents = true;
20
- const pointList = contour.getPoints();
21
- const flatPoints = contour.getFlatPointsArray();
22
- const color = contour.getColor();
23
- const type = contour.getType();
24
- const p = pointList.map((_, i) => i);
25
- if (type === core_1.Enums.ContourType.CLOSED_PLANAR) {
26
- p.push(0);
27
- }
28
- const var1 = Float32Array.from(flatPoints);
29
- const var2 = Uint32Array.from([p.length, ...p]);
30
- const colorToUse = color.map((c) => c / 255);
31
- const points = Points_1.default.newInstance();
32
- points.setData(var1, 3);
33
- const lines = CellArray_1.default.newInstance();
34
- lines.setData(var2, 3);
35
- const polygon = PolyData_1.default.newInstance();
36
- polygon.setPoints(points);
37
- polygon.setLines(lines);
38
- const mapper1 = Mapper_1.default.newInstance();
39
- mapper1.setInputData(polygon);
40
- const actor1 = Actor_1.default.newInstance();
41
- actor1.setMapper(mapper1);
42
- actor1.getProperty().setLineWidth(4);
43
- actor1.getProperty().setColor(colorToUse[0], colorToUse[1], colorToUse[2]);
44
- viewport.addActor({ actor: actor1, uid: actorUID });
45
- }
46
- exports.addContourToElement = addContourToElement;
47
- function addContourSetToElement(element, contourSet, actorUID) {
48
- const enabledElement = (0, core_1.getEnabledElement)(element);
49
- const { renderingEngine, viewport } = enabledElement;
50
- const { id: viewportId } = viewport;
51
- const visibility = true;
52
- const immediateRender = false;
53
- const suppressEvents = true;
54
- const actor1 = Actor_1.default.newInstance();
55
- let color;
56
- const pointArray = [];
57
- const points = Points_1.default.newInstance();
58
- const lines = CellArray_1.default.newInstance();
59
- let pointIndex = 0;
60
- contourSet.getContours().forEach((contour) => {
61
- const pointList = contour.getPoints();
62
- const flatPoints = contour.getFlatPointsArray();
63
- color = contour.getColor();
64
- const type = contour.getType();
65
- const pointIndexes = pointList.map((_, i) => i + pointIndex);
66
- if (type === core_1.Enums.ContourType.CLOSED_PLANAR) {
67
- pointIndexes.push(pointIndexes[0]);
68
- }
69
- const linePoints = Float32Array.from(flatPoints);
70
- pointArray.push(...linePoints);
71
- lines.insertNextCell([...pointIndexes]);
72
- pointIndex = pointIndex + pointList.length;
73
- });
74
- points.setData(pointArray, 3);
75
- const polygon = PolyData_1.default.newInstance();
76
- polygon.setPoints(points);
77
- polygon.setLines(lines);
78
- const mapper1 = Mapper_1.default.newInstance();
79
- mapper1.setInputData(polygon);
80
- actor1.setMapper(mapper1);
81
- actor1.getProperty().setLineWidth(4);
82
- const colorToUse = color.map((c) => c / 255);
83
- actor1.getProperty().setColor(colorToUse[0], colorToUse[1], colorToUse[2]);
84
- viewport.addActor({ actor: actor1, uid: actorUID });
85
- }
86
- exports.addContourSetToElement = addContourSetToElement;
87
- //# sourceMappingURL=addContourToElement.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"addContourToElement.js","sourceRoot":"","sources":["../../../../../src/tools/displayTools/Contour/addContourToElement.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAsE;AACtE,yFAAoE;AACpE,sFAAiE;AACjE,gFAA2D;AAC3D,mFAA8D;AAC9D,iFAA4D;AAK5D,SAAS,mBAAmB,CAC1B,OAAuB,EACvB,OAAuB,EACvB,QAAgB;IAEhB,MAAM,cAAc,GAAG,IAAA,wBAAiB,EAAC,OAAO,CAAC,CAAC;IAClD,MAAM,EAAE,eAAe,EAAE,QAAQ,EAAE,GAAG,cAAc,CAAC;IACrD,MAAM,EAAE,EAAE,EAAE,UAAU,EA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AAU,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;IAC7C,MAAM,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IAE3E,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC;AACtD,CAAC;AAE6B,wDAAsB"}
@@ -1,4 +0,0 @@
1
- import { Types } from '@cornerstonejs/core';
2
- declare function addContourToElement(element: HTMLDivElement, contour: Types.IContour, actorUID: string): void;
3
- declare function addContourSetToElement(element: HTMLDivElement, contourSet: Types.IContourSet, actorUID: string): void;
4
- export { addContourToElement, addContourSetToElement };
@@ -1,80 +0,0 @@
1
- import { getEnabledElement, Enums } from '@cornerstonejs/core';
2
- import vtkPolyData from '@kitware/vtk.js/Common/DataModel/PolyData';
3
- import vtkCellArray from '@kitware/vtk.js/Common/Core/CellArray';
4
- import vtkPoints from '@kitware/vtk.js/Common/Core/Points';
5
- import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper';
6
- import vtkActor from '@kitware/vtk.js/Rendering/Core/Actor';
7
- function addContourToElement(element, contour, actorUID) {
8
- const enabledElement = getEnabledElement(element);
9
- const { renderingEngine, viewport } = enabledElement;
10
- const { id: viewportId } = viewport;
11
- const visibility = true;
12
- const immediateRender = false;
13
- const suppressEvents = true;
14
- const pointList = contour.getPoints();
15
- const flatPoints = contour.getFlatPointsArray();
16
- const color = contour.getColor();
17
- const type = contour.getType();
18
- const p = pointList.map((_, i) => i);
19
- if (type === Enums.ContourType.CLOSED_PLANAR) {
20
- p.push(0);
21
- }
22
- const var1 = Float32Array.from(flatPoints);
23
- const var2 = Uint32Array.from([p.length, ...p]);
24
- const colorToUse = color.map((c) => c / 255);
25
- const points = vtkPoints.newInstance();
26
- points.setData(var1, 3);
27
- const lines = vtkCellArray.newInstance();
28
- lines.setData(var2, 3);
29
- const polygon = vtkPolyData.newInstance();
30
- polygon.setPoints(points);
31
- polygon.setLines(lines);
32
- const mapper1 = vtkMapper.newInstance();
33
- mapper1.setInputData(polygon);
34
- const actor1 = vtkActor.newInstance();
35
- actor1.setMapper(mapper1);
36
- actor1.getProperty().setLineWidth(4);
37
- actor1.getProperty().setColor(colorToUse[0], colorToUse[1], colorToUse[2]);
38
- viewport.addActor({ actor: actor1, uid: actorUID });
39
- }
40
- function addContourSetToElement(element, contourSet, actorUID) {
41
- const enabledElement = getEnabledElement(element);
42
- const { renderingEngine, viewport } = enabledElement;
43
- const { id: viewportId } = viewport;
44
- const visibility = true;
45
- const immediateRender = false;
46
- const suppressEvents = true;
47
- const actor1 = vtkActor.newInstance();
48
- let color;
49
- const pointArray = [];
50
- const points = vtkPoints.newInstance();
51
- const lines = vtkCellArray.newInstance();
52
- let pointIndex = 0;
53
- contourSet.getContours().forEach((contour) => {
54
- const pointList = contour.getPoints();
55
- const flatPoints = contour.getFlatPointsArray();
56
- color = contour.getColor();
57
- const type = contour.getType();
58
- const pointIndexes = pointList.map((_, i) => i + pointIndex);
59
- if (type === Enums.ContourType.CLOSED_PLANAR) {
60
- pointIndexes.push(pointIndexes[0]);
61
- }
62
- const linePoints = Float32Array.from(flatPoints);
63
- pointArray.push(...linePoints);
64
- lines.insertNextCell([...pointIndexes]);
65
- pointIndex = pointIndex + pointList.length;
66
- });
67
- points.setData(pointArray, 3);
68
- const polygon = vtkPolyData.newInstance();
69
- polygon.setPoints(points);
70
- polygon.setLines(lines);
71
- const mapper1 = vtkMapper.newInstance();
72
- mapper1.setInputData(polygon);
73
- actor1.setMapper(mapper1);
74
- actor1.getProperty().setLineWidth(4);
75
- const colorToUse = color.map((c) => c / 255);
76
- actor1.getProperty().setColor(colorToUse[0], colorToUse[1], colorToUse[2]);
77
- viewport.addActor({ actor: actor1, uid: actorUID });
78
- }
79
- export { addContourToElement, addContourSetToElement };
80
- //# sourceMappingURL=addContourToElement.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"addContourToElement.js","sourceRoot":"","sources":["../../../../../src/tools/displayTools/Contour/addContourToElement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAS,KAAK,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,WAAW,MAAM,2CAA2C,CAAC;AACpE,OAAO,YAAY,MAAM,uCAAuC,CAAC;AACjE,OAAO,SAAS,MAAM,oCAAoC,CAAC;AAC3D,OAAO,SAAS,MAAM,uCAAuC,CAAC;AAC9D,OAAO,QAAQ,MAAM,sCAAsC,CAAC;AAK5D,SAAS,mBAAmB,CAC1B,OAAuB,EACvB,OAAuB,EACvB,QAAgB;IAEhB,MAAM,cAAc,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAClD,MAAM,EAAE,eAAe,EAAE,QAAQ,EAAE,GAAG,cAAc,CAAC;IACrD,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,GAAG,QAAQ,CAAC;IAKpC,MAAM,UAAU,GAAG,IAAI,CAAC;IACxB,MAAM,eAAe,GAAG,KAAK,CAAC;IAC9B,MAAM,cAAc,GAAG,IAAI,CAAC;IAE5B,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IACtC,MAAM,UAAU,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAChD,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IACjC,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAE/B,MAAM,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;IAErC,IAAI,IAAI,KAAK,KAAK,CAAC,WAAW,CAAC,aAAa,EAAE;QAC5C,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC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AC,GAAG,UAAU,CAAC,CAAC;QAE/B,KAAK,CAAC,cAAc,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC;QAExC,UAAU,GAAG,UAAU,GAAG,SAAS,CAAC,MAAM,CAAC;IAC7C,CAAC,CAAC,CAAC;IAGH,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;IAG9B,MAAM,OAAO,GAAG,WAAW,CAAC,WAAW,EAAE,CAAC;IAC1C,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAC1B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAExB,MAAM,OAAO,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC;IACxC,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IAC9B,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IAC1B,MAAM,CAAC,WAAW,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAIrC,MAAM,UAAU,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;IAC7C,MAAM,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IAE3E,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC;AACtD,CAAC;AAED,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,CAAC"}
@@ -1,135 +0,0 @@
1
- import { getEnabledElement, Types, Enums } from '@cornerstonejs/core';
2
- import vtkPolyData from '@kitware/vtk.js/Common/DataModel/PolyData';
3
- import vtkCellArray from '@kitware/vtk.js/Common/Core/CellArray';
4
- import vtkPoints from '@kitware/vtk.js/Common/Core/Points';
5
- import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper';
6
- import vtkActor from '@kitware/vtk.js/Rendering/Core/Actor';
7
-
8
- // Todo: this seems to have performance issues when there are many contours
9
- // Maybe we should not create one actor per contour, but rather one actor per
10
- // contourSet?
11
- function addContourToElement(
12
- element: HTMLDivElement,
13
- contour: Types.IContour,
14
- actorUID: string
15
- ): void {
16
- const enabledElement = getEnabledElement(element);
17
- const { renderingEngine, viewport } = enabledElement;
18
- const { id: viewportId } = viewport;
19
-
20
- // Default to true since we are setting a new segmentation, however,
21
- // in the event listener, we will make other segmentations visible/invisible
22
- // based on the config
23
- const visibility = true;
24
- const immediateRender = false;
25
- const suppressEvents = true;
26
-
27
- const pointList = contour.getPoints();
28
- const flatPoints = contour.getFlatPointsArray();
29
- const color = contour.getColor();
30
- const type = contour.getType();
31
-
32
- const p = pointList.map((_, i) => i);
33
-
34
- if (type === Enums.ContourType.CLOSED_PLANAR) {
35
- p.push(0);
36
- }
37
-
38
- const var1 = Float32Array.from(flatPoints);
39
- const var2 = Uint32Array.from([p.length, ...p]);
40
-
41
- const colorToUse = color.map((c) => c / 255);
42
-
43
- const points = vtkPoints.newInstance();
44
- points.setData(var1, 3);
45
-
46
- const lines = vtkCellArray.newInstance();
47
- // @ts-ignore
48
- lines.setData(var2, 3);
49
-
50
- const polygon = vtkPolyData.newInstance();
51
- polygon.setPoints(points);
52
- polygon.setLines(lines);
53
-
54
- const mapper1 = vtkMapper.newInstance();
55
- mapper1.setInputData(polygon);
56
- const actor1 = vtkActor.newInstance();
57
- actor1.setMapper(mapper1);
58
- actor1.getProperty().setLineWidth(4);
59
- actor1.getProperty().setColor(colorToUse[0], colorToUse[1], colorToUse[2]);
60
-
61
- viewport.addActor({ actor: actor1, uid: actorUID });
62
- }
63
-
64
- function addContourSetToElement(
65
- element: HTMLDivElement,
66
- contourSet: Types.IContourSet,
67
- actorUID: string
68
- ): void {
69
- const enabledElement = getEnabledElement(element);
70
- const { renderingEngine, viewport } = enabledElement;
71
- const { id: viewportId } = viewport;
72
-
73
- // Default to true since we are setting a new segmentation, however,
74
- // in the event listener, we will make other segmentations visible/invisible
75
- // based on the config
76
- const visibility = true;
77
- const immediateRender = false;
78
- const suppressEvents = true;
79
-
80
- const actor1 = vtkActor.newInstance();
81
- let color;
82
-
83
- const pointArray = [];
84
-
85
- const points = vtkPoints.newInstance();
86
- const lines = vtkCellArray.newInstance();
87
-
88
- // this variable will indicate the index of the first point in the current line
89
- // so we can correctly generate the point index list to add in the cellArray
90
- let pointIndex = 0;
91
- contourSet.getContours().forEach((contour: Types.IContour) => {
92
- const pointList = contour.getPoints();
93
- const flatPoints = contour.getFlatPointsArray();
94
- color = contour.getColor();
95
- const type = contour.getType();
96
-
97
- // creating a point index list that defines a line
98
- const pointIndexes = pointList.map((_, i) => i + pointIndex);
99
-
100
- // if close planar, add the first point index to the list
101
- if (type === Enums.ContourType.CLOSED_PLANAR) {
102
- pointIndexes.push(pointIndexes[0]);
103
- }
104
-
105
- const linePoints = Float32Array.from(flatPoints);
106
- // add the curent points into the point list
107
- pointArray.push(...linePoints);
108
- // add the point indexes into the cell array
109
- lines.insertNextCell([...pointIndexes]);
110
- // update the first point index
111
- pointIndex = pointIndex + pointList.length;
112
- });
113
-
114
- // converts the pointArray into vtkPoints
115
- points.setData(pointArray, 3);
116
-
117
- // creates the polydata
118
- const polygon = vtkPolyData.newInstance();
119
- polygon.setPoints(points);
120
- polygon.setLines(lines);
121
-
122
- const mapper1 = vtkMapper.newInstance();
123
- mapper1.setInputData(polygon);
124
- actor1.setMapper(mapper1);
125
- actor1.getProperty().setLineWidth(4);
126
-
127
- // despite each contour can have its own color, we assign the last color to
128
- // all contours
129
- const colorToUse = color.map((c) => c / 255);
130
- actor1.getProperty().setColor(colorToUse[0], colorToUse[1], colorToUse[2]);
131
-
132
- viewport.addActor({ actor: actor1, uid: actorUID });
133
- }
134
-
135
- export { addContourToElement, addContourSetToElement };