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);
}
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);
}
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]);
}
}
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;
}
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;
}
Aggregations