/**
   * Once all the necessary variables are set, call the Gaussian Blur algorithm based on what type
   * of image this is and whether or not there is a separate destination image.
   */
  protected void callAlgorithm() {

    try {

      centerDistanceAlgo =
          new PlugInAlgorithmCenterDistance2(
              image,
              blueMin,
              redMin,
              redFraction,
              mergingDistance,
              greenMin,
              greenFraction,
              greenRegionNumber,
              twoGreenLevels,
              blueBoundaryFraction,
              blueSmooth,
              interpolationDivisor);

      // This is very important. Adding this object as a listener allows
      // the algorithm to
      // notify this object when it has completed or failed. See algorithm
      // performed event.
      // This is made possible by implementing AlgorithmedPerformed
      // interface
      centerDistanceAlgo.addListener(this);
      createProgressBar(image.getImageName(), " ...", centerDistanceAlgo);

      setVisible(false); // Hide dialog

      if (isRunInSeparateThread()) {

        // Start the thread as a low priority because we wish to still
        // have user interface work fast.
        if (centerDistanceAlgo.startMethod(Thread.MIN_PRIORITY) == false) {
          MipavUtil.displayError("A thread is already running on this object");
        }
      } else {
        centerDistanceAlgo.run();
      }
    } catch (OutOfMemoryError x) {
      MipavUtil.displayError("Center Distance: unable to allocate enough memory");

      return;
    }
  } // end callAlgorithm()
  /**
   * Creates new dialog for distances within a cell from the geometric center using a plugin.
   *
   * @param theParentFrame Parent frame.
   * @param im Source image.
   */
  public PlugInDialogCenterDistance2(Frame theParentFrame, ModelImage im) {
    super(theParentFrame, false);

    if (!im.isColorImage()) {
      MipavUtil.displayError("Source Image must be Color");
      dispose();

      return;
    }

    image = im;
    init();
  }
Example #3
0
  /** Calls the algorithm. */
  protected void callAlgorithm() {

    try {
      resultImage =
          new ModelImage(imageA.getType(), imageA.getExtents(), (imageA.getImageName() + "_isn"));
      resultImage.copyFileTypeInfo(imageA);

      // Make algorithm
      isnAlgo = new PlugInAlgorithmISN(resultImage, imageA);

      // This is very important. Adding this object as a listener allows the algorithm to
      // notify this object when it has completed of failed. See algorithm performed event.
      // This is made possible by implementing AlgorithmedPerformed interface
      isnAlgo.addListener(this);

      createProgressBar(imageA.getImageName(), " ...", isnAlgo);

      // Hide dialog
      setVisible(false);

      if (isRunInSeparateThread()) {

        // Start the thread as a low priority because we wish to still have user interface work
        // fast.
        if (isnAlgo.startMethod(Thread.MIN_PRIORITY) == false) {
          MipavUtil.displayError("A thread is already running on this object");
        }
      } else {
        isnAlgo.run();
      }
    } catch (OutOfMemoryError x) {
      System.gc();
      MipavUtil.displayError("AlgorithmAbsoluteValue: unable to allocate enough memory");

      return;
    }
  }
  /**
   * Use the GUI results to set up the variables needed to run the algorithm.
   *
   * @return <code>true</code> if parameters set successfully, <code>false</code> otherwise.
   */
  private boolean setVariables() {
    String tmpStr;
    int i;

    int totLength = image.getExtents()[0];

    for (i = 1; i < image.getNDims(); i++) {
      totLength *= image.getExtents()[i];
    }

    tmpStr = greenMergingText.getText();
    mergingDistance = Float.parseFloat(tmpStr);
    if (mergingDistance < 0.0f) {
      MipavUtil.displayError("Merging distance cannot be less than 0");
      greenMergingText.requestFocus();
      greenMergingText.selectAll();
      return false;
    }

    tmpStr = redMinText.getText();
    redMin = Integer.parseInt(tmpStr);

    if (redMin < 1) {
      MipavUtil.displayError("red minimum must be at least 1");
      redMinText.requestFocus();
      redMinText.selectAll();

      return false;
    } else if (redMin > totLength) {
      MipavUtil.displayError("red minimum must not exceed " + totLength);
      redMinText.requestFocus();
      redMinText.selectAll();

      return false;
    }

    tmpStr = redFractionText.getText();
    redFraction = Float.parseFloat(tmpStr);

    if (redFraction <= 0.0f) {
      MipavUtil.displayError("red fraction must be greater than zero");
      redFractionText.requestFocus();
      redFractionText.selectAll();

      return false;
    } else if (redFraction > 1.0f) {
      MipavUtil.displayError("red fraction must not exceed one");
      redFractionText.requestFocus();
      redFractionText.selectAll();

      return false;
    }

    tmpStr = greenMinText.getText();
    greenMin = Integer.parseInt(tmpStr);

    if (greenMin < 1) {
      MipavUtil.displayError("green minimum must be at least 1");
      greenMinText.requestFocus();
      greenMinText.selectAll();

      return false;
    } else if (greenMin > totLength) {
      MipavUtil.displayError("green minimum must not exceed " + totLength);
      greenMinText.requestFocus();
      greenMinText.selectAll();

      return false;
    }

    tmpStr = greenFractionText.getText();
    greenFraction = Float.parseFloat(tmpStr);

    if (greenFraction <= 0.0f) {
      MipavUtil.displayError("green fraction must be greater than zero");
      greenFractionText.requestFocus();
      greenFractionText.selectAll();

      return false;
    } else if (greenFraction > 1.0f) {
      MipavUtil.displayError("green fraction must not exceed one");
      greenFractionText.requestFocus();
      greenFractionText.selectAll();

      return false;
    }

    tmpStr = blueMinText.getText();
    blueMin = Integer.parseInt(tmpStr);
    if (blueMin <= 0) {
      MipavUtil.displayError("Number of blue pixels must be greater than 0");
      blueMinText.requestFocus();
      blueMinText.selectAll();
      return false;
    } else if (blueMin > totLength) {
      MipavUtil.displayError("blue minimum must not exceed " + totLength);
      blueMinText.requestFocus();
      blueMinText.selectAll();

      return false;
    }

    if (oneButton.isSelected()) {
      greenRegionNumber = 1;
    } else if (twoButton.isSelected()) {
      greenRegionNumber = 2;
    } else if (threeButton.isSelected()) {
      greenRegionNumber = 3;
    } else {
      greenRegionNumber = 4;
    }

    twoGreenLevels = twoBox.isSelected();

    tmpStr = blueValueText.getText();
    blueBoundaryFraction = Float.parseFloat(tmpStr);
    if (blueBoundaryFraction < 0.0f) {
      MipavUtil.displayError("Blue boundary fraction cannot be less than 0.0");
      blueValueText.requestFocus();
      blueValueText.selectAll();
      return false;
    } else if (blueBoundaryFraction > 1.0f) {
      MipavUtil.displayError("Blue boundary value cannot be greater than 1.0");
      blueValueText.requestFocus();
      blueValueText.selectAll();
      return false;
    }

    blueSmooth = blueSmoothBox.isSelected();

    tmpStr = interpolationText.getText();
    interpolationDivisor = Float.parseFloat(tmpStr);
    if (interpolationDivisor <= 1.0f) {
      MipavUtil.displayError("Interpolation divisor must be greater than 1");
      interpolationText.requestFocus();
      interpolationText.selectAll();
      return false;
    }

    return true;
  } // end setVariables()