Example usage for java.nio ShortBuffer position

List of usage examples for java.nio ShortBuffer position

Introduction

In this page you can find the example usage for java.nio ShortBuffer position.

Prototype

public final int position() 

Source Link

Document

Returns the position of this buffer.

Usage

From source file:MainClass.java

public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.wrap(new byte[] { 0, 0, 0, 0, 0, 0, 0, 'a' });
    bb.rewind();/*from   w  w w.j  av a  2s  . c o m*/
    ShortBuffer sb = ((ByteBuffer) bb.rewind()).asShortBuffer();
    System.out.println("Short Buffer");
    while (sb.hasRemaining())
        System.out.println(sb.position() + " -> " + sb.get());

}

From source file:Main.java

public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.wrap(new byte[] { 0, 0, 0, 0, 0, 0, 0, 'a' });
    bb.rewind();//  w  ww  .j  a  v  a  2s.co m
    System.out.println("Byte Buffer");
    while (bb.hasRemaining())
        System.out.println(bb.position() + " -> " + bb.get());
    CharBuffer cb = ((ByteBuffer) bb.rewind()).asCharBuffer();
    System.out.println("Char Buffer");
    while (cb.hasRemaining())
        System.out.println(cb.position() + " -> " + cb.get());
    FloatBuffer fb = ((ByteBuffer) bb.rewind()).asFloatBuffer();
    System.out.println("Float Buffer");
    while (fb.hasRemaining())
        System.out.println(fb.position() + " -> " + fb.get());
    IntBuffer ib = ((ByteBuffer) bb.rewind()).asIntBuffer();
    System.out.println("Int Buffer");
    while (ib.hasRemaining())
        System.out.println(ib.position() + " -> " + ib.get());
    LongBuffer lb = ((ByteBuffer) bb.rewind()).asLongBuffer();
    System.out.println("Long Buffer");
    while (lb.hasRemaining())
        System.out.println(lb.position() + " -> " + lb.get());
    ShortBuffer sb = ((ByteBuffer) bb.rewind()).asShortBuffer();
    System.out.println("Short Buffer");
    while (sb.hasRemaining())
        System.out.println(sb.position() + " -> " + sb.get());
    DoubleBuffer db = ((ByteBuffer) bb.rewind()).asDoubleBuffer();
    System.out.println("Double Buffer");
    while (db.hasRemaining())
        System.out.println(db.position() + " -> " + db.get());
}

From source file:c.depthchart.ViewerPanel.java

private void updateDepthImage()
/* build a new histogram of 8-bit depth values, and convert it to
   image pixels (as bytes) *//*ww  w  .  j a va2  s  . c om*/
{
    ShortBuffer depthBuf = depthMD.getData().createShortBuffer();
    calcHistogram(depthBuf);
    depthBuf.rewind();

    while (depthBuf.remaining() > 0) {
        int pos = depthBuf.position();
        short depth = depthBuf.get();
        imgbytes[pos] = (byte) histogram[depth];
    }
}

From source file:TrackerPanel.java

private void updateUserDepths() {
    depthMD = depthGen.getMetaData();/* www  . j  a v a2 s  .  com*/
    ShortBuffer depthBuf = depthMD.getData().createShortBuffer();
    calcHistogram(depthBuf);
    depthBuf.rewind();

    ShortBuffer usersBuf = sceneMD.getData().createShortBuffer();

    while (depthBuf.remaining() > 0) {
        int pos = depthBuf.position();
        short depthVal = depthBuf.get();
        short userID = usersBuf.get();

        imgbytes[3 * pos] = 0; // default colour is black when there's no
        // depth data
        imgbytes[3 * pos + 1] = 0;
        imgbytes[3 * pos + 2] = 0;

        if (depthVal != 0) { // there is depth data
            // convert userID to index into USER_COLORS[]
            int colorIdx = userID % (USER_COLORS.length - 1); // skip last
            // color

            if (userID == 0) // not a user; actually the background
                colorIdx = USER_COLORS.length - 1;
            // use last index: the position of white in USER_COLORS[]

            // convert histogram value (0.0-1.0f) to a RGB color
            float histValue = histogram[depthVal];
            imgbytes[3 * pos] = (byte) (histValue * USER_COLORS[colorIdx].getRed());
            imgbytes[3 * pos + 1] = (byte) (histValue * USER_COLORS[colorIdx].getGreen());
            imgbytes[3 * pos + 2] = (byte) (histValue * USER_COLORS[colorIdx].getBlue());
        }
    }
}

From source file:TrackerPanel.java

private void hideBackground(int[] cameraPixels) {
    depthMD = depthGen.getMetaData();/* w ww .  ja  v  a  2s .co  m*/

    ShortBuffer usersBuf = sceneMD.getData().createShortBuffer();
    int userCount = 0;
    int maxUserCount = 0;
    int userCountMaxRow = 0;
    int maxY = 0;
    int row = 0;
    int rowCount = 0;

    while (usersBuf.remaining() > 0) {
        int pos = usersBuf.position();
        short userID = usersBuf.get();
        if (userID == 0) {
            // if not a user (i.e. is part of the background)
            cameraPixels[pos] = hideBGPixel; // make pixel transparent
        } else {
            userCount++;
            int y = imHeight - row;
            if (y > maxY) {
                maxY = y;
            }
        }
        rowCount++;
        if (rowCount == imWidth) {
            if (userCount > maxUserCount) {
                maxUserCount = userCount;
                userCountMaxRow = row;
            }
            row++;
            rowCount = 0;
            userCount = 0;
        }
    }
    int startPoint = imWidth * (imHeight - maxY);
    int finalPoint = startPoint + imWidth;
    if (maxY != 0) {
        printLine(startPoint, finalPoint, Color.YELLOW.getRGB());
    }
    startPoint = imWidth * (userCountMaxRow);
    finalPoint = startPoint + imWidth;
    if (userCountMaxRow != 0) {
        SimpleHTTPPOSTRequester httpPost = new SimpleHTTPPOSTRequester();
        try {
            httpPost.makeHTTPPOSTRequest(userCountMaxRow);
        } catch (ParseException e1) {
            e1.printStackTrace();
        }
        Util.insertLastPoint(userCountMaxRow);
        int response = Util.analyzeLastFivePoints();

        if (response == Util.NOT_READY) {
            printLine(startPoint, finalPoint, Color.RED.getRGB());
        } else if (response == Util.READY) {
            printLine(startPoint, finalPoint, Color.WHITE.getRGB());
        } else if (response == Util.GOING_UP) {
            printLine(startPoint, finalPoint, Color.GREEN.getRGB());
        } else if (response == Util.GOING_DOWN) {
            printLine(startPoint, finalPoint, Color.PINK.getRGB());
        }

    }
}