/** Loads the default settings from Preferences to set up the dialog. */
  public void legacyLoadDefaults() {
    String defaultsString = Preferences.getDialogDefaults(getDialogName());

    if ((defaultsString != null) && (newImage != null)) {

      try {
        StringTokenizer st = new StringTokenizer(defaultsString, ",");

        textSearchWindowSide.setText("" + MipavUtil.getInt(st));
        textSimilarityWindowSide.setText("" + MipavUtil.getInt(st));
        textNoiseStandardDeviation.setText("" + MipavUtil.getFloat(st));
        textDegree.setText("" + MipavUtil.getFloat(st));
        doRician = MipavUtil.getBoolean(st);
        doRicianCheckBox.setSelected(doRician);
        textDegree.setEnabled(doRician);
        labelDegree.setEnabled(doRician);
        image25DCheckBox.setSelected(MipavUtil.getBoolean(st));

        if (MipavUtil.getBoolean(st)) {
          newImage.setSelected(true);
        } else {
          replaceImage.setSelected(true);
        }

      } catch (Exception ex) {

        // since there was a problem parsing the defaults string, start over with the original
        // defaults
        Preferences.debug("Resetting defaults for dialog: " + getDialogName());
        Preferences.removeProperty(getDialogName());
      }
    }
  }
  /** algorithm performed */
  public void algorithmPerformed(AlgorithmBase algorithm) {
    if (alg.isCompleted()) {
      alg = null;
      // if OKButton is not null, then the rest are not null
      // we don't want to do these if this algoritm was done via a script
      if (OKButton != null) {
        OKButton.setEnabled(true);
        dwiPathBrowseButton.setEnabled(true);
        gradFileRadio.setEnabled(true);
        bmtxtFileRadio.setEnabled(true);
        performRegistrationCheckbox.setEnabled(true);
        registrationSettingsButton.setEnabled(true);
        dwiLabel.setEnabled(true);
        dicomB0VolumeLabel.setEnabled(true);
        // interleavedCheckbox.setEnabled(true);
        if (gradFileRadio.isSelected()) {
          gradientFileBrowseButton.setEnabled(true);
        } else {
          bmtxtFileBrowseButton.setEnabled(true);
        }
        setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        outputTextArea.append("*** End DTI Sorting Process *** \n");
      }

      // insertScriptLine();
      Preferences.debug("*** End DTI Sorting Process *** \n", Preferences.DEBUG_ALGORITHM);
      // System.out.println("*** End DTI Sorting Process *** \n");
    }
  }
Example #3
0
 /**
  * Default constructor which sets thread stopped to false, source and destination images to null,
  * and destination flag to false.
  */
 public AlgorithmBase() {
   this.destImage = null;
   this.srcImage = null;
   destFlag = false;
   threadStopped = false;
   nthreads = ThreadUtil.getAvailableCores();
   multiThreadingEnabled = Preferences.isMultiThreadingEnabled();
 }
  /**
   * 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)) {
      return getResultImage().getImageName();
    }

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

    return null;
  }
Example #5
0
  /**
   * Performs start-up and tear-down operations that should be done by all algorithms (timing,
   * history log). Since this class extends the Thread class it can be run in its own thread by
   * invoking object.start(); It can also be invoked without a new thread by calling the the run()
   * method directly (ie. object.run()).
   */
  public void run() {
    setStartTime();
    runAlgorithm();

    if (threadStopped) {
      return;
    }
    double timeinSec = computeElapsedTime();
    Preferences.debug("Elapsed time: " + timeinSec + "\n", Preferences.DEBUG_ALGORITHM);
    notifyListeners(this);

    /// finalize();
  }
Example #6
0
  /**
   * Constructor which sets thread stopped to false and sets source and destination images.
   *
   * @param destImage Destination image, can be null.
   * @param srcImage Source image, should not be null.
   */
  public AlgorithmBase(ModelImage destImage, ModelImage srcImage) {
    this.destImage = destImage;
    this.srcImage = srcImage;

    if (destImage == null) {
      destFlag = false;
    } else {
      destFlag = true;
    }

    threadStopped = false;
    nthreads = ThreadUtil.getAvailableCores();
    multiThreadingEnabled = Preferences.isMultiThreadingEnabled();
  }
Example #7
0
 public JTextField buildFileField(
     String labelText,
     String initText,
     final boolean multiSelect,
     final int fileSelectionMode,
     ActionListener updateAction) {
   return buildFileField(
       labelText,
       initText,
       Preferences.getImageDirectory(),
       multiSelect,
       fileSelectionMode,
       false,
       updateAction);
 }
  /**
   * 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;
  }
Example #9
0
  /**
   * The top level rendering call. This function calls beforeResampleAll, resampleAll, and
   * mapIntermediateToFinal, all virtual functions that are implemented in derived classes.
   *
   * @param iDS The number of slices to increment during the resampling phase. The value should be
   *     one or larger. If one, all slices of the volume data are resampled. If two, only every
   *     other slice is resampled. An input larger than one is used to allow fast rendering during
   *     rotation of the volume data. Once the rotation terminates, a composite with input of one
   *     should be called.
   */
  public synchronized void composite(int iDS) {
    long startTime = 0, now = 0;
    double elapsedTime = 0d;

    // compute maximum component of the box direction vector
    float fMax = 0.0f;
    int i, iMax = -1;

    for (i = 0; i < 3; i++) {
      float fAbs = Math.abs(m_aafBox[2][i]);

      if (fAbs > fMax) {
        fMax = fAbs;
        iMax = i;
      }
    }

    startTime = System.currentTimeMillis();
    traceInit();

    // composite in the appropriate direction
    if (iMax == 0) {
      beforeResampleAll(1, 2, 0);
    } else if (iMax == 1) {
      beforeResampleAll(2, 0, 1);
    } else {
      beforeResampleAll(0, 1, 2);
    }

    resampleAll(iDS);
    mapIntermediateToFinal();
    now = System.currentTimeMillis();
    elapsedTime = (double) (now - startTime);

    if (elapsedTime <= 0) {
      elapsedTime = (double) 0.0;
    }

    Preferences.debug(
        "Shear elapse time = " + (double) (elapsedTime / 1000.0) + "\n"); // in seconds
  }
  /** Saves the default settings into the Preferences file. */
  public void legacySaveDefaults() {
    String defaultsString = new String(getParameterString(",") + "," + newImage.isSelected());

    Preferences.saveDialogDefaults(getDialogName(), defaultsString);
  }
Example #11
0
  /**
   * Reads a DIMSE-C message.
   *
   * @param pdu the context pdu DICOMClientServer
   * @param dco the incoming DICOM message
   * @param ddo a place to store the incoming DICOM data object or null if not required
   * @exception DICOM_Exception DOCUMENT ME!
   */
  public void readCResponseAlias(
      final DICOM_PDUService pdu, final DICOM_Object dco, final DICOM_Object ddo)
      throws DICOM_Exception {

    if (dco == null) {
      throw new DICOM_Exception("null dco");
    }

    final int command = dco.getInt16(DICOM_RTC.DD_CommandField);

    if (command != COMMAND) { // not correct command
      throw new DICOM_Exception(
          "DIMSE-C Request error: "
              + DICOM_Util.toHexString((short) command)
              + " looking for "
              + DICOM_Util.toHexString(COMMAND));
    }

    final int dstype = dco.getInt16(DICOM_RTC.DD_DataSetType);

    if (dstype != DICOM_Constants.DSTYPE_NODATAPRESENT) {

      // data is present
      if (Preferences.debugLevel(Preferences.DEBUG_COMMS)) {
        Preferences.debug("CRequest.readCResponseAlias DCO : Data is present" + "\n");
      }

      if (ddo == null) {
        throw new DICOM_Exception("null ddo");
      }

      if (pdu == null) {
        throw new DICOM_Exception("null pdu");
      }

      pdu.readInObject(ddo);
    } else {

      if (ddo != null) {
        ddo.clear();
      }
    }

    final int status = dco.getInt16(DICOM_RTC.DD_Status);

    if (Preferences.debugLevel(Preferences.DEBUG_COMMS)) {

      if (dco != null) {
        Preferences.debug("CRequest.readCResponseAlias DCO : " + dco.toString("DCO") + "\n");
      }

      if (ddo != null) {
        Preferences.debug("CRequest.readCResponseAlias DDO : " + ddo.toString("DDO") + "\n");
      }
    }

    if ((status >= DICOM_Constants.STATUS_ERRORFIRST)
        && (status <= DICOM_Constants.STATUS_ERRORLAST)) {
      String str1, errorComment;

      str1 =
          "Status error for command  = "
              + DICOM_Constants.convertCommandToString(COMMAND)
              + // +DICOM_Util.toHexString(
              // (short)
              // COMMAND ) +
              " status = ["
              + DICOM_Util.toHexString((short) status)
              + "] ";
      errorComment = dco.getStr(DICOM_RTC.DD_ErrorComment); // + dco.getOffending Element;

      // Preferences.debug("CRequest.readCResponseAlias DCO : " + dco.toString("DCO") + "\n");
      // Preferences.debug("CRequest.readCResponseAlias DDO : " + ddo.toString("DDO") + "\n");
      // System.out.println("DD_ErrorComment = " + errorComment);

      if (errorComment != null) {
        str1 = str1 + errorComment + "\n";
      }

      throw new DICOM_Exception(str1);
    }
  }
Example #12
0
 public JTextField buildFileField(
     String labelText, String initText, final boolean multiSelect, final int fileSelectionMode) {
   return buildFileField(
       labelText, initText, Preferences.getImageDirectory(), multiSelect, fileSelectionMode);
 }
  /** 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);
  }
  /** Constructor. */
  public JDialogEditUserDefinedFileTypes() {

    setTitle("Edit User Defined Filter");

    // get the user defined file types preferences
    if (Preferences.getProperty(Preferences.PREF_USER_FILETYPES) != null) {
      if (!Preferences.getProperty(Preferences.PREF_USER_FILETYPES).trim().equals("")) {
        preferencesFileTypes = Preferences.getProperty(Preferences.PREF_USER_FILETYPES).split("; ");
      }
    }

    displayPanel = new JPanel();
    GridBagLayout gbl = new GridBagLayout();
    GridBagConstraints gbc = new GridBagConstraints();
    displayPanel.setLayout(gbl);

    int x = 0;
    int y = 0;
    Iterator<String> iter = fileExtensionsTS.iterator();
    while (iter.hasNext()) {
      String extensionLabel = (String) "*" + iter.next();
      JCheckBox checkBox = new JCheckBox(extensionLabel);
      checkBoxArrList.add(checkBox);
      checkboxNames.add(extensionLabel);
      if (checkPreference(extensionLabel)) {
        checkBox.setSelected(true);
      }
      renderCheckBox(checkBox, gbl, gbc, x, y);
      if (x < 4) {
        x++;
      } else {
        x = 0;
        y++;
      }
    }

    gbc.gridx = 0;
    gbc.gridy = ++y;
    gbc.gridwidth = 5;
    gbc.insets = new Insets(10, 5, 10, 5);
    JLabel label1 =
        new JLabel("Enter additional file extensions below. ( format: *.abc;*.def;*.ghi )");
    gbl.setConstraints(label1, gbc);
    displayPanel.add(label1);

    gbc.gridx = 0;
    gbc.gridy = ++y;
    gbc.gridwidth = 5;
    gbc.insets = new Insets(10, 5, 10, 5);
    userInput = new JTextField(30);

    if (Preferences.getProperty(Preferences.PREF_USER_FILETYPES_TEXTFIELDS) != null) {
      userInput.setText(Preferences.getProperty(Preferences.PREF_USER_FILETYPES_TEXTFIELDS));
    }
    gbl.setConstraints(userInput, gbc);
    displayPanel.add(userInput);

    applyClosePanel = new JPanel();
    buildOKButton();
    OKButton.setText("Apply");
    applyClosePanel.add(OKButton, BorderLayout.WEST);
    buildCancelButton();
    cancelButton.setText("Cancel");
    cancelButton.setActionCommand("close");
    applyClosePanel.add(cancelButton, BorderLayout.CENTER);

    this.getContentPane().add(displayPanel, BorderLayout.CENTER);
    this.getContentPane().add(applyClosePanel, BorderLayout.SOUTH);

    pack();
    this.setResizable(false);
    setVisible(true);
  }
  /**
   * The actionPerformed method
   *
   * @param event the ActionEvent
   */
  public void actionPerformed(ActionEvent event) {
    String command = event.getActionCommand();

    if (command.equalsIgnoreCase("apply")) {
      checkedFileTypes = new ArrayList<String>();

      for (int i = 0; i < checkBoxArrList.size(); i++) {
        JCheckBox cBox = (JCheckBox) checkBoxArrList.get(i);
        if (cBox.isSelected()) {
          checkedFileTypes.add(cBox.getText());
        }
      }

      StringBuffer sb = new StringBuffer();

      // add the checked box file types to the string buffer
      for (int i = 0; i < checkedFileTypes.size(); i++) {
        sb.append((String) checkedFileTypes.get(i));
        if (i != checkedFileTypes.size() - 1) {
          sb.append("; ");
        }
      }

      // determine if user entered any file extensions in the user input area..if so...validate and
      // if passed, add
      // on to string buffer
      if (!(userInput.getText().trim().equals(""))) {
        if (!validateUserInputString(userInput.getText().trim())) {
          MipavUtil.displayError(
              "Additional file extensions must be unique and in the proper format. \n"
                  + "                                       ex. (*.abc;*.def)");
          userInput.setText("");
          return;
        } else {
          if (checkedFileTypes.size() > 0) {
            sb.append("; ");
          }
          for (int i = 0; i < userInputFileTypes.length; i++) {
            sb.append(userInputFileTypes[i]);
            if (i != userInputFileTypes.length - 1) {
              sb.append("; ");
            }
          }
        }
      }

      // set the udef description
      if (checkedFileTypes.size() == 0 && userInputFileTypes == null) {
        ViewImageFileFilter.setUdefDescription("User Defined");
      } else {
        ViewImageFileFilter.setUdefDescription("User Defined (" + sb.toString() + ")");
      }

      // set the preferences
      Preferences.setProperty(Preferences.PREF_USER_FILETYPES, sb.toString());
      StringBuffer inputStringSB = new StringBuffer();
      if (userInputFileTypes != null) {
        for (int i = 0; i < userInputFileTypes.length; i++) {
          inputStringSB.append(userInputFileTypes[i]);
          if (i != userInputFileTypes.length - 1) {
            inputStringSB.append(";");
          }
        }
      }
      Preferences.setProperty(Preferences.PREF_USER_FILETYPES_TEXTFIELDS, inputStringSB.toString());

      // don't remember why i had this following code...the comment makes no sense....i commented
      // out the
      // whole thing...and everything seems to work

      // need to disasscociate and reset userdefinedFileTypesAssociations if user
      // has deleted a userDefined Extension that was part of that preferences
      /*if (userInput.getText().trim().equals("")) {
          Preferences.setProperty(Preferences.PREF_USER_FILETYPES, "");
      } else {
          if (Preferences.getProperty(Preferences.PREF_USER_FILETYPES) != null) {
              if ( !Preferences.getProperty(Preferences.PREF_USER_FILETYPES).trim().equals("")) {
                  String[] associations = Preferences.getProperty(Preferences.PREF_USER_FILETYPES).split(";");
                  StringBuffer assocSB = new StringBuffer();
                  for (int i = 0; i < associations.length; i++) {
                      for (int k = 0; k < userInputFileTypes.length; k++) {
                          String uiFileType = userInputFileTypes[k].split("\\.")[1];
                          uiFileType = "." + uiFileType;
                          if (associations[i].split(":")[0].equals(uiFileType)) {

                              if (sb.length() != 0) {
                                  assocSB.append(";");
                              }
                              assocSB.append(associations[i]);
                              break;
                          }
                      }
                  }
                  System.out.println("assocSB is " + assocSB.toString());
                  Preferences.setProperty(Preferences.PREF_USER_FILETYPES, assocSB.toString());
              }
          }
      }*/

      // set the cancel button text to 'close' since the changes were accepted
      cancelButton.setText("Close");
    } else if (command.equalsIgnoreCase("close")) { // close box
      dispose();
    } else {
      super.actionPerformed(event);
    }
  }
Example #16
0
  /**
   * Writes a DIMSE-C message.
   *
   * @param pdu the context pdu DICOMClientServer
   * @param transferSyntax transfer syntax.
   * @param classUID the SOP Class UID.
   * @param instanceUID DOCUMENT ME!
   * @param ddo the outgoing DICOM data object (null if none required)
   * @param AETitle byte array to store the destination Application Entity title for C-Moves
   * @exception DICOM_Exception DOCUMENT ME!
   */
  public void write(
      final DICOM_PDUService pdu,
      String transferSyntax,
      final String classUID,
      final String instanceUID,
      final DICOM_Object ddo,
      final byte[] AETitle)
      throws DICOM_Exception {

    if (Preferences.debugLevel(Preferences.DEBUG_COMMS)) {
      Preferences.debug(DICOM_Util.timeStamper() + " CRequest.write: Start \n");
    }

    final DICOM_Object dcor = new DICOM_Object();

    // these are filled in the order of the Part 7 Section 9.1.x charts...
    dcor.setInt16(DICOM_RTC.DD_CommandField, COMMAND);
    dcor.setInt16(DICOM_RTC.DD_MessageID, MSG_ID);

    DICOM_Util.determineSOPClassUIDAndPush(classUID, null, ddo, dcor);

    if ((COMMAND == DICOM_Constants.COMMAND_CStoreRQ) && (ddo != null)) {

      dcor.setStr(DICOM_RTC.DD_AffectedSOPInstanceUID, instanceUID);
      // copy Affected SOP Instance UID
    } else if ((COMMAND == DICOM_Constants.COMMAND_CStoreRQ)) {
      final String s = ddo.getStr(DICOM_RTC.DD_SOPInstanceUID);

      if (s != null) {
        dcor.setStr(DICOM_RTC.DD_AffectedSOPInstanceUID, s);
      }
    }

    dcor.setInt16(
        DICOM_RTC.DD_Priority,
        DICOM_CRequest.MEDIUM); // See class definition for other priority codes

    if (ddo != null) {
      dcor.setInt16(DICOM_RTC.DD_DataSetType, DICOM_Constants.DSTYPE_DATAPRESENT);
    } else {
      dcor.setInt16(DICOM_RTC.DD_DataSetType, DICOM_Constants.DSTYPE_NODATAPRESENT);
    }

    if (COMMAND == DICOM_Constants.COMMAND_CMoveRQ) {

      if (AETitle == null) {
        throw new DICOM_Exception("AETitle = Null");
      }

      final byte[] serverAETitle = new byte[16];
      DICOM_Util.fillByteArray(serverAETitle, ' ');
      DICOM_Util.copyByteArray(serverAETitle, AETitle);

      dcor.setStr(
          DICOM_RTC.DD_MoveDestination,
          DICOM_CRequest.fixMoveDestString(new String(serverAETitle)));
    }

    if (Preferences.debugLevel(Preferences.DEBUG_COMMS)) {
      Preferences.debug(
          DICOM_Util.timeStamper() + " CRequest.write DCO: " + dcor.toString("Command") + "  \n");
    }

    pdu.write(dcor, classUID, (byte) 1); // 1 = Message command information

    if (ddo != null) {
      Preferences.debug(
          DICOM_Util.timeStamper() + " CRequest.write DDO: " + ddo.toString("Data") + "  \n");
      transferSyntax = pdu.getTransferSyntaxID();
      pdu.write(transferSyntax, ddo, classUID, (byte) 0);
    }
  }
  /** call algorithm */
  protected void callAlgorithm() {
    boolean performRegistration = performRegistrationCheckbox.isSelected();

    Preferences.debug("*** Beginning DTI Sorting Process *** \n", Preferences.DEBUG_ALGORITHM);
    if (outputTextArea != null) {
      outputTextArea.append("*** Beginning DTI Sorting Process *** \n");
    }
    // System.out.println("*** Beginning DTI Sorting Process *** \n");
    if (isDICOM) {
      if (performRegistration) {
        int cost = regOptions.getCost();
        int DOF = regOptions.getDOF();
        int interp = regOptions.getInterp();
        int interp2 = regOptions.getInterp2();
        float rotateBeginX = regOptions.getRotateBeginX();
        float rotateEndX = regOptions.getRotateEndX();
        float coarseRateX = regOptions.getCoarseRateX();
        float fineRateX = regOptions.getFineRateX();
        float rotateBeginY = regOptions.getRotateBeginY();
        float rotateEndY = regOptions.getRotateEndY();
        float coarseRateY = regOptions.getCoarseRateY();
        float fineRateY = regOptions.getFineRateY();
        float rotateBeginZ = regOptions.getRotateBeginZ();
        float rotateEndZ = regOptions.getRotateEndZ();
        float coarseRateZ = regOptions.getCoarseRateZ();
        float fineRateZ = regOptions.getFineRateZ();
        boolean maxOfMinResol = regOptions.isMaxOfMinResol();
        boolean doSubsample = regOptions.isDoSubsample();
        boolean doMultiThread = regOptions.isDoMultiThread();
        boolean fastMode = regOptions.isFastMode();
        int bracketBound = regOptions.getBracketBound();
        int maxIterations = regOptions.getMaxIterations();
        int numMinima = regOptions.getNumMinima();
        alg =
            new AlgorithmDTICreateListFile(
                studyPath,
                studyName,
                dicomB0VolumePath,
                gradientPath,
                bmatrixPath,
                outputTextArea,
                isInterleaved,
                performRegistration,
                cost,
                DOF,
                interp,
                interp2,
                rotateBeginX,
                rotateEndX,
                coarseRateX,
                fineRateX,
                rotateBeginY,
                rotateEndY,
                coarseRateY,
                fineRateY,
                rotateBeginZ,
                rotateEndZ,
                coarseRateZ,
                fineRateZ,
                maxOfMinResol,
                doSubsample,
                doMultiThread,
                fastMode,
                bracketBound,
                maxIterations,
                numMinima,
                dwiPathTextField);
      } else {
        alg =
            new AlgorithmDTICreateListFile(
                studyPath,
                studyName,
                gradientPath,
                bmatrixPath,
                outputTextArea,
                isInterleaved,
                performRegistration);
      }
    } else {
      if (performRegistration) {
        int cost = regOptions.getCost();
        int DOF = regOptions.getDOF();
        int interp = regOptions.getInterp();
        int interp2 = regOptions.getInterp2();
        int registerTo = regOptions.getRegisterTo();
        float rotateBegin = regOptions.getRotateBegin();
        float rotateEnd = regOptions.getRotateEnd();
        float coarseRate = regOptions.getCoarseRate();
        float fineRate = regOptions.getFineRate();
        boolean doSubsample = regOptions.isDoSubsample();
        boolean doMultiThread = regOptions.isDoMultiThread();
        boolean fastMode = regOptions.isFastMode();
        int bracketBound = regOptions.getBracketBound();
        int maxIterations = regOptions.getMaxIterations();
        int numMinima = regOptions.getNumMinima();

        alg =
            new AlgorithmDTICreateListFile(
                prFileName,
                prFileDir,
                gradientPath,
                bmatrixPath,
                outputTextArea,
                performRegistration,
                cost,
                DOF,
                interp,
                interp2,
                registerTo,
                rotateBegin,
                rotateEnd,
                coarseRate,
                fineRate,
                doSubsample,
                doMultiThread,
                fastMode,
                bracketBound,
                maxIterations,
                numMinima,
                dwiPathTextField);
      } else {
        alg =
            new AlgorithmDTICreateListFile(
                prFileName,
                prFileDir,
                gradientPath,
                bmatrixPath,
                outputTextArea,
                performRegistration);
      }
    }
    alg.addListener(this);

    if (isRunInSeparateThread()) {

      // Start the thread as a low priority because we wish to still
      // have user interface work fast.
      if (alg.startMethod(Thread.MIN_PRIORITY) == false) {
        MipavUtil.displayError("A thread is already running on this object");
      }
    } else {
      alg.run();
    }
  }
Example #18
0
  /**
   * Reads a DIMSE-C message.
   *
   * @param pdu the context pdu
   * @param dco the incoming DICOM message
   * @param ddo store the incoming DICOM data object in this object
   * @exception DICOM_Exception DOCUMENT ME!
   */
  public void read(final DICOM_PDUService pdu, final DICOM_Object dco, final DICOM_Object ddo)
      throws DICOM_Exception {

    if (Preferences.debugLevel(Preferences.DEBUG_COMMS)) {
      Preferences.debug(DICOM_Util.timeStamper() + " CRequest.read: \n");
    }

    if (dco == null) {

      if (Preferences.debugLevel(Preferences.DEBUG_COMMS)) {
        Preferences.debug(DICOM_Util.timeStamper() + " CRequest.read: DCO is null \n");
      }

      throw new DICOM_Exception("DCO is null");
    }

    final int command = dco.getInt16(DICOM_RTC.DD_CommandField);

    if (command != COMMAND) {
      throw new DICOM_Exception(
          " DIMSE-C Request error : "
              + DICOM_Util.toHexString((short) command)
              + " looking for "
              + DICOM_Util.toHexString(COMMAND));
    }

    final int dataSetType = dco.getInt16(DICOM_RTC.DD_DataSetType);

    if (dataSetType != DICOM_Constants.DSTYPE_NODATAPRESENT) {

      if (ddo == null) {
        throw new DICOM_Exception("DICOM data object is null");
      }

      if (pdu == null) {
        throw new DICOM_Exception("PDU is null");
      }

      pdu.readInObject(ddo);
    } else {

      if (ddo != null) {
        ddo.clear();
      } // Information is not present
    }

    final int status = dco.getInt16(DICOM_RTC.DD_Status);

    if ((status >= DICOM_Constants.STATUS_ERRORFIRST)
        && (status <= DICOM_Constants.STATUS_ERRORLAST)) {
      String str1, str2;

      str1 =
          "Status in error "
              + DICOM_Util.toHexString((short) COMMAND)
              + " ["
              + DICOM_Util.toHexString((short) status)
              + "] ";
      str2 = dco.getStr(DICOM_RTC.DD_ErrorComment);

      if (str2 != null) {
        str1 = str1 + str2;
      }

      throw new DICOM_Exception(str1);
    }
  }