Example usage for java.nio FloatBuffer limit

List of usage examples for java.nio FloatBuffer limit

Introduction

In this page you can find the example usage for java.nio FloatBuffer limit.

Prototype

public final int limit() 

Source Link

Document

Returns the limit of this buffer.

Usage

From source file:io.anserini.embeddings.WordEmbeddingDictionary.java

public float[] getEmbeddingVector(String term) throws IOException {
    Query query = AnalyzerUtils.buildBagOfWordsQuery(FIELD_ID, analyzer, term);
    TopDocs rs = searcher.search(query, 1);
    ScoredDocuments docs = ScoredDocuments.fromTopDocs(rs, searcher);

    byte[] val = docs.documents[0].getField(FIELD_BODY).binaryValue().bytes;
    FloatBuffer floatBuffer = ByteBuffer.wrap(val).asFloatBuffer();
    float[] floatArray = new float[floatBuffer.limit()];
    floatBuffer.get(floatArray);/* w w  w .j  a v a  2s.  c o  m*/
    return floatArray;
}

From source file:GeometryByReferenceNIOBuffer.java

public void updateData(Geometry geometry) {
    int i;//from  ww w  .  ja v a2s .  com
    float val;
    float val1;
    if (updateIndex == 1) { // geometry
        // Translate the geometry by a small amount in x
        vertexCount++;
        if ((vertexCount & 1) == 1)
            val = 0.2f;
        else
            val = -0.2f;

        FloatBuffer indexedCoord = (FloatBuffer) indexedFloatBufferCoord.getBuffer();
        indexedCoord.rewind();
        FloatBuffer coord = (FloatBuffer) floatBufferCoord.getBuffer();
        coord.rewind();

        if (vertexIndex == 0) {
            // Do Indexed geometry
            for (i = 0; i < indexedCoord.limit(); i += 3) {
                val1 = indexedCoord.get(i);
                indexedCoord.put(i, val1 + val);
            }
            // Do non-indexed float geometry
            for (i = 0; i < coord.limit(); i += 3) {
                val1 = coord.get(i);
                coord.put(i, val1 + val);
            }
        }
    } else if (updateIndex == 2) { // colors
        colorCount++;
        if ((colorCount & 1) == 1)
            val = 0.4f;
        else
            val = -0.4f;

        FloatBuffer indexedColors = (FloatBuffer) indexedFloatBufferColor.getBuffer();
        indexedColors.rewind();
        FloatBuffer colors = (FloatBuffer) floatBufferColor.getBuffer();
        colors.rewind();

        if (colorIndex == 0) {
            // Do Indexed geometry
            for (i = 0; i < indexedColors.limit(); i += 3) {
                indexedColors.put(i, indexedColors.get(i) + val);
            }
            // Do non-indexed float geometry
            for (i = 0; i < colors.limit(); i += 3) {
                colors.put(i, colors.get(i) + val);
            }
        }

    }

}

From source file:com.alvermont.terraj.fracplanet.geom.VertexBufferArray.java

/**
 * Resize the buffer. This is done by reallocating a new one and copying
 * data from the old buffer to the new one. This is necessary as buffers
 * cannot be dynamically resized.//from   w w w. ja va  2s  .co m
 */
protected void resizeBuffer() {
    // we can't resize it so we have to allocate a new one and copy the data
    final int slots = (buffer.capacity() / ELEMENTSIZE);
    final int newCapacity = buffer.capacity()
            + (((slots * CAPACITY_PCT_INCREASE) / HUNDRED_PERCENT) * ELEMENTSIZE);

    final ByteBuffer newBuffer = ByteBuffer.allocateDirect(newCapacity).order(ByteOrder.nativeOrder());

    if (log.isDebugEnabled()) {
        log.debug("Resizing vertex buffer capacity to: " + newBuffer.capacity());
    }

    final FloatBuffer oldVertexBuffer = positionBuffer;
    final FloatBuffer oldNormalBuffer = normalBuffer;
    final ByteBuffer oldColourBuffer = colourBuffer;
    final ByteBuffer oldEmissiveBuffer = emissiveBuffer;

    this.buffer = newBuffer;

    sliceAndDice(newCapacity / ELEMENTSIZE);

    oldVertexBuffer.rewind();
    positionBuffer.rewind();
    positionBuffer.limit(oldVertexBuffer.limit());
    positionBuffer.put(oldVertexBuffer);

    oldNormalBuffer.rewind();
    normalBuffer.rewind();
    normalBuffer.limit(oldNormalBuffer.limit());
    normalBuffer.put(oldNormalBuffer);

    oldColourBuffer.rewind();
    colourBuffer.rewind();
    colourBuffer.limit(oldColourBuffer.limit());
    colourBuffer.put(oldColourBuffer);

    oldEmissiveBuffer.rewind();
    emissiveBuffer.rewind();
    emissiveBuffer.limit(oldEmissiveBuffer.limit());
    emissiveBuffer.put(oldEmissiveBuffer);
}