@@ -18,7 +18,7 @@ export async function readDicom(files: FileList, state) {
18
18
}
19
19
}
20
20
21
- export async function createSegmentation ( state ) {
21
+ export async function createEmptySegmentation ( state ) {
22
22
const { referenceImageIds, segmentationId } = state ;
23
23
24
24
const derivedSegmentationImages =
@@ -44,6 +44,25 @@ export async function createSegmentation(state) {
44
44
] ) ;
45
45
}
46
46
47
+ export async function createSegmentation ( { state, labelMapImages } ) {
48
+ const { segmentationId } = state ;
49
+
50
+ const imageIds = labelMapImages ?. flat ( ) . map ( image => image . imageId ) ;
51
+
52
+ csToolsSegmentation . addSegmentations ( [
53
+ {
54
+ segmentationId,
55
+ representation : {
56
+ type : cornerstoneTools . Enums . SegmentationRepresentations
57
+ . Labelmap ,
58
+ data : {
59
+ imageIds
60
+ }
61
+ }
62
+ }
63
+ ] ) ;
64
+ }
65
+
47
66
export async function readSegmentation ( file : File , state ) {
48
67
const imageId = wadouri . fileManager . add ( file ) ;
49
68
const image = await imageLoader . loadAndCacheImage ( imageId ) ;
@@ -67,7 +86,7 @@ export async function readSegmentation(file: File, state) {
67
86
export async function loadSegmentation ( arrayBuffer : ArrayBuffer , state ) {
68
87
const { referenceImageIds, skipOverlapping, segmentationId } = state ;
69
88
70
- const generateToolState =
89
+ const { labelMapImages } =
71
90
await Cornerstone3D . Segmentation . createFromDICOMSegBuffer (
72
91
referenceImageIds ,
73
92
arrayBuffer ,
@@ -77,24 +96,7 @@ export async function loadSegmentation(arrayBuffer: ArrayBuffer, state) {
77
96
}
78
97
) ;
79
98
80
- await createSegmentation ( state ) ;
81
-
82
- const segmentation =
83
- csToolsSegmentation . state . getSegmentation ( segmentationId ) ;
84
-
85
- const { imageIds } = segmentation . representationData . Labelmap ;
86
- const derivedSegmentationImages = imageIds . map ( imageId =>
87
- cache . getImage ( imageId )
88
- ) ;
89
-
90
- const labelmapImagesNonOverlapping = generateToolState . labelMapImages [ 0 ] ;
91
-
92
- for ( let i = 0 ; i < derivedSegmentationImages . length ; i ++ ) {
93
- const voxelManager = derivedSegmentationImages [ i ] . voxelManager ;
94
- const scalarData = voxelManager . getScalarData ( ) ;
95
- scalarData . set ( labelmapImagesNonOverlapping [ i ] . getPixelData ( ) ) ;
96
- voxelManager . setScalarData ( scalarData ) ;
97
- }
99
+ await createSegmentation ( { state, labelMapImages } ) ;
98
100
}
99
101
100
102
export async function exportSegmentation ( state ) {
0 commit comments