extensions/xnat/src/utils/IO/classes/MaskImporter.js
/**
   * importDICOMSEG - Imports a DICOM SEG file to CornerstoneTools.
   *
   * @param  {ArrayBuffer} dicomSegArrayBuffer An arraybuffer of the DICOM SEG object.
   * @returns {null}                     description
   */
Imports a DICOM SEG file to CornerstoneTools.
@param  {ArrayBuffer} dicomSegArrayBuffer An arraybuffer of the DICOM SEG object.
@returns {null}                     description
Imports a DICOM SEG file to CornerstoneTools . @param { ArrayBuffer } dicomSegArrayBuffer An arraybuffer of the DICOM SEG object . @returns { null } description
importDICOMSEG(dicomSegArrayBuffer) {
    return new Promise(resolve => {
      const imageIds = this._imageIds;
      const imagePromises = [];
      const numImages = imageIds.length;
      let processed = 0;
      for (let i = 0; i < imageIds.length; i++) {
        const promise = cornerstone.loadAndCacheImage(imageIds[i]);
        promise.then(() => {
          processed++;
          this.updateProgressCallback(
            Math.floor((processed * 100) / numImages)
          );
        });
        imagePromises.push(promise);
      }
      Promise.all(imagePromises).then(() => {
        const {
          labelmapBuffer,
          segMetadata,
          probabilityMapBuffer,
          isFractional,
          segmentsOnFrame,
        } = Segmentation_4X_fork.generateToolState(
          imageIds,
          dicomSegArrayBuffer,
          cornerstone.metaData
        );
        const firstImageId = imageIds[0];
        if (segmentationModule.state.series[firstImageId]) {
          delete segmentationModule.state.series[firstImageId];
        }
        const metadata = segMetadata.data;
        metadata.forEach(seg => {
          if (seg !== undefined) {
            seg.uid = generateUID();
          }
        });
        if (isFractional) {
          segmentationModule.setters.fractionalLabelmap3DByFirstImageId(
            firstImageId,
            labelmapBuffer,
            probabilityMapBuffer,
            0,
            metadata,
            imageIds.length,
            segmentsOnFrame
          );
          Object.assign(
            segmentationModule.configuration,
            fractionalLabelmapConfiguration
          );
          const colorLUT = segmentationModule.state.colorLutTables[0];
          if (!Array.isArray(colorLUT[1][0][0])) {
            colorLUT[1] = colorMaps[0].colormap;
            colorLUT[1].ID = colorMaps[0].ID;
          }
        } else {
          segmentationModule.setters.labelmap3DByFirstImageId(
            firstImageId,
            labelmapBuffer,
            0, 
            metadata,
            imageIds.length,
            segmentsOnFrame
          );
          Object.assign(
            segmentationModule.configuration,
            labelmapConfiguration
          );
        }
        cornerstoneTools.store.state.enabledElements.forEach(element =>
          cornerstone.updateImage(element)
        );
        resolve();
      });
    });
  }
importDICOMSEG ( dicomSegArrayBuffer ) { return new Promise ( resolve => { const imageIds = this . _imageIds ; const imagePromises = [ ] ; const numImages = imageIds . length ; let processed = 0 ; for ( let i = 0 ; i < imageIds . length ; i ++ ) { const promise = cornerstone . loadAndCacheImage ( imageIds [ i ] ) ; promise . then ( ( ) => { processed ++ ; this . updateProgressCallback ( Math . floor ( ( processed * 100 ) / numImages ) ) ; } ) ; imagePromises . push ( promise ) ; } Promise . all ( imagePromises ) . then ( ( ) => { const { labelmapBuffer , segMetadata , probabilityMapBuffer , isFractional , segmentsOnFrame , } = Segmentation_4X_fork . generateToolState ( imageIds , dicomSegArrayBuffer , cornerstone . metaData ) ; const firstImageId = imageIds [ 0 ] ; if ( segmentationModule . state . series [ firstImageId ] ) { delete segmentationModule . state . series [ firstImageId ] ; } const metadata = segMetadata . data ; metadata . forEach ( seg => { if ( seg !== undefined ) { seg . uid = generateUID ( ) ; } } ) ; if ( isFractional ) { segmentationModule . setters . fractionalLabelmap3DByFirstImageId ( firstImageId , labelmapBuffer , probabilityMapBuffer , 0 , metadata , imageIds . length , segmentsOnFrame ) ; Object . assign ( segmentationModule . configuration , fractionalLabelmapConfiguration ) ; const colorLUT = segmentationModule . state . colorLutTables [ 0 ] ; if ( ! Array . isArray ( colorLUT [ 1 ] [ 0 ] [ 0 ] ) ) { colorLUT [ 1 ] = colorMaps [ 0 ] . colormap ; colorLUT [ 1 ] . ID = colorMaps [ 0 ] . ID ; } } else { segmentationModule . setters . labelmap3DByFirstImageId ( firstImageId , labelmapBuffer , 0 , metadata , imageIds . length , segmentsOnFrame ) ; Object . assign ( segmentationModule . configuration , labelmapConfiguration ) ; } cornerstoneTools . store . state . enabledElements . forEach ( element => cornerstone . updateImage ( element ) ) ; resolve ( ) ; } ) ; } ) ; }
importDICOMSEG - Imports a DICOM SEG file to CornerstoneTools.
importDICOMSEG - Imports a DICOM SEG file to CornerstoneTools .
// Delete old labelmap // Set fractional labelmap rendering options // If the first is a color, set it to a colormap. // TODO -> Can define a color LUT based on colors in the SEG later. // Set labelmap rendering options