Class Parser


  • public class Parser
    extends java.lang.Object
    This is the main class used to parse and run scripts. It may also be used to retrieve the image placeholder variables (e.g., $image1) used in a script and the number of VOIs required for a particular image placeholder.
    • Constructor Summary

      Constructors 
      Constructor Description
      Parser()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String[] getActionsForImagesUsedInScript​(java.lang.String scriptFile)
      Returns an array of the actions in which external images are used in a given script.
      static java.lang.String[] getImageLabelsUsedInScript​(java.lang.String scriptFile)
      Returns an array of image parameters labels used in a given script.
      static java.lang.String[] getImageVarsUsedInScript​(java.lang.String scriptFile)
      Returns an array of image placeholder variables used in a given script.
      static int getNumberOfVOIsRequiredForImageVar​(java.lang.String scriptFile, java.lang.String imageVarName)
      Returns the number of VOIs which will be opened for a given image (imageVarName) when a particular script is run.
      private static java.lang.String getVOIParentImage​(ParsedActionLine parsedLine)
      Returns the image placeholder variable referenced by an 'OpenVOI' action.
      private static boolean hasExitAction​(java.lang.String scriptFile)
      Search the script file for an Exit action (required when running in hidden GUI mode from the command line).
      private static boolean isOpenVOIAction​(java.lang.String action)
      Returns whether a action string would result in the opening of a VOI.
      static void runScript​(java.lang.String scriptFile)
      Parses and runs the commands contained within a given script file.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Parser

        public Parser()
    • Method Detail

      • getActionsForImagesUsedInScript

        public static final java.lang.String[] getActionsForImagesUsedInScript​(java.lang.String scriptFile)
                                                                        throws ParserException
        Returns an array of the actions in which external images are used in a given script.
        Parameters:
        scriptFile - The full path to the script file on disk which should be parsed.
        Returns:
        An array of the names of script actions which use each external image parameter in the given script in the same order as getImageVarsUsedInScript().
        Throws:
        ParserException - If a problem is encountered while parsing the script.
      • getImageLabelsUsedInScript

        public static final java.lang.String[] getImageLabelsUsedInScript​(java.lang.String scriptFile)
                                                                   throws ParserException
        Returns an array of image parameters labels used in a given script.
        Parameters:
        scriptFile - The full path to the script file on disk which should be parsed.
        Returns:
        An array of the image parameter labels (e.g., input_image_1 or reference_image) used in scriptFile in the same order as getImageVarsUsedInScript().
        Throws:
        ParserException - If a problem is encountered while parsing the script.
      • getImageVarsUsedInScript

        public static final java.lang.String[] getImageVarsUsedInScript​(java.lang.String scriptFile)
                                                                 throws ParserException
        Returns an array of image placeholder variables used in a given script.
        Parameters:
        scriptFile - The full path to the script file on disk which should be parsed.
        Returns:
        An array of the image placeholder variables (e.g. $image1) used in scriptFile.
        Throws:
        ParserException - If a problem is encountered while parsing the script.
      • getNumberOfVOIsRequiredForImageVar

        public static final int getNumberOfVOIsRequiredForImageVar​(java.lang.String scriptFile,
                                                                   java.lang.String imageVarName)
                                                            throws ParserException
        Returns the number of VOIs which will be opened for a given image (imageVarName) when a particular script is run.
        Parameters:
        scriptFile - The full path to the script file on disk which should be parsed.
        imageVarName - The image placeholder variable (e.g. $image1) for which to count required VOIs.
        Returns:
        The number of VOIs required for the given imageVarName.
        Throws:
        ParserException - If a problem is encountered while parsing the script.
      • runScript

        public static final void runScript​(java.lang.String scriptFile)
                                    throws ParserException
        Parses and runs the commands contained within a given script file.
        Parameters:
        scriptFile - The full path to the script file on disk which should be parsed.
        Throws:
        ParserException - If a problem is encountered while parsing the script.
      • getVOIParentImage

        private static java.lang.String getVOIParentImage​(ParsedActionLine parsedLine)
        Returns the image placeholder variable referenced by an 'OpenVOI' action.
        Parameters:
        parsedLine - A parsed line from a script (should be an 'OpenVOI' action).
        Returns:
        The image placeholder variable for the image the VOI will be loaded into.
      • hasExitAction

        private static boolean hasExitAction​(java.lang.String scriptFile)
                                      throws ParserException
        Search the script file for an Exit action (required when running in hidden GUI mode from the command line).
        Parameters:
        scriptFile - The full path to the script file on disk which should be parsed.
        Returns:
        True if the script contains an Exit command, false otherwise.
        Throws:
        ParserException - If a problem is encountered while parsing the script.
      • isOpenVOIAction

        private static boolean isOpenVOIAction​(java.lang.String action)
        Returns whether a action string would result in the opening of a VOI.
        Parameters:
        action - The action string to check.
        Returns:
        Whether the given action will open a VOI.