Skip to content

Commit

Permalink
Replace constructSliceLabel with FormatTools
Browse files Browse the repository at this point in the history
  • Loading branch information
dgault committed Aug 3, 2017
1 parent e618ace commit ffd7629
Showing 1 changed file with 2 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,7 @@ private ImageStack createVirtualStack(ImportProcess process, int s,
final BFVirtualStack virtualStack = new BFVirtualStack(options.getId(),
reader, false, false, false);
for (int i=0; i<imageCount; i++) {
final String label = constructSliceLabel(i,
reader, meta, s, zCount, cCount, tCount);
String label = FormatTools.getFilename(s, i, reader, LociPrefs.getSliceLabelPattern(), false);
virtualStack.addSlice(label);
}

Expand Down Expand Up @@ -387,8 +386,7 @@ private ImageStack readPlanes(ImportProcess process, int s, List<LUT> luts,
throw new FormatException("Cannot read plane #" + i);
}
// generate a label for ith plane
final String label = constructSliceLabel(i,
reader, meta, s, zCount, cCount, tCount);
String label = FormatTools.getFilename(s, i, reader, LociPrefs.getSliceLabelPattern(), false);

for (ImageProcessor ip : p) {
procs.add(ip);
Expand Down Expand Up @@ -574,78 +572,6 @@ private String constructImageTitle(IFormatReader r,
return title;
}

private String constructSliceLabel(int ndx, IFormatReader r,
IMetadata meta, int series, int zCount, int cCount, int tCount)
{
r.setSeries(series);

String sliceLabelPattern = LociPrefs.getSliceLabelPattern();

MetadataStore store = r.getMetadataStore();
MetadataRetrieve retrieve = store instanceof MetadataRetrieve ? (MetadataRetrieve) store : new DummyMetadata();
String filename = sliceLabelPattern.replaceAll(FormatTools.SERIES_NUM, String.format("%d", series));

String imageName = retrieve.getImageName(series);
if (imageName == null) imageName = "Series" + series;
filename = filename.replaceAll(FormatTools.SERIES_NAME, imageName);

String order = r.getDimensionOrder();
int sizeC = r.getEffectiveSizeC();
int sizeT = r.getSizeT();
int sizeZ = r.getSizeZ();
int[] coordinates = FormatTools.getZCTCoords(order, sizeZ, sizeC, sizeT, sizeZ*sizeC*sizeT, ndx);

if (sizeC > 1) {
filename = filename.replaceAll(FormatTools.CHANNEL_NUM, "c:" + String.format("%d", coordinates[1] + 1) + "/" + String.format("%d", sizeC) + " ");
}
else {
filename = filename.replaceAll(FormatTools.CHANNEL_NUM, "");
}
if (sizeZ > 1) {
filename = filename.replaceAll(FormatTools.Z_NUM, "z:" + String.format("%d", coordinates[0] + 1) + "/" + String.format("%d", sizeZ) + " ");
}
else {
filename = filename.replaceAll(FormatTools.Z_NUM, "");
}
if (sizeT > 1) {
filename = filename.replaceAll(FormatTools.T_NUM, "t:" + String.format("%d", coordinates[2] + 1) + "/" + String.format("%d", sizeT) + " ");
}
else {
filename = filename.replaceAll(FormatTools.T_NUM, "");
}

int channelCount = retrieve.getChannelCount(series);
if (coordinates[1] < channelCount) {
String channelName = retrieve.getChannelName(series, coordinates[1]);
if (channelName == null) channelName = String.valueOf(coordinates[1]);
filename = filename.replaceAll(FormatTools.CHANNEL_NAME, channelName);
}
else {
filename = filename.replaceAll(FormatTools.CHANNEL_NAME, String.valueOf(coordinates[1]));
}

Timestamp timestamp = retrieve.getImageAcquisitionDate(series);
long stamp = 0;
String date = null;
if (timestamp != null) {
date = timestamp.getValue();
if (retrieve.getPlaneCount(series) > ndx) {
Time deltaT = retrieve.getPlaneDeltaT(series, ndx);
if (deltaT != null) {
stamp = (long) (deltaT.value(UNITS.SECOND).doubleValue() * 1000);
}
}
stamp += DateTools.getTime(date, DateTools.ISO8601_FORMAT);
}
else {
stamp = System.currentTimeMillis();
}
date = DateTools.convertDate(stamp, (int) DateTools.UNIX_EPOCH);

filename = filename.replaceAll(FormatTools.TIMESTAMP, date);
return filename;
}

private static void saveLUTs(ImagePlus imp, List<LUT> luts) {
// NB: Save individual planar LUTs as properties, for later access.
// This step is necessary because ImageStack.addSlice only extracts the
Expand Down

0 comments on commit ffd7629

Please sign in to comment.