Commit 2e1c69b0 authored by Andrey Filippov's avatar Andrey Filippov

CLAUDE: Add transposeJagged() utility to ShowDoubleFloatArrays; refactor getNadirDisparityMaps()

Add ShowDoubleFloatArrays.transposeJagged(double[][][], int n_comp, int n_inner)
which converts the common [outer][inner][comp] layout (with null outer or inner
entries) to [outer][comp][inner] substituting NaN for nulls.  This pattern
appeared inline in getNadirDisparityMaps() and recurs in other tile-processing
code.

Refactor getNadirDisparityMaps() to replace the 12-line inline transpose loop
with a single call to the new utility, keeping the same semantics.
Co-authored-by: 's avatarClaude <claude@elphel.com>
parent 72a8b1df
...@@ -1189,6 +1189,41 @@ G= Y +Pr*(- 2*Kr*(1-Kr))/Kg + Pb*(-2*Kb*(1-Kb))/Kg ...@@ -1189,6 +1189,41 @@ G= Y +Pr*(- 2*Kr*(1-Kr))/Kg + Pb*(-2*Kb*(1-Kb))/Kg
return out_data; return out_data;
} }
/**
* Transpose a jagged [outer][inner][comp] array to [outer][comp][inner],
* substituting NaN for null entries at either level.
*
* <p>This is a common pattern when tile-level results are stored as
* {@code arr[frame][tile][comp]} (inner entries may be null for missing tiles,
* outer entries may be null for missing frames) and need to be reorganised into
* the {@code [frame][comp][tile]} layout expected by
* {@link #showArraysHyperstack}.
*
* @param arr source array; {@code arr[i]} may be null (whole frame absent);
* {@code arr[i][j]} may be null (individual tile absent);
* for non-null innermost entries the length must equal {@code n_comp}
* @param n_comp number of components (innermost dimension in {@code arr})
* @param n_inner number of inner entries (tile count; used as second dimension of output)
* @return {@code [outer][n_comp][n_inner]} array with {@link Double#NaN} substituted
* for null entries
*/
public static double[][][] transposeJagged(double[][][] arr, int n_comp, int n_inner) {
double[][][] out = new double[arr.length][n_comp][n_inner];
for (int i = 0; i < arr.length; i++) {
for (int c = 0; c < n_comp; c++) {
Arrays.fill(out[i][c], Double.NaN);
}
if (arr[i] != null) {
for (int j = 0; j < n_inner; j++) {
if (arr[i][j] != null) {
for (int c = 0; c < n_comp; c++) {
out[i][c][j] = arr[i][j][c];
}
}
}
}
}
return out;
}
} }
\ No newline at end of file
...@@ -10883,22 +10883,11 @@ java.lang.NullPointerException ...@@ -10883,22 +10883,11 @@ java.lang.NullPointerException
int ntiles = tilesX * tilesY; int ntiles = tilesX * tilesY;
String [] slice_titles = {"pX", "pY", "D"}; String [] slice_titles = {"pX", "pY", "D"};
String [] frame_titles = new String[selected_scenes.length]; String [] frame_titles = new String[selected_scenes.length];
double [][][] disp_maps = new double[selected_scenes.length][3][ntiles];
for (int ns = 0; ns < selected_scenes.length; ns++) { for (int ns = 0; ns < selected_scenes.length; ns++) {
frame_titles[ns] = selected_scenes[ns].getImageName(); frame_titles[ns] = selected_scenes[ns].getImageName();
Arrays.fill(disp_maps[ns][0], Double.NaN);
Arrays.fill(disp_maps[ns][1], Double.NaN);
Arrays.fill(disp_maps[ns][2], Double.NaN);
if (nadir_pXpYD[ns] != null) {
for (int t = 0; t < ntiles; t++) {
if (nadir_pXpYD[ns][t] != null) {
disp_maps[ns][0][t] = nadir_pXpYD[ns][t][0]; // pX
disp_maps[ns][1][t] = nadir_pXpYD[ns][t][1]; // pY
disp_maps[ns][2][t] = nadir_pXpYD[ns][t][2]; // D (disparity)
}
}
}
} }
// Transpose [scene][tile][3] (nulls) -> [scene][3][tile] (NaN) for showArraysHyperstack
double [][][] disp_maps = ShowDoubleFloatArrays.transposeJagged(nadir_pXpYD, 3, ntiles);
ImagePlus imp_disp_maps = ShowDoubleFloatArrays.showArraysHyperstack( ImagePlus imp_disp_maps = ShowDoubleFloatArrays.showArraysHyperstack(
disp_maps, // double [][][] pixels, disp_maps, // double [][][] pixels,
tilesX, // int width, tilesX, // int width,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment