Skip to content

Commit

Permalink
Reorder tiles by changing their tileIds
Browse files Browse the repository at this point in the history
  • Loading branch information
minnerbe committed Mar 26, 2024
1 parent 13aa28d commit 5ecedc9
Showing 1 changed file with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
import com.beust.jcommander.Parameter;
import com.beust.jcommander.ParametersDelegate;
import org.janelia.alignment.spec.ResolvedTileSpecCollection;
import org.janelia.alignment.spec.TileSpec;
import org.janelia.alignment.spec.stack.StackMetaData;
import org.janelia.render.client.parameter.CommandLineParameters;
import org.janelia.render.client.parameter.RenderWebServiceParameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
* This client reorders the tiles in a multi-sem stack in a way that the rendering order
Expand Down Expand Up @@ -43,7 +47,7 @@ public static void main(final String[] args) {
"--owner", "hess_wafer_53b",
"--project", "cut_070_to_079",
"--stack", "c070_s032_v01_align_ic",
"--targetStack", "c070_s032_v01_mi_reordering_test"
"--targetStack", "c070_s032_v01_mi_reordering_test_scan_order"
};
final ClientRunner clientRunner = new ClientRunner(xargs) {
@Override
Expand All @@ -67,6 +71,22 @@ public void runClient(final String[] args) throws Exception {
private final Parameters parameters;
private final RenderDataClient dataClient;

// The new order of the tiles in the multi-sem stack:
// Number the tiles in an SFOV from 1 to 91, starting in the top left corner and going
// row by row. Then, record these numbers in the original order of the tiles (i.e.,
// starting in the middle of the SFOV and spiraling outwards counterclockwise).
private final int[] newNumber = {
46, 47, 36, 35, 45, 56, 57, 48, 37, 27,
26, 25, 34, 44, 55, 65, 66, 67, 58, 49,
38, 28, 19, 18, 17, 16, 24, 33, 43, 54,
64, 73, 74, 75, 76, 68, 59, 50, 39, 29,
20, 12, 11, 10, 9, 8, 15, 23, 32, 42,
53, 63, 72, 80, 81, 82, 83, 84, 77, 69,
60, 51, 40, 30, 21, 13, 6, 5, 4, 3,
2, 1, 7, 14, 22, 31, 41, 52, 62, 71,
79, 86, 87, 88, 89, 90, 91, 85, 78, 70, 61
};

private TileReorderingClient(final Parameters parameters) {
this.parameters = parameters;
this.dataClient = parameters.renderWeb.getDataClient();
Expand Down Expand Up @@ -94,10 +114,22 @@ private void transferLayer(final Double z) throws Exception {
final ResolvedTileSpecCollection sourceCollection = dataClient.getResolvedTiles(parameters.stack, z);
LOG.info("transferLayer: transferring layer {} with {} tiles", z, sourceCollection.getTileCount());

for (final String tileId : sourceCollection.getTileIds()) {
final TileSpec tileSpec = sourceCollection.getTileSpec(tileId);
tileSpec.setTileId(updateSfovNumber(tileId));
}

if (sourceCollection.getTileCount() > 0) {
dataClient.saveResolvedTiles(sourceCollection, parameters.targetStack, z);
}
}

private String updateSfovNumber(final String tileId) {
final String[] tileIdComponents = tileId.split("_");
final int oldNumber = Integer.parseInt(tileIdComponents[2]);
tileIdComponents[2] = String.format("%03d", newNumber[oldNumber - 1]);
return String.join("_", tileIdComponents);
}

private static final Logger LOG = LoggerFactory.getLogger(TileReorderingClient.class);
}

0 comments on commit 5ecedc9

Please sign in to comment.