List of usage examples for java.nio IntBuffer get
public abstract int get(int index);
From source file:com.linkedin.pinot.core.startree.StarTreeDataTable.java
public void sort(int startRecordId, int endRecordId, final int startOffsetInRecord, final int endOffsetInRecord) { final MMapBuffer mappedByteBuffer; try {/* www . j a v a 2s . c o m*/ int length = endRecordId - startRecordId; final long startOffset = startRecordId * (long) totalSizeInBytes; mappedByteBuffer = new MMapBuffer(file, startOffset, length * (long) totalSizeInBytes, MMapMode.READ_WRITE); List<Integer> idList = new ArrayList<Integer>(); for (int i = startRecordId; i < endRecordId; i++) { idList.add(i - startRecordId); } Comparator<Integer> comparator = new Comparator<Integer>() { byte[] buf1 = new byte[dimensionSizeInBytes]; byte[] buf2 = new byte[dimensionSizeInBytes]; @Override public int compare(Integer o1, Integer o2) { long pos1 = (o1) * (long) totalSizeInBytes; long pos2 = (o2) * (long) totalSizeInBytes; //System.out.println("pos1="+ pos1 +" , pos2="+ pos2); mappedByteBuffer.toDirectByteBuffer(pos1, dimensionSizeInBytes).get(buf1); mappedByteBuffer.toDirectByteBuffer(pos2, dimensionSizeInBytes).get(buf2); IntBuffer bb1 = ByteBuffer.wrap(buf1).asIntBuffer(); IntBuffer bb2 = ByteBuffer.wrap(buf2).asIntBuffer(); for (int dimIndex : sortOrder) { int v1 = bb1.get(dimIndex); int v2 = bb2.get(dimIndex); if (v1 != v2) { return v1 - v2; } } return 0; } }; Collections.sort(idList, comparator); //System.out.println("AFter sorting:" + idList); int[] currentPositions = new int[length]; int[] indexToRecordIdMapping = new int[length]; byte[] buf1 = new byte[totalSizeInBytes]; byte[] buf2 = new byte[totalSizeInBytes]; for (int i = 0; i < length; i++) { currentPositions[i] = i; indexToRecordIdMapping[i] = i; } for (int i = 0; i < length; i++) { int thisRecordId = indexToRecordIdMapping[i]; int thisRecordIdPos = currentPositions[thisRecordId]; int thatRecordId = idList.get(i); int thatRecordIdPos = currentPositions[thatRecordId]; //swap the buffers mappedByteBuffer.toDirectByteBuffer(thisRecordIdPos * (long) totalSizeInBytes, totalSizeInBytes) .get(buf1); mappedByteBuffer.toDirectByteBuffer(thatRecordIdPos * (long) totalSizeInBytes, totalSizeInBytes) .get(buf2); // mappedByteBuffer.position(thisRecordIdPos * totalSizeInBytes); // mappedByteBuffer.get(buf1); // mappedByteBuffer.position(thatRecordIdPos * totalSizeInBytes); // mappedByteBuffer.get(buf2); mappedByteBuffer.readFrom(buf2, 0, thisRecordIdPos * (long) totalSizeInBytes, totalSizeInBytes); mappedByteBuffer.readFrom(buf1, 0, thatRecordIdPos * (long) totalSizeInBytes, totalSizeInBytes); // mappedByteBuffer.position(thisRecordIdPos * totalSizeInBytes); // mappedByteBuffer.put(buf2); // mappedByteBuffer.position(thatRecordIdPos * totalSizeInBytes); // mappedByteBuffer.put(buf1); //update the positions indexToRecordIdMapping[i] = thatRecordId; indexToRecordIdMapping[thatRecordIdPos] = thisRecordId; currentPositions[thatRecordId] = i; currentPositions[thisRecordId] = thatRecordIdPos; } if (mappedByteBuffer != null) { mappedByteBuffer.flush(); mappedByteBuffer.close(); } } catch (IOException e) { e.printStackTrace(); } finally { // IOUtils.closeQuietly(randomAccessFile); } }
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 ww w .j a va2s . c o m*/ */ 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:vazkii.botania.client.core.handler.MiscellaneousIcons.java
@SubscribeEvent public void dumpAtlas(ArrowLooseEvent evt) { if (!evt.getEntityPlayer().worldObj.isRemote || !((Boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment")) || !evt.getEntityPlayer().isSneaking()) return;/*from w ww . j av a2 s. co m*/ Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE); int width = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_WIDTH); int height = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_HEIGHT); Botania.LOGGER.debug("Dumped atlas %d wide by %d tall%n", width, height); int pixels = width * height; IntBuffer buffer = BufferUtils.createIntBuffer(pixels); int[] pixelValues = new int[pixels]; GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, buffer); buffer.get(pixelValues); BufferedImage bufferedimage = new BufferedImage(width, height, 2); for (int k = 0; k < height; ++k) { for (int l = 0; l < width; ++l) { bufferedimage.setRGB(l, k, pixelValues[k * width + l]); } } File mcFolder = Minecraft.getMinecraft().mcDataDir; File result = new File(mcFolder, "atlas.png"); try { ImageIO.write(bufferedimage, "png", result); } catch (IOException e) { Botania.LOGGER.warn("Failed to dump debug atlas"); } }
From source file:fr.amap.viewer3d.loading.shader.Shader.java
private void extractActiveUniforms() { IntBuffer buf = IntBuffer.allocate(1); gl.glGetProgramiv(programId, GL3.GL_ACTIVE_UNIFORMS, buf); IntBuffer size = IntBuffer.allocate(40); IntBuffer length = IntBuffer.allocate(40); ByteBuffer nm = ByteBuffer.allocate(256); IntBuffer type = IntBuffer.allocate(1); for (int i = 0; i < buf.get(0); i++) { gl.glGetActiveUniform(programId, i, 40, length, size, type, nm); String uniformName = new String(ArrayUtils.subarray(nm.array(), 0, length.get(0))); uniformMap.put(uniformName, gl.glGetUniformLocation(programId, uniformName)); }/* w ww . jav a 2s . c o m*/ }
From source file:fr.amap.viewer3d.loading.shader.Shader.java
private void extractActiveAttributes() { IntBuffer buf = IntBuffer.allocate(1); gl.glGetProgramiv(programId, GL3.GL_ACTIVE_ATTRIBUTES, buf); IntBuffer size = IntBuffer.allocate(40); IntBuffer length = IntBuffer.allocate(40); ByteBuffer nm = ByteBuffer.allocate(256); IntBuffer type = IntBuffer.allocate(1); for (int i = 0; i < buf.get(0); i++) { gl.glGetActiveAttrib(programId, i, 40, length, size, type, nm); String attributeName = new String(ArrayUtils.subarray(nm.array(), 0, length.get(0))); attributeMap.put(attributeName, gl.glGetAttribLocation(programId, attributeName)); }/*from w w w. jav a 2 s . com*/ }
From source file:ubic.basecode.io.ByteArrayConverter.java
/** * @param barray//from w w w . ja v a 2s .c om * @return int[] */ public int[] byteArrayToInts(byte[] barray) { if (barray == null) return null; IntBuffer intBuf = ByteBuffer.wrap(barray).asIntBuffer(); int[] array = new int[intBuf.remaining()]; intBuf.get(array); return array; }
From source file:org.spoutcraft.client.gui.MCRenderDelegate.java
public void render(GenericBitmap bitmap) { int textureId; if (bitmapId.containsKey(bitmap)) { textureId = bitmapId.get(bitmap); } else {//ww w . j a va2 s . co m IntBuffer tmp = IntBuffer.allocate(1); GL11.glGenTextures(tmp); textureId = tmp.get(0); bitmapId.put(bitmap, textureId); } int width = (int) bitmap.getActualWidth(); int height = (int) bitmap.getActualHeight(); int left = bitmap.getLeft(); int top = bitmap.getTop(); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, bitmap.getRawWidth(), bitmap.getRawHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, bitmap.getBuffer()); GL11.glTranslatef((float) bitmap.getScreenX(), (float) bitmap.getScreenY(), 0); // moves texture into place GL11.glPushMatrix(); GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(770, 771); GL11.glDepthMask(false); bindColor(new Color(1.0F, 1.0F, 1.0F)); GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); double tLeft = 0, tTop = 0, rWidth = bitmap.getWidth(), rHeight = bitmap.getHeight(), tWidth = rWidth, tHeight = rHeight; if (top >= 0 && left >= 0) { tWidth = Math.min(tWidth, width); tHeight = Math.min(tHeight, height); tLeft = Math.min(Math.max(0, left), rWidth); tTop = Math.min(Math.max(0, top), rHeight); } Tessellator tessellator = Tessellator.instance; tessellator.startDrawingQuads(); tessellator.addVertexWithUV(0.0D, height, -90, tLeft, tTop); // draw corners tessellator.addVertexWithUV(width, height, -90, tWidth, tTop); tessellator.addVertexWithUV(width, 0.0D, -90, tWidth, tHeight); tessellator.addVertexWithUV(0.0D, 0.0D, -90, tLeft, tHeight); tessellator.draw(); GL11.glDepthMask(true); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glPopMatrix(); GL11.glDisable(GL11.GL_BLEND); }
From source file:org.tsho.dmc2.core.chart.AbsorbingAreaRenderer.java
public void copyDisplay() { IntBuffer buffer = IntBuffer.allocate(grid.length); buffer.put(grid); buffer.flip(); buffer.get(gridBackup); }
From source file:org.tsho.dmc2.core.chart.AbsorbingAreaRenderer.java
public void plotCopiedDisplay() { IntBuffer buffer = IntBuffer.allocate(grid.length); buffer.put(gridBackup); buffer.flip(); buffer.get(grid); }
From source file:uk.org.openseizuredetector.SdServer.java
/** * Set this server to receive pebble data by registering it as * A PebbleDataReceiver/* ww w.java 2 s . c o m*/ */ private void startPebbleServer() { Log.v(TAG, "StartPebbleServer()"); final Handler handler = new Handler(); msgDataHandler = new PebbleKit.PebbleDataReceiver(SD_UUID) { @Override public void receiveData(final Context context, final int transactionId, final PebbleDictionary data) { Log.v(TAG, "Received message from Pebble - data type=" + data.getUnsignedIntegerAsLong(KEY_DATA_TYPE)); // If we have a message, the app must be running mPebbleAppRunningCheck = true; PebbleKit.sendAckToPebble(context, transactionId); //Log.v(TAG,"Message is: "+data.toJsonString()); if (data.getUnsignedIntegerAsLong(KEY_DATA_TYPE) == DATA_TYPE_RESULTS) { Log.v(TAG, "DATA_TYPE = Results"); sdData.dataTime.setToNow(); Log.v(TAG, "sdData.dataTime=" + sdData.dataTime); sdData.alarmState = data.getUnsignedIntegerAsLong(KEY_ALARMSTATE); sdData.maxVal = data.getUnsignedIntegerAsLong(KEY_MAXVAL); sdData.maxFreq = data.getUnsignedIntegerAsLong(KEY_MAXFREQ); sdData.specPower = data.getUnsignedIntegerAsLong(KEY_SPECPOWER); sdData.roiPower = data.getUnsignedIntegerAsLong(KEY_ROIPOWER); sdData.alarmPhrase = "Unknown"; if (sdData.alarmState == 0) { sdData.alarmPhrase = "OK"; } if (sdData.alarmState == 1) { sdData.alarmPhrase = "WARNING"; if (mLogAlarms) { Log.v(TAG, "WARNING - Loggin to SD Card"); writeAlarmToSD(); logData(); } else { Log.v(TAG, "WARNING"); } warningBeep(); } if (sdData.alarmState == 2) { sdData.alarmPhrase = "ALARM"; if (mLogAlarms) { Log.v(TAG, "***ALARM*** - Loggin to SD Card"); writeAlarmToSD(); logData(); } else { Log.v(TAG, "***ALARM***"); } // Make alarm beep tone alarmBeep(); // Send SMS Alarm. if (mSMSAlarm) { Time tnow = new Time(Time.getCurrentTimezone()); tnow.setToNow(); // limit SMS alarms to one per minute if ((tnow.toMillis(false) - mSMSTime.toMillis(false)) > 60000) { sendSMSAlarm(); mSMSTime = tnow; } } } // Read the data that has been sent, and convert it into // an integer array. byte[] byteArr = data.getBytes(KEY_SPEC_DATA); IntBuffer intBuf = ByteBuffer.wrap(byteArr).order(ByteOrder.LITTLE_ENDIAN).asIntBuffer(); int[] intArray = new int[intBuf.remaining()]; intBuf.get(intArray); for (int i = 0; i < intArray.length; i++) { sdData.simpleSpec[i] = intArray[i]; } } if (data.getUnsignedIntegerAsLong(KEY_DATA_TYPE) == DATA_TYPE_SETTINGS) { Log.v(TAG, "DATA_TYPE = Settings"); sdData.alarmFreqMin = data.getUnsignedIntegerAsLong(KEY_ALARM_FREQ_MIN); sdData.alarmFreqMax = data.getUnsignedIntegerAsLong(KEY_ALARM_FREQ_MAX); sdData.nMin = data.getUnsignedIntegerAsLong(KEY_NMIN); sdData.nMax = data.getUnsignedIntegerAsLong(KEY_NMAX); sdData.warnTime = data.getUnsignedIntegerAsLong(KEY_WARN_TIME); sdData.alarmTime = data.getUnsignedIntegerAsLong(KEY_ALARM_TIME); sdData.alarmThresh = data.getUnsignedIntegerAsLong(KEY_ALARM_THRESH); sdData.alarmRatioThresh = data.getUnsignedIntegerAsLong(KEY_ALARM_RATIO_THRESH); sdData.batteryPc = data.getUnsignedIntegerAsLong(KEY_BATTERY_PC); sdData.haveSettings = true; } } }; PebbleKit.registerReceivedDataHandler(this, msgDataHandler); }