List of usage examples for java.nio FloatBuffer put
public FloatBuffer put(FloatBuffer src)
From source file:BufferTest.java
private long singlePut(float[] data, int elements, FloatBuffer target, int testTime) { long start = System.currentTimeMillis(); long elapsed = 0; int reps = 0; target.clear();//from w w w . jav a 2 s.c om do { for (int i = 0; i < elements; i++) { target.put(data[i]); } target.flip(); reps++; elapsed = System.currentTimeMillis() - start; } while (elapsed < testTime); long bytes = (long) elements * (long) reps * 4; return bytes / elapsed / 1024; }
From source file:haven.Utils.java
public static FloatBuffer bufcp(float[] a) { FloatBuffer b = mkfbuf(a.length); b.put(a); b.rewind();/*from w w w .ja v a2 s .c o m*/ return (b); }
From source file:haven.Utils.java
public static FloatBuffer bufcp(FloatBuffer a) { a.rewind();/* w w w.java2 s. c o m*/ FloatBuffer ret = mkfbuf(a.remaining()); ret.put(a).rewind(); return (ret); }
From source file:org.goko.tools.viewer.jogl.utils.render.basic.PolylineRenderer.java
/** (inheritDoc) * @see org.goko.tools.viewer.jogl.utils.render.internal.AbstractVboJoglRenderer#buildGeometry() *//*from w w w . j ava 2 s .c o m*/ @Override protected void buildGeometry() throws GkException { if (closed) { setVerticesCount(CollectionUtils.size(points) + 1); } else { setVerticesCount(CollectionUtils.size(points)); } FloatBuffer vertices = FloatBuffer.allocate(getVerticesCount() * 4); FloatBuffer colors = FloatBuffer.allocate(getVerticesCount() * 4); if (CollectionUtils.isNotEmpty(points)) { for (Point3d p : points) { vertices.put(new float[] { (float) p.x, (float) p.y, (float) p.z, 1 }); colors.put(new float[] { color.x, color.y, color.z, color.w }); } if (closed) { Point3d p = points.get(0); vertices.put(new float[] { (float) p.x, (float) p.y, (float) p.z, 1 }); colors.put(new float[] { color.x, color.y, color.z, color.w }); } } vertices.rewind(); colors.rewind(); setVerticesBuffer(vertices); setColorsBuffer(colors); }
From source file:org.rifidi.jme.quadtree.QuadTree.java
/** * Helpermethod to create a boundingbox from a node. * @param node//from w w w. j a v a 2s . c o m * @return */ private BoundingBox createBoundingBox(Node node) { FloatBuffer vertexBuffer = null; BoundingBox bbox = new BoundingBox(); //walk through all children for (Spatial child : node.getChildren()) { //check if it contains tri data if (child instanceof Geometry) { Geometry geom = ((Geometry) child); for (int count = 0; count < geom.getBatchCount(); count++) { if (vertexBuffer == null) { vertexBuffer = geom.getVertexBuffer(count); } else { FloatBuffer tempBuffer = FloatBuffer .allocate(vertexBuffer.capacity() + geom.getVertexBuffer(count).capacity()); tempBuffer.put(vertexBuffer); tempBuffer.put(geom.getVertexBuffer(count)); vertexBuffer = tempBuffer; } } //compute the boundingbox bbox.computeFromPoints(vertexBuffer); } } if (node.getLocalTranslation() == new Vector3f()) { bbox.setCenter(node.getLocalTranslation()); } return bbox; }
From source file:nitf.imageio.NITFReader.java
/** * Optimization to read the entire image in one fell swoop... This is most * likely the common use case for this codec, so we hope this optimization * will be helpful./*from w ww . ja v a 2 s . c om*/ * * @param imageIndex * @param sourceXSubsampling * @param sourceYSubsampling * @param bandOffsets * @param pixelSize * @param imRas * @throws IOException */ protected void readFullImage(int imageIndex, Rectangle destRegion, int sourceXSubsampling, int sourceYSubsampling, int[] bandOffsets, int pixelSize, WritableRaster imRas) throws IOException { try { ImageSubheader subheader = record.getImages()[imageIndex].getSubheader(); int numCols = destRegion.width; int numRows = destRegion.height; int nBands = subheader.getBandCount(); /* * NOTE: This is a "fix" that will be removed once the underlying * NITRO library gets patched. Currently, if you make a request of a * single band, it doesn't matter which band you request - the data * from the first band will be returned regardless. This is * obviously wrong. To thwart this, we will read all bands, then * scale down what we return to the user based on their actual * request. */ int[] requestBands = bandOffsets; /* * if (nBands != bandOffsets.length && bandOffsets.length == 1 * && bandOffsets[0] != 0) * { * requestBands = new int[nBands]; * for (int i = 0; i < nBands; ++i) * requestBands[i] = i; * } */ int bufSize = numCols * numRows * pixelSize; byte[][] imageBuf = new byte[requestBands.length][bufSize]; // make a SubWindow from the params // TODO may want to read by blocks or rows to make faster and more // memory efficient SubWindow window; window = new SubWindow(); window.setNumBands(requestBands.length); window.setBandList(requestBands); window.setNumCols(numCols); window.setNumRows(numRows); window.setStartCol(0); window.setStartRow(0); // the NITRO library can do the subsampling for us if (sourceYSubsampling != 1 || sourceXSubsampling != 1) { DownSampler downSampler = new PixelSkipDownSampler(sourceYSubsampling, sourceXSubsampling); window.setDownSampler(downSampler); } // String pixelJustification = subheader.getPixelJustification() // .getStringData().trim(); // boolean shouldSwap = pixelJustification.equals("R"); // since this is Java, we need the data in big-endian format // boolean shouldSwap = ByteOrder.nativeOrder() != // ByteOrder.BIG_ENDIAN; nitf.ImageReader imageReader = getImageReader(imageIndex); imageReader.read(window, imageBuf); List<ByteBuffer> bandBufs = new ArrayList<ByteBuffer>(); for (int i = 0; i < bandOffsets.length; ++i) { ByteBuffer bandBuf = null; // the special "fix" we added needs to do this if (bandOffsets.length != requestBands.length) { bandBuf = ByteBuffer.wrap(imageBuf[bandOffsets[i]]); } else { bandBuf = ByteBuffer.wrap(imageBuf[i]); } // ban dBuf.order(ByteOrder.nativeOrder()); // shouldSwap ? ByteOrder.LITTLE_ENDIAN // : ByteOrder.BIG_ENDIAN); bandBufs.add(bandBuf); } // optimization for 1 band case... just dump the whole thing if (bandOffsets.length == 1) { ByteBuffer bandBuf = bandBufs.get(0); switch (pixelSize) { case 1: ByteBuffer rasterByteBuf = ByteBuffer.wrap(((DataBufferByte) imRas.getDataBuffer()).getData()); rasterByteBuf.put(bandBuf); break; case 2: ShortBuffer rasterShortBuf = ShortBuffer .wrap(((DataBufferUShort) imRas.getDataBuffer()).getData()); rasterShortBuf.put(bandBuf.asShortBuffer()); break; case 4: FloatBuffer rasterFloatBuf = FloatBuffer .wrap(((DataBufferFloat) imRas.getDataBuffer()).getData()); rasterFloatBuf.put(bandBuf.asFloatBuffer()); break; case 8: DoubleBuffer rasterDoubleBuf = DoubleBuffer .wrap(((DataBufferDouble) imRas.getDataBuffer()).getData()); rasterDoubleBuf.put(bandBuf.asDoubleBuffer()); break; } } else { // for multi-band case, we need to iterate over each pixel... // TODO -- optimize this!... somehow for (int srcY = 0, srcX = 0; srcY < numRows; srcY++) { // Copy each (subsampled) source pixel into imRas for (int dstX = 0; dstX < numCols; srcX += pixelSize, dstX++) { for (int i = 0; i < bandOffsets.length; ++i) { ByteBuffer bandBuf = bandBufs.get(i); switch (pixelSize) { case 1: imRas.setSample(dstX, srcY, i, bandBuf.get(srcX)); break; case 2: imRas.setSample(dstX, srcY, i, bandBuf.getShort(srcX)); break; case 4: imRas.setSample(dstX, srcY, i, bandBuf.getFloat(srcX)); break; case 8: imRas.setSample(dstX, srcY, i, bandBuf.getDouble(srcX)); break; } } } } } } catch (NITFException e1) { throw new IOException(ExceptionUtils.getStackTrace(e1)); } }
From source file:org.bimserver.GeometryGenerator.java
private byte[] floatArrayToByteArray(float[] vertices) { if (vertices == null) { return null; }/*from w ww . jav a2s .co m*/ ByteBuffer buffer = ByteBuffer.wrap(new byte[vertices.length * 4]); buffer.order(ByteOrder.LITTLE_ENDIAN); FloatBuffer asFloatBuffer = buffer.asFloatBuffer(); for (float f : vertices) { asFloatBuffer.put(f); } return buffer.array(); }
From source file:org.bimserver.GeometryGenerator.java
private void setTransformationMatrix(GeometryInfo geometryInfo, float[] transformationMatrix) { ByteBuffer byteBuffer = ByteBuffer.allocate(16 * 4); byteBuffer.order(ByteOrder.nativeOrder()); FloatBuffer asFloatBuffer = byteBuffer.asFloatBuffer(); for (float f : transformationMatrix) { asFloatBuffer.put(f); }// www. j ava 2 s. com geometryInfo.setTransformation(byteBuffer.array()); }
From source file:org.jtrfp.trcl.core.ResourceManager.java
public ResourceManager(final TR tr) { this.tr = tr; try {/*from w w w . j a va2 s. c o m*/ Class.forName("de.quippy.javamod.multimedia.mod.loader.tracker.ProTrackerMod"); Class.forName("de.quippy.javamod.multimedia.mod.ModContainer"); // ModContainer uses the ModFactory!! } catch (Exception e) { tr.showStopper(e); } gpuResidentMODs = new CachedObjectFactory<String, GPUResidentMOD>() { @Override protected GPUResidentMOD generate(String key) { return new GPUResidentMOD(tr, getMOD(key)); }//end generate(...) }; soundTextures = new CachedObjectFactory<String, SoundTexture>() { @Override protected SoundTexture generate(String key) { try { final AudioInputStream ais = AudioSystem .getAudioInputStream(getInputStreamFromResource("SOUND\\" + key)); final FloatBuffer fb = ByteBuffer.allocateDirect((int) ais.getFrameLength() * 4) .order(ByteOrder.nativeOrder()).asFloatBuffer(); int value; while ((value = ais.read()) != -1) { fb.put(((float) (value - 128)) / 128f); } fb.clear(); return tr.soundSystem.get().newSoundTexture(fb, (int) ais.getFormat().getFrameRate()); } catch (Exception e) { tr.showStopper(e); return null; } } }; setupPODListeners(); }
From source file:org.shaman.terrain.polygonal.PolygonalMapGenerator.java
private void updateGraphNode() { if (graphNode == null) { return;//from w ww.j a v a 2s .c o m } //edges Mesh edgeMesh = new Mesh(); FloatBuffer pos = BufferUtils.createVector3Buffer(graph.corners.size()); IntBuffer index = BufferUtils.createIntBuffer(graph.edges.size() * 2); pos.rewind(); for (Graph.Corner c : graph.corners) { pos.put(c.point.x).put(c.point.y).put(0); } pos.rewind(); index.rewind(); for (Graph.Edge e : graph.edges) { index.put(e.v0.index).put(e.v1.index); } index.rewind(); edgeMesh.setBuffer(VertexBuffer.Type.Position, 3, pos); edgeMesh.setBuffer(VertexBuffer.Type.Index, 1, index); edgeMesh.setMode(Mesh.Mode.Lines); edgeMesh.setLineWidth(1); edgeMesh.updateCounts(); edgeMesh.updateBound(); Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); mat.setColor("Color", ColorRGBA.Gray); Geometry edgeGeom = new Geometry("edgeGeom", edgeMesh); edgeGeom.setMaterial(mat); edgeGeom.setCullHint(Spatial.CullHint.Never); edgeNode.detachAllChildren(); edgeNode.attachChild(edgeGeom); LOG.info("edge geometry updated"); }