Search in sources :

Example 56 with DoubleBuffer

use of java.nio.DoubleBuffer in project BIMserver by opensourceBIM.

the class BinUtils method doubleToByteArray.

public static byte[] doubleToByteArray(Double inDouble) {
    byte[] bArray = new byte[8];
    ByteBuffer bBuffer = ByteBuffer.wrap(bArray);
    DoubleBuffer lBuffer = bBuffer.asDoubleBuffer();
    lBuffer.put(inDouble);
    return bArray;
}
Also used : DoubleBuffer(java.nio.DoubleBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 57 with DoubleBuffer

use of java.nio.DoubleBuffer in project BIMserver by opensourceBIM.

the class LittleEndianBinUtils method doubleToByteArray.

public static byte[] doubleToByteArray(Double inDouble) {
    byte[] bArray = new byte[8];
    ByteBuffer bBuffer = ByteBuffer.wrap(bArray);
    bBuffer.order(ByteOrder.LITTLE_ENDIAN);
    DoubleBuffer lBuffer = bBuffer.asDoubleBuffer();
    lBuffer.put(inDouble);
    return bArray;
}
Also used : DoubleBuffer(java.nio.DoubleBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 58 with DoubleBuffer

use of java.nio.DoubleBuffer in project BIMserver by opensourceBIM.

the class GeometryUtils method toDoubleArray.

public static double[] toDoubleArray(byte[] data) {
    ByteBuffer buffer = ByteBuffer.wrap(data);
    buffer.order(ByteOrder.LITTLE_ENDIAN);
    DoubleBuffer doubleBuffer = buffer.asDoubleBuffer();
    double[] result = new double[data.length / 8];
    for (int i = 0; i < data.length / 8; i++) {
        result[i] = doubleBuffer.get();
    }
    return result;
}
Also used : DoubleBuffer(java.nio.DoubleBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 59 with DoubleBuffer

use of java.nio.DoubleBuffer in project vcell by virtualcell.

the class MovingBoundaryVtkFileWriter method getVtuMeshData.

public double[] getVtuMeshData(MovingBoundarySimFiles movingBoundarySimFiles, double[] fullRasterData, File destinationDirectory, VtuVarInfo var, int timeIndex) throws Exception {
    MovingBoundaryReader reader = new MovingBoundaryReader(movingBoundarySimFiles.hdf5OutputFile.getAbsolutePath());
    Plane plane = reader.getPlane(timeIndex);
    int numX = plane.getSizeX();
    int numY = plane.getSizeY();
    DoubleBuffer buffer = DoubleBuffer.wrap(new double[numX * numY]);
    for (int j = 0; j < numY; j++) {
        for (int i = 0; i < numX; i++) {
            Element element = plane.get(i, j);
            if (element != null) {
                if (var.variableDomain == VariableDomain.VARIABLEDOMAIN_VOLUME && var.domainName.equals(reader.getFakeInsideDomainName())) {
                    if (element.position == Position.BOUNDARY || element.position == Position.INSIDE) {
                        buffer.put(fullRasterData[i + numX * j]);
                    // buffer.put(species.mass);
                    // buffer.put(i+j*numX);
                    // buffer.put(i);
                    // buffer.put(j);
                    } else {
                    // skip this element, it is "outside" domain.
                    }
                }
            } else {
                System.out.println("found empty species at index(" + i + "," + j + ")");
            }
        }
    }
    double[] volumeData = buffer.array();
    double[] data = null;
    switch(var.variableDomain) {
        case VARIABLEDOMAIN_CONTOUR:
            {
                break;
            }
        case VARIABLEDOMAIN_MEMBRANE:
            {
                /*
				MovingBoundaryIndexData movingBoundaryIndexData = VisMeshUtils.readChomboIndexData(chomboIndexDataFile);
				List<ChomboVisMembraneIndex> cellIndices = new ArrayList<ChomboVisMembraneIndex>();
				for (ChomboSurfaceIndex chomboSurfaceIndex : chomboIndexData.chomboSurfaceIndices){
					cellIndices.add(new SimpleChomboVisMembraneIndex(chomboSurfaceIndex.index));
				}
				data = chomboMeshData.getMembraneCellData(var.name, cellIndices);
				*/
                break;
            }
        case VARIABLEDOMAIN_NONSPATIAL:
            {
                break;
            }
        case VARIABLEDOMAIN_POSTPROCESSING:
            {
                break;
            }
        case VARIABLEDOMAIN_UNKNOWN:
            {
                break;
            }
        case VARIABLEDOMAIN_VOLUME:
            {
                MovingBoundaryIndexData movingBoundaryIndexData = getMovingBoundaryIndexData(movingBoundarySimFiles, destinationDirectory, var, timeIndex);
                if (var.functionExpression != null) {
                    throw new UnsupportedOperationException();
                } else {
                    int numElements = movingBoundaryIndexData.movingBoundaryVolumeIndices.size();
                    data = new double[numElements];
                    int i = 0;
                    for (MovingBoundaryVolumeIndex mbvIndex : movingBoundaryIndexData.movingBoundaryVolumeIndices) {
                        data[i++] = volumeData[mbvIndex.index];
                    }
                }
                break;
            }
        default:
            {
                throw new RuntimeException("unsupported variable type " + var.variableDomain.name() + " for variable " + var.name);
            }
    }
    return data;
}
Also used : DoubleBuffer(java.nio.DoubleBuffer) MovingBoundaryIndexData(org.vcell.vis.vismesh.thrift.MovingBoundaryIndexData) Plane(cbit.vcell.solvers.mb.MovingBoundaryTypes.Plane) Element(cbit.vcell.solvers.mb.MovingBoundaryTypes.Element) MovingBoundaryReader(cbit.vcell.solvers.mb.MovingBoundaryReader) MovingBoundaryVolumeIndex(org.vcell.vis.vismesh.thrift.MovingBoundaryVolumeIndex)

Example 60 with DoubleBuffer

use of java.nio.DoubleBuffer in project javacpp by bytedeco.

the class PointerTest method testDoublePointer.

@Test
public void testDoublePointer() {
    System.out.println("DoublePointer");
    int doubleSize = Double.SIZE / 8;
    assertEquals(doubleSize, Loader.sizeof(DoublePointer.class));
    double[] array = new double[8192];
    DoublePointer pointer = new DoublePointer(array);
    assertEquals(array.length, pointer.limit());
    assertEquals(array.length, pointer.capacity());
    for (int i = 0; i < array.length; i++) {
        array[i] = i;
        pointer.put(i, i);
        assertEquals(array[i], pointer.get(i), 0);
    }
    for (int i = 0; i < array.length; i++) {
        pointer.position(i).put(array[i]);
        assertEquals(array[i], pointer.position(i).get(), 0);
    }
    double[] array2 = new double[array.length];
    pointer.position(0).get(array2);
    assertArrayEquals(array, array2, 0);
    DoubleBuffer buffer = pointer.asBuffer();
    assertTrue(buffer.compareTo(DoubleBuffer.wrap(array)) == 0);
    assertEquals(pointer.address(), new DoublePointer(buffer).address());
    int offset = 42;
    pointer.put(array, offset, array.length - offset);
    pointer.get(array2, offset, array.length - offset);
    assertArrayEquals(array, array2, 0);
    DoublePointer pointer2 = new DoublePointer(array.length).zero();
    pointer2.position(10).limit(30).fill(0xFF);
    pointer2.position(20).put(pointer.position(20).limit(30));
    pointer.position(0);
    pointer2.position(0);
    for (int i = 0; i < array.length; i++) {
        if (i < 10) {
            assertEquals(0, pointer2.get(i), 0);
        } else if (i < 20) {
            assertEquals(Double.longBitsToDouble((long) -1), pointer2.get(i), 0);
        } else if (i < 30) {
            assertEquals(pointer.get(i), pointer2.get(i), 0);
        } else {
            assertEquals(0, pointer2.get(i), 0);
        }
    }
    assertEquals(maxBytes, Pointer.maxBytes);
    int chunks = 10;
    DoublePointer[] pointers = new DoublePointer[chunks];
    long chunkSize = Pointer.maxBytes / doubleSize / chunks;
    for (int j = 0; j < chunks - 1; j++) {
        pointers[j] = new DoublePointer(chunkSize);
    }
    assertTrue(Pointer.DeallocatorReference.totalBytes >= (chunks - 1) * chunkSize * doubleSize);
    try {
        fieldReference = pointers;
        new DoublePointer(chunkSize);
        fail("OutOfMemoryError should have been thrown.");
    } catch (OutOfMemoryError e) {
    // System.out.println(e);
    // System.out.println(e.getCause());
    }
    for (int j = 0; j < chunks; j++) {
        pointers[j] = null;
    }
    // make sure garbage collection runs
    fieldReference = null;
    pointers[0] = new DoublePointer(chunkSize);
    assertTrue(Pointer.DeallocatorReference.totalBytes < (chunks - 1) * chunkSize * doubleSize);
    assertTrue(Pointer.DeallocatorReference.totalBytes >= chunkSize * doubleSize);
    System.out.println(Pointer.DeallocatorReference.totalBytes + " " + chunkSize * doubleSize);
}
Also used : DoubleBuffer(java.nio.DoubleBuffer) Test(org.junit.Test)

Aggregations

DoubleBuffer (java.nio.DoubleBuffer)162 ByteBuffer (java.nio.ByteBuffer)39 FloatBuffer (java.nio.FloatBuffer)26 IntBuffer (java.nio.IntBuffer)25 ShortBuffer (java.nio.ShortBuffer)22 LongBuffer (java.nio.LongBuffer)14 CharBuffer (java.nio.CharBuffer)11 BufferOverflowException (java.nio.BufferOverflowException)8 IOException (java.io.IOException)5 BufferUnderflowException (java.nio.BufferUnderflowException)5 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 ServerDenseDoubleRow (com.tencent.angel.ps.impl.matrix.ServerDenseDoubleRow)4 Test (org.junit.Test)4 InvalidMarkException (java.nio.InvalidMarkException)3 Random (java.util.Random)3 BytePointer (org.bytedeco.javacpp.BytePointer)3 DoublePointer (org.bytedeco.javacpp.DoublePointer)3 FloatPointer (org.bytedeco.javacpp.FloatPointer)3 IntPointer (org.bytedeco.javacpp.IntPointer)3