@Override public void putImage(TaggedImage taggedImage) throws MMException { if (!newDataSet_) { throw new MMException("This ImageFileManager is read-only."); } int fileSetIndex = 0; if (splitByXYPosition_) { try { fileSetIndex = MDUtils.getPositionIndex(taggedImage.tags); } catch (JSONException ex) { ReportingUtils.logError(ex); } } String label = MDUtils.getLabel(taggedImage.tags); if (fileSets_ == null) { try { fileSets_ = new HashMap<Integer, FileSet>(); createDirectory(directory_); } catch (Exception ex) { ReportingUtils.logError(ex); } } if (omeTiff_) { if (omeMetadata_ == null) { omeMetadata_ = new OMEMetadata(this); } } if (fileSets_.get(fileSetIndex) == null) { fileSets_.put(fileSetIndex, new FileSet(taggedImage.tags, this)); } FileSet set = fileSets_.get(fileSetIndex); try { set.writeImage(taggedImage); } catch (IOException ex) { ReportingUtils.showError("problem writing image to file"); } tiffReadersByLabel_.put(label, set.getCurrentReader()); int frame; try { frame = MDUtils.getFrameIndex(taggedImage.tags); } catch (JSONException ex) { frame = 0; } lastFrameOpenedDataSet_ = Math.max(frame, lastFrameOpenedDataSet_); cached_.add(taggedImage, label); }
@Override public TaggedImage getImage(int channelIndex, int sliceIndex, int frameIndex, int positionIndex) { String label = MDUtils.generateLabel(channelIndex, sliceIndex, frameIndex, positionIndex); TaggedImage img = cached_.get(label); if (img != null) { return img; } if (!tiffReadersByLabel_.containsKey(label)) { return null; } return tiffReadersByLabel_.get(label).readImage(label); }
// <editor-fold defaultstate="collapsed" desc=" Metadata "> // private void processSummaryMD() { // TODO displayAndComments_ = // VirtualAcquisitionDisplay.getDisplaySettingsFromSummary(summaryMetadata_); try { numPositions_ = MDUtils.getNumPositions(summaryMetadata_); if (numPositions_ <= 0) { numPositions_ = 1; } } catch (JSONException ex) { ReportingUtils.logError(ex); numPositions_ = 1; } try { // Estimate of max number of image planes numChannels_ = MDUtils.getNumChannels(summaryMetadata_); numSlices_ = MDUtils.getNumSlices(summaryMetadata_); totalNumImagePlanes_ = numChannels_ * MDUtils.getNumFrames(summaryMetadata_) * numPositions_ * numSlices_; } catch (Exception ex) { ReportingUtils.logError("Error estimating total number of image planes"); totalNumImagePlanes_ = 1; } }
private void openExistingDataSet() throws IOException { // Need to throw error if file not found MultipageTiffReader reader = null; File dir = new File(directory_); for (File f : dir.listFiles()) { if (f.getName().endsWith(".tif") || f.getName().endsWith(".TIF")) { reader = new MultipageTiffReader(f); Set<String> labels = reader.getIndexKeys(); for (String label : labels) { tiffReadersByLabel_.put(label, reader); int frameIndex = Integer.parseInt(label.split("_")[2]); lastFrameOpenedDataSet_ = Math.max(frameIndex, lastFrameOpenedDataSet_); } } } try { setSummaryMetadata(reader.getSummaryMetadata()); numPositions_ = MDUtils.getNumPositions(summaryMetadata_); displayAndComments_ = reader.getDisplayAndComments(); } catch (JSONException ex) { ReportingUtils.logError(ex); } }