Search in sources :

Example 81 with FloatBuffer

use of java.nio.FloatBuffer in project mongomvcc by igd-geo.

the class MongoDBVLargeCollectionTest method largeObjectFloat.

/**
	 * Tests if large objects with float arrays/streams/buffers can be saved in the database
	 * @throws Exception if something goes wrong
	 */
@Test
public void largeObjectFloat() throws Exception {
    VCollection coll = _master.getLargeCollection("images");
    float[] test = new float[1024 * 1024];
    for (int i = 0; i < test.length; ++i) {
        test[i] = (byte) (i & 0xFF);
    }
    Map<String, Object> obj = new HashMap<String, Object>();
    obj.put("name", "Mona Lisa");
    obj.put("data", test);
    coll.insert(obj);
    VCursor vc = coll.find();
    assertEquals(1, vc.size());
    Map<String, Object> obj2 = vc.iterator().next();
    assertEquals("Mona Lisa", obj2.get("name"));
    assertArrayEquals(test, (float[]) obj2.get("data"), 0.00001f);
    FloatBuffer bb = FloatBuffer.wrap(test);
    obj = new HashMap<String, Object>();
    obj.put("name", "Mona Lisa");
    obj.put("data", bb);
    coll.insert(obj);
    Map<String, Object> obj4 = coll.findOne(_factory.createDocument("uid", obj.get("uid")));
    assertEquals("Mona Lisa", obj4.get("name"));
    FloatBuffer bb4 = (FloatBuffer) obj4.get("data");
    bb4.rewind();
    float[] test4 = new float[bb4.remaining()];
    bb4.get(test4);
    assertArrayEquals(test, test4, 0.00001f);
}
Also used : HashMap(java.util.HashMap) FloatBuffer(java.nio.FloatBuffer) VCursor(de.fhg.igd.mongomvcc.VCursor) VCollection(de.fhg.igd.mongomvcc.VCollection) Test(org.junit.Test)

Example 82 with FloatBuffer

use of java.nio.FloatBuffer in project jna by java-native-access.

the class PointerBufferTest method testFloatBufferGet.

public void testFloatBufferGet() {
    final float MAGIC = 1234.5678f;
    Memory m = new Memory(8);
    ByteBuffer buf = m.getByteBuffer(0, m.size()).order(ByteOrder.nativeOrder());
    FloatBuffer fb = buf.asFloatBuffer();
    m.setFloat(0, MAGIC);
    assertEquals("Float not read from memory", MAGIC, fb.get(0), 0f);
}
Also used : FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 83 with FloatBuffer

use of java.nio.FloatBuffer in project jna by java-native-access.

the class BufferArgumentsMarshalTest method testWrappedFloatArrayArguent.

public void testWrappedFloatArrayArguent() {
    float[] array = new float[1024];
    FloatBuffer buf = FloatBuffer.wrap(array, 512, 512);
    final float MAGIC = -118.625f;
    lib.fillFloatBuffer(buf, 512, MAGIC);
    for (int i = 0; i < array.length; i++) {
        assertEquals("Bad value at index " + i, i < 512 ? 0 : MAGIC, array[i]);
    }
}
Also used : FloatBuffer(java.nio.FloatBuffer)

Example 84 with FloatBuffer

use of java.nio.FloatBuffer in project Horizon by Yalantis.

the class Buffers method makeInterleavedBuffer.

public static FloatBuffer makeInterleavedBuffer(float[] tData, int triangles) {
    int dataLength = tData.length;
    final FloatBuffer interleavedBuffer = ByteBuffer.allocateDirect(dataLength * Const.BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
    int tOffset = 0;
    for (int i = 0; i < triangles; i++) {
        for (int j = 0; j < Const.POINTS_PER_TRIANGLE; j++) {
            /**
                 * This doesn't seem to do make much sense for one array, but we might need to scale it up
                 */
            interleavedBuffer.put(tData, tOffset, Const.T_DATA_SIZE);
            tOffset += Const.T_DATA_SIZE;
        }
    }
    interleavedBuffer.position(0);
    return interleavedBuffer;
}
Also used : FloatBuffer(java.nio.FloatBuffer)

Example 85 with FloatBuffer

use of java.nio.FloatBuffer in project StarWars.Android by Yalantis.

the class Buffers method makeInterleavedBuffer.

public static FloatBuffer makeInterleavedBuffer(float[] positionData, float[] normals, float[] uvData, float[] tileXyData, int tiles) {
    int dataLength = positionData.length + normals.length * tiles + uvData.length + tileXyData.length;
    final FloatBuffer interleavedBuffer = ByteBuffer.allocateDirect(dataLength * Const.BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
    int positionOffset = 0, normalOffset = 0, textureOffset = 0, tileXyOffset = 0;
    for (int i = 0; i < tiles; i++) {
        for (int j = 0; j < Const.POINTS_PER_TILE; j++) {
            interleavedBuffer.put(positionData, positionOffset, Const.POSITION_DATA_SIZE);
            positionOffset += Const.POSITION_DATA_SIZE;
            interleavedBuffer.put(normals, normalOffset, Const.NORMALS_DATA_SIZE);
            // Normals are the same
            interleavedBuffer.put(uvData, textureOffset, Const.TEXTURE_COORDS_DATA_SIZE);
            textureOffset += Const.TEXTURE_COORDS_DATA_SIZE;
            interleavedBuffer.put(tileXyData, tileXyOffset, Const.TILE_DATA_SIZE);
            tileXyOffset += Const.TILE_DATA_SIZE;
        }
    }
    interleavedBuffer.position(0);
    return interleavedBuffer;
}
Also used : FloatBuffer(java.nio.FloatBuffer)

Aggregations

FloatBuffer (java.nio.FloatBuffer)291 ByteBuffer (java.nio.ByteBuffer)82 IntBuffer (java.nio.IntBuffer)43 ShortBuffer (java.nio.ShortBuffer)39 Vector3f (com.jme3.math.Vector3f)27 VertexBuffer (com.jme3.scene.VertexBuffer)27 DoubleBuffer (java.nio.DoubleBuffer)17 IndexBuffer (com.jme3.scene.mesh.IndexBuffer)16 LongBuffer (java.nio.LongBuffer)10 Mesh (com.jme3.scene.Mesh)9 CharBuffer (java.nio.CharBuffer)9 FrameBuffer2D (androidx.media.filterfw.FrameBuffer2D)8 OutputPort (androidx.media.filterfw.OutputPort)7 Matrix4f (com.jme3.math.Matrix4f)7 Buffer (java.nio.Buffer)7 TempVars (com.jme3.util.TempVars)6 IOException (java.io.IOException)6 BufferOverflowException (java.nio.BufferOverflowException)6 BufferUnderflowException (java.nio.BufferUnderflowException)6 ArrayList (java.util.ArrayList)6