Fixed potential threading issue with Swing and the Layer panels when
[trakem2.git] / mpi / fruitfly / general / ArrayConverter.java
blob267a589c2f17a4f24ca69cc8a2f4a0cc41bf4bee
1 package mpi.fruitfly.general;
3 /**
4 * <p>Title: </p>
6 * <p>Description: </p>
8 * <p>Copyright: Copyright (c) 2006</p>
10 * <p>Company: </p>
12 * @author not attributable
13 * @version 1.0
16 public class ArrayConverter
18 public static float[] twoDimArrayToOneDimArray(float[][] filter)
20 float[] result = new float[filter.length * filter[0].length];
22 for (int y = 0; y < filter[0].length; y++)
23 for (int x = 0; x < filter.length; x++)
24 result[x + filter.length*y] = filter[x][y];
26 return result;
29 public static double[] twoDimArrayToOneDimArray(double[][] filter)
31 double[] result = new double[filter.length * filter[0].length];
33 for (int y = 0; y < filter[0].length; y++)
34 for (int x = 0; x < filter.length; x++)
35 result[x + filter.length*y] = filter[x][y];
37 return result;
40 public static double[][] oneDimArrayToTwoDimArray(double[] filter, int width, int height)
42 double[][] result = new double[width][height];
44 for (int y = 0; y < height; y++)
45 for (int x = 0; x < width; x++)
46 result[x][y] = filter[x + width*y];
48 return result;
51 // needed because matrix dimension is [row][column] which is the opposite of [x][y]!!!
53 public static double[][] oneDimArrayToTwoDimArrayInvert(double[] filter, int width /*columns*/, int height /*rows*/)
55 // row column
56 double[][] result = new double[height][width];
58 for (int row = 0; row < height; row++)
59 for (int column = 0; column < width; column++)
60 result[row][column] = filter[column + width*row];
62 return result;