Java Cube cube2rect(byte[][][] cube)

Here you can find the source of cube2rect(byte[][][] cube)

Description

cuberect

License

Apache License

Declaration

public static byte[][] cube2rect(byte[][][] cube) 

Method Source Code

//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;

    }
}

Related

  1. cube(double d)
  2. cube(double value)
  3. cube(int a)
  4. cube(int value)
  5. cubed(final int input)
  6. cubeIntersectsSphere(int x1, int y1, int z1, int x2, int y2, int z2, int sX, int sY, int sZ, int radius)
  7. cubeTextureArray(float x0, float y0, float x1, float y1)
  8. cubeTextureFace(float x0, float y0, float x1, float y1)