Here you can find the source of cube2rect(byte[][][] cube)
public static byte[][] cube2rect(byte[][][] cube)
//package com.java2s; /*========================================================================= * * Copyright (c) Karl T. Diedrich // w w w . j a v a 2s . com * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0.txt * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * *=========================================================================*/ public class Main { public static byte[][] cube2rect(byte[][][] cube) { int zSize = cube.length; byte[][] rect = new byte[zSize][cube[0].length * cube[0][0].length]; for (int z = 0; z < zSize; z++) { rect[z] = square2array(cube[z]); } return rect; } public static short[][] cube2rect(short[][][] cube) { int zSize = cube.length; short[][] rect = new short[zSize][cube[0].length * cube[0][0].length]; for (int z = 0; z < zSize; z++) { rect[z] = square2array(cube[z]); } return rect; } public static float[][] cube2rect(float[][][] cube) { int zSize = cube.length; float[][] rect = new float[zSize][cube[0].length * cube[0][0].length]; for (int z = 0; z < zSize; z++) { rect[z] = square2array(cube[z]); } return rect; } public static byte[] square2array(byte[][] square) { int height = square.length; int width = square[0].length; byte[] ar = new byte[height * width]; int i = 0; for (int r = 0; r < height; r++) { for (int c = 0; c < width; c++) { ar[i] = square[r][c]; i++; } } return ar; } public static short[] square2array(short[][] square) { int height = square.length; int width = square[0].length; short[] ar = new short[height * width]; int i = 0; for (int r = 0; r < height; r++) { for (int c = 0; c < width; c++) { ar[i] = square[r][c]; i++; } } return ar; } public static float[] square2array(float[][] square) { int height = square.length; int width = square[0].length; float[] ar = new float[height * width]; int i = 0; for (int r = 0; r < height; r++) { for (int c = 0; c < width; c++) { ar[i] = square[r][c]; i++; } } return ar; } }