Example usage for java.nio IntBuffer allocate

List of usage examples for java.nio IntBuffer allocate

Introduction

In this page you can find the example usage for java.nio IntBuffer allocate.

Prototype

public static IntBuffer allocate(int capacity) 

Source Link

Document

Creates an int buffer based on a newly allocated int array.

Usage

From source file:org.goko.core.gcode.rs274ngcv3.jogl.renderer.RS274GCodeRenderer.java

/** (inheritDoc)
 * @see org.goko.tools.viewer.jogl.utils.render.internal.AbstractVboJoglRenderer#buildGeometry()
 *//*from w ww. ja  v a  2 s.c  om*/
@Override
protected void buildGeometry() throws GkException {
    ArrayList<Point3d> lstVertices = new ArrayList<Point3d>();
    ArrayList<Color4f> lstColors = new ArrayList<Color4f>();

    mapVerticesGroupByIdLine = new HashMap<Integer, VerticesGroupByLine>();

    GCodeContext context = new GCodeContext(gcodeContextProvider.getGCodeContext());

    IGCodeProvider provider = Activator.getRS274NGCService().getGCodeProvider(idGCodeProvider);
    InstructionProvider instructionSet = Activator.getRS274NGCService().getInstructions(context, provider);

    IInstructionSetIterator<GCodeContext, AbstractInstruction> iterator = Activator.getRS274NGCService()
            .getIterator(instructionSet, context);
    IInstructionColorizer<GCodeContext, AbstractInstruction> colorizer = new MotionModeColorizer();
    //IInstructionColorizer<GCodeContext, AbstractInstruction> colorizer = new SelectedPlaneColorizer();
    //IInstructionColorizer<GCodeContext, AbstractInstruction> colorizer = new ArcAngleColorizer(); 

    while (iterator.hasNext()) {
        GCodeContext preContext = new GCodeContext(iterator.getContext());
        AbstractInstruction instruction = iterator.next();

        // TEST : Make sure we have a complete start position for rendering. 
        if (preContext.getX() != null && preContext.getY() != null && preContext.getZ() != null) {
            List<Point3d> vertices = InstructionGeometryFactory.build(preContext, instruction);

            addVerticesGroup(instruction.getIdGCodeLine(), lstVertices.size(), vertices);
            lstVertices.addAll(vertices);

            // Let's generate the colors and update the bounds as well
            Color4f color = colorizer.getColor(preContext, instruction);
            for (int i = 0; i < vertices.size(); i++) {
                lstColors.add(color);
            }
        }
    }

    setVerticesCount(CollectionUtils.size(lstVertices));

    stateBuffer = IntBuffer.allocate(getVerticesCount());
    stateBuffer.rewind();

    setColorsBuffer(JoglUtils.buildFloatBuffer4f(lstColors));
    setVerticesBuffer(JoglUtils.buildFloatBuffer3d(lstVertices));
}

From source file:org.goko.tools.viewer.jogl.shaders.ShaderLoader.java

private static void checkValidateProgramm(GL3 gl, int program) {
    IntBuffer b = IntBuffer.allocate(10);
    gl.glGetProgramiv(program, GL3.GL_VALIDATE_STATUS, b);
    ByteBuffer logBuffer = ByteBuffer.allocate(10000);

    gl.glGetProgramInfoLog(program, 10000, null, logBuffer);
    try {//  w  w w .  ja  va2 s .  co  m
        String logBufferStr = new String(logBuffer.array(), "UTF-8");
        if (StringUtils.isNotBlank(StringUtils.defaultString(logBufferStr).trim())) {
            LOG.error("Check validate programm :" + logBufferStr);
        }
    } catch (UnsupportedEncodingException e) {
        LOG.error(e);
    }
}

From source file:net.dv8tion.jda.core.audio.AudioConnection.java

private synchronized void setupSendSystem() {
    if (udpSocket != null && !udpSocket.isClosed() && sendHandler != null && sendSystem == null) {
        IntBuffer error = IntBuffer.allocate(4);
        opusEncoder = Opus.INSTANCE.opus_encoder_create(OPUS_SAMPLE_RATE, OPUS_CHANNEL_COUNT,
                Opus.OPUS_APPLICATION_AUDIO, error);

        IAudioSendFactory factory = ((JDAImpl) channel.getJDA()).getAudioSendFactory();
        sendSystem = factory.createSendSystem(new PacketProvider());
        sendSystem.start();/*from w w  w.j a  v  a2s .  c om*/
    } else if (sendHandler == null && sendSystem != null) {
        sendSystem.shutdown();
        sendSystem = null;

        if (opusEncoder != null) {
            Opus.INSTANCE.opus_encoder_destroy(opusEncoder);
            opusEncoder = null;
        }
    }
}

From source file:org.goko.tools.viewer.jogl.shaders.ShaderLoader.java

private static void checkCompiling(GL3 gl, int shader) {
    IntBuffer b = IntBuffer.allocate(10);
    gl.glGetShaderiv(shader, GL3.GL_COMPILE_STATUS, b);
    ByteBuffer logBuffer = ByteBuffer.allocate(10000);

    gl.glGetShaderInfoLog(shader, 10000, null, logBuffer);
    try {/*  w w  w  .  j  av  a2  s .co m*/
        String logBufferStr = new String(logBuffer.array(), "UTF-8");
        if (StringUtils.isNotBlank(StringUtils.defaultString(logBufferStr).trim())) {
            LOG.error("CheckCompiling :" + logBufferStr);
        }
    } catch (UnsupportedEncodingException e) {
        LOG.error(e);
    }
}

From source file:org.goko.viewer.jogl.utils.render.internal.AbstractVboJoglRenderer.java

/**
 * Initializes and bind the main vertex array object
 * @param gl the GL/*from   w  w  w. j  a  va  2 s .c  om*/
 */
private void initializeVertexArrayObject(GL3 gl) {
    IntBuffer vao = IntBuffer.allocate(1);
    gl.glGenVertexArrays(1, vao);
    this.vertexArrayObject = vao.get(0);
    gl.glBindVertexArray(this.vertexArrayObject);

}

From source file:com.l2jfree.gameserver.geodata.pathfinding.geonodes.GeoPathFinding.java

private void LoadPathNodeFile(byte rx, byte ry) {
    String fname = "./data/pathnode/" + rx + "_" + ry + ".pn";
    short regionoffset = getRegionOffset(rx, ry);
    _log.info("PathFinding Engine: - Loading: " + fname + " -> region offset: " + regionoffset + "X: " + rx
            + " Y: " + ry);
    File Pn = new File(fname);
    int node = 0, size, index = 0;
    FileChannel roChannel = null;
    try {/*w w w . j  a v  a2  s .  c  o  m*/
        // Create a read-only memory-mapped file
        roChannel = new RandomAccessFile(Pn, "r").getChannel();
        size = (int) roChannel.size();
        MappedByteBuffer nodes;
        if (Config.FORCE_GEODATA) //Force O/S to Loads this buffer's content into physical memory.
            //it is not guarantee, because the underlying operating system may have paged out some of the buffer's data
            nodes = roChannel.map(FileChannel.MapMode.READ_ONLY, 0, size).load();
        else
            nodes = roChannel.map(FileChannel.MapMode.READ_ONLY, 0, size);

        // Indexing pathnode files, so we will know where each block starts
        IntBuffer indexs = IntBuffer.allocate(65536);

        while (node < 65536) {
            byte layer = nodes.get(index);
            indexs.put(node++, index);
            index += layer * 10 + 1;
        }
        _pathNodesIndex.set(regionoffset, indexs);
        _pathNodes.set(regionoffset, nodes);
    } catch (Exception e) {
        _log.warn("Failed to Load PathNode File: " + fname + "\n", e);
    } finally {
        try {
            if (roChannel != null)
                roChannel.close();
        } catch (Exception e) {
        }
    }

}

From source file:edu.iu.daal_pca.Service.java

public static void printAprioriItemsets(HomogenNumericTable largeItemsetsTable,
        HomogenNumericTable largeItemsetsSupportTable) {
    /* Get sizes of tables to store large item sets */
    int nItemsInLargeItemsets = (int) largeItemsetsTable.getNumberOfRows();
    int largeItemsetCount = (int) largeItemsetsSupportTable.getNumberOfRows();
    int nItemsetToPrint = 20;

    /* Get item sets and their support values */
    IntBuffer bufLargeItemsets = IntBuffer
            .allocate(nItemsInLargeItemsets * (int) largeItemsetsTable.getNumberOfColumns());
    bufLargeItemsets = largeItemsetsTable.getBlockOfRows(0, nItemsInLargeItemsets, bufLargeItemsets);
    int[] largeItemsets = new int[bufLargeItemsets.capacity()];
    bufLargeItemsets.get(largeItemsets);

    IntBuffer bufLargeItemsetsSupportData = IntBuffer
            .allocate(largeItemsetCount * (int) largeItemsetsSupportTable.getNumberOfColumns());
    bufLargeItemsetsSupportData = largeItemsetsSupportTable.getBlockOfRows(0, largeItemsetCount,
            bufLargeItemsetsSupportData);
    int[] largeItemsetsSupportData = new int[bufLargeItemsetsSupportData.capacity()];
    bufLargeItemsetsSupportData.get(largeItemsetsSupportData);

    ArrayList<ArrayList<Integer>> largeItemsetsVector = new ArrayList<ArrayList<Integer>>(largeItemsetCount);

    for (int i = 0; i < largeItemsetCount; i++) {
        largeItemsetsVector.add(new ArrayList<Integer>());
    }/*w  w  w  . j  a v a 2 s  .c o m*/

    for (int i = 0; i < nItemsInLargeItemsets; i++) {
        largeItemsetsVector.get(largeItemsets[2 * i]).add(largeItemsets[2 * i + 1]);
    }

    ArrayList<Integer> supportVector = new ArrayList<Integer>(largeItemsetCount);
    for (int i = 0; i < largeItemsetCount; i++) {
        supportVector.add(0);
    }

    for (int i = 0; i < largeItemsetCount; i++) {
        int index = largeItemsetsSupportData[2 * i];
        supportVector.set(index, largeItemsetsSupportData[2 * i + 1]);
    }

    System.out.println("Apriori example program results");

    System.out.println("Last " + nItemsetToPrint + " large itemsets: ");
    System.out.println("Itemset\t\t\tSupport");

    int iMin = ((largeItemsetCount > nItemsetToPrint) ? largeItemsetCount - nItemsetToPrint : 0);
    for (int i = iMin; i < largeItemsetCount; i++) {
        System.out.print("{");
        for (int l = 0; l < largeItemsetsVector.get(i).size() - 1; l++) {
            System.out.print(largeItemsetsVector.get(i).get(l) + ", ");
        }
        System.out.print(largeItemsetsVector.get(i).get(largeItemsetsVector.get(i).size() - 1) + "}\t\t");

        System.out.println(supportVector.get(i));
    }
}

From source file:com.atilika.kuromoji.trie.DoubleArrayTrie.java

private void extendBuffers(int nextIndex) {
    int newLength = nextIndex + (int) (baseBuffer.capacity() * BUFFER_GROWTH_PERCENTAGE);
    ProgressLog.println("Buffers extended to " + baseBuffer.capacity() + " entries");

    IntBuffer newBaseBuffer = IntBuffer.allocate(newLength);
    baseBuffer.rewind();/*w ww  . j a v  a  2  s.  c o  m*/
    newBaseBuffer.put(baseBuffer);
    baseBuffer = newBaseBuffer;

    IntBuffer newCheckBuffer = IntBuffer.allocate(newLength);//ByteBuffer.allocate(newLength).asIntBuffer();
    checkBuffer.rewind();
    newCheckBuffer.put(checkBuffer);
    checkBuffer = newCheckBuffer;
}

From source file:com.adobe.plugins.FastCanvasRenderer.java

public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    Log.i("CANVAS", "CanvasRenderer onSurfaceCreated. config:" + config.toString() + " gl:" + gl.toString());

    IntBuffer ib = IntBuffer.allocate(100);
    ib.position(0);/*from ww w.j a  v a 2  s.c  o  m*/
    GLES10.glGetIntegerv(GLES10.GL_RED_BITS, ib);
    int red = ib.get(0);
    GLES10.glGetIntegerv(GLES10.GL_GREEN_BITS, ib);
    int green = ib.get(0);
    GLES10.glGetIntegerv(GLES10.GL_BLUE_BITS, ib);
    int blue = ib.get(0);
    GLES10.glGetIntegerv(GLES10.GL_STENCIL_BITS, ib);
    int stencil = ib.get(0);
    GLES10.glGetIntegerv(GLES10.GL_DEPTH_BITS, ib);
    int depth = ib.get(0);

    Log.i("CANVAS", "CanvasRenderer R=" + red + " G=" + green + " B=" + blue + " DEPETH=" + depth + " STENCIL="
            + stencil);
}

From source file:org.goko.viewer.jogl.utils.render.internal.AbstractVboJoglRenderer.java

/** (inheritDoc)
 * @see org.goko.viewer.jogl.service.ICoreJoglRenderer#performDestroy(javax.media.opengl.GL3)
 *///from   w  w w . j a  va2  s. c o m
@Override
public void performDestroy(GL3 gl) throws GkException {
    if (!isInitialized()) {
        return;
    }
    List<Integer> lstBuffers = new ArrayList<Integer>();

    if (useVerticesBuffer) {
        lstBuffers.add(verticesBufferObject);
    }
    if (useColorsBuffer) {
        lstBuffers.add(colorsBufferObject);
    }
    if (useUvsBuffer) {
        lstBuffers.add(uvsBufferObject);
    }

    IntBuffer buffers = IntBuffer.allocate(lstBuffers.size());
    for (Integer integer : lstBuffers) {
        buffers.put(integer);
    }
    buffers.rewind();
    gl.glDeleteBuffers(lstBuffers.size(), buffers);
    IntBuffer intBuffer = IntBuffer.wrap(new int[] { vertexArrayObject });
    gl.glDeleteVertexArrays(1, intBuffer);
}