Java Code Examples for java.nio.DoubleBuffer#position()

The following examples show how to use java.nio.DoubleBuffer#position() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Image.java    From JavaAV with GNU General Public License v2.0 6 votes vote down vote up
public static void copy(DoubleBuffer srcBuf, int srcStep, DoubleBuffer dstBuf, int dstStep) {
	int w = Math.min(srcStep, dstStep);
	int srcLine = srcBuf.position();
	int dstLine = dstBuf.position();

	while (srcLine < srcBuf.capacity() && dstLine < dstBuf.capacity()) {
		srcBuf.position(srcLine);
		dstBuf.position(dstLine);

		w = Math.min(Math.min(w, srcBuf.remaining()), dstBuf.remaining());

		for (int x = 0; x < w; x++) {
			double in = srcBuf.get();
			double out = in;

			dstBuf.put(out);
		}

		srcLine += srcStep;
		dstLine += dstStep;
	}
}
 
Example 2
Source File: DoubleNioDataBuffer.java    From java with Apache License 2.0 5 votes vote down vote up
@Override
public DoubleDataBuffer slice(long index, long size) {
  Validator.sliceArgs(this, index, size);
  DoubleBuffer sliceBuf = buf.duplicate();
  sliceBuf.position((int)index);
  sliceBuf.limit((int)index + (int)size);
  return new DoubleNioDataBuffer(sliceBuf.slice());
}
 
Example 3
Source File: SearcherImpl.java    From Word2VecJava with MIT License 5 votes vote down vote up
private double[] getVectorOrNull(final String word) {
final Integer index = word2vectorOffset.get(word);
  if(index == null)
	return null;

final DoubleBuffer vectors = model.vectors.duplicate();
double[] result = new double[model.layerSize];
vectors.position(index);
vectors.get(result);
return result;
 }
 
Example 4
Source File: VectorAlgebra.java    From OSPREY3 with GNU General Public License v2.0 4 votes vote down vote up
public static void copy(double[] src, int srcOffset, DoubleBuffer dest, int destOffset) {
	dest.position(destOffset);
	dest.put(src, srcOffset, 3);
}
 
Example 5
Source File: VectorAlgebra.java    From OSPREY3 with GNU General Public License v2.0 4 votes vote down vote up
public static void copy(DoubleBuffer src, int srcOffset, double[] dest, int destOffset) {
	src.position(srcOffset);
	dest[destOffset + 0] = src.get();
	dest[destOffset + 1] = src.get();
	dest[destOffset + 2] = src.get();
}
 
Example 6
Source File: NioBufferInvocations.java    From bazel with Apache License 2.0 4 votes vote down vote up
public static DoubleBuffer getDoubleBufferPosition(DoubleBuffer buffer, int position) {
  return buffer.position(position);
}
 
Example 7
Source File: GeometryRunner.java    From BIMserver with GNU Affero General Public License v3.0 4 votes vote down vote up
private BufferSet appendInvertedGeometry(IntBuffer indicesAsInt, DoubleBuffer verticesAsDouble, FloatBuffer normalsAsFloat, IntBuffer colorIndices) {
	indicesAsInt.position(0);
	normalsAsFloat.position(0);
	
	ByteBuffer newVerticesByteBuffer = ByteBuffer.allocate(verticesAsDouble.capacity() * 16);
	DoubleBuffer newVerticesBuffer = newVerticesByteBuffer.order(ByteOrder.LITTLE_ENDIAN).asDoubleBuffer();
	verticesAsDouble.position(0);
	newVerticesBuffer.put(verticesAsDouble);
	verticesAsDouble.position(0);
	newVerticesBuffer.put(verticesAsDouble);
	
	int nrVertices = verticesAsDouble.capacity() / 3;
	
	ByteBuffer newIntByteBuffer = ByteBuffer.allocate(indicesAsInt.capacity() * 8);
	IntBuffer newIntBuffer = newIntByteBuffer.order(ByteOrder.LITTLE_ENDIAN).asIntBuffer();
	for (int i=0; i<indicesAsInt.capacity(); i+=3) {
		int index1 = indicesAsInt.get();
		int index2 = indicesAsInt.get();
		int index3 = indicesAsInt.get();
		newIntBuffer.put(i, index1);
		newIntBuffer.put(i + 1, index2);
		newIntBuffer.put(i + 2, index3);
		
		// And draw the same triangle again in a different order
		newIntBuffer.put(i + indicesAsInt.capacity(), index1 + nrVertices);
		newIntBuffer.put(i + indicesAsInt.capacity() + 1, index3 + nrVertices);
		newIntBuffer.put(i + indicesAsInt.capacity() + 2, index2 + nrVertices);
	}

	ByteBuffer newNormalsByteBuffer = ByteBuffer.allocate(normalsAsFloat.capacity() * 8);
	FloatBuffer newNormalsBuffer = newNormalsByteBuffer.order(ByteOrder.LITTLE_ENDIAN).asFloatBuffer();
	normalsAsFloat.position(0);
	newNormalsBuffer.put(normalsAsFloat);
	for (int i=0; i<normalsAsFloat.capacity(); i+=3) {
		float[] normal = new float[] {normalsAsFloat.get(i + 0), normalsAsFloat.get(i + 1), normalsAsFloat.get(i + 2)};
		normal = Vector.invert(normal);
		newNormalsBuffer.put(i + normalsAsFloat.capacity(), normal[0]);
		newNormalsBuffer.put(i + 1 + normalsAsFloat.capacity(), normal[1]);
		newNormalsBuffer.put(i + 2 + normalsAsFloat.capacity(), normal[2]);
	}
	
	ByteBuffer newColorsByteBuffer = ByteBuffer.allocate(colorIndices.capacity() * 8);
	IntBuffer newColorsBuffer = newColorsByteBuffer.order(ByteOrder.LITTLE_ENDIAN).asIntBuffer();
	colorIndices.position(0);
	newColorsBuffer.put(colorIndices);
	colorIndices.position(0);
	newColorsBuffer.put(colorIndices);
	
	return new BufferSet(newIntByteBuffer, newVerticesByteBuffer, newNormalsByteBuffer, newColorsByteBuffer);
}
 
Example 8
Source File: Matrix3x2d.java    From JOML with MIT License 2 votes vote down vote up
/**
 * Set the values of this matrix by reading 6 double values from the given {@link DoubleBuffer} in column-major order,
 * starting at its current position.
 * <p>
 * The DoubleBuffer is expected to contain the values in column-major order.
 * <p>
 * The position of the DoubleBuffer will not be changed by this method.
 * 
 * @param buffer
 *              the DoubleBuffer to read the matrix values from in column-major order
 * @return this
 */
public Matrix3x2d set(DoubleBuffer buffer) {
    int pos = buffer.position();
    MemUtil.INSTANCE.get(this, pos, buffer);
    return this;
}