예제 #1
0
 private void readIndexMap() throws IOException {
   MappedByteBuffer mapOffset = makeReadOnlyBuffer(8, 8);
   if (mapOffset.getInt() != MultipageTiffWriter.INDEX_MAP_OFFSET_HEADER) {
     ReportingUtils.logError("Image map offset header incorrect");
     indexMap_ = null;
     return;
   }
   long offset = unsignInt(mapOffset.getInt());
   MappedByteBuffer mapHeader = makeReadOnlyBuffer(offset, 8);
   int headerCode = mapHeader.getInt();
   if (headerCode != MultipageTiffWriter.INDEX_MAP_HEADER) {
     ReportingUtils.logError("Image index map header incorrect");
     indexMap_ = null;
     return;
   }
   int numMappings = mapHeader.getInt();
   MappedByteBuffer mapData = makeReadOnlyBuffer(offset + 8, 24 * numMappings);
   for (int i = 0; i < numMappings; i++) {
     int channel = mapData.getInt();
     int slice = mapData.getInt();
     int frame = mapData.getInt();
     int position = mapData.getInt();
     long imageOffset = mapData.getLong();
     indexMap_.put(MDUtils.generateLabel(channel, slice, frame, position), imageOffset);
   }
 }
  public DisplayPlus(
      final ImageCache stitchedCache,
      AcquisitionEngine eng,
      JSONObject summaryMD,
      boolean invX,
      boolean invY,
      boolean swapXY) {
    eng_ = eng;
    invertX_ = invX;
    invertY_ = invY;
    swapXY_ = swapXY;
    try {
      MultiStagePosition pos0 = MMStudioMainFrame.getInstance().getPositionList().getPosition(0);
      pos0x_ = pos0.getX();
      pos0y_ = pos0.getY();
      tileWidth_ = MDUtils.getHeight(summaryMD);
      tileHeight_ = MDUtils.getWidth(summaryMD);
    } catch (Exception e) {
      ReportingUtils.showError("Couldnt get grid info");
    }
    vad_ =
        new VirtualAcquisitionDisplay(stitchedCache, eng, WINDOW_TITLE) {
          public void showImage(final JSONObject tags, boolean waitForDisplay)
              throws InterruptedException, InvocationTargetException {
            // Since this is multichannel camera, only show when last channel arrives
            try {
              if (MDUtils.getChannelIndex(tags) == super.getNumChannels() - 1) {
                super.showImage(tags, waitForDisplay);
              } else {
                ImagePlus ip = super.getHyperImage();
                if (ip != null) {
                  // canvas never gets painted so need to set painpending false
                  ip.getCanvas().setPaintPending(false);
                }
              }
            } catch (JSONException ex) {
            }
          }
        };
    DisplayControls controls = new Controls();

    // Add in custom controls
    try {
      JavaUtils.setRestrictedFieldValue(
          vad_, VirtualAcquisitionDisplay.class, "controls_", controls);
    } catch (NoSuchFieldException ex) {
      ReportingUtils.showError("Couldn't create display controls");
    }
    vad_.show();
    // Zoom to 100%
    vad_.getImagePlus().getWindow().getCanvas().unzoom();

    // add mouse listeners for moving grids
    addMouseListeners();

    stitchedCache.addImageCacheListener(this);
  }
예제 #3
0
 public JSONObject readSummaryMD() throws IOException {
   MappedByteBuffer mdInfo = makeReadOnlyBuffer(16, 8);
   if (mdInfo.getInt() != MultipageTiffWriter.SUMMARY_MD_HEADER) {
     ReportingUtils.logError("Summary Metadata Header Incorrect");
     return null;
   }
   long length = unsignInt(mdInfo.getInt());
   try {
     return readJSONObject(24, length);
   } catch (JSONException ex) {
     ReportingUtils.showError("Error reading summary metadata");
     return null;
   }
 }
    @Override
    public void newImageUpdate(JSONObject tags) {
      if (tags == null) {
        return;
      }
      updateLabels(tags);
      try {
        if (vad_.acquisitionIsRunning() && vad_.getNextWakeTime() > 0) {
          final long nextImageTime = vad_.getNextWakeTime();
          if (System.nanoTime() / 1000000 < nextImageTime) {
            final java.util.Timer timer = new java.util.Timer("Next frame display");
            TimerTask task =
                new TimerTask() {

                  public void run() {
                    double timeRemainingS = (nextImageTime - System.nanoTime() / 1000000) / 1000;
                    if (timeRemainingS > 0 && vad_.acquisitionIsRunning()) {
                      setStatusLabel(
                          "Next frame: "
                              + NumberUtils.doubleToDisplayString(1 + timeRemainingS)
                              + " s");
                    } else {
                      timer.cancel();
                      setStatusLabel("");
                    }
                  }
                };
            timer.schedule(task, 2000, 100);
          }
        }

      } catch (Exception ex) {
        ReportingUtils.logError(ex);
      }
    }
    private void updateLabels(JSONObject tags) {
      // Z position label
      String zPosition = "";
      try {
        zPosition = NumberUtils.doubleStringCoreToDisplay(tags.getString("ZPositionUm"));
      } catch (Exception e) {
        try {
          zPosition = NumberUtils.doubleStringCoreToDisplay(tags.getString("Z-um"));
        } catch (Exception e1) {
          // Do nothing...
        }
      }
      zPosLabel_.setText("Z Position: " + zPosition + " um        ");

      // time label
      try {
        int ms = (int) tags.getDouble("ElapsedTime-ms");
        int s = ms / 1000;
        int min = s / 60;
        int h = min / 60;

        String time =
            twoDigitFormat(h)
                + ":"
                + twoDigitFormat(min % 60)
                + ":"
                + twoDigitFormat(s % 60)
                + "."
                + threeDigitFormat(ms % 1000);
        timeStampLabel_.setText("Elapsed time: " + time + "      ");
      } catch (JSONException ex) {
        ReportingUtils.logError("MetaData did not contain ElapsedTime-ms field");
      }
    }
예제 #6
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_);
  }
예제 #7
0
 private JSONObject readMMMetadata(IFDData data) throws IOException {
   try {
     return readJSONObject(data.mdOffset, data.mdLength);
   } catch (JSONException ex) {
     ReportingUtils.showError("Error reading image metadata");
     return new JSONObject();
   }
 }
예제 #8
0
 @Override
 public void setValueAt(Object value, int row, int col) {
   if (col == 1) {
     try {
       labels_[row] = (String) value;
       curDevice_.setSetupLabel(row, (String) value);
       fireTableCellUpdated(row, col);
     } catch (Exception e) {
       ReportingUtils.showError(e);
     }
   }
 }
  @Override
  public void imageReceived(TaggedImage taggedImage) {
    try {
      // duplicate so image storage doesnt see incorrect tags
      JSONObject newTags = new JSONObject(taggedImage.tags.toString());
      MDUtils.setPositionIndex(newTags, 0);
      taggedImage = new TaggedImage(taggedImage.pix, newTags);
    } catch (JSONException ex) {
      ReportingUtils.showError("Couldn't manipulate image tags for display");
    }

    vad_.imageReceived(taggedImage);
  }
예제 #10
0
 public void readFromHardware() {
   LabelTableModel labelTableModel = (LabelTableModel) labelTable_.getModel();
   Device selectedDevice = labelTableModel.getCurrentDevice();
   if (selectedDevice != null) {
     try {
       selectedDevice.getSetupLabelsFromHardware(core_);
       labelTableModel.setData(model_, selectedDevice.getName());
       labelTableModel.fireTableStructureChanged();
     } catch (Exception e) {
       ReportingUtils.logError(e);
     }
   }
 }
 public void start() {
   for (DataProcessor<E> processor : processors_) {
     if (!processor.isAlive()) {
       if (processor.isStarted()) {
         ReportingUtils.showError(
             "Processor: "
                 + processor.getName()
                 + " is no longer running. Remove and re-insert to get it to go again");
       } else {
         processor.start();
       }
     }
   }
 }
예제 #12
0
  public boolean enterPage(boolean next) {
    DevTableModel tm = (DevTableModel) devTable_.getModel();
    tm.setData(model_);
    try {
      try {
        model_.loadStateLabelsFromHardware(core_);
      } catch (Throwable t) {
        ReportingUtils.logError(t);
      }

      // default the selection to the first row
      if (devTable_.getSelectedRowCount() < 1) {
        TableModel m2 = devTable_.getModel();
        if (0 < m2.getRowCount()) devTable_.setRowSelectionInterval(0, 0);
      }

    } catch (Exception e) {
      ReportingUtils.showError(e);
      return false;
    }

    resetLabels();
    return true;
  }
예제 #13
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);
     }
   }
 }
예제 #14
0
  public TaggedImage readImage(String label) {
    if (indexMap_.containsKey(label)) {
      try {
        long byteOffset = indexMap_.get(label);
        IFDData data = readIFD(byteOffset);
        Object pixels = readPixels(data);
        JSONObject md = readMMMetadata(data);
        return new TaggedImage(pixels, md);
      } catch (IOException ex) {
        ReportingUtils.logError(ex);
        return null;
      }

    } else {
      // label not in map--maybe parse whole file?
      return null;
    }
  }
예제 #15
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);
     }
   }
 }
예제 #16
0
 protected void handleException(Exception e) {
   ReportingUtils.showError(e);
 }