function onImageRendered(e) {
  var eventData = e.detail;

  // If we have no toolData for this element, return immediately as there is nothing to do
  var toolData = (0, _toolState.getToolState)(e.currentTarget, toolType);

  if (toolData === undefined) {
    return;
  }

  var cornerstone = _externalModules2.default.cornerstone;
  var image = eventData.image;
  var element = eventData.element;
  var config = freehand.getConfiguration();
  var seriesModule = cornerstone.metaData.get('generalSeriesModule', image.imageId);
  var modality = void 0;

  var _getColRowPixelSpacin2 = (0, _getColRowPixelSpacing2.default)(image),
      rowPixelSpacing = _getColRowPixelSpacin2.rowPixelSpacing,
      colPixelSpacing = _getColRowPixelSpacin2.colPixelSpacing;

  if (seriesModule) {
    modality = seriesModule.modality;
  }

  // We have tool data for this element - iterate over each one and draw it
  var context = (0, _drawing.getNewContext)(eventData.canvasContext.canvas);

  var lineWidth = _toolStyle2.default.getToolWidth();

  var _loop = function _loop(i) {
    var data = toolData.data[i];

    if (data.visible === false) {
      return 'continue';
    }

    (0, _drawing.draw)(context, function (context) {
      var color = _toolColors2.default.getColorIfActive(data);
      var fillColor = void 0;

      if (data.active) {
        if (data.handles.invalidHandlePlacement) {
          color = config.invalidColor;
          fillColor = config.invalidColor;
        } else {
          color = _toolColors2.default.getColorIfActive(data);
          fillColor = _toolColors2.default.getFillColor();
        }
      } else {
        fillColor = _toolColors2.default.getToolColor();
      }

      if (data.handles.length) {
        for (var j = 0; j < data.handles.length; j++) {
          var points = [].concat(_toConsumableArray(data.handles[j].lines));

          if (j === data.handles.length - 1 && !data.polyBoundingBox) {
            // If it's still being actively drawn, keep the last line to
            // The mouse location
            points.push(config.mouseLocation.handles.start);
          }
          (0, _drawing.drawJoinedLines)(context, eventData.element, data.handles[j], points, { color: color });
        }
      }

      // Draw handles

      var options = {
        fill: fillColor
      };

      if (config.alwaysShowHandles || config.keyDown.ctrl || data.active && data.polyBoundingBox) {
        // Render all handles
        options.handleRadius = config.activeHandleRadius;
        (0, _drawHandles2.default)(context, eventData, data.handles, color, options);
      }

      if (data.canComplete) {
        // Draw large handle at the origin if can complete drawing
        options.handleRadius = config.completeHandleRadius;
        (0, _drawHandles2.default)(context, eventData, [data.handles[0]], color, options);
      }

      if (data.active && !data.polyBoundingBox) {
        // Draw handle at origin and at mouse if actively drawing
        options.handleRadius = config.activeHandleRadius;
        (0, _drawHandles2.default)(context, eventData, config.mouseLocation.handles, color, options);
        (0, _drawHandles2.default)(context, eventData, [data.handles[0]], color, options);
      }

      // Define variables for the area and mean/standard deviation
      calculateStatistics(data, element, image, modality, rowPixelSpacing, colPixelSpacing);

      // Only render text if polygon ROI has been completed and freehand 'shiftKey' mode was not used:
      if (data.polyBoundingBox && !data.textBox.freehand) {
        // If the textbox has not been moved by the user, it should be displayed on the right-most
        // Side of the tool.
        if (!data.textBox.hasMoved) {
          // Find the rightmost side of the polyBoundingBox at its vertical center, and place the textbox here
          // Note that this calculates it in image coordinates
          data.textBox.x = data.polyBoundingBox.left + data.polyBoundingBox.width;
          data.textBox.y = data.polyBoundingBox.top + data.polyBoundingBox.height / 2;
        }

        var text = textBoxText(data);

        (0, _drawLinkedTextBox2.default)(context, element, data.textBox, text, data.handles, textBoxAnchorPoints, color, lineWidth, 0, true);
      }
    });
  };

  for (var i = 0; i < toolData.data.length; i++) {
    var _ret = _loop(i);

    if (_ret === 'continue') continue;
  }

  function textBoxText(data) {
    var meanStdDev = data.meanStdDev,
        meanStdDevSUV = data.meanStdDevSUV,
        area = data.area;
    // Define an array to store the rows of text for the textbox

    var textLines = [];

    // If the mean and standard deviation values are present, display them
    if (meanStdDev && meanStdDev.mean !== undefined) {
      // If the modality is CT, add HU to denote Hounsfield Units
      var moSuffix = '';

      if (modality === 'CT') {
        moSuffix = ' HU';
      }

      // Create a line of text to display the mean and any units that were specified (i.e. HU)
      var meanText = 'Mean: ' + numberWithCommas(meanStdDev.mean.toFixed(2)) + moSuffix;
      // Create a line of text to display the standard deviation and any units that were specified (i.e. HU)
      var stdDevText = 'StdDev: ' + numberWithCommas(meanStdDev.stdDev.toFixed(2)) + moSuffix;

      // If this image has SUV values to display, concatenate them to the text line
      if (meanStdDevSUV && meanStdDevSUV.mean !== undefined) {
        var SUVtext = ' SUV: ';

        meanText += SUVtext + numberWithCommas(meanStdDevSUV.mean.toFixed(2));
        stdDevText += SUVtext + numberWithCommas(meanStdDevSUV.stdDev.toFixed(2));
      }

      // Add these text lines to the array to be displayed in the textbox
      textLines.push(meanText);
      textLines.push(stdDevText);
    }

    // If the area is a sane value, display it
    if (area) {
      // Determine the area suffix based on the pixel spacing in the image.
      // If pixel spacing is present, use millimeters. Otherwise, use pixels.
      // This uses Char code 178 for a superscript 2
      var suffix = ' mm' + String.fromCharCode(178);

      if (!rowPixelSpacing || !colPixelSpacing) {
        suffix = ' pixels' + String.fromCharCode(178);
      }

      // Create a line of text to display the area and its units
      var areaText = 'Area: ' + numberWithCommas(area.toFixed(2)) + suffix;

      // Add this text line to the array to be displayed in the textbox
      textLines.push(areaText);
    }

    return textLines;
  }

  function textBoxAnchorPoints(handles) {
    return handles;
  }
}
/**
* Event handler for IMAGE_RENDERED event.
*
* @event
* @param {Object} e - The event.
*/
Event handler for IMAGE_RENDERED event.
Event handler for IMAGE_RENDERED event .
function onImageRendered(e) {
  var eventData = e.detail;
  var toolData = (0, _toolState.getToolState)(e.currentTarget, toolType);
  if (toolData === undefined) {
    return;
  }
  var cornerstone = _externalModules2.default.cornerstone;
  var image = eventData.image;
  var element = eventData.element;
  var config = freehand.getConfiguration();
  var seriesModule = cornerstone.metaData.get('generalSeriesModule', image.imageId);
  var modality = void 0;
  var _getColRowPixelSpacin2 = (0, _getColRowPixelSpacing2.default)(image),
      rowPixelSpacing = _getColRowPixelSpacin2.rowPixelSpacing,
      colPixelSpacing = _getColRowPixelSpacin2.colPixelSpacing;
  if (seriesModule) {
    modality = seriesModule.modality;
  }
  var context = (0, _drawing.getNewContext)(eventData.canvasContext.canvas);
  var lineWidth = _toolStyle2.default.getToolWidth();
  var _loop = function _loop(i) {
    var data = toolData.data[i];
    if (data.visible === false) {
      return 'continue';
    }
    (0, _drawing.draw)(context, function (context) {
      var color = _toolColors2.default.getColorIfActive(data);
      var fillColor = void 0;
      if (data.active) {
        if (data.handles.invalidHandlePlacement) {
          color = config.invalidColor;
          fillColor = config.invalidColor;
        } else {
          color = _toolColors2.default.getColorIfActive(data);
          fillColor = _toolColors2.default.getFillColor();
        }
      } else {
        fillColor = _toolColors2.default.getToolColor();
      }
      if (data.handles.length) {
        for (var j = 0; j < data.handles.length; j++) {
          var points = [].concat(_toConsumableArray(data.handles[j].lines));
          if (j === data.handles.length - 1 && !data.polyBoundingBox) {
            points.push(config.mouseLocation.handles.start);
          }
          (0, _drawing.drawJoinedLines)(context, eventData.element, data.handles[j], points, { color: color });
        }
      }
      var options = {
        fill: fillColor
      };
      if (config.alwaysShowHandles || config.keyDown.ctrl || data.active && data.polyBoundingBox) {
        options.handleRadius = config.activeHandleRadius;
        (0, _drawHandles2.default)(context, eventData, data.handles, color, options);
      }
      if (data.canComplete) {
        options.handleRadius = config.completeHandleRadius;
        (0, _drawHandles2.default)(context, eventData, [data.handles[0]], color, options);
      }
      if (data.active && !data.polyBoundingBox) {
        options.handleRadius = config.activeHandleRadius;
        (0, _drawHandles2.default)(context, eventData, config.mouseLocation.handles, color, options);
        (0, _drawHandles2.default)(context, eventData, [data.handles[0]], color, options);
      }
      calculateStatistics(data, element, image, modality, rowPixelSpacing, colPixelSpacing);
      if (data.polyBoundingBox && !data.textBox.freehand) {
        if (!data.textBox.hasMoved) {
          data.textBox.x = data.polyBoundingBox.left + data.polyBoundingBox.width;
          data.textBox.y = data.polyBoundingBox.top + data.polyBoundingBox.height / 2;
        }
        var text = textBoxText(data);
        (0, _drawLinkedTextBox2.default)(context, element, data.textBox, text, data.handles, textBoxAnchorPoints, color, lineWidth, 0, true);
      }
    });
  };
  for (var i = 0; i < toolData.data.length; i++) {
    var _ret = _loop(i);
    if (_ret === 'continue') continue;
  }
  function textBoxText(data) {
    var meanStdDev = data.meanStdDev,
        meanStdDevSUV = data.meanStdDevSUV,
        area = data.area;
    var textLines = [];
    if (meanStdDev && meanStdDev.mean !== undefined) {
      var moSuffix = '';
      if (modality === 'CT') {
        moSuffix = ' HU';
      }
      var meanText = 'Mean: ' + numberWithCommas(meanStdDev.mean.toFixed(2)) + moSuffix;
      var stdDevText = 'StdDev: ' + numberWithCommas(meanStdDev.stdDev.toFixed(2)) + moSuffix;
      if (meanStdDevSUV && meanStdDevSUV.mean !== undefined) {
        var SUVtext = ' SUV: ';
        meanText += SUVtext + numberWithCommas(meanStdDevSUV.mean.toFixed(2));
        stdDevText += SUVtext + numberWithCommas(meanStdDevSUV.stdDev.toFixed(2));
      }
      textLines.push(meanText);
      textLines.push(stdDevText);
    }
    if (area) {
      var suffix = ' mm' + String.fromCharCode(178);
      if (!rowPixelSpacing || !colPixelSpacing) {
        suffix = ' pixels' + String.fromCharCode(178);
      }
      var areaText = 'Area: ' + numberWithCommas(area.toFixed(2)) + suffix;
      textLines.push(areaText);
    }
    return textLines;
  }
  function textBoxAnchorPoints(handles) {
    return handles;
  }
}
function onImageRendered ( e ) { var eventData = e . detail ; var toolData = ( 0 , _toolState . getToolState ) ( e . currentTarget , toolType ) ; if ( toolData === undefined ) { return ; } var cornerstone = _externalModules2 . default . cornerstone ; var image = eventData . image ; var element = eventData . element ; var config = freehand . getConfiguration ( ) ; var seriesModule = cornerstone . metaData . get ( 'generalSeriesModule' , image . imageId ) ; var modality = void 0 ; var _getColRowPixelSpacin2 = ( 0 , _getColRowPixelSpacing2 . default ) ( image ) , rowPixelSpacing = _getColRowPixelSpacin2 . rowPixelSpacing , colPixelSpacing = _getColRowPixelSpacin2 . colPixelSpacing ; if ( seriesModule ) { modality = seriesModule . modality ; } var context = ( 0 , _drawing . getNewContext ) ( eventData . canvasContext . canvas ) ; var lineWidth = _toolStyle2 . default . getToolWidth ( ) ; var _loop = function _loop ( i ) { var data = toolData . data [ i ] ; if ( data . visible === false ) { return 'continue' ; } ( 0 , _drawing . draw ) ( context , function ( context ) { var color = _toolColors2 . default . getColorIfActive ( data ) ; var fillColor = void 0 ; if ( data . active ) { if ( data . handles . invalidHandlePlacement ) { color = config . invalidColor ; fillColor = config . invalidColor ; } else { color = _toolColors2 . default . getColorIfActive ( data ) ; fillColor = _toolColors2 . default . getFillColor ( ) ; } } else { fillColor = _toolColors2 . default . getToolColor ( ) ; } if ( data . handles . length ) { for ( var j = 0 ; j < data . handles . length ; j ++ ) { var points = [ ] . concat ( _toConsumableArray ( data . handles [ j ] . lines ) ) ; if ( j === data . handles . length - 1 && ! data . polyBoundingBox ) { points . push ( config . mouseLocation . handles . start ) ; } ( 0 , _drawing . drawJoinedLines ) ( context , eventData . element , data . handles [ j ] , points , { color : color } ) ; } } var options = { fill : fillColor } ; if ( config . alwaysShowHandles || config . keyDown . ctrl || data . active && data . polyBoundingBox ) { options . handleRadius = config . activeHandleRadius ; ( 0 , _drawHandles2 . default ) ( context , eventData , data . handles , color , options ) ; } if ( data . canComplete ) { options . handleRadius = config . completeHandleRadius ; ( 0 , _drawHandles2 . default ) ( context , eventData , [ data . handles [ 0 ] ] , color , options ) ; } if ( data . active && ! data . polyBoundingBox ) { options . handleRadius = config . activeHandleRadius ; ( 0 , _drawHandles2 . default ) ( context , eventData , config . mouseLocation . handles , color , options ) ; ( 0 , _drawHandles2 . default ) ( context , eventData , [ data . handles [ 0 ] ] , color , options ) ; } calculateStatistics ( data , element , image , modality , rowPixelSpacing , colPixelSpacing ) ; if ( data . polyBoundingBox && ! data . textBox . freehand ) { if ( ! data . textBox . hasMoved ) { data . textBox . x = data . polyBoundingBox . left + data . polyBoundingBox . width ; data . textBox . y = data . polyBoundingBox . top + data . polyBoundingBox . height / 2 ; } var text = textBoxText ( data ) ; ( 0 , _drawLinkedTextBox2 . default ) ( context , element , data . textBox , text , data . handles , textBoxAnchorPoints , color , lineWidth , 0 , true ) ; } } ) ; } ; for ( var i = 0 ; i < toolData . data . length ; i ++ ) { var _ret = _loop ( i ) ; if ( _ret === 'continue' ) continue ; } function textBoxText ( data ) { var meanStdDev = data . meanStdDev , meanStdDevSUV = data . meanStdDevSUV , area = data . area ; var textLines = [ ] ; if ( meanStdDev && meanStdDev . mean !== undefined ) { var moSuffix = '' ; if ( modality === 'CT' ) { moSuffix = ' HU' ; } var meanText = 'Mean: ' + numberWithCommas ( meanStdDev . mean . toFixed ( 2 ) ) + moSuffix ; var stdDevText = 'StdDev: ' + numberWithCommas ( meanStdDev . stdDev . toFixed ( 2 ) ) + moSuffix ; if ( meanStdDevSUV && meanStdDevSUV . mean !== undefined ) { var SUVtext = ' SUV: ' ; meanText += SUVtext + numberWithCommas ( meanStdDevSUV . mean . toFixed ( 2 ) ) ; stdDevText += SUVtext + numberWithCommas ( meanStdDevSUV . stdDev . toFixed ( 2 ) ) ; } textLines . push ( meanText ) ; textLines . push ( stdDevText ) ; } if ( area ) { var suffix = ' mm' + String . fromCharCode ( 178 ) ; if ( ! rowPixelSpacing || ! colPixelSpacing ) { suffix = ' pixels' + String . fromCharCode ( 178 ) ; } var areaText = 'Area: ' + numberWithCommas ( area . toFixed ( 2 ) ) + suffix ; textLines . push ( areaText ) ; } return textLines ; } function textBoxAnchorPoints ( handles ) { return handles ; } }
Event handler for IMAGE_RENDERED event.
Event handler for IMAGE_RENDERED event .
// If we have no toolData for this element, return immediately as there is nothing to do // We have tool data for this element - iterate over each one and draw it // If it's still being actively drawn, keep the last line to // The mouse location // Draw handles // Render all handles // Draw large handle at the origin if can complete drawing // Draw handle at origin and at mouse if actively drawing // Define variables for the area and mean/standard deviation // Only render text if polygon ROI has been completed and freehand 'shiftKey' mode was not used: // If the textbox has not been moved by the user, it should be displayed on the right-most // Side of the tool. // Find the rightmost side of the polyBoundingBox at its vertical center, and place the textbox here // Note that this calculates it in image coordinates // Define an array to store the rows of text for the textbox // If the mean and standard deviation values are present, display them // If the modality is CT, add HU to denote Hounsfield Units // Create a line of text to display the mean and any units that were specified (i.e. HU) // Create a line of text to display the standard deviation and any units that were specified (i.e. HU) // If this image has SUV values to display, concatenate them to the text line // Add these text lines to the array to be displayed in the textbox // If the area is a sane value, display it // Determine the area suffix based on the pixel spacing in the image. // If pixel spacing is present, use millimeters. Otherwise, use pixels. // This uses Char code 178 for a superscript 2 // Create a line of text to display the area and its units // Add this text line to the array to be displayed in the textbox