Ejemplo n.º 1
0
  /**
   * Constructs a special JComboBox with all cameras that have only 1 channel
   *
   * @param deviceName
   * @return
   */
  public JComboBox makeSingleCameraDeviceBox(Devices.Keys deviceName, int maximumWidth) {
    List<String> singleCameras = new ArrayList<String>();
    singleCameras.add(0, "");
    String originalCamera = core_.getCameraDevice();
    try {
      StrVector strvDevices = core_.getLoadedDevicesOfType(mmcorej.DeviceType.CameraDevice);
      for (int i = 0; i < strvDevices.size(); i++) {
        String test = strvDevices.get(i);
        core_.setCameraDevice(test);
        if (core_.getNumberOfCameraChannels() == 1) {
          singleCameras.add(test);
        }
      }
    } catch (Exception ex) {
      MyDialogUtils.showError("Error detecting single camera devices");
    } finally {
      try {
        core_.setCameraDevice(originalCamera);
      } catch (Exception e) {
        MyDialogUtils.showError(e);
      }
    }

    JComboBox deviceBox = new JComboBox(singleCameras.toArray());
    deviceBox.addActionListener(new DeviceBoxListener(deviceName, deviceBox));
    deviceBox.setSelectedItem(
        devices_.getMMDevice(deviceName)); // selects whatever device was read in by prefs
    deviceBox.setMaximumSize(new Dimension(maximumWidth, 30));
    return deviceBox;
  }
Ejemplo n.º 2
0
 /**
  * Sets the current position to be the origin.
  *
  * @param devKey
  * @param dir
  * @param pos
  */
 public void setOrigin(Devices.Keys devKey, Joystick.Directions dir) {
   try {
     String mmDevice = devices_.getMMDeviceException(devKey);
     switch (dir) {
       case X:
         if (devices_.isXYStage(devKey)) {
           double ypos = getUpdatedPosition(devKey, Joystick.Directions.Y);
           core_.setAdapterOriginXY(
               mmDevice, 0.0, ypos); // so serial com, since adapter keeps own origin
         }
         break;
       case Y:
         if (devices_.isXYStage(devKey)) {
           double xpos = getUpdatedPosition(devKey, Joystick.Directions.X);
           core_.setAdapterOriginXY(
               mmDevice, xpos, 0.0); // so serial com, since adapter keeps own origin
         }
         break;
       case NONE:
       default:
         if (devices_.is1DStage(devKey)) {
           core_.setOrigin(mmDevice);
         }
         break;
     }
   } catch (Exception ex) {
     MyDialogUtils.showError(ex);
   }
 }
Ejemplo n.º 3
0
  /**
   * Constructs a special JComboBox with all cameras that have more than 1 channel, which we expect
   * to just be a single Multicamera device
   *
   * @param deviceName
   * @return
   */
  public JComboBox makeMultiCameraDeviceBox(Devices.Keys deviceName, int maximumWidth) {
    List<String> multiCameras = new ArrayList<String>();
    multiCameras.add(0, "");
    try {
      StrVector strvDevices = core_.getLoadedDevicesOfType(mmcorej.DeviceType.CameraDevice);
      for (int i = 0; i < strvDevices.size(); i++) {
        // find all Multi-camera devices (usually just one)
        String test = strvDevices.get(i);
        if (core_.getDeviceLibrary(test).equals(Devices.Libraries.UTILITIES.toString())
            && core_
                .getDeviceDescription(test)
                .equals("Combine multiple physical cameras into a single logical camera")) {
          multiCameras.add(strvDevices.get(i));
        }
      }
    } catch (Exception ex) {
      MyDialogUtils.showError("Error detecting multi camera devices");
    }

    JComboBox deviceBox = new JComboBox(multiCameras.toArray());
    deviceBox.addActionListener(new DeviceBoxListener(deviceName, deviceBox));
    // if we have one and only one multi-camera then set box to it
    if (multiCameras.size() == 2) { // recall we added empty string as the first entry
      deviceBox.setSelectedIndex(1);
    } else {
      deviceBox.setSelectedItem(
          devices_.getMMDevice(deviceName)); // selects whatever device was read in by prefs
    }
    deviceBox.setMaximumSize(new Dimension(maximumWidth, 30));
    return deviceBox;
  }
Ejemplo n.º 4
0
 /**
  * Returns the current position of the specified stage, or 0 if the stage wasn't found. Updates
  * the cache with the value as well.
  *
  * @param devKey
  * @param dir
  * @return
  */
 public double getUpdatedPosition(Devices.Keys devKey, Joystick.Directions dir) {
   String mmDevice = devices_.getMMDevice(devKey);
   if (mmDevice == null) {
     return 0;
   }
   try {
     if (devices_.is1DStage(devKey)) {
       double pt = core_.getPosition(mmDevice);
       oneAxisDrivePositions_.put(devKey, pt);
       return pt;
     }
     Point2D.Double pt;
     if (devices_.isXYStage(devKey)) {
       pt = core_.getXYStagePosition(mmDevice);
     } else if (devices_.isGalvo(devKey)) {
       pt = core_.getGalvoPosition(mmDevice);
     } else {
       pt = new Point2D.Double();
     }
     twoAxisDrivePositions_.put(devKey, pt);
     if (dir == Joystick.Directions.X) {
       return pt.x;
     } else if (dir == Joystick.Directions.Y) {
       return pt.y;
     }
   } catch (Exception ex) {
     MyDialogUtils.showError(ex);
   }
   return 0;
 }
Ejemplo n.º 5
0
 public void enableContinuousFocus(boolean enable) throws MMException {
   try {
     core_.setAutoFocusDevice(devName_);
     core_.enableContinuousFocus(enable);
   } catch (Exception e) {
     throw new MMException(e.getMessage());
   }
 }
Ejemplo n.º 6
0
 public boolean isContinuousFocusLocked() throws MMException {
   try {
     core_.setAutoFocusDevice(devName_);
     return core_.isContinuousFocusLocked();
   } catch (Exception e) {
     throw new MMException(e.getMessage());
   }
 }
Ejemplo n.º 7
0
 public double getCurrentFocusScore() {
   try {
     core_.setAutoFocusDevice(devName_);
   } catch (Exception e) {
     ReportingUtils.logError(e);
     return 0;
   }
   return core_.getCurrentFocusScore();
 }
  public void readFromCore(CMMCore core, String deviceName, String propertyName, boolean cached) {
    device = deviceName;
    name = propertyName;
    try {
      readOnly = core.isPropertyReadOnly(deviceName, propertyName);
      preInit = core.isPropertyPreInit(deviceName, propertyName);
      hasRange = core.hasPropertyLimits(deviceName, propertyName);
      lowerLimit = core.getPropertyLowerLimit(deviceName, propertyName);
      upperLimit = core.getPropertyUpperLimit(deviceName, propertyName);
      type = core.getPropertyType(deviceName, propertyName);
      StrVector values = core.getAllowedPropertyValues(deviceName, propertyName);
      allowed = new String[(int) values.size()];
      for (int k = 0; k < values.size(); k++) {
        allowed[k] = values.get(k);
      }

      sort();

      String coreVal;
      if (cached) coreVal = core.getPropertyFromCache(deviceName, propertyName);
      else coreVal = core.getProperty(deviceName, propertyName);
      setValueFromCoreString(coreVal);
    } catch (Exception e) {
      ReportingUtils.logError(e);
    }
  }
Ejemplo n.º 9
0
 public String[] getPropertyNames() {
   Vector<String> propNames = new Vector<String>();
   try {
     core_.setAutoFocusDevice(devName_);
     StrVector propNamesVect = core_.getDevicePropertyNames(devName_);
     for (int i = 0; i < propNamesVect.size(); i++)
       if (!core_.isPropertyReadOnly(devName_, propNamesVect.get(i))
           && !core_.isPropertyPreInit(devName_, propNamesVect.get(i)))
         propNames.add(propNamesVect.get(i));
   } catch (Exception e) {
     ReportingUtils.logError(e);
   }
   return (String[]) propNames.toArray();
 }
Ejemplo n.º 10
0
 /**
  * Sets the position of specified stage to the specified value using appropriate core calls
  *
  * @param devKey
  * @param dir
  * @param pos new position of the stage
  * @param ignoreErrors true will return without any errors (or any action) if device is missing
  */
 public boolean setPosition(
     Devices.Keys devKey, Joystick.Directions dir, double pos, boolean ignoreErrors) {
   try {
     if (ignoreErrors && !devices_.isValidMMDevice(devKey)) {
       return false;
     }
     String mmDevice = devices_.getMMDeviceException(devKey);
     if (devices_.is1DStage(devKey)) {
       core_.setPosition(mmDevice, pos);
     } else if (devices_.isXYStage(devKey)) {
       if (dir == Joystick.Directions.X) {
         // would prefer setXPosition but it doesn't exist so we stop any Y motion
         double ypos = core_.getYPosition(mmDevice);
         core_.setXYPosition(mmDevice, pos, ypos);
       } else if (dir == Joystick.Directions.Y) {
         double xpos = core_.getXPosition(mmDevice);
         // would prefer setYPosition but it doesn't exist so we stop any X motion
         core_.setXYPosition(mmDevice, xpos, pos);
       }
     } else if (devices_.isGalvo(devKey)) {
       Point2D.Double pos2D = core_.getGalvoPosition(mmDevice);
       if (dir == Joystick.Directions.X) {
         core_.setGalvoPosition(mmDevice, pos, pos2D.y);
       } else if (dir == Joystick.Directions.Y) {
         core_.setGalvoPosition(mmDevice, pos2D.x, pos);
       }
     }
     return true;
   } catch (Exception ex) {
     MyDialogUtils.showError(ex);
     return false;
   }
 }
Ejemplo n.º 11
0
  public PropertyItem[] getProperties() {
    StrVector propNamesVect;
    Vector<PropertyItem> props = new Vector<PropertyItem>();
    try {
      core_.setAutoFocusDevice(devName_);
      propNamesVect = core_.getDevicePropertyNames(devName_);
      for (int i = 0; i < propNamesVect.size(); i++) {
        PropertyItem p = new PropertyItem();
        p.device = devName_;
        p.name = propNamesVect.get(i);
        p.value = core_.getProperty(devName_, p.name);
        p.readOnly = core_.isPropertyReadOnly(devName_, p.name);
        if (core_.hasPropertyLimits(devName_, p.name)) {
          p.lowerLimit = core_.getPropertyLowerLimit(devName_, p.name);
          p.upperLimit = core_.getPropertyUpperLimit(devName_, p.name);
        }

        StrVector vals = core_.getAllowedPropertyValues(devName_, p.name);
        p.allowed = new String[(int) vals.size()];
        for (int j = 0; j < vals.size(); j++) p.allowed[j] = vals.get(j);

        props.add(p);
      }
    } catch (Exception e) {
      ReportingUtils.logError(e);
    }

    return props.toArray(new PropertyItem[0]);
  }
Ejemplo n.º 12
0
  protected void initializeFlags() {
    flags_ = new ShowFlags();

    if (showFlagsPanelVisible) {
      flags_.load(getPrefsNode());
      Configuration cfg;
      try {
        if (presetName_.length() == 0) cfg = new Configuration();
        else cfg = core_.getConfigState(groupName_, presetName_);
        showFlagsPanel_ = new ShowFlagsPanel(data_, flags_, core_, cfg);
      } catch (Exception e) {
        ReportingUtils.showError(e);
      }
      getContentPane().add(showFlagsPanel_);
      springLayout_.putConstraint(
          SpringLayout.EAST, showFlagsPanel_, 440, SpringLayout.WEST, getContentPane());
      springLayout_.putConstraint(
          SpringLayout.WEST, showFlagsPanel_, 290, SpringLayout.WEST, getContentPane());
      springLayout_.putConstraint(
          SpringLayout.SOUTH, showFlagsPanel_, 135, SpringLayout.NORTH, getContentPane());
      springLayout_.putConstraint(
          SpringLayout.NORTH, showFlagsPanel_, 5, SpringLayout.NORTH, getContentPane());
    }

    data_.setFlags(flags_);
  }
Ejemplo n.º 13
0
 public void setProperty(PropertyItem p) throws MMException {
   try {
     core_.setProperty(devName_, p.name, p.value);
   } catch (Exception e) {
     throw new MMException(e.getMessage());
   }
 }
Ejemplo n.º 14
0
 public void setPropertyValue(String name, String value) throws MMException {
   try {
     core_.setProperty(devName_, name, value);
   } catch (Exception e) {
     throw new MMException(e.getMessage());
   }
 }
Ejemplo n.º 15
0
 public String getPropertyValue(String name) throws MMException {
   try {
     return core_.getProperty(devName_, name);
   } catch (Exception e) {
     throw new MMException(e.getMessage());
   }
 }
Ejemplo n.º 16
0
  public double incrementalFocus() throws MMException {
    if (core_ == null) return 0.0;

    try {
      core_.setAutoFocusDevice(devName_);
      core_.incrementalFocus();
    } catch (Exception e) {
      throw new MMException(e.getMessage());
    }

    try {
      return core_.getLastFocusScore();
    } catch (Exception e) {
      ReportingUtils.logError(e);
      return 0.0;
    }
  }
Ejemplo n.º 17
0
 // Set ImageJ pixel calibration
 public void setIJCal() {
   double pixSizeUm = core_.getPixelSizeUm();
   Calibration cal = new Calibration();
   if (pixSizeUm > 0) {
     cal.setUnit("um");
     cal.pixelWidth = pixSizeUm;
     cal.pixelHeight = pixSizeUm;
   }
   getImagePlus().setCalibration(cal);
 }
Ejemplo n.º 18
0
 private static Image5D createImage5D(CMMCore core, String wndTitle) throws Exception {
   core_ = core;
   ImageProcessor ip;
   int type = 0;
   int width_ = (int) core_.getImageWidth();
   int height_ = (int) core_.getImageHeight();
   long byteDepth = core_.getBytesPerPixel();
   long channels = core_.getNumberOfChannels();
   if (byteDepth == 1 && channels == 1) {
     type = ImagePlus.GRAY8;
     ip = new ByteProcessor(width_, height_);
     if (contrastSettings8_.getRange() == 0.0) ip.setMinAndMax(0, 255);
     else ip.setMinAndMax(contrastSettings8_.min, contrastSettings8_.max);
   } else if (byteDepth == 2 && channels == 1) {
     type = ImagePlus.GRAY16;
     ip = new ShortProcessor(width_, height_);
     if (contrastSettings16_.getRange() == 0.0) ip.setMinAndMax(0, 65535);
     else ip.setMinAndMax(contrastSettings16_.min, contrastSettings16_.max);
   } else if (byteDepth == 0) {
     throw (new Exception(logError("Imaging device not initialized")));
   } else if (byteDepth == 1 && channels == 4) {
     // assuming RGB32 format
     ip = new ColorProcessor(width_, height_);
     if (contrastSettings8_.getRange() == 0.0) ip.setMinAndMax(0, 255);
     else ip.setMinAndMax(contrastSettings8_.min, contrastSettings8_.max);
   } else {
     String message =
         "Unsupported pixel depth: "
             + core_.getBytesPerPixel()
             + " byte(s) and "
             + channels
             + " channel(s).";
     throw (new Exception(logError(message)));
   }
   ip.setColor(Color.black);
   if (currentColorModel_ != null) ip.setColorModel(currentColorModel_);
   ip.fill();
   Image5D img5d = new Image5D(wndTitle, type, width_, height_, 1, 1, 1, false);
   @SuppressWarnings("unused")
   Image5DWindow i5dw = new Image5DWindow(img5d);
   return img5d;
 }
Ejemplo n.º 19
0
 private void refreshTwoAxisStagePositions() {
   for (Devices.Keys devKey : Devices.STAGES2D) {
     String mmDevice = devices_.getMMDevice(devKey);
     if (mmDevice == null) { // skip devices not set in devices tab
       twoAxisDrivePositions_.put(devKey, null);
       continue;
     }
     Point2D.Double pt;
     try {
       if (devices_.isXYStage(devKey)) {
         pt = core_.getXYStagePosition(mmDevice);
       } else if (devices_.isGalvo(devKey)) {
         pt = core_.getGalvoPosition(mmDevice);
       } else {
         pt = new Point2D.Double();
       }
       twoAxisDrivePositions_.put(devKey, pt);
     } catch (Exception ex) {
       ReportingUtils.logMessage("Problem getting position of " + mmDevice);
     }
   }
 }
Ejemplo n.º 20
0
 private void refreshOneAxisStagePositions() {
   for (Devices.Keys devKey : Devices.STAGES1D) {
     String mmDevice = devices_.getMMDevice(devKey);
     if (mmDevice == null) { // skip devices not set in devices tab
       oneAxisDrivePositions_.put(devKey, null);
       continue;
     }
     try {
       if (devices_.is1DStage(devKey)) {
         double pt = core_.getPosition(mmDevice);
         oneAxisDrivePositions_.put(devKey, pt);
       }
     } catch (Exception ex) {
       ReportingUtils.logMessage("Problem getting position of " + mmDevice);
     }
   }
 }
Ejemplo n.º 21
0
 /**
  * Constructs a JComboBox populated with devices of specified Micro-Manager type Attaches a
  * listener and sets selected item to what is specified in the Devices class.
  *
  * @param deviceType - Micro-Manager device type (mmcorej.DeviceType)
  * @param deviceKey - ASi diSPIM device key (see Devices class)
  * @param maximumWidth -
  * @return final JComboBox
  */
 public JComboBox makeDeviceSelectionBox(
     mmcorej.DeviceType deviceType, Devices.Keys deviceKey, int maximumWidth) {
   // when editing this method do the same to the one with array argument too
   JComboBox deviceBox = new JComboBox();
   ArrayList<String> devices = new ArrayList<String>();
   StrVector strvDevices = core_.getLoadedDevicesOfType(deviceType);
   devices.addAll(Arrays.asList(strvDevices.toArray()));
   devices.add(0, "");
   deviceBox.removeAllItems();
   for (String device : devices) {
     deviceBox.addItem(device);
   }
   deviceBox.addActionListener(new DeviceBoxListener(deviceKey, deviceBox));
   deviceBox.setSelectedItem(
       devices_.getMMDevice(deviceKey)); // selects whatever device was read in by prefs
   deviceBox.setMaximumSize(new Dimension(maximumWidth, 30));
   return deviceBox;
 }
Ejemplo n.º 22
0
  public PropertyItem getProperty(String name) throws MMException {
    try {
      if (core_.hasProperty(devName_, name)) {
        PropertyItem p = new PropertyItem();
        p.device = devName_;
        p.name = name;
        p.value = core_.getProperty(devName_, p.name);
        p.readOnly = core_.isPropertyReadOnly(devName_, p.name);
        if (core_.hasPropertyLimits(devName_, p.name)) {
          p.lowerLimit = core_.getPropertyLowerLimit(devName_, p.name);
          p.upperLimit = core_.getPropertyUpperLimit(devName_, p.name);
        }

        StrVector vals = core_.getAllowedPropertyValues(devName_, p.name);
        p.allowed = new String[(int) vals.size()];
        for (int j = 0; j < vals.size(); j++) p.allowed[j] = vals.get(j);
        return p;
      } else {
        throw new MMException("Unknown property: " + name);
      }
    } catch (Exception e) {
      throw new MMException(e.getMessage());
    }
  }
Ejemplo n.º 23
0
 /**
  * Sets the relative position of specified stage to the specified value using appropriate core
  * calls
  *
  * @param devKey
  * @param dir
  * @param pos new position of the stage
  */
 public void setPositionRelative(Devices.Keys devKey, Joystick.Directions dir, double delta) {
   try {
     String mmDevice = devices_.getMMDeviceException(devKey);
     if (devices_.is1DStage(devKey)) {
       core_.setRelativePosition(mmDevice, delta);
     } else if (devices_.isXYStage(devKey)) {
       if (dir == Joystick.Directions.X) {
         core_.setRelativeXYPosition(mmDevice, delta, 0);
       } else if (dir == Joystick.Directions.Y) {
         core_.setRelativeXYPosition(mmDevice, 0, delta);
       }
     } else if (devices_.isGalvo(devKey)) {
       Point2D.Double pos2D = core_.getGalvoPosition(mmDevice);
       if (dir == Joystick.Directions.X) {
         core_.setGalvoPosition(mmDevice, pos2D.x + delta, pos2D.y);
       } else if (dir == Joystick.Directions.Y) {
         core_.setGalvoPosition(mmDevice, pos2D.x, pos2D.y + delta);
       }
     }
   } catch (Exception ex) {
     MyDialogUtils.showError(ex);
   }
 }
Ejemplo n.º 24
0
 public int getNumberOfImages() {
   return core_.getRemainingImageCount();
 }
Ejemplo n.º 25
0
 public void setApp(ScriptInterface app) {
   core_ = app.getMMCore();
   devName_ = core_.getAutoFocusDevice();
 }