Class AlgorithmImageCalculator

  • All Implemented Interfaces:
    java.awt.event.ActionListener, java.awt.event.FocusListener, java.awt.event.WindowListener, java.lang.Runnable, java.util.EventListener

    public class AlgorithmImageCalculator
    extends AlgorithmBase
    implements java.awt.event.ActionListener, java.awt.event.FocusListener
    Algorithm that adds, subtracts, multiplies, or divides an image by by another image. In addition, two images can be ANDed, ORed or XORed together. Also, more advanced operator expressions can be entered in a dialog text field.
    Version:
    1.0 Oct 1, 2000
    Author:
    Matthew J. McAuliffe, Ph.D.
    • Field Detail

      • aButton

        private javax.swing.JButton aButton
        DOCUMENT ME!
      • bButton

        private javax.swing.JButton bButton
        DOCUMENT ME!
      • backSpaceButton

        private javax.swing.JButton backSpaceButton
        DOCUMENT ME!
      • ceButton

        private javax.swing.JButton ceButton
        DOCUMENT ME!
      • leftParButton

        private javax.swing.JButton leftParButton
        DOCUMENT ME!
      • rightParButton

        private javax.swing.JButton rightParButton
        DOCUMENT ME!
      • adOpDialog

        private javax.swing.JDialog adOpDialog
        DOCUMENT ME!
      • adOpString

        private java.lang.String adOpString
        DOCUMENT ME!
      • aVal

        private double aVal
        DOCUMENT ME!
      • bestMin

        private double bestMin
        /**.
      • bestMax

        private double bestMax
        /**.
      • bVal

        private double bVal
        DOCUMENT ME!
      • cancel

        private boolean cancel
        DOCUMENT ME!
      • clipMin

        private double clipMin
        Minimum and maximum clipping modes.
      • clipMax

        private double clipMax
        Minimum and maximum clipping modes.
      • clipMode

        private int clipMode
        Clipping mode.
                                  CLIP          = 0;   clamp result data to the bounds of the input image type
                                  PROMOTE       = 1;   promote image type so that the range of the result fits into
                                                       the new image type. ( ie. byte to short).
                           
      • colorFactor

        private int colorFactor
        DOCUMENT ME!
      • entireImage

        private boolean entireImage
        Flag, if true, indicates that the whole image should be processed. If false, process the image over the mask areas.
      • expButton

        private javax.swing.JButton expButton
        DOCUMENT ME!
      • lnButton

        private javax.swing.JButton lnButton
        DOCUMENT ME!
      • sevenButton

        private javax.swing.JButton sevenButton
        DOCUMENT ME!
      • eightButton

        private javax.swing.JButton eightButton
        DOCUMENT ME!
      • nineButton

        private javax.swing.JButton nineButton
        DOCUMENT ME!
      • divButton

        private javax.swing.JButton divButton
        DOCUMENT ME!
      • logButton

        private javax.swing.JButton logButton
        DOCUMENT ME!
      • absButton

        private javax.swing.JButton absButton
        DOCUMENT ME!
      • minA

        private double minA
        /**.
      • maxA

        private double maxA
        /**.
      • minB

        private double minB
        /**.
      • maxB

        private double maxB
        /**.
      • minAB

        private double minAB
        DOCUMENT ME!
      • maxAB

        private double maxAB
        DOCUMENT ME!
      • minBB

        private double minBB
        DOCUMENT ME!
      • maxBB

        private double maxBB
        DOCUMENT ME!
      • minAG

        private double minAG
        DOCUMENT ME!
      • maxAG

        private double maxAG
        DOCUMENT ME!
      • minBG

        private double minBG
        DOCUMENT ME!
      • maxBG

        private double maxBG
        DOCUMENT ME!
      • minAR

        private double minAR
        DOCUMENT ME!
      • maxAR

        private double maxAR
        DOCUMENT ME!
      • minBR

        private double minBR
        DOCUMENT ME!
      • maxBR

        private double maxBR
        DOCUMENT ME!
      • OK

        private boolean OK
        DOCUMENT ME!
      • OKButton

        private javax.swing.JButton OKButton
        DOCUMENT ME!
      • cancelButton

        private javax.swing.JButton cancelButton
        DOCUMENT ME!
      • opType

        private int opType
        Operation to be performed on the images (i.e. Add, ...)
      • powButton

        private javax.swing.JButton powButton
        DOCUMENT ME!
      • commaButton

        private javax.swing.JButton commaButton
        DOCUMENT ME!
      • fourButton

        private javax.swing.JButton fourButton
        DOCUMENT ME!
      • fiveButton

        private javax.swing.JButton fiveButton
        DOCUMENT ME!
      • sixButton

        private javax.swing.JButton sixButton
        DOCUMENT ME!
      • multButton

        private javax.swing.JButton multButton
        DOCUMENT ME!
      • pressedOK

        private boolean pressedOK
        DOCUMENT ME!
      • sinButton

        private javax.swing.JButton sinButton
        DOCUMENT ME!
      • cosButton

        private javax.swing.JButton cosButton
        DOCUMENT ME!
      • oneButton

        private javax.swing.JButton oneButton
        DOCUMENT ME!
      • twoButton

        private javax.swing.JButton twoButton
        DOCUMENT ME!
      • threeButton

        private javax.swing.JButton threeButton
        DOCUMENT ME!
      • subButton

        private javax.swing.JButton subButton
        DOCUMENT ME!
      • srcImageA

        private ModelImage srcImageA
        Source image A.
      • srcImageB

        private ModelImage srcImageB
        Source image B.
      • tanButton

        private javax.swing.JButton tanButton
        DOCUMENT ME!
      • piButton

        private javax.swing.JButton piButton
        DOCUMENT ME!
      • zeroButton

        private javax.swing.JButton zeroButton
        DOCUMENT ME!
      • decimalButton

        private javax.swing.JButton decimalButton
        DOCUMENT ME!
      • modButton

        private javax.swing.JButton modButton
        DOCUMENT ME!
      • addButton

        private javax.swing.JButton addButton
        DOCUMENT ME!
      • textOperator

        private javax.swing.JTextField textOperator
        DOCUMENT ME!
      • srcImages

        private ModelImage[] srcImages
        when performing bulk operations via Image Calculator (Bulk Images) dialog, this array is populated
      • rpn

        private java.lang.String rpn
    • Constructor Detail

      • AlgorithmImageCalculator

        public AlgorithmImageCalculator​(ModelImage srcImgA,
                                        ModelImage srcImgB,
                                        int type,
                                        int _clipMode,
                                        boolean maskFlag,
                                        java.lang.String adOpString)
        Creates a new AlgorithmImageCalculator object using srcImgA srcImgB.
        Parameters:
        srcImgA - source image A model
        srcImgB - source image B model
        type - operation type
        _clipMode - CLIP or PROMOTE input image data
        maskFlag - Flag that indicates that the operator will be calculated for the whole image if equal to true
        adOpString - text for advanced operations
      • AlgorithmImageCalculator

        public AlgorithmImageCalculator​(ModelImage destImg,
                                        ModelImage srcImgA,
                                        ModelImage srcImgB,
                                        int type,
                                        int _clipMode,
                                        boolean maskFlag,
                                        java.lang.String adOpString)
        Creates a new AlgorithmImageCalculator object.
        Parameters:
        destImg - image model where result image is to stored
        srcImgA - source image A model
        srcImgB - source image B model
        type - operation type
        _clipMode - CLIP or PROMOTE input image data
        maskFlag - Flag that indicates that the operator will be calculated for the whole image if equal to true
        adOpString - text for advanced operations
      • AlgorithmImageCalculator

        public AlgorithmImageCalculator​(ModelImage destImage,
                                        ModelImage[] srcImages,
                                        int opType,
                                        int clipMode)
        constructor used for bulk images
        Parameters:
        destImage -
        srcImages -
        opType -
        clipMode -
    • Method Detail

      • actionPerformed

        public void actionPerformed​(java.awt.event.ActionEvent event)
        Calls various methods depending on the action used by the advanced calculator.
        Specified by:
        actionPerformed in interface java.awt.event.ActionListener
        Overrides:
        actionPerformed in class AlgorithmBase
        Parameters:
        event - event that triggered function
      • finalize

        public void finalize()
        Prepares this class for destruction.
        Overrides:
        finalize in class AlgorithmBase
      • focusGained

        public void focusGained​(java.awt.event.FocusEvent event)
        Unchanged.
        Specified by:
        focusGained in interface java.awt.event.FocusListener
        Parameters:
        event - DOCUMENT ME!
      • focusLost

        public void focusLost​(java.awt.event.FocusEvent event)
        Unchanged.
        Specified by:
        focusLost in interface java.awt.event.FocusListener
        Parameters:
        event - DOCUMENT ME!
      • getAdvFunction

        public java.lang.String getAdvFunction()
        Accessor to return the advanced function string.
        Returns:
        adOpString advanced function string
      • calcMSE

        private void calcMSE()
      • calcInPlace

        private void calcInPlace()
        Runs the calculation and stores the result into the same source buffer.
      • performBulkAdding

        private void performBulkAdding()
        perform bulk adidng
      • performBulkMin

        private void performBulkMin()
        perform bulk adidng
      • performBulkMax

        private void performBulkMax()
        perform bulk adidng
      • performBulkAveraging

        private void performBulkAveraging​(boolean findSD)
        perform bulk averaging
      • calcStoreInDest

        private void calcStoreInDest()
        Runs the calculation and stores it in a new ModelImage.
      • createAdOpDialog

        private void createAdOpDialog​(java.awt.event.ActionListener al)
        Builds the advanced function dialog - looks like a calculator.
        Parameters:
        al - DOCUMENT ME!
      • evaluateRPNExpression

        public double evaluateRPNExpression​(double a,
                                            double b,
                                            java.lang.String rpn)
        Method that evaluates the RPN expression and returns the value
      • evaluateToRPN

        public java.lang.String evaluateToRPN​(java.lang.String expression)
        method that determines the RPN
        Parameters:
        expression -
        Returns:
      • initialValidate

        public boolean initialValidate​(java.lang.String expression)
        method that does some initial validation of the expression
        Parameters:
        expression -
        Returns:
      • tokenize

        public boolean tokenize​(java.lang.String expression,
                                java.util.Vector<java.lang.String> tokens)
        method that tokenizes the expression
        Parameters:
        expression -
        tokens -
        Returns:
      • convertToRPN

        public java.lang.String convertToRPN​(java.util.Vector<java.lang.String> tokens)
        method that converts the tokens to RPN
        Parameters:
        tokens -
        Returns:
      • precedence

        public int precedence​(java.lang.String op)
        method that determines precedence
        Parameters:
        op -
        Returns:
      • isOperator

        public boolean isOperator​(java.lang.String token)
        method determining if token is an operator
        Parameters:
        token -
        Returns:
      • isFunction

        public boolean isFunction​(java.lang.String token)
        method determining if token is function
        Parameters:
        token -
        Returns:
      • readChar

        public char readChar​(java.lang.String exp,
                             int pos)
        reads char
        Parameters:
        exp -
        pos -
        Returns:
      • isDigit

        public boolean isDigit​(char c)
        determines if char is a digit
        Parameters:
        c -
        Returns:
      • isValidNumber

        public boolean isValidNumber​(java.lang.String s)
      • findType

        private int findType​(int stType)
        Find the type able to contain the full range of the data.
        Parameters:
        stType - starting type of image. Image will be promoted above this type if needed.
        Returns:
        type capable of storing full range of data. See ModelStorageBase for image types.
      • promoteType

        private int promoteType​(int presentType)
        DOCUMENT ME!
        Parameters:
        presentType - DOCUMENT ME!
        Returns:
        DOCUMENT ME!
      • setClipValues

        private void setClipValues()
        Sets the minimum and maximum clipping values.
      • testType

        private boolean testType​(int type,
                                 double minVal,
                                 double maxVal)
        Determine if the min and max values are in the image types range.
        Parameters:
        type - image type
        minVal - min value of the image
        maxVal - max value of the image
        Returns:
        true if min and max are within the image type specified