@@ -291,10 +291,6 @@ function generateToolState(
291
291
292
292
const SeriesInstanceUID = generalSeriesModule . seriesInstanceUID ;
293
293
294
- console . warn (
295
- "Note the cornerstoneTools 4.0 currently assumes the labelmaps are non-overlapping. Overlapping segments will allocate incorrectly. Feel free to submit a PR to improve this behaviour!"
296
- ) ;
297
-
298
294
if ( ! imagePlaneModule ) {
299
295
console . warn ( "Insufficient metadata, imagePlaneModule missing." ) ;
300
296
}
@@ -636,16 +632,18 @@ function checkSEGsOverlapping(
636
632
: undefined ;
637
633
const sliceLength = Columns * Rows ;
638
634
639
- var firstSegIndex = - 1 ;
640
- var previousimageIdIndex = - 1 ;
641
- var temp2DArray = new Uint16Array ( sliceLength ) . fill ( 0 ) ;
642
- var groupsLen = PerFrameFunctionalGroupsSequence . length ;
643
- var numberOfSegs = multiframe . SegmentSequence . length ;
644
- var numberOfFrames = imageIds . length ;
635
+ let firstSegIndex = - 1 ;
636
+ let previousimageIdIndex = - 1 ;
637
+ let temp2DArray = new Uint16Array ( sliceLength ) . fill ( 0 ) ;
638
+ const groupsLen = PerFrameFunctionalGroupsSequence . length ;
639
+ const numberOfSegs = multiframe . SegmentSequence . length ;
640
+ const numberOfFrames = imageIds . length ;
645
641
646
642
if ( numberOfSegs * numberOfFrames !== groupsLen ) {
647
643
console . warn (
648
- "Failed to check for overlap of segments: missing frames in PerFrameFunctionalGroupsSequence."
644
+ "Failed to check for overlap of segments: " +
645
+ "missing frames in PerFrameFunctionalGroupsSequence " +
646
+ "or the segmentation has different geometry respect to the source image."
649
647
) ;
650
648
return false ;
651
649
}
@@ -663,7 +661,7 @@ function checkSEGsOverlapping(
663
661
return false ;
664
662
}
665
663
666
- var i = 0 ;
664
+ let i = 0 ;
667
665
while ( i < groupsLen ) {
668
666
const PerFrameFunctionalGroups = PerFrameFunctionalGroupsSequence [ i ] ;
669
667
@@ -684,34 +682,18 @@ function checkSEGsOverlapping(
684
682
) ;
685
683
686
684
if ( ! alignedPixelDataI ) {
687
- // Individual SEG frames are out of plane with respect to the first SEG frame, this is not yet supported
688
- i = i + numberOfFrames ;
689
- if ( i >= groupsLen ) {
690
- i = i - numberOfFrames * numberOfSegs + 1 ;
691
- if ( i >= numberOfFrames ) {
692
- break ;
693
- }
694
- }
695
-
696
- continue ;
685
+ console . warn (
686
+ "Individual SEG frames are out of plane with respect to the first SEG frame, this is not yet supported, skipping this frame."
687
+ ) ;
688
+ return false ;
697
689
}
698
690
699
691
const segmentIndex = getSegmentIndex ( multiframe , i ) ;
700
-
701
692
if ( segmentIndex === undefined ) {
702
693
console . warn (
703
- "Could not retrieve the segment index, skipping this frame. "
694
+ "Could not retrieve the segment index, skipping this frame."
704
695
) ;
705
-
706
- i = i + numberOfFrames ;
707
- if ( i >= groupsLen ) {
708
- i = i - numberOfFrames * numberOfSegs + 1 ;
709
- if ( i >= numberOfFrames ) {
710
- break ;
711
- }
712
- }
713
-
714
- continue ;
696
+ return false ;
715
697
}
716
698
717
699
let SourceImageSequence ;
@@ -724,6 +706,13 @@ function checkSEGsOverlapping(
724
706
. SourceImageSequence ;
725
707
}
726
708
709
+ if ( ! SourceImageSequence ) {
710
+ console . warn (
711
+ "Source Image Sequence information missing: individual SEG frames are out of plane, this is not yet supported, skipping this frame."
712
+ ) ;
713
+ return false ;
714
+ }
715
+
727
716
const imageId = getImageIdOfSourceImage (
728
717
SourceImageSequence ,
729
718
imageIds ,
@@ -805,16 +794,16 @@ function insertOverlappingPixelDataPlanar(
805
794
const arrayBufferLength = sliceLength * imageIds . length * 2 ; // 2 bytes per label voxel in cst4.
806
795
807
796
// indicate the number of labelMaps
808
- var M = 1 ;
797
+ let M = 1 ;
809
798
810
799
// indicate the current labelMap array index;
811
- var m = 0 ;
800
+ let m = 0 ;
812
801
813
802
// temp array for checking overlaps
814
- var tempBuffer = labelmapBufferArray [ m ] . slice ( 0 ) ;
803
+ let tempBuffer = labelmapBufferArray [ m ] . slice ( 0 ) ;
815
804
816
805
// temp list for checking overlaps
817
- var tempSegmentsOnFrame = cloneDeep ( segmentsOnFrameArray [ m ] ) ;
806
+ let tempSegmentsOnFrame = cloneDeep ( segmentsOnFrameArray [ m ] ) ;
818
807
819
808
/* split overlapping SEGs algorithm for each segment:
820
809
A) copy the labelmapBuffer in the array with index 0
@@ -823,7 +812,7 @@ function insertOverlappingPixelDataPlanar(
823
812
D) if overlap, repeat increasing the index m up to M (if out of memory, add new buffer in the array and M++);
824
813
*/
825
814
826
- var numberOfSegs = multiframe . SegmentSequence . length ;
815
+ let numberOfSegs = multiframe . SegmentSequence . length ;
827
816
for (
828
817
let segmentIndexToProcess = 1 ;
829
818
segmentIndexToProcess <= numberOfSegs ;
@@ -839,10 +828,9 @@ function insertOverlappingPixelDataPlanar(
839
828
840
829
const segmentIndex = getSegmentIndex ( multiframe , i ) ;
841
830
if ( segmentIndex === undefined ) {
842
- console . warn (
843
- "Could not retrieve the segment index, skipping this frame. "
831
+ throw new Error (
832
+ "Could not retrieve the segment index. Aborting segmentation loading. "
844
833
) ;
845
- continue ;
846
834
}
847
835
848
836
if ( segmentIndex !== segmentIndexToProcess ) {
@@ -866,15 +854,14 @@ function insertOverlappingPixelDataPlanar(
866
854
) ;
867
855
868
856
if ( ! alignedPixelDataI ) {
869
- console . warn (
870
- "Individual SEG frames are out of plane with respect to the first SEG frame, this is not yet supported, skipping this frame."
857
+ throw new Error (
858
+ "Individual SEG frames are out of plane with respect to the first SEG frame. " +
859
+ "This is not yet supported. Aborting segmentation loading."
871
860
) ;
872
-
873
- inPlane = false ;
874
- break ;
875
861
}
876
862
877
- let SourceImageSequence ;
863
+ let imageId = undefined ;
864
+ let SourceImageSequence = undefined ;
878
865
879
866
if ( multiframe . SourceImageSequence ) {
880
867
SourceImageSequence = multiframe . SourceImageSequence [ i ] ;
@@ -884,7 +871,14 @@ function insertOverlappingPixelDataPlanar(
884
871
. SourceImageSequence ;
885
872
}
886
873
887
- const imageId = getImageIdOfSourceImage (
874
+ if ( ! SourceImageSequence ) {
875
+ throw new Error (
876
+ "Source Image Sequence information missing: individual SEG frames are out of plane. " +
877
+ "This is not yet supported. Aborting segmentation loading."
878
+ ) ;
879
+ }
880
+
881
+ imageId = getImageIdOfSourceImage (
888
882
SourceImageSequence ,
889
883
imageIds ,
890
884
metadataProvider
@@ -895,6 +889,21 @@ function insertOverlappingPixelDataPlanar(
895
889
continue ;
896
890
}
897
891
892
+ const sourceImageMetadata = cornerstone . metaData . get (
893
+ "instance" ,
894
+ imageId
895
+ ) ;
896
+ if (
897
+ Rows !== sourceImageMetadata . Rows ||
898
+ Columns !== sourceImageMetadata . Columns
899
+ ) {
900
+ throw new Error (
901
+ "Individual SEG frames have different geometry dimensions (Rows and Columns) " +
902
+ "respect to the source image reference frame. This is not yet supported. " +
903
+ "Aborting segmentation loading. "
904
+ ) ;
905
+ }
906
+
898
907
const imageIdIndex = imageIds . findIndex (
899
908
element => element === imageId
900
909
) ;
@@ -1022,24 +1031,21 @@ function insertPixelDataPlanar(
1022
1031
) ;
1023
1032
1024
1033
if ( ! alignedPixelDataI ) {
1025
- console . warn (
1026
- "Individual SEG frames are out of plane with respect to the first SEG frame, this is not yet supported, skipping this frame."
1034
+ throw new Error (
1035
+ "Individual SEG frames are out of plane with respect to the first SEG frame. " +
1036
+ "This is not yet supported. Aborting segmentation loading."
1027
1037
) ;
1028
-
1029
- inPlane = false ;
1030
- break ;
1031
1038
}
1032
1039
1033
1040
const segmentIndex = getSegmentIndex ( multiframe , i ) ;
1034
1041
if ( segmentIndex === undefined ) {
1035
- console . warn (
1036
- "Could not retrieve the segment index, skipping this frame. "
1042
+ throw new Error (
1043
+ "Could not retrieve the segment index. Aborting segmentation loading. "
1037
1044
) ;
1038
- break ;
1039
1045
}
1040
1046
1041
- let SourceImageSequence ;
1042
-
1047
+ let imageId = undefined ;
1048
+ let SourceImageSequence = undefined ;
1043
1049
if ( multiframe . SourceImageSequence ) {
1044
1050
SourceImageSequence = multiframe . SourceImageSequence [ i ] ;
1045
1051
} else {
@@ -1048,7 +1054,14 @@ function insertPixelDataPlanar(
1048
1054
. SourceImageSequence ;
1049
1055
}
1050
1056
1051
- const imageId = getImageIdOfSourceImage (
1057
+ if ( ! SourceImageSequence ) {
1058
+ throw new Error (
1059
+ "Source Image Sequence information missing: individual SEG frames are out of plane. " +
1060
+ "This is not yet supported. Aborting segmentation loading."
1061
+ ) ;
1062
+ }
1063
+
1064
+ imageId = getImageIdOfSourceImage (
1052
1065
SourceImageSequence ,
1053
1066
imageIds ,
1054
1067
metadataProvider
@@ -1059,6 +1072,21 @@ function insertPixelDataPlanar(
1059
1072
continue ;
1060
1073
}
1061
1074
1075
+ const sourceImageMetadata = cornerstone . metaData . get (
1076
+ "instance" ,
1077
+ imageId
1078
+ ) ;
1079
+ if (
1080
+ Rows !== sourceImageMetadata . Rows ||
1081
+ Columns !== sourceImageMetadata . Columns
1082
+ ) {
1083
+ throw new Error (
1084
+ "Individual SEG frames have different geometry dimensions (Rows and Columns) " +
1085
+ "respect to the source image reference frame. This is not yet supported. " +
1086
+ "Aborting segmentation loading. "
1087
+ ) ;
1088
+ }
1089
+
1062
1090
const imageIdIndex = imageIds . findIndex ( element => element === imageId ) ;
1063
1091
const byteOffset = sliceLength * 2 * imageIdIndex ; // 2 bytes/pixel
1064
1092
0 commit comments