Esempio n. 1
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;
    }
  }
  /**
   * 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;
  }
  /**
   * 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()
  /** Starts the program. */
  public void runAlgorithm() {
    int i, j, k;

    if (srcImage == null) {
      displayError("Source Image is null");
      finalize();

      return;
    }

    if (threadStopped) {
      finalize();

      return;
    }

    trueVOIs = srcImage.getVOIs();
    nTrueVOIs = trueVOIs.size();
    testVOIs = testImage.getVOIs();
    nTestVOIs = testVOIs.size();
    length = srcImage.getExtents()[0];

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

    testLength = testImage.getExtents()[0];

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

    if (length != testLength) {
      MipavUtil.displayError(
          srcImage.getImageName()
              + " and "
              + testImage.getImageName()
              + " are unequal in dimensions");
      setCompleted(false);

      return;
    }

    trueMask = new short[length];
    testMask = new short[length];
    ViewUserInterface.getReference().setGlobalDataText(srcImage.getImageName() + " = true\n");
    ViewUserInterface.getReference().setGlobalDataText(testImage.getImageName() + " = test\n");

    for (i = 0; i < nTrueVOIs; i++) {

      if ((trueVOIs.VOIAt(i).getCurveType() == VOI.CONTOUR)
          || (trueVOIs.VOIAt(i).getCurveType() == VOI.POLYLINE)) {
        trueID = trueVOIs.VOIAt(i).getID();

        for (j = 0; j < nTestVOIs; j++) {
          testID = testVOIs.VOIAt(j).getID();

          if (trueID == testID) {

            for (k = 0; k < length; k++) {
              trueMask[k] = -1;
              testMask[k] = -1;
            }

            trueMask = srcImage.generateVOIMask(trueMask, i);
            testMask = testImage.generateVOIMask(testMask, j);
            absoluteTrue = 0;
            trueFound = 0;
            falseNegative = 0;
            falsePositive = 0;

            for (k = 0; k < length; k++) {

              if (trueMask[k] == trueID) {
                absoluteTrue++;

                if (testMask[k] == trueID) {
                  trueFound++;
                } else {
                  falseNegative++;
                }
              } // if (trueMask[k] == trueID)
              else { // trueMask[k] != trueID

                if (testMask[k] == trueID) {
                  falsePositive++;
                }
              } // else trueMask[k] != trueID
            } // for (k = 0; k < length; k++)

            ViewUserInterface.getReference()
                .setGlobalDataText(
                    "Statistics for VOIs with ID = " + String.valueOf(trueID) + "\n");
            fnvf = (float) falseNegative / (float) absoluteTrue;
            ViewUserInterface.getReference()
                .setGlobalDataText(
                    "     False negative volume fraction = " + String.valueOf(fnvf) + "\n");
            fpvf = (float) falsePositive / (float) absoluteTrue;
            ViewUserInterface.getReference()
                .setGlobalDataText(
                    "     False positive volume fraction = " + String.valueOf(fpvf) + "\n");
            tpvf = (float) trueFound / (float) absoluteTrue;
            ViewUserInterface.getReference()
                .setGlobalDataText(
                    "     True Positive volume fraction = " + String.valueOf(tpvf) + "\n\n");
          } // if (trueID == testID)
        } // for (j = 0; j < nTestVOIs; j++)
      } // if ((trueVOIs.VOIAt(i).getCurveType() == VOI.CONTOUR)
    } // for (i = 0; i < nTrueVOIs; i++)

    setCompleted(true);
  }
  /**
   * Once all the necessary variables are set, call the Nonlocal Means filter algorithm based on
   * what type of image this is and whether or not there is a separate destination image.
   */
  protected void callAlgorithm() {
    String name = makeImageName(image.getImageName(), "_NonlocalMeans");
    int[] destExtents;

    if (image.getNDims() == 2) { // source image is 2D
      destExtents = new int[2];
      destExtents[0] = image.getExtents()[0]; // X dim
      destExtents[1] = image.getExtents()[1]; // Y dim
    } else {
      destExtents = new int[3];
      destExtents[0] = image.getExtents()[0];
      destExtents[1] = image.getExtents()[1];
      destExtents[2] = image.getExtents()[2];
    }

    if (displayLoc == NEW) {

      try {

        // Make result image of float type
        if (image.isColorImage()) {
          resultImage = new ModelImage(ModelImage.ARGB, destExtents, name);
        } else {
          resultImage = new ModelImage(ModelImage.FLOAT, destExtents, name);
        }

        // resultImage = (ModelImage)image.clone();
        // resultImage.setImageName(name);
        // Make algorithm
        nlMeansFilterAlgo =
            new AlgorithmNonlocalMeansFilter(
                resultImage,
                image,
                searchWindowSide,
                similarityWindowSide,
                noiseStandardDeviation,
                degreeOfFiltering,
                doRician,
                image25D);

        // 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
        nlMeansFilterAlgo.addListener(this);
        createProgressBar(image.getImageName(), nlMeansFilterAlgo);

        // Hide dialog
        setVisible(false);

        if (isRunInSeparateThread()) {

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

        if (resultImage != null) {
          resultImage.disposeLocal(); // Clean up memory of result image
          resultImage = null;
        }

        return;
      }
    } else {

      try {

        // No need to make new image space because the user has choosen to replace the source image
        // Make the algorithm class
        nlMeansFilterAlgo =
            new AlgorithmNonlocalMeansFilter(
                null,
                image,
                searchWindowSide,
                similarityWindowSide,
                noiseStandardDeviation,
                degreeOfFiltering,
                doRician,
                image25D);

        // 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
        nlMeansFilterAlgo.addListener(this);
        createProgressBar(image.getImageName(), nlMeansFilterAlgo);

        // Hide the dialog since the algorithm is about to run.
        setVisible(false);

        // These next lines set the titles in all frames where the source image is displayed to
        // "locked - " image name so as to indicate that the image is now read/write locked!
        // The image frames are disabled and then unregisted from the userinterface until the
        // algorithm has completed.
        Vector<ViewImageUpdateInterface> imageFrames = image.getImageFrameVector();
        titles = new String[imageFrames.size()];

        for (int i = 0; i < imageFrames.size(); i++) {
          titles[i] = ((Frame) (imageFrames.elementAt(i))).getTitle();
          ((Frame) (imageFrames.elementAt(i))).setTitle("Locked: " + titles[i]);
          ((Frame) (imageFrames.elementAt(i))).setEnabled(false);
          userInterface.unregisterFrame((Frame) (imageFrames.elementAt(i)));
        }

        if (isRunInSeparateThread()) {

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

        return;
      }
    }
  }
Esempio n. 6
0
  /** cat. */
  private void cat3D_4D_4D() {

    int length;
    int xDim, yDim;
    float[] buffer;
    int cFactor = 1;
    int i, j;
    float[] resols = new float[3];
    float[] origins = new float[3];
    FileInfoBase[] fileInfo = null;
    FileInfoDicom[] fileInfoDicom = null;
    int srcALength, srcBLength;

    try {
      fireProgressStateChanged(srcImage1.getImageName(), "Concatenating images ...");
      resols = new float[4];
      origins = new float[4];
      xDim = srcImage1.getExtents()[0];
      yDim = srcImage1.getExtents()[1];

      if (srcImage1.isColorImage()) {
        cFactor = 4;
      }

      length = cFactor * xDim * yDim;
      buffer = new float[length];

      int nImages;

      if (srcImage1.getNDims() > srcImage2.getNDims()) {
        nImages =
            (srcImage1.getExtents()[2] * srcImage1.getExtents()[3]) + srcImage2.getExtents()[2];

        for (i = 0;
            (i < (srcImage1.getExtents()[2] * srcImage1.getExtents()[3])) && !threadStopped;
            i++) {
          fireProgressStateChanged(Math.round((float) (i) / (nImages - 1) * 100));

          srcImage1.exportData(i * length, length, buffer);
          destImage.importData(i * length, buffer, false);
        }

        if (threadStopped) {
          buffer = null;
          finalize();

          return;
        }

        for (j = 0; (j < srcImage2.getExtents()[2]) && !threadStopped; j++) {
          fireProgressStateChanged(Math.round((float) (i + j) / (nImages - 1) * 100));

          srcImage2.exportData(j * length, length, buffer);
          destImage.importData((i + j) * length, buffer, false);
        }

        if (threadStopped) {
          buffer = null;
          finalize();

          return;
        }

        destImage.calcMinMax();
      } else {
        nImages =
            (srcImage2.getExtents()[2] * srcImage2.getExtents()[3]) + srcImage1.getExtents()[2];

        for (j = 0; (j < srcImage1.getExtents()[2]) && !threadStopped; j++) {
          fireProgressStateChanged(Math.round((float) (j) / (nImages - 1) * 100));

          srcImage1.exportData(j * length, length, buffer);
          destImage.importData(j * length, buffer, false);
        }

        if (threadStopped) {
          buffer = null;
          finalize();

          return;
        }

        for (i = 0;
            (i < (srcImage2.getExtents()[2] * srcImage2.getExtents()[3])) && !threadStopped;
            i++) {
          fireProgressStateChanged(Math.round((float) (i + j) / (nImages - 1) * 100));

          srcImage2.exportData(i * buffer.length, length, buffer);
          destImage.importData((i + j) * buffer.length, buffer, false);
        }

        if (threadStopped) {
          buffer = null;
          finalize();

          return;
        }

        destImage.calcMinMax();
      }
    } catch (IOException error) {
      buffer = null;
      destImage.disposeLocal(); // Clean up memory of result image
      destImage = null;
      errorCleanUp("Algorithm Concat. Images: Image(s) locked", true);

      return;
    } catch (OutOfMemoryError e) {
      buffer = null;
      destImage.disposeLocal(); // Clean up memory of result image
      destImage = null;
      errorCleanUp("Algorithm Concat. Images: Out of memory", true);

      return;
    }

    resols[0] = srcImage1.getFileInfo()[0].getResolutions()[0];
    resols[1] = srcImage1.getFileInfo()[0].getResolutions()[1];
    resols[2] = srcImage1.getFileInfo()[0].getResolutions()[2];
    resols[3] = srcImage1.getFileInfo()[0].getResolutions()[3];
    origins[0] = srcImage1.getFileInfo()[0].getOrigin()[0];
    origins[1] = srcImage1.getFileInfo()[0].getOrigin()[1];
    origins[2] = srcImage1.getFileInfo()[0].getOrigin()[2];
    origins[3] = srcImage1.getFileInfo()[0].getOrigin()[3];

    if ((srcImage1.getFileInfo()[0] instanceof FileInfoDicom)
        && (srcImage2.getFileInfo()[0] instanceof FileInfoDicom)) {
      fileInfoDicom = new FileInfoDicom[destImage.getExtents()[2] * destImage.getExtents()[3]];

      if (srcImage1.getNDims() > srcImage2.getNDims()) {
        srcALength = srcImage1.getExtents()[2] * srcImage1.getExtents()[3];

        for (i = 0; (i < srcALength) && !threadStopped; i++) {
          fileInfoDicom[i] = (FileInfoDicom) (((FileInfoDicom) srcImage1.getFileInfo()[i]).clone());
          fileInfoDicom[i].setOrigin(origins);
        }

        for (i = 0; (i < srcImage2.getExtents()[2]) && !threadStopped; i++) {
          fileInfoDicom[srcALength + i] =
              (FileInfoDicom) (((FileInfoDicom) srcImage2.getFileInfo()[i]).clone());
          fileInfoDicom[srcALength + i].setOrigin(origins);
        }
      } else {
        srcBLength = srcImage2.getExtents()[2] * srcImage2.getExtents()[3];

        for (i = 0; (i < srcImage1.getExtents()[2]) && !threadStopped; i++) {
          fileInfoDicom[i] = (FileInfoDicom) (((FileInfoDicom) srcImage1.getFileInfo()[i]).clone());
          fileInfoDicom[i].setOrigin(origins);
        }

        for (i = 0; (i < srcBLength) && !threadStopped; i++) {
          fileInfoDicom[srcImage1.getExtents()[2] + i] =
              (FileInfoDicom) (((FileInfoDicom) srcImage2.getFileInfo()[i]).clone());
          fileInfoDicom[srcImage1.getExtents()[2] + i].setOrigin(origins);
        }
      }

      destImage.setFileInfo(fileInfoDicom);
    } else {
      fileInfo = destImage.getFileInfo();

      for (i = 0;
          (i < (destImage.getExtents()[2] * destImage.getExtents()[3])) && !threadStopped;
          i++) {
        fileInfo[i].setModality(srcImage1.getFileInfo()[0].getModality());
        fileInfo[i].setFileDirectory(srcImage1.getFileInfo()[0].getFileDirectory());
        fileInfo[i].setEndianess(srcImage1.getFileInfo()[0].getEndianess());
        fileInfo[i].setUnitsOfMeasure(srcImage1.getFileInfo()[0].getUnitsOfMeasure());
        fileInfo[i].setResolutions(resols);
        fileInfo[i].setExtents(destImage.getExtents());
        fileInfo[i].setMax(destImage.getMax());
        fileInfo[i].setMin(destImage.getMin());
        fileInfo[i].setImageOrientation(srcImage1.getImageOrientation());
        fileInfo[i].setPixelPadValue(srcImage1.getFileInfo()[0].getPixelPadValue());
        fileInfo[i].setPhotometric(srcImage1.getFileInfo()[0].getPhotometric());
        fileInfo[i].setAxisOrientation(srcImage1.getAxisOrientation());
      }

      if (srcImage1.getFileInfo()[0] instanceof FileInfoImageXML) {

        if (srcImage1.getNDims() > srcImage2.getNDims()) {
          srcALength = srcImage1.getExtents()[2] * srcImage1.getExtents()[3];

          for (i = 0; (i < srcALength) && !threadStopped; i++) {

            if (((FileInfoImageXML) srcImage1.getFileInfo()[i]).getPSetHashtable() != null) {
              ((FileInfoImageXML) fileInfo[i])
                  .setPSetHashtable(
                      ((FileInfoImageXML) srcImage1.getFileInfo()[i]).getPSetHashtable());
            }
          }
        } else {

          for (i = 0; (i < srcImage1.getExtents()[2]) && !threadStopped; i++) {

            if (((FileInfoImageXML) srcImage1.getFileInfo()[i]).getPSetHashtable() != null) {
              ((FileInfoImageXML) fileInfo[i])
                  .setPSetHashtable(
                      ((FileInfoImageXML) srcImage1.getFileInfo()[i]).getPSetHashtable());
            }
          }
        }
      }

      if (srcImage2.getFileInfo()[0] instanceof FileInfoImageXML) {

        if (srcImage1.getNDims() > srcImage2.getNDims()) {
          srcALength = srcImage1.getExtents()[2] * srcImage1.getExtents()[3];

          for (i = 0; (i < srcImage2.getExtents()[2]) && !threadStopped; i++) {

            if (((FileInfoImageXML) srcImage2.getFileInfo()[i]).getPSetHashtable() != null) {
              ((FileInfoImageXML) fileInfo[srcALength + i])
                  .setPSetHashtable(
                      ((FileInfoImageXML) srcImage2.getFileInfo()[i]).getPSetHashtable());
            }
          }

        } else {
          srcBLength = srcImage2.getExtents()[2] * srcImage2.getExtents()[3];

          for (i = 0; (i < srcBLength) && !threadStopped; i++) {

            if (((FileInfoImageXML) srcImage2.getFileInfo()[i]).getPSetHashtable() != null) {
              ((FileInfoImageXML) fileInfo[srcImage1.getExtents()[2] + i])
                  .setPSetHashtable(
                      ((FileInfoImageXML) srcImage2.getFileInfo()[i]).getPSetHashtable());
            }
          }
        }
      }
    }

    if (threadStopped) {
      buffer = null;
      finalize();

      return;
    }

    setCompleted(true);
    fileInfo = null;
    fileInfoDicom = null;
  }
  /** Sets up the GUI (panels, buttons, etc) and displays it on the screen. */
  private void init() {
    if (image.getFileInfo(0).getFileFormat() == FileUtility.DICOM) {
      FileInfoDicom dicomInfo = (FileInfoDicom) image.getFileInfo(0);
      FileDicomTagTable tagTable = dicomInfo.getTagTable();
      if (tagTable.getValue("0018,1310") != null) {
        // Acquisition matrix
        FileDicomTag tag = tagTable.get(new FileDicomKey("0018,1310"));
        Object[] values = tag.getValueList();
        int valNumber = values.length;
        if ((valNumber == 4) && (values instanceof Short[])) {
          int frequencyRows = ((Short) values[0]).intValue();
          Preferences.debug("frequencyRows = " + frequencyRows + "\n");
          int frequencyColumns = ((Short) values[1]).intValue();
          Preferences.debug("frequencyColumns = " + frequencyColumns + "\n");
          int phaseRows = ((Short) values[2]).intValue();
          Preferences.debug("phaseRows = " + phaseRows + "\n");
          int phaseColumns = ((Short) values[3]).intValue();
          Preferences.debug("phaseColumns = " + phaseColumns + "\n");
          if ((frequencyRows > 0) && (phaseRows == 0)) {
            subYDim = frequencyRows;
          } else if ((frequencyRows == 0) && (phaseRows > 0)) {
            subYDim = phaseRows;
          }
          if ((frequencyColumns > 0) && (phaseColumns == 0)) {
            subXDim = frequencyColumns;
          } else if ((frequencyColumns == 0) && (phaseColumns > 0)) {
            subXDim = phaseColumns;
          }
        }
      } // if (tagTable.getValue("0018,1310") != null)
      if (tagTable.getValue("0019,100A") != null) {
        FileDicomTag tag = tagTable.get(new FileDicomKey("0019,100A"));
        Object value = tag.getValue(false);
        if (value instanceof Short) {
          numberOfImagesInMosaic = ((Short) value).intValue();
          Preferences.debug("Number of images in mosaic = " + numberOfImagesInMosaic + "\n");
        }
      } // if (tagTable.getValue("0019,100A") != null)
    } // if (image.getFileInfo(0).getFileFormat() == FileUtility.DICOM)*/
    setForeground(Color.black);
    setTitle("Mosaic To 3D Volume");

    JPanel inputPanel = new JPanel(new GridBagLayout());
    inputPanel.setForeground(Color.black);

    inputPanel.setBorder(buildTitledBorder("Image"));

    JLabel labelUse = new JLabel("Image:");
    labelUse.setForeground(Color.black);
    labelUse.setFont(serif12);

    JLabel labelImage = new JLabel(image.getImageName());
    labelImage.setForeground(Color.black);
    labelImage.setFont(serif12);

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridheight = 1;
    gbc.gridwidth = 1;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.weightx = 1;
    gbc.insets = new Insets(5, 5, 5, 5);
    inputPanel.add(labelUse, gbc);
    gbc.gridx = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    inputPanel.add(labelImage, gbc);

    JPanel dimensionPanel = new JPanel(new GridBagLayout());
    dimensionPanel.setForeground(Color.black);
    dimensionPanel.setBorder(buildTitledBorder("X and Y Dimensions of Result"));

    JLabel labelXDim = new JLabel("X dimension of slices");
    labelXDim.setForeground(Color.black);
    labelXDim.setFont(serif12);

    textXDim = new JTextField(10);
    if (subXDim != 0) {
      textXDim.setText(String.valueOf(subXDim));
    }
    textXDim.setFont(serif12);
    textXDim.setForeground(Color.black);

    JLabel labelYDim = new JLabel("Y dimension of slices");
    labelYDim.setForeground(Color.black);
    labelYDim.setFont(serif12);

    textYDim = new JTextField(10);
    if (subYDim != 0) {
      textYDim.setText(String.valueOf(subYDim));
    }
    textYDim.setFont(serif12);
    textYDim.setForeground(Color.black);

    JLabel labelNumberImages = new JLabel("Number of images in mosaic");
    labelNumberImages.setForeground(Color.black);
    labelNumberImages.setFont(serif12);

    textNumberImages = new JTextField(10);
    if (numberOfImagesInMosaic != 0) {
      textNumberImages.setText(String.valueOf(numberOfImagesInMosaic));
    }
    textNumberImages.setFont(serif12);
    textNumberImages.setForeground(Color.black);

    gbc.gridx = 0;
    gbc.gridy = 0;
    dimensionPanel.add(labelXDim, gbc);
    gbc.gridx = 1;
    dimensionPanel.add(textXDim, gbc);
    gbc.gridx = 0;
    gbc.gridy = 1;
    dimensionPanel.add(labelYDim, gbc);
    gbc.gridx = 1;
    dimensionPanel.add(textYDim, gbc);
    gbc.gridx = 0;
    gbc.gridy = 2;
    dimensionPanel.add(labelNumberImages, gbc);
    gbc.gridx = 1;
    dimensionPanel.add(textNumberImages, gbc);

    JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(inputPanel, BorderLayout.NORTH);
    mainPanel.add(dimensionPanel, BorderLayout.CENTER);
    mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    JPanel buttonPanel = new JPanel();
    buttonPanel.add(buildButtons());

    getContentPane().add(mainPanel);
    getContentPane().add(buttonPanel, BorderLayout.SOUTH);
    pack();
    setVisible(true);
  }
  /**
   * Once all the necessary variables are set, call the Concat algorithm based on what type of image
   * this is and whether or not there is a separate destination image.
   */
  protected void callAlgorithm() {
    int destExtents[] = new int[3];
    ModelImage destImage = null;

    destExtents[0] = subXDim;
    destExtents[1] = subYDim;
    destExtents[2] = numberOfImagesInMosaic;

    destImage =
        new ModelImage(
            image.getType(), destExtents, makeImageName(image.getImageName(), "_mosaic_to_slices"));

    try {

      // Make algorithm
      mathAlgo = new AlgorithmMosaicToSlices(image, destImage);

      // 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
      mathAlgo.addListener(this);

      createProgressBar(image.getImageName(), mathAlgo);

      // Hide dialog
      setVisible(false);

      if (displayLoc == REPLACE) {

        // These next lines set the titles in all frames where the source image is displayed to
        // "locked - " image name so as to indicate that the image is now read/write locked!
        // The image frames are disabled and then unregisted from the userinterface until the
        // algorithm has completed.
        Vector<ViewImageUpdateInterface> imageFrames = image.getImageFrameVector();
        titles = new String[imageFrames.size()];

        for (int i = 0; i < imageFrames.size(); i++) {
          titles[i] = ((Frame) (imageFrames.elementAt(i))).getTitle();
          ((Frame) (imageFrames.elementAt(i))).setTitle("Locked: " + titles[i]);
          ((Frame) (imageFrames.elementAt(i))).setEnabled(false);
          userInterface.unregisterFrame((Frame) (imageFrames.elementAt(i)));
        }
      }

      if (isRunInSeparateThread()) {

        // Start the thread as a low priority because we wish to still have user interface work
        // fast.
        if (mathAlgo.startMethod(Thread.MIN_PRIORITY) == false) {
          MipavUtil.displayError("A thread is already running on this object");
        }

      } else {

        mathAlgo.run();
      }
    } catch (OutOfMemoryError x) {
      System.gc();
      MipavUtil.displayError("Dialog Concatenation: unable to allocate enough memory");

      return;
    }
  }