src/tools/DragProbeTool.js
/**
 * Minimal strategy will position a circle and use the center of the circle to calculate and display probe data.
 *
 * @param  {Object} evt Image rendered event
 * @returns {void}
 */
Minimal strategy will position a circle and use the center of the circle to calculate and display probe data.
@param  {Object} evt Image rendered event
@returns {void}
Minimal strategy will position a circle and use the center of the circle to calculate and display probe data . @param { Object } evt Image rendered event @returns { void }
function minimalStrategy(evt) {
  const config = this.configuration;
  const cornerstone = external.cornerstone;
  const eventData = evt.detail;
  const {
    element,
    image,
    currentPoints,
    canvasContext,
    isTouchEvent,
  } = eventData;
  const context = getNewContext(canvasContext.canvas);
  const color = toolColors.getActiveColor();
  let pageCoordY = currentPoints.page.y - textStyle.getFontSize() / 2;
  if (isTouchEvent) {
    pageCoordY = currentPoints.page.y - textStyle.getFontSize() * 4;
  }
  const toolCoords = cornerstone.pageToPixel(
    element,
    currentPoints.page.x,
    pageCoordY
  );
  if (
    toolCoords.x < 0 ||
    toolCoords.y < 0 ||
    toolCoords.x >= image.columns ||
    toolCoords.y >= image.rows
  ) {
    return;
  }
  draw(context, context => {
    setShadow(context, config);
    const seriesModule = cornerstone.metaData.get(
      'generalSeriesModule',
      image.imageId
    );
    const modality = seriesModule && seriesModule.modality;
    let storedPixels;
    let text = '';
    if (image.color) {
      storedPixels = getRGBPixels(element, toolCoords.x, toolCoords.y, 1, 1);
      text = `R: ${storedPixels[0]} G: ${storedPixels[1]} B: ${
        storedPixels[2]
      }`;
    } else {
      storedPixels = cornerstone.getStoredPixels(
        element,
        toolCoords.x,
        toolCoords.y,
        1,
        1
      );
      const sp = storedPixels[0];
      const mo = sp * image.slope + image.intercept;
      const modalityPixelValueText = parseFloat(mo.toFixed(2));
      if (modality === 'CT') {
        text += `HU: ${modalityPixelValueText}`;
      } else if (modality === 'PT') {
        text += modalityPixelValueText;
        const suv = calculateSUV(image, sp);
        if (suv) {
          text += ` SUV: ${parseFloat(suv.toFixed(2))}`;
        }
      } else {
        text += modalityPixelValueText;
      }
    }
    const textCoords = cornerstone.pixelToCanvas(element, toolCoords);
    let translation = {
      x: 12,
      y: -(textStyle.getFontSize() + 10) / 2,
    };
    const handleRadius = 6;
    const padding = 5;
    const width = textBoxWidth(context, text, padding);
    if (isTouchEvent) {
      translation = {
        x: -width / 2,
        y: -textStyle.getFontSize() - 10 - 2 * handleRadius,
      };
    }
    drawCircle(context, element, textCoords, handleRadius, { color }, 'canvas');
    drawTextBox(
      context,
      text,
      textCoords.x + translation.x,
      textCoords.y + translation.y,
      color
    );
  });
}
function minimalStrategy ( evt ) { const config = this . configuration ; const cornerstone = external . cornerstone ; const eventData = evt . detail ; const { element , image , currentPoints , canvasContext , isTouchEvent , } = eventData ; const context = getNewContext ( canvasContext . canvas ) ; const color = toolColors . getActiveColor ( ) ; let pageCoordY = currentPoints . page . y - textStyle . getFontSize ( ) / 2 ; if ( isTouchEvent ) { pageCoordY = currentPoints . page . y - textStyle . getFontSize ( ) * 4 ; } const toolCoords = cornerstone . pageToPixel ( element , currentPoints . page . x , pageCoordY ) ; if ( toolCoords . x < 0 || toolCoords . y < 0 || toolCoords . x >= image . columns || toolCoords . y >= image . rows ) { return ; } draw ( context , context => { setShadow ( context , config ) ; const seriesModule = cornerstone . metaData . get ( 'generalSeriesModule' , image . imageId ) ; const modality = seriesModule && seriesModule . modality ; let storedPixels ; let text = '' ; if ( image . color ) { storedPixels = getRGBPixels ( element , toolCoords . x , toolCoords . y , 1 , 1 ) ; text = ` ${ storedPixels [ 0 ] } ${ storedPixels [ 1 ] } ${ storedPixels [ 2 ] } ` ; } else { storedPixels = cornerstone . getStoredPixels ( element , toolCoords . x , toolCoords . y , 1 , 1 ) ; const sp = storedPixels [ 0 ] ; const mo = sp * image . slope + image . intercept ; const modalityPixelValueText = parseFloat ( mo . toFixed ( 2 ) ) ; if ( modality === 'CT' ) { text += ` ${ modalityPixelValueText } ` ; } else if ( modality === 'PT' ) { text += modalityPixelValueText ; const suv = calculateSUV ( image , sp ) ; if ( suv ) { text += ` ${ parseFloat ( suv . toFixed ( 2 ) ) } ` ; } } else { text += modalityPixelValueText ; } } const textCoords = cornerstone . pixelToCanvas ( element , toolCoords ) ; let translation = { x : 12 , y : - ( textStyle . getFontSize ( ) + 10 ) / 2 , } ; const handleRadius = 6 ; const padding = 5 ; const width = textBoxWidth ( context , text , padding ) ; if ( isTouchEvent ) { translation = { x : - width / 2 , y : - textStyle . getFontSize ( ) - 10 - 2 * handleRadius , } ; } drawCircle ( context , element , textCoords , handleRadius , { color } , 'canvas' ) ; drawTextBox ( context , text , textCoords . x + translation . x , textCoords . y + translation . y , color ) ; } ) ; }
Minimal strategy will position a circle and use the center of the circle to calculate and display probe data.
Minimal strategy will position a circle and use the center of the circle to calculate and display probe data .
// Prepare text // Translate the x/y away from the cursor