From 5ecedc91879912721b66bed1d314f6b2a7ac3939 Mon Sep 17 00:00:00 2001 From: Michael Innerberger Date: Tue, 26 Mar 2024 18:44:22 -0400 Subject: [PATCH] Reorder tiles by changing their tileIds --- .../render/client/TileReorderingClient.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/render-ws-java-client/src/main/java/org/janelia/render/client/TileReorderingClient.java b/render-ws-java-client/src/main/java/org/janelia/render/client/TileReorderingClient.java index 2ae1ae93f..c9c002087 100644 --- a/render-ws-java-client/src/main/java/org/janelia/render/client/TileReorderingClient.java +++ b/render-ws-java-client/src/main/java/org/janelia/render/client/TileReorderingClient.java @@ -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 @@ -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 @@ -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(); @@ -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); }