@cornerstonejs/tools 3.6.0 → 3.6.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.
@@ -1,6 +1,7 @@
1
- import { cache, utilities as csUtils, volumeLoader } from '@cornerstonejs/core';
1
+ import { cache, utilities as csUtils } from '@cornerstonejs/core';
2
2
  import StrategyCallbacks from '../../../../enums/StrategyCallbacks';
3
3
  import { getSegmentation } from '../../../../stateManagement/segmentation/getSegmentation';
4
+ import getOrCreateImageVolume from '../../../../utilities/segmentation/getOrCreateImageVolume';
4
5
  export default {
5
6
  [StrategyCallbacks.EnsureImageVolumeFor3DManipulation]: (data) => {
6
7
  const { operationData, viewport } = data;
@@ -21,14 +22,10 @@ export default {
21
22
  return image.referencedImageId;
22
23
  });
23
24
  }
24
- const volumeId = cache.generateVolumeId(referencedImageIds);
25
- let imageVolume = cache.getVolume(volumeId);
26
- if (imageVolume) {
27
- operationData.imageVoxelManager = imageVolume.voxelManager;
28
- operationData.imageData = imageVolume.imageData;
29
- return;
25
+ const imageVolume = getOrCreateImageVolume(referencedImageIds);
26
+ if (!imageVolume) {
27
+ throw new Error('Failed to create or get image volume');
30
28
  }
31
- imageVolume = volumeLoader.createAndCacheVolumeFromImagesSync(volumeId, referencedImageIds);
32
29
  operationData.imageVoxelManager = imageVolume.voxelManager;
33
30
  operationData.imageData = imageVolume.imageData;
34
31
  },
@@ -45,6 +45,12 @@ type NamedStatistics = {
45
45
  lesionGlycolysis?: Statistics & {
46
46
  name: 'lesionGlycolysis';
47
47
  };
48
+ maxLPS?: Statistics & {
49
+ name: 'maxLPS';
50
+ };
51
+ minLPS?: Statistics & {
52
+ name: 'minLPS';
53
+ };
48
54
  maxIJKs?: Array<{
49
55
  value: number;
50
56
  pointIJK: Types.Point3;
@@ -55,15 +55,15 @@ function basicStatsCallback(state, newValue, pointLPS = null, pointIJK = null) {
55
55
  if (value < state.min[idx]) {
56
56
  state.min[idx] = value;
57
57
  if (idx === 0) {
58
- state.minIJK = pointIJK;
59
- state.minLPS = pointLPS;
58
+ state.minIJK = pointIJK ? [...pointIJK] : null;
59
+ state.minLPS = pointLPS ? [...pointLPS] : null;
60
60
  }
61
61
  }
62
62
  if (value > state.max[idx]) {
63
63
  state.max[idx] = value;
64
64
  if (idx === 0) {
65
- state.maxIJK = pointIJK;
66
- state.maxLPS = pointLPS;
65
+ state.maxIJK = pointIJK ? [...pointIJK] : null;
66
+ state.maxLPS = pointLPS ? [...pointLPS] : null;
67
67
  }
68
68
  }
69
69
  });
@@ -105,16 +105,16 @@ function basicGetStatistics(state, unit) {
105
105
  label: 'Max Pixel',
106
106
  value: state.max.length === 1 ? state.max[0] : state.max,
107
107
  unit,
108
- pointIJK: state.maxIJK,
109
- pointLPS: state.maxLPS,
108
+ pointIJK: state.maxIJK ? [...state.maxIJK] : null,
109
+ pointLPS: state.maxLPS ? [...state.maxLPS] : null,
110
110
  },
111
111
  min: {
112
112
  name: 'min',
113
113
  label: 'Min Pixel',
114
114
  value: state.min.length === 1 ? state.min[0] : state.min,
115
115
  unit,
116
- pointIJK: state.minIJK,
117
- pointLPS: state.minLPS,
116
+ pointIJK: state.minIJK ? [...state.minIJK] : null,
117
+ pointLPS: state.minLPS ? [...state.minLPS] : null,
118
118
  },
119
119
  mean: {
120
120
  name: 'mean',
@@ -152,10 +152,22 @@ function basicGetStatistics(state, unit) {
152
152
  value: kurtosis.length === 1 ? kurtosis[0] : kurtosis,
153
153
  unit: null,
154
154
  },
155
+ maxLPS: {
156
+ name: 'maxLPS',
157
+ label: 'Max LPS',
158
+ value: state.maxLPS ? Array.from(state.maxLPS) : null,
159
+ unit: null,
160
+ },
161
+ minLPS: {
162
+ name: 'minLPS',
163
+ label: 'Min LPS',
164
+ value: state.minLPS ? Array.from(state.minLPS) : null,
165
+ unit: null,
166
+ },
155
167
  pointsInShape: state.pointsInShape,
156
168
  array: [],
157
169
  };
158
- named.array.push(named.max, named.mean, named.stdDev, named.median, named.skewness, named.kurtosis, named.count);
170
+ named.array.push(named.min, named.max, named.mean, named.stdDev, named.median, named.skewness, named.kurtosis, named.count, named.maxLPS, named.minLPS);
159
171
  const store = state.pointsInShape !== null;
160
172
  const freshState = createBasicStatsState(store);
161
173
  state.max = freshState.max;
@@ -14,13 +14,22 @@ function volumetricStatsCallback(state, data) {
14
14
  (length >= TEST_MAX_LOCATIONS && value < maxIJKs[0].value)) {
15
15
  return;
16
16
  }
17
+ const dataCopy = {
18
+ value: data.value,
19
+ pointLPS: data.pointLPS
20
+ ? [data.pointLPS[0], data.pointLPS[1], data.pointLPS[2]]
21
+ : undefined,
22
+ pointIJK: data.pointIJK
23
+ ? [data.pointIJK[0], data.pointIJK[1], data.pointIJK[2]]
24
+ : undefined,
25
+ };
17
26
  if (!length || value >= maxIJKs[length - 1].value) {
18
- maxIJKs.push(data);
27
+ maxIJKs.push(dataCopy);
19
28
  }
20
29
  else {
21
30
  for (let i = 0; i < length; i++) {
22
31
  if (value <= maxIJKs[i].value) {
23
- maxIJKs.splice(i, 0, data);
32
+ maxIJKs.splice(i, 0, dataCopy);
24
33
  break;
25
34
  }
26
35
  }
@@ -0,0 +1,8 @@
1
+ import type { NamedStatistics } from '../../types';
2
+ declare function computeMetabolicStats({ segmentationIds, segmentIndex, }: {
3
+ segmentationIds: string[];
4
+ segmentIndex: number;
5
+ }): Promise<NamedStatistics | {
6
+ [segmentIndex: number]: NamedStatistics;
7
+ }>;
8
+ export { computeMetabolicStats };
@@ -0,0 +1,58 @@
1
+ import { utilities, getWebWorkerManager } from '@cornerstonejs/core';
2
+ import { triggerWorkerProgress } from './utilsForWorker';
3
+ import { WorkerTypes } from '../../enums';
4
+ import { registerComputeWorker } from '../registerComputeWorker';
5
+ import createMergedLabelmapForIndex from './createMergedLabelmapForIndex';
6
+ import { getSegmentation } from '../../stateManagement/segmentation/getSegmentation';
7
+ import getOrCreateSegmentationVolume from './getOrCreateSegmentationVolume';
8
+ import { getReferenceVolumeForSegmentation } from './getReferenceVolumeForSegmentation';
9
+ async function computeMetabolicStats({ segmentationIds, segmentIndex, }) {
10
+ registerComputeWorker();
11
+ triggerWorkerProgress(WorkerTypes.COMPUTE_STATISTICS, 0);
12
+ const segmentation = getSegmentation(segmentationIds[0]);
13
+ const { imageIds: segImageIds } = segmentation.representationData
14
+ .Labelmap;
15
+ const isValidVolume = utilities.isValidVolume(segImageIds);
16
+ if (!isValidVolume) {
17
+ throw new Error('Invalid volume - TMTV cannot be calculated');
18
+ }
19
+ const stats = await calculateForVolume({
20
+ segmentationIds,
21
+ segmentIndex,
22
+ });
23
+ return stats;
24
+ }
25
+ async function calculateForVolume({ segmentationIds, segmentIndex }) {
26
+ const labelmapVolumes = segmentationIds.map((id) => {
27
+ return getOrCreateSegmentationVolume(id);
28
+ });
29
+ const mergedLabelmap = createMergedLabelmapForIndex(labelmapVolumes, segmentIndex);
30
+ if (!mergedLabelmap) {
31
+ throw new Error('Invalid volume - TMTV cannot be calculated');
32
+ }
33
+ const { imageData, dimensions, direction, origin, voxelManager } = mergedLabelmap;
34
+ const spacing = imageData.getSpacing();
35
+ const segmentationScalarData = voxelManager.getCompleteScalarDataArray();
36
+ const segmentationInfo = {
37
+ scalarData: segmentationScalarData,
38
+ dimensions,
39
+ spacing,
40
+ origin,
41
+ direction,
42
+ };
43
+ const referenceVolume = getReferenceVolumeForSegmentation(segmentationIds[0]);
44
+ const imageInfo = {
45
+ dimensions: referenceVolume.dimensions,
46
+ spacing: referenceVolume.spacing,
47
+ origin: referenceVolume.origin,
48
+ direction: referenceVolume.direction,
49
+ scalarData: referenceVolume.voxelManager.getCompleteScalarDataArray(),
50
+ };
51
+ const stats = await getWebWorkerManager().executeTask('compute', 'computeMetabolicStats', {
52
+ segmentationInfo,
53
+ imageInfo,
54
+ });
55
+ triggerWorkerProgress(WorkerTypes.COMPUTE_STATISTICS, 100);
56
+ return stats;
57
+ }
58
+ export { computeMetabolicStats };
@@ -1,4 +1,4 @@
1
- import { volumeLoader, utilities as csUtils } from '@cornerstonejs/core';
1
+ import { volumeLoader, utilities as csUtils, cache } from '@cornerstonejs/core';
2
2
  function createMergedLabelmapForIndex(labelmaps, segmentIndex = 1, volumeId = 'mergedLabelmap') {
3
3
  labelmaps.forEach(({ direction, dimensions, origin, spacing }) => {
4
4
  if (!csUtils.isEqual(dimensions, labelmaps[0].dimensions) ||
@@ -28,7 +28,15 @@ function createMergedLabelmapForIndex(labelmaps, segmentIndex = 1, volumeId = 'm
28
28
  direction: labelmap.direction,
29
29
  dimensions: labelmap.dimensions,
30
30
  };
31
- const mergedVolume = volumeLoader.createLocalVolume(volumeId, options);
31
+ const cachedVolume = cache.getVolume(volumeId);
32
+ let mergedVolume;
33
+ if (cachedVolume) {
34
+ mergedVolume = cachedVolume;
35
+ mergedVolume.voxelManager.setCompleteScalarDataArray(outputData);
36
+ }
37
+ else {
38
+ mergedVolume = volumeLoader.createLocalVolume(volumeId, options);
39
+ }
32
40
  return mergedVolume;
33
41
  }
34
42
  export default createMergedLabelmapForIndex;
@@ -0,0 +1,3 @@
1
+ import { type Types } from '@cornerstonejs/core';
2
+ declare function getOrCreateImageVolume(referencedImageIds: string[]): Types.IImageVolume | undefined;
3
+ export default getOrCreateImageVolume;
@@ -0,0 +1,18 @@
1
+ import { cache, volumeLoader, utilities as csUtils, } from '@cornerstonejs/core';
2
+ function getOrCreateImageVolume(referencedImageIds) {
3
+ if (!referencedImageIds || referencedImageIds.length <= 1) {
4
+ return;
5
+ }
6
+ const isValidVolume = csUtils.isValidVolume(referencedImageIds);
7
+ if (!isValidVolume) {
8
+ return;
9
+ }
10
+ const volumeId = cache.generateVolumeId(referencedImageIds);
11
+ let imageVolume = cache.getVolume(volumeId);
12
+ if (imageVolume) {
13
+ return imageVolume;
14
+ }
15
+ imageVolume = volumeLoader.createAndCacheVolumeFromImagesSync(volumeId, referencedImageIds);
16
+ return imageVolume;
17
+ }
18
+ export default getOrCreateImageVolume;
@@ -1,2 +1,3 @@
1
- declare function getOrCreateSegmentationVolume(segmentationId: any): any;
1
+ import { type Types } from '@cornerstonejs/core';
2
+ declare function getOrCreateSegmentationVolume(segmentationId: any): Types.IImageVolume | undefined;
2
3
  export default getOrCreateSegmentationVolume;
@@ -1,4 +1,4 @@
1
- import { cache, volumeLoader, utilities } from '@cornerstonejs/core';
1
+ import { cache, volumeLoader, utilities, } from '@cornerstonejs/core';
2
2
  import { getSegmentation } from '../../stateManagement/segmentation/getSegmentation';
3
3
  function getOrCreateSegmentationVolume(segmentationId) {
4
4
  const { representationData } = getSegmentation(segmentationId);
@@ -0,0 +1 @@
1
+ export declare function getReferenceVolumeForSegmentation(segmentationId: string): import("@cornerstonejs/core").ImageVolume;
@@ -0,0 +1,34 @@
1
+ import { cache } from '@cornerstonejs/core';
2
+ import { getSegmentation } from '../../stateManagement/segmentation/getSegmentation';
3
+ import getOrCreateImageVolume from './getOrCreateImageVolume';
4
+ export function getReferenceVolumeForSegmentation(segmentationId) {
5
+ const segmentation = getSegmentation(segmentationId);
6
+ if (!segmentation) {
7
+ return null;
8
+ }
9
+ let referenceImageIds;
10
+ const labelmap = segmentation.representationData.Labelmap;
11
+ if ('imageIds' in labelmap) {
12
+ const { imageIds } = labelmap;
13
+ const firstImage = cache.getImage(imageIds[0]);
14
+ const volumeInfo = cache.getVolumeContainingImageId(firstImage.referencedImageId);
15
+ if (volumeInfo?.volume) {
16
+ return volumeInfo.volume;
17
+ }
18
+ referenceImageIds = imageIds.map((imageId) => cache.getImage(imageId).referencedImageId);
19
+ }
20
+ else if ('volumeId' in labelmap) {
21
+ const { volumeId, referencedVolumeId } = labelmap;
22
+ if (referencedVolumeId) {
23
+ const refVolume = cache.getVolume(referencedVolumeId);
24
+ if (refVolume) {
25
+ return refVolume;
26
+ }
27
+ }
28
+ const segVolume = cache.getVolume(volumeId);
29
+ if (segVolume) {
30
+ referenceImageIds = segVolume.imageIds.map((imageId) => cache.getImage(imageId).referencedImageId);
31
+ }
32
+ }
33
+ return getOrCreateImageVolume(referenceImageIds);
34
+ }
@@ -116,7 +116,14 @@ const processSegmentationStatistics = ({ stats, unit, spacing, segmentationImage
116
116
  value: mean.value,
117
117
  unit,
118
118
  };
119
+ stats.peakPoint = {
120
+ name: 'peakLPS',
121
+ label: 'Peak SUV Point',
122
+ value: testMax.pointLPS ? [...testMax.pointLPS] : null,
123
+ unit: null,
124
+ };
119
125
  updateStatsArray(stats, stats.peakValue);
126
+ updateStatsArray(stats, stats.peakPoint);
120
127
  }
121
128
  }
122
129
  if (stats.volume && stats.mean) {
@@ -169,7 +176,7 @@ async function calculateStackStatistics({ segImageIds, indices, unit, mode }) {
169
176
  }
170
177
  }
171
178
  function getSphereStats(testMax, radiusIJK, segData, imageVoxels, spacing) {
172
- const { pointIJK: centerIJK } = testMax;
179
+ const { pointIJK: centerIJK, pointLPS: centerLPS } = testMax;
173
180
  if (!centerIJK) {
174
181
  return;
175
182
  }
@@ -22,10 +22,12 @@ import * as growCut from './growCut';
22
22
  import * as LabelmapMemo from './createLabelmapMemo';
23
23
  import IslandRemoval from './islandRemoval';
24
24
  import getOrCreateSegmentationVolume from './getOrCreateSegmentationVolume';
25
+ import getOrCreateImageVolume from './getOrCreateImageVolume';
25
26
  import getStatistics from './getStatistics';
26
27
  import * as validateLabelmap from './validateLabelmap';
27
28
  import { computeStackLabelmapFromVolume } from '../../stateManagement/segmentation/helpers/computeStackLabelmapFromVolume';
28
29
  import { computeVolumeLabelmapFromStack } from '../../stateManagement/segmentation/helpers/computeVolumeLabelmapFromStack';
29
30
  import { getReferenceVolumeForSegmentationVolume } from './getReferenceVolumeForSegmentationVolume';
30
31
  import { getSegmentLargestBidirectional } from './getSegmentLargestBidirectional';
31
- export { thresholdVolumeByRange, createMergedLabelmapForIndex, createLabelmapVolumeForViewport, rectangleROIThresholdVolumeByRange, triggerSegmentationRender, triggerSegmentationRenderBySegmentationId, floodFill, getBrushSizeForToolGroup, setBrushSizeForToolGroup, getBrushThresholdForToolGroup, setBrushThresholdForToolGroup, VolumetricCalculator, SegmentStatsCalculator, thresholdSegmentationByRange, contourAndFindLargestBidirectional, createBidirectionalToolData, segmentContourAction, invalidateBrushCursor, getUniqueSegmentIndices, getSegmentIndexAtWorldPoint, getSegmentIndexAtLabelmapBorder, getHoveredContourSegmentationAnnotation, getBrushToolInstances, growCut, LabelmapMemo, IslandRemoval, getOrCreateSegmentationVolume, getStatistics, validateLabelmap, computeStackLabelmapFromVolume, computeVolumeLabelmapFromStack, getReferenceVolumeForSegmentationVolume, getSegmentLargestBidirectional, };
32
+ import { computeMetabolicStats } from './computeMetabolicStats';
33
+ export { thresholdVolumeByRange, createMergedLabelmapForIndex, createLabelmapVolumeForViewport, rectangleROIThresholdVolumeByRange, triggerSegmentationRender, triggerSegmentationRenderBySegmentationId, floodFill, getBrushSizeForToolGroup, setBrushSizeForToolGroup, getBrushThresholdForToolGroup, setBrushThresholdForToolGroup, VolumetricCalculator, SegmentStatsCalculator, thresholdSegmentationByRange, contourAndFindLargestBidirectional, createBidirectionalToolData, segmentContourAction, invalidateBrushCursor, getUniqueSegmentIndices, getSegmentIndexAtWorldPoint, getSegmentIndexAtLabelmapBorder, getHoveredContourSegmentationAnnotation, getBrushToolInstances, growCut, LabelmapMemo, IslandRemoval, getOrCreateSegmentationVolume, getOrCreateImageVolume, getStatistics, validateLabelmap, computeStackLabelmapFromVolume, computeVolumeLabelmapFromStack, getReferenceVolumeForSegmentationVolume, getSegmentLargestBidirectional, computeMetabolicStats, };
@@ -22,10 +22,12 @@ import * as growCut from './growCut';
22
22
  import * as LabelmapMemo from './createLabelmapMemo';
23
23
  import IslandRemoval from './islandRemoval';
24
24
  import getOrCreateSegmentationVolume from './getOrCreateSegmentationVolume';
25
+ import getOrCreateImageVolume from './getOrCreateImageVolume';
25
26
  import getStatistics from './getStatistics';
26
27
  import * as validateLabelmap from './validateLabelmap';
27
28
  import { computeStackLabelmapFromVolume } from '../../stateManagement/segmentation/helpers/computeStackLabelmapFromVolume';
28
29
  import { computeVolumeLabelmapFromStack } from '../../stateManagement/segmentation/helpers/computeVolumeLabelmapFromStack';
29
30
  import { getReferenceVolumeForSegmentationVolume } from './getReferenceVolumeForSegmentationVolume';
30
31
  import { getSegmentLargestBidirectional } from './getSegmentLargestBidirectional';
31
- export { thresholdVolumeByRange, createMergedLabelmapForIndex, createLabelmapVolumeForViewport, rectangleROIThresholdVolumeByRange, triggerSegmentationRender, triggerSegmentationRenderBySegmentationId, floodFill, getBrushSizeForToolGroup, setBrushSizeForToolGroup, getBrushThresholdForToolGroup, setBrushThresholdForToolGroup, VolumetricCalculator, SegmentStatsCalculator, thresholdSegmentationByRange, contourAndFindLargestBidirectional, createBidirectionalToolData, segmentContourAction, invalidateBrushCursor, getUniqueSegmentIndices, getSegmentIndexAtWorldPoint, getSegmentIndexAtLabelmapBorder, getHoveredContourSegmentationAnnotation, getBrushToolInstances, growCut, LabelmapMemo, IslandRemoval, getOrCreateSegmentationVolume, getStatistics, validateLabelmap, computeStackLabelmapFromVolume, computeVolumeLabelmapFromStack, getReferenceVolumeForSegmentationVolume, getSegmentLargestBidirectional, };
32
+ import { computeMetabolicStats } from './computeMetabolicStats';
33
+ export { thresholdVolumeByRange, createMergedLabelmapForIndex, createLabelmapVolumeForViewport, rectangleROIThresholdVolumeByRange, triggerSegmentationRender, triggerSegmentationRenderBySegmentationId, floodFill, getBrushSizeForToolGroup, setBrushSizeForToolGroup, getBrushThresholdForToolGroup, setBrushThresholdForToolGroup, VolumetricCalculator, SegmentStatsCalculator, thresholdSegmentationByRange, contourAndFindLargestBidirectional, createBidirectionalToolData, segmentContourAction, invalidateBrushCursor, getUniqueSegmentIndices, getSegmentIndexAtWorldPoint, getSegmentIndexAtLabelmapBorder, getHoveredContourSegmentationAnnotation, getBrushToolInstances, growCut, LabelmapMemo, IslandRemoval, getOrCreateSegmentationVolume, getOrCreateImageVolume, getStatistics, validateLabelmap, computeStackLabelmapFromVolume, computeVolumeLabelmapFromStack, getReferenceVolumeForSegmentationVolume, getSegmentLargestBidirectional, computeMetabolicStats, };
@@ -29,15 +29,24 @@ const computeWorker = {
29
29
  scalarData,
30
30
  };
31
31
  },
32
- createVTKImageData: (dimensions, origin, direction, spacing) => {
32
+ createVTKImageData: (dimensions, origin, direction, spacing, scalarData) => {
33
33
  const imageData = vtkImageData.newInstance();
34
34
  imageData.setDimensions(dimensions);
35
35
  imageData.setOrigin(origin);
36
36
  imageData.setDirection(direction);
37
37
  imageData.setSpacing(spacing);
38
+ if (!scalarData) {
39
+ return imageData;
40
+ }
41
+ const scalarArray = vtkDataArray.newInstance({
42
+ name: 'Scalars',
43
+ numberOfComponents: 1,
44
+ values: scalarData,
45
+ });
46
+ imageData.getPointData().setScalars(scalarArray);
38
47
  return imageData;
39
48
  },
40
- processSegmentStatistics: (segVoxelManager, imageVoxelManager, indices, bounds) => {
49
+ processSegmentStatistics: ({ segVoxelManager, imageVoxelManager, indices, bounds, imageData, }) => {
41
50
  segVoxelManager.forEach(({ value, pointIJK, pointLPS, index }) => {
42
51
  if (indices.indexOf(value) === -1) {
43
52
  return;
@@ -51,6 +60,7 @@ const computeWorker = {
51
60
  });
52
61
  }, {
53
62
  boundsIJK: bounds || imageVoxelManager.getDefaultBounds(),
63
+ imageData,
54
64
  });
55
65
  },
56
66
  performMarchingSquares: (imageData, sliceIndex = null, slicingMode = null) => {
@@ -99,8 +109,14 @@ const computeWorker = {
99
109
  const { segmentation, image } = computeWorker.getArgsFromInfo(args);
100
110
  const { voxelManager: segVoxelManager, spacing: segmentationSpacing } = segmentation;
101
111
  const { voxelManager: imageVoxelManager } = image;
112
+ const imageData = computeWorker.createVTKImageData(segmentation.dimensions, segmentation.origin, segmentation.direction, segmentation.spacing);
102
113
  SegmentStatsCalculator.statsInit({ storePointData: false, indices, mode });
103
- computeWorker.processSegmentStatistics(segVoxelManager, imageVoxelManager, indices);
114
+ computeWorker.processSegmentStatistics({
115
+ segVoxelManager,
116
+ imageVoxelManager,
117
+ indices,
118
+ imageData,
119
+ });
104
120
  const stats = SegmentStatsCalculator.getStatistics({
105
121
  spacing: segmentationSpacing,
106
122
  unit: 'mm',
@@ -108,6 +124,33 @@ const computeWorker = {
108
124
  });
109
125
  return stats;
110
126
  },
127
+ computeMetabolicStats({ segmentationInfo, imageInfo }) {
128
+ const { scalarData, dimensions, spacing, origin, direction } = segmentationInfo;
129
+ const { spacing: imageSpacing, dimensions: imageDimensions, direction: imageDirection, origin: imageOrigin, scalarData: imageScalarData, } = imageInfo;
130
+ const segVoxelManager = computeWorker.createVoxelManager(segmentationInfo.dimensions, segmentationInfo.scalarData);
131
+ const refVoxelManager = computeWorker.createVoxelManager(imageDimensions, imageScalarData);
132
+ let suv = 0;
133
+ let numVoxels = 0;
134
+ const scalarDataLength = segVoxelManager.getScalarDataLength();
135
+ for (let i = 0; i < scalarDataLength; i++) {
136
+ if (segVoxelManager.getAtIndex(i) !== 0) {
137
+ suv += refVoxelManager.getAtIndex(i);
138
+ numVoxels++;
139
+ }
140
+ }
141
+ const tmtv = 1e-3 * numVoxels * spacing[0] * spacing[1] * spacing[2];
142
+ const averageSuv = numVoxels > 0 ? suv / numVoxels : 0;
143
+ const tlg = averageSuv *
144
+ numVoxels *
145
+ imageSpacing[0] *
146
+ imageSpacing[1] *
147
+ imageSpacing[2] *
148
+ 1e-3;
149
+ return {
150
+ tmtv,
151
+ tlg,
152
+ };
153
+ },
111
154
  calculateSegmentsStatisticsStack: (args) => {
112
155
  const { segmentationInfo, imageInfo, indices, mode } = args;
113
156
  SegmentStatsCalculator.statsInit({ storePointData: true, indices, mode });
@@ -121,7 +164,13 @@ const computeWorker = {
121
164
  ];
122
165
  const segVoxelManager = computeWorker.createVoxelManager(segDimensions, segInfo.scalarData);
123
166
  const imageVoxelManager = computeWorker.createVoxelManager(segDimensions, imgInfo.scalarData);
124
- computeWorker.processSegmentStatistics(segVoxelManager, imageVoxelManager, indices);
167
+ const imageData = computeWorker.createVTKImageData(segDimensions, segInfo.origin, segInfo.direction, segInfo.spacing);
168
+ computeWorker.processSegmentStatistics({
169
+ segVoxelManager,
170
+ imageVoxelManager,
171
+ indices,
172
+ imageData,
173
+ });
125
174
  }
126
175
  const spacing = segmentationInfo[0].spacing;
127
176
  const stats = SegmentStatsCalculator.getStatistics({
@@ -141,58 +190,119 @@ const computeWorker = {
141
190
  segmentationInfo: segmentationInfo[0],
142
191
  }));
143
192
  }
144
- const { voxelManager, dimensions, origin, direction, spacing } = segmentation;
145
- const stackDimensions = isStack
146
- ? [dimensions[0], dimensions[1], 2]
147
- : dimensions;
148
- const stackSpacing = isStack ? [spacing[0], spacing[1], 1] : spacing;
149
- const imageData = computeWorker.createVTKImageData(stackDimensions, origin, direction, stackSpacing);
150
- let contourSets;
151
- if (!isStack) {
152
- contourSets = computeWorker.generateContourSetsFromLabelmapVolume({
153
- segmentation,
193
+ return isStack
194
+ ? computeWorker.calculateBidirectionalStack({
195
+ segmentationInfo,
154
196
  indices,
155
- imageData,
156
197
  mode,
157
- });
158
- }
159
- else {
160
- contourSets = computeWorker.generateContourSetsFromLabelmapStack({
161
- segmentationInfo,
198
+ })
199
+ : computeWorker.calculateVolumetricBidirectional({
200
+ segmentation,
162
201
  indices,
163
202
  mode,
164
203
  });
204
+ },
205
+ findLargestBidirectionalFromContours: (contours, isInSegment, segmentIndex) => {
206
+ let maxBidirectional;
207
+ for (const sliceContour of contours) {
208
+ const bidirectional = createBidirectionalForSlice(sliceContour, isInSegment, maxBidirectional);
209
+ if (!bidirectional) {
210
+ continue;
211
+ }
212
+ maxBidirectional = bidirectional;
165
213
  }
166
- const bidirectionalData = [];
214
+ if (maxBidirectional) {
215
+ return {
216
+ segmentIndex,
217
+ majorAxis: maxBidirectional.majorAxis,
218
+ minorAxis: maxBidirectional.minorAxis,
219
+ maxMajor: maxBidirectional.maxMajor,
220
+ maxMinor: maxBidirectional.maxMinor,
221
+ };
222
+ }
223
+ return null;
224
+ },
225
+ calculateBidirectionalStack: ({ segmentationInfo, indices, mode }) => {
226
+ const segments = computeWorker.createSegmentsFromIndices(indices);
227
+ let bidirectionalResults = [];
228
+ for (let i = 0; i < segmentationInfo.length; i++) {
229
+ const segInfo = segmentationInfo[i];
230
+ const dimensions = segInfo.dimensions;
231
+ const segScalarData = segInfo.scalarData;
232
+ const { spacing, direction, origin } = segInfo;
233
+ const voxelManager = computeWorker.createVoxelManager(dimensions, segScalarData);
234
+ const pixelsPerSlice = dimensions[0] * dimensions[1];
235
+ for (let segIndex = 1; segIndex < segments.length; segIndex++) {
236
+ const segment = segments[segIndex];
237
+ if (!segment) {
238
+ continue;
239
+ }
240
+ const segmentIndex = segment.segmentIndex;
241
+ if (computeWorker.isSliceEmptyForSegmentVolume(0, segScalarData, pixelsPerSlice, segmentIndex)) {
242
+ continue;
243
+ }
244
+ const sliceContours = [];
245
+ const filteredData = new Uint8Array(segScalarData.length);
246
+ for (let i = 0; i < segScalarData.length; i++) {
247
+ filteredData[i] = segScalarData[i] === segmentIndex ? 1 : 0;
248
+ }
249
+ const scalarArray = vtkDataArray.newInstance({
250
+ name: 'Pixels',
251
+ numberOfComponents: 1,
252
+ values: filteredData,
253
+ });
254
+ const imageData = computeWorker.createVTKImageData(dimensions, origin, direction, [spacing[0], spacing[1], 1]);
255
+ imageData.getPointData().setScalars(scalarArray);
256
+ try {
257
+ const msOutput = computeWorker.performMarchingSquares(imageData, null, 2);
258
+ const contourData = computeWorker.createContoursFromPolyData(msOutput);
259
+ if (contourData) {
260
+ sliceContours.push(contourData);
261
+ }
262
+ }
263
+ catch (e) {
264
+ console.warn(e);
265
+ }
266
+ const isInSegment = createIsInSegmentMetadata({
267
+ dimensions,
268
+ imageData,
269
+ voxelManager,
270
+ segmentIndex,
271
+ });
272
+ const bidirectionalResult = computeWorker.findLargestBidirectionalFromContours(sliceContours, isInSegment, segmentIndex);
273
+ if (bidirectionalResult) {
274
+ bidirectionalResults.push(bidirectionalResult);
275
+ }
276
+ }
277
+ }
278
+ return bidirectionalResults;
279
+ },
280
+ calculateVolumetricBidirectional: ({ segmentation, indices, mode }) => {
281
+ const { voxelManager, dimensions, origin, direction, spacing } = segmentation;
282
+ const imageData = computeWorker.createVTKImageData(dimensions, origin, direction, spacing);
283
+ const contourSets = computeWorker.generateContourSetsFromLabelmapVolume({
284
+ segmentation,
285
+ indices,
286
+ imageData,
287
+ mode,
288
+ });
289
+ const bidirectionalResults = [];
167
290
  for (let i = 0; i < contourSets.length; i++) {
168
291
  const contourSet = contourSets[i];
169
292
  const { segmentIndex } = contourSet.segment;
170
293
  const contours = contourSet.sliceContours;
171
- let maxBidirectional;
172
294
  const isInSegment = createIsInSegmentMetadata({
173
295
  dimensions,
174
296
  imageData,
175
297
  voxelManager,
176
298
  segmentIndex,
177
299
  });
178
- for (const sliceContour of contours) {
179
- const bidirectional = createBidirectionalForSlice(sliceContour, isInSegment, maxBidirectional);
180
- if (!bidirectional) {
181
- continue;
182
- }
183
- maxBidirectional = bidirectional;
184
- }
185
- if (maxBidirectional) {
186
- bidirectionalData.push({
187
- segmentIndex,
188
- majorAxis: maxBidirectional.majorAxis,
189
- minorAxis: maxBidirectional.minorAxis,
190
- maxMajor: maxBidirectional.maxMajor,
191
- maxMinor: maxBidirectional.maxMinor,
192
- });
300
+ const bidirectionalResult = computeWorker.findLargestBidirectionalFromContours(contours, isInSegment, segmentIndex);
301
+ if (bidirectionalResult) {
302
+ bidirectionalResults.push(bidirectionalResult);
193
303
  }
194
304
  }
195
- return bidirectionalData;
305
+ return bidirectionalResults;
196
306
  },
197
307
  generateContourSetsFromLabelmapVolume: (args) => {
198
308
  const { segmentation, indices, imageData } = args;
@@ -259,62 +369,6 @@ const computeWorker = {
259
369
  }
260
370
  return ContourSets;
261
371
  },
262
- generateContourSetsFromLabelmapStack: (args) => {
263
- const { segmentationInfo, indices } = args;
264
- let ContourSets = [];
265
- for (let i = 0; i < segmentationInfo.length; i++) {
266
- const segInfo = segmentationInfo[i];
267
- const dimensions = segInfo.dimensions;
268
- const segScalarData = segInfo.scalarData;
269
- const { spacing, direction, origin } = segInfo;
270
- const segments = computeWorker.createSegmentsFromIndices(indices);
271
- const pixelsPerSlice = dimensions[0] * dimensions[1];
272
- const numSegments = segments.length;
273
- for (let segIndex = 0; segIndex < numSegments; segIndex++) {
274
- const segment = segments[segIndex];
275
- if (!segment) {
276
- continue;
277
- }
278
- const segmentIndex = segment.segmentIndex;
279
- if (computeWorker.isSliceEmptyForSegmentVolume(0, segScalarData, pixelsPerSlice, segmentIndex)) {
280
- continue;
281
- }
282
- const sliceContours = [];
283
- const filteredData = new Uint8Array(segScalarData.length);
284
- for (let i = 0; i < segScalarData.length; i++) {
285
- if (segScalarData[i] === segmentIndex) {
286
- filteredData[i] = 1;
287
- }
288
- else {
289
- filteredData[i] = 0;
290
- }
291
- }
292
- const scalarArray = vtkDataArray.newInstance({
293
- name: 'Pixels',
294
- numberOfComponents: 1,
295
- values: filteredData,
296
- });
297
- const imageData = computeWorker.createVTKImageData(dimensions, origin, direction, [spacing[0], spacing[1], 1]);
298
- imageData.getPointData().setScalars(scalarArray);
299
- try {
300
- const msOutput = computeWorker.performMarchingSquares(imageData, null, 2);
301
- const contourData = computeWorker.createContoursFromPolyData(msOutput);
302
- if (contourData) {
303
- sliceContours.push(contourData);
304
- }
305
- }
306
- catch (e) {
307
- console.warn(e);
308
- }
309
- const ContourSet = {
310
- sliceContours,
311
- segment,
312
- };
313
- ContourSets.push(ContourSet);
314
- }
315
- }
316
- return ContourSets;
317
- },
318
372
  isSliceEmptyForSegmentVolume: (sliceIndex, segData, pixelsPerSlice, segIndex) => {
319
373
  const startIdx = sliceIndex * pixelsPerSlice;
320
374
  const endIdx = startIdx + pixelsPerSlice;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/tools",
3
- "version": "3.6.0",
3
+ "version": "3.6.1",
4
4
  "description": "Cornerstone3D Tools",
5
5
  "types": "./dist/esm/index.d.ts",
6
6
  "module": "./dist/esm/index.js",
@@ -103,8 +103,8 @@
103
103
  "canvas": "^2.11.2"
104
104
  },
105
105
  "peerDependencies": {
106
- "@cornerstonejs/core": "^3.6.0",
107
- "@kitware/vtk.js": "32.12.0",
106
+ "@cornerstonejs/core": "^3.6.1",
107
+ "@kitware/vtk.js": "32.12.1",
108
108
  "@types/d3-array": "^3.0.4",
109
109
  "@types/d3-interpolate": "^3.0.1",
110
110
  "d3-array": "^3.2.3",
@@ -122,5 +122,5 @@
122
122
  "type": "individual",
123
123
  "url": "https://ohif.org/donate"
124
124
  },
125
- "gitHead": "480e48c2a25ce79a4a90be6fe180d1bcdd1b831e"
125
+ "gitHead": "a262fd519f1ceabe2e1d1d01a382087920657f65"
126
126
  }