Making a MIPAV Algorithm JISTable

From MIPAV
Revision as of 20:43, 24 May 2010 by Mccreedy (Talk | contribs)

(diff) <previousrevision> | Latest revision (diff) | <nextrevision> (diff)
Jump to: navigation, search

This page describes how to make a MIPAV algorithm JISTable (aka implement the ActionDiscovery interface).

Step 1

Implement ScriptableActionInterface (or extend JDialogScriptableBase). This should already be done for any algorithm that would benefit from implementing ActionDiscovery. Make sure scriptRun() and the default constructor exist and are complete.

Step 2

Implement the ActionDiscovery interface:

getActionMetadata()

  • Example (alter as needed, see MipavActionMetadata for other metadata set by default):
    /**
     * Return meta-information about this discoverable action for categorization and labeling purposes.
     * 
     * @return Metadata for this action.
     */
    public ActionMetadata getActionMetadata() {
        return new MipavActionMetadata() {
            public String getCategory() {
                return new String("Algorithms.Filters (spatial)");
            }

            public String getDescription() {
                return new String("Applies a simple gaussian blur filter.");
            }

            public String getDescriptionLong() {
                return new String("Applies a simple gaussian blur filter.");
            }

            public String getShortLabel() {
                return new String("GaussianBlur");
            }

            public String getLabel() {
                return new String("Gaussian blur");
            }

            public String getName() {
                return new String("Gaussian blur");
            }
        };
    }
  • Category should match the menu location of the algo/util
  • Descriptions can be as long or short as neccessary (or left blank, possibly)
  • ShortLabel is used to call actions from the JIST command line
  • Label is what appears on the action's box in JIST
  • Name is the unique name of the action (not shown to the user)

createInputParameters()

  • Example:
    /**
     * Returns a table listing the input parameters of this algorithm (which should match up with the scripting
     * parameters used in {@link #setGUIFromParams()}).
     * 
     * @return A parameter table listing the inputs of this algorithm.
     */
    public ParameterTable createInputParameters() {
        final ParameterTable table = new ParameterTable();

        try {
            table.put(new ParameterExternalImage(AlgorithmParameters.getInputImageLabel(1)));
            table.put(new ParameterBoolean(AlgorithmParameters.DO_OUTPUT_NEW_IMAGE, true));
            table.put(new ParameterBoolean(AlgorithmParameters.DO_PROCESS_WHOLE_IMAGE, true));
            table.put(new ParameterBoolean(AlgorithmParameters.DO_PROCESS_SEPARABLE, true));
            table.put(new ParameterBoolean(AlgorithmParameters.DO_PROCESS_3D_AS_25D, false));
            table.put(new ParameterList(AlgorithmParameters.SIGMAS, Parameter.PARAM_FLOAT, "1.0,1.0,1.0"));
            table.put(new ParameterBoolean(AlgorithmParameters.SIGMA_DO_Z_RES_CORRECTION, true));
            table.put(new ParameterList(AlgorithmParameters.DO_PROCESS_RGB, Parameter.PARAM_BOOLEAN, "true,true,true"));
        } catch (final ParserException e) {
            // this shouldn't really happen since there isn't any real parsing going on...
            e.printStackTrace();
        }

        return table;
    }
  • The input parameters should be the same as those used in the scripting system (see the algorithm's setGUIFromParams()).
  • Including (default) values with the input parameters is optional (but would be nice). They should match the values that the GUI defaults to, if possible.
  • If a parameter should not be shown/used unless another parameter has a given value, then this dependency can be noted by creating the parameter and then calling the parameter's setParentCondition(Parameter parent, String parentValue) method. Applications which are retrieving this list of parameters would then know to only present the parameter to the user if the parent condition is met.

createOutputParameters()

  • Example:
    /**
     * Returns a table listing the output parameters of this algorithm (usually just labels used to obtain output image
     * names later).
     * 
     * @return A parameter table listing the outputs of this algorithm.
     */
    public ParameterTable createOutputParameters() {
        final ParameterTable table = new ParameterTable();

        try {
            table.put(new ParameterImage(AlgorithmParameters.RESULT_IMAGE));
        } catch (final ParserException e) {
            // this shouldn't really happen since there isn't any real parsing going on...
            e.printStackTrace();
        }

        return table;
    }
  • This should list all of the images produced by the algorithm.
  • Some algorithms output different numbers of images based on the input parameters. The exact way this should be handled hasn't been settled yet, but put them all in the output param table, for now.
  • For an idea of what output images an algorithm produces, first look at the scripting method doPostAlgorithmActions().

getOutputImageName()

  • Example:
    /**
     * Returns the name of an image output by this algorithm, the image returned depends on the parameter label given
     * (which can be used to retrieve the image object from the image registry).
     * 
     * @param imageParamName The output image parameter label for which to get the image name.
     * @return The image name of the requested output image parameter label.
     */
    public String getOutputImageName(final String imageParamName) {
        if (imageParamName.equals(AlgorithmParameters.RESULT_IMAGE)) {
            if (getResultImage() != null) {
                // algo produced a new result image
                return getResultImage().getImageName();
            } else {
                // algo was done in place
                return image.getImageName();
            }
        }

        Preferences.debug("Unrecognized output image parameter: " + imageParamName + "\n", Preferences.DEBUG_SCRIPTING);

        return null;
    }
  • Should handle any ParameterImage parameter name/label contained in the createOutputParameters() table.
  • Most algorithms/utils retain the result image(s) in a class field or allow them to be retrieved through a method call (e.g., getResultImage()).
  • Guessing/hardcoding the result image names will not work in all situations due to the way MIPAV handles name collisions ("_blur" -> "_blur1").

isActionComplete()

  • Example:
    /**
     * Returns whether the action has successfully completed its execution.
     * 
     * @return True, if the action is complete. False, if the action failed or is still running.
     */
    public boolean isActionComplete() {
        return isComplete();
    }
  • Will be slightly different for each action, depending on how the algorithm handle is stored.
  • Some action dialogs might not have a class field for the algorithm, don't know exactly what we'll do for these...
  • Added isComplete class var to JDialogScriptableBase, along with isComplete() and setComplete(boolean) to retain the status even after the algorithm(s) have been finalized (which caused previous versions of isActionComplete() to always return false. To get this to work, add the following code to the dialog's algorithmPerformed(algorithm) method at a point before any finalize() calls are made:
// save the completion status for later
setComplete(algorithm.isCompleted());