Class Parser

java.lang.Object
gov.nih.mipav.model.scripting.Parser

public class Parser extends 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 Details

    • Parser

      public Parser()
  • Method Details

    • getActionsForImagesUsedInScript

      public static final String[] getActionsForImagesUsedInScript(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 String[] getImageLabelsUsedInScript(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 String[] getImageVarsUsedInScript(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(String scriptFile, 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(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 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(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(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.