@@ -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 ) ;
@@ -65,9 +84,9 @@ export async function readSegmentation(file: File, state) {
65
84
}
66
85
67
86
export async function loadSegmentation ( arrayBuffer : ArrayBuffer , state ) {
68
- const { referenceImageIds, skipOverlapping, segmentationIds } = state ;
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,29 +96,27 @@ export async function loadSegmentation(arrayBuffer: ArrayBuffer, state) {
77
96
}
78
97
) ;
79
98
80
- for ( let i = 0 ; i < generateToolState . labelMapImages . length ; i ++ ) {
81
- const segmentationId = "LOAD_SEG_ID:" + cornerstone . utilities . uuidv4 ( ) ;
82
- segmentationIds . push ( segmentationId ) ;
83
- await createSegmentation ( { ...state , segmentationId } ) ;
84
-
85
- const segmentation =
86
- csToolsSegmentation . state . getSegmentation ( segmentationId ) ;
87
-
88
- const { imageIds } = segmentation . representationData . Labelmap ;
89
- const derivedSegmentationImages = imageIds . map ( imageId =>
90
- cache . getImage ( imageId )
91
- ) ;
92
-
93
- const labelmapImagesNonOverlapping =
94
- generateToolState . labelMapImages [ i ] ;
95
-
96
- for ( let j = 0 ; j < derivedSegmentationImages . length ; j ++ ) {
97
- const voxelManager = derivedSegmentationImages [ j ] . voxelManager ;
98
- const scalarData = voxelManager . getScalarData ( ) ;
99
- scalarData . set ( labelmapImagesNonOverlapping [ j ] . getPixelData ( ) ) ;
100
- voxelManager . setScalarData ( scalarData ) ;
101
- }
102
- }
99
+ await createSegmentation ( { state, labelMapImages } ) ;
100
+ // for (let i = 0; i < labelMapImages.length; i++) {
101
+ // const segmentation =
102
+ // csToolsSegmentation.state.getSegmentation(segmentationId);
103
+
104
+ // const { imageIds } = segmentation.representationData.Labelmap;
105
+ // console.log("🚀 ~ loadSegmentation ~ imageIds:", imageIds);
106
+ // const derivedSegmentationImages = imageIds.map(imageId =>
107
+ // cache.getImage(imageId)
108
+ // );
109
+
110
+ // const labelmapImagesNonOverlapping = labelMapImages[i];
111
+
112
+ // for (let j = 0; j < derivedSegmentationImages.length; j++) {
113
+ // const voxelManager = derivedSegmentationImages[j].voxelManager;
114
+ // const scalarData = voxelManager.getScalarData();
115
+ // const derivedImage = labelmapImagesNonOverlapping[j];
116
+ // scalarData.set(labelmapImagesNonOverlapping[j].getPixelData());
117
+ // voxelManager.setScalarData(scalarData);
118
+ // }
119
+ // }
103
120
}
104
121
105
122
export async function exportSegmentation ( state ) {
0 commit comments