示例#1
0
  private double interpolate_value(
      final UnstructuredVolumeObject volume, final int index0, final int index1)
      throws KVSException {
    Buffer buf = volume.values();
    float[] coords = volume.coords();

    final float value0 = this.substitute_plane_equation(new Vector3f(coords, 3 * index0));
    final float value1 = this.substitute_plane_equation(new Vector3f(coords, 3 * index1));
    final float ratio = kvs.core.util.Math.abs(value0 / (value1 - value0));

    if (buf instanceof ByteBuffer) {
      ByteBuffer values = (ByteBuffer) buf;
      return (values.get(index0) + ratio * (values.get(index1) - values.get(index0)));
    } else if (buf instanceof ShortBuffer) {
      ShortBuffer values = (ShortBuffer) buf;
      return (values.get(index0) + ratio * (values.get(index1) - values.get(index0)));
    } else if (buf instanceof IntBuffer) {
      IntBuffer values = (IntBuffer) buf;
      return (values.get(index0) + ratio * (values.get(index1) - values.get(index0)));
    } else if (buf instanceof LongBuffer) {
      LongBuffer values = (LongBuffer) buf;
      return (values.get(index0) + ratio * (values.get(index1) - values.get(index0)));
    } else if (buf instanceof FloatBuffer) {
      FloatBuffer values = (FloatBuffer) buf;
      return (values.get(index0) + ratio * (values.get(index1) - values.get(index0)));
    } else if (buf instanceof DoubleBuffer) {
      DoubleBuffer values = (DoubleBuffer) buf;
      return (values.get(index0) + ratio * (values.get(index1) - values.get(index0)));
    } else if (buf instanceof CharBuffer) {
      CharBuffer values = (CharBuffer) buf;
      return (values.get(index0) + ratio * (values.get(index1) - values.get(index0)));
    } else {
      throw new KVSException("Unsupported data type");
    }
  }
示例#2
0
  protected void loadData(String s) {
    try {
      double[] doubles = parseDoubles(s);

      if (doubles.length != width * height) {
        throw new IOException(
            "File doesn't contain width x height (" + (width * height) + ") values");
      }

      DoubleBuffer buffer = Buffers.newDirectDoubleBuffer(width * height);
      buffer.put(doubles);
      buffer.rewind();

      for (int i = 0; i < width * height; i++) {
        double elev = buffer.get();
        minElevation = Math.min(minElevation, elev);
        maxElevation = Math.max(maxElevation, elev);
      }

      synchronized (elevationLock) {
        this.elevations = buffer;
      }
      // force a recalculate
      lastGlobe = null;
      firePropertyChange(AVKey.LAYER, null, this);
    } catch (IOException e) {
      if (loadAttempts < MAX_DOWNLOAD_ATTEMPTS) {
        loaded = false;
        Downloader.removeCache(url);
        Logging.logger().warning("Deleted corrupt cached data file for " + url);
      } else {
        e.printStackTrace();
      }
    }
  }
 @NotNull
 public static IndexedCollection<Double> ofDouble(@NotNull Collection<Double> intCollection) {
   DoubleBuffer vals = DoubleBuffer.allocate(intCollection.size());
   intCollection.forEach(vals::put);
   vals.flip();
   return new DoubleBufferCollection(vals);
 }
  @Test
  public final void testBufferEndianness() {
    final T m = this.newMatrix();
    final DoubleBuffer b = m.getDirectDoubleBuffer();

    Assert.assertEquals(ByteOrder.nativeOrder(), b.order());
  }
示例#5
0
 public void testToString() {
   String str = buf.toString();
   assertTrue(str.indexOf("Double") >= 0 || str.indexOf("double") >= 0);
   assertTrue(str.indexOf("" + buf.position()) >= 0);
   assertTrue(str.indexOf("" + buf.limit()) >= 0);
   assertTrue(str.indexOf("" + buf.capacity()) >= 0);
 }
示例#6
0
 /**
  * Store this vector into the supplied {@link DoubleBuffer} starting at the specified absolute
  * buffer position/index.
  *
  * <p>This method will not increment the position of the given DoubleBuffer.
  *
  * @param index the absolute position into the DoubleBuffer
  * @param buffer will receive the values of this vector in <tt>x, y, z, w</tt> order
  * @return the passed in buffer
  */
 public DoubleBuffer get(int index, DoubleBuffer buffer) {
   buffer.put(index, x);
   buffer.put(index + 1, y);
   buffer.put(index + 2, z);
   buffer.put(index + 3, w);
   return buffer;
 }
示例#7
0
 public static void main(String[] args) {
   ByteBuffer bb = ByteBuffer.wrap(new byte[] {0, 0, 0, 0, 0, 0, 0, 'a'});
   bb.rewind();
   printnb("Byte Buffer ");
   while (bb.hasRemaining()) printnb(bb.position() + " -> " + bb.get() + ", ");
   print();
   CharBuffer cb = ((ByteBuffer) bb.rewind()).asCharBuffer();
   printnb("Char Buffer ");
   while (cb.hasRemaining()) printnb(cb.position() + " -> " + cb.get() + ", ");
   print();
   FloatBuffer fb = ((ByteBuffer) bb.rewind()).asFloatBuffer();
   printnb("Float Buffer ");
   while (fb.hasRemaining()) printnb(fb.position() + " -> " + fb.get() + ", ");
   print();
   IntBuffer ib = ((ByteBuffer) bb.rewind()).asIntBuffer();
   printnb("Int Buffer ");
   while (ib.hasRemaining()) printnb(ib.position() + " -> " + ib.get() + ", ");
   print();
   LongBuffer lb = ((ByteBuffer) bb.rewind()).asLongBuffer();
   printnb("Long Buffer ");
   while (lb.hasRemaining()) printnb(lb.position() + " -> " + lb.get() + ", ");
   print();
   ShortBuffer sb = ((ByteBuffer) bb.rewind()).asShortBuffer();
   printnb("Short Buffer ");
   while (sb.hasRemaining()) printnb(sb.position() + " -> " + sb.get() + ", ");
   print();
   DoubleBuffer db = ((ByteBuffer) bb.rewind()).asDoubleBuffer();
   printnb("Double Buffer ");
   while (db.hasRemaining()) printnb(db.position() + " -> " + db.get() + ", ");
 }
示例#8
0
 /**
  * Read this vector from the supplied {@link DoubleBuffer} starting at the specified absolute
  * buffer position/index.
  *
  * <p>This method will not increment the position of the given DoubleBuffer.
  *
  * @param index the absolute position into the DoubleBuffer
  * @param buffer values will be read in <tt>x, y, z, w</tt> order
  * @return this
  */
 public Vector4d set(int index, DoubleBuffer buffer) {
   x = buffer.get(index);
   y = buffer.get(index + 1);
   z = buffer.get(index + 2);
   w = buffer.get(index + 3);
   return this;
 }
示例#9
0
  /**
   * Create a data buffer from the given length
   *
   * @param buffer
   * @param length
   */
  public BaseDataBuffer(ByteBuffer buffer, int length) {
    allocationMode = Nd4j.alloc;
    this.length = length;
    buffer.order(ByteOrder.nativeOrder());
    if (allocationMode() == AllocationMode.DIRECT) {
      this.wrappedBuffer = buffer;
    } else if (dataType() == Type.INT) {
      intData = new int[length];
      IntBuffer intBuffer = buffer.asIntBuffer();
      for (int i = 0; i < length; i++) {
        intData[i] = intBuffer.get(i);
      }
    } else if (dataType() == Type.DOUBLE) {
      doubleData = new double[length];
      DoubleBuffer doubleBuffer = buffer.asDoubleBuffer();
      for (int i = 0; i < length; i++) {
        doubleData[i] = doubleBuffer.get(i);
      }

    } else if (dataType() == Type.FLOAT) {
      floatData = new float[length];
      FloatBuffer floatBuffer = buffer.asFloatBuffer();
      for (int i = 0; i < length; i++) {
        floatData[i] = floatBuffer.get(i);
      }
    }
  }
示例#10
0
  @Override
  public DoubleBuffer asNioDouble() {
    if (wrappedBuffer == null) {
      if (offset() == 0) {
        return DoubleBuffer.wrap(doubleData);
      } else return (DoubleBuffer) DoubleBuffer.wrap(doubleData).position(offset());
    }

    if (offset() == 0) {
      return wrappedBuffer.asDoubleBuffer();
    } else return (DoubleBuffer) wrappedBuffer.asDoubleBuffer().position(offset());
  }
 @TestTargetNew(
     level = TestLevel.PARTIAL_COMPLETE,
     notes = "",
     method = "toString",
     args = {})
 public void testToString() {
   String str = buf.toString();
   assertTrue(str.indexOf("Double") >= 0 || str.indexOf("double") >= 0);
   assertTrue(str.indexOf("" + buf.position()) >= 0);
   assertTrue(str.indexOf("" + buf.limit()) >= 0);
   assertTrue(str.indexOf("" + buf.capacity()) >= 0);
 }
  public void double2byte(double[] src, int off, int len, byte[] dst, int off2) {

    if (len > (BUFFER_SIZE / 8)) {
      DoubleBuffer buffer = ByteBuffer.wrap(dst, off2, len * 8).order(order).asDoubleBuffer();
      buffer.put(src, off, len);
    } else {
      doubleBuffer.clear();
      doubleBuffer.put(src, off, len);

      byteBuffer.position(0).limit(len * 8);
      byteBuffer.get(dst, off2, len * 8);
    }
  }
  public void byte2double(byte[] src, int index_src, double[] dst, int index_dst, int len) {

    if (len > (BUFFER_SIZE / 8)) {
      DoubleBuffer buffer = ByteBuffer.wrap(src, index_src, len * 8).order(order).asDoubleBuffer();
      buffer.get(dst, index_dst, len);
    } else {
      byteBuffer.clear();
      byteBuffer.put(src, index_src, len * 8);

      doubleBuffer.position(0).limit(len);
      doubleBuffer.get(dst, index_dst, len);
    }
  }
  /*
   * test for method static DoubleBuffer wrap(double[] array, int offset, int
   * length) test covers following usecases: 1. case for check DoubleBuffer
   * buf2 properties 2. case for check equal between buf2 and double array[]
   * 3. case for check a buf2 dependens to array[] 4. case expected
   * IndexOutOfBoundsException
   */
  @TestTargetNew(
      level = TestLevel.PARTIAL_COMPLETE,
      notes = "",
      method = "wrap",
      args = {double[].class, int.class, int.class})
  public void test_Wrap$DII() {
    double array[] = new double[BUFFER_LENGTH];
    int offset = 5;
    int length = BUFFER_LENGTH - offset;
    loadTestData1(array, 0, BUFFER_LENGTH);
    DoubleBuffer buf2 = DoubleBuffer.wrap(array, offset, length);

    // case: DoubleBuffer buf2 properties is satisfy the conditions
    // specification
    assertEquals(buf2.capacity(), array.length);
    assertEquals(buf2.position(), offset);
    assertEquals(buf2.limit(), offset + length);
    assertEquals(buf2.arrayOffset(), 0);

    // case: DoubleBuffer buf2 is equal to double array[]
    assertContentEquals(buf2, array, 0, array.length);

    // case: DoubleBuffer buf2 is depended to double array[]
    loadTestData2(array, 0, buf.capacity());
    assertContentEquals(buf2, array, 0, array.length);

    // case: expected IndexOutOfBoundsException
    try {
      offset = 7;
      buf2 = DoubleBuffer.wrap(array, offset, length);
      fail("wrap method does not throws expected exception");
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
  }
  /*
   * Class under test for java.nio.DoubleBuffer get(double[])
   */
  @TestTargetNew(
      level = TestLevel.PARTIAL_COMPLETE,
      notes = "",
      method = "get",
      args = {double[].class})
  public void testGetdoubleArray() {
    double array[] = new double[1];
    buf.clear();
    for (int i = 0; i < buf.capacity(); i++) {
      assertEquals(buf.position(), i);
      DoubleBuffer ret = buf.get(array);
      assertEquals(array[0], buf.get(i), 0.01);
      assertSame(ret, buf);
    }

    buf.get(new double[0]);

    try {
      buf.get(array);
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (BufferUnderflowException e) {
      // expected
    }

    try {
      buf.get((double[]) null);
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (NullPointerException e) {
      // expected
    }
  }
示例#16
0
 private void recalculateColors() {
   synchronized (elevationLock) {
     if (elevations != null) {
       elevations.rewind();
       colors.rewind();
       for (int i = 0; i < width * height; i++) {
         double[] color =
             chroma(
                 (elevations.get() - minElevation) / (maxElevation - minElevation), getOpacity());
         colors.put(color);
       }
     }
   }
 }
 /*
  * Class under test for java.nio.DoubleBuffer put(int, double)
  */
 @TestTargetNew(
     level = TestLevel.PARTIAL_COMPLETE,
     notes = "Doesn't verify ReadOnlyBufferException.",
     method = "put",
     args = {int.class, double.class})
 public void testPutintdouble() {
   buf.clear();
   for (int i = 0; i < buf.capacity(); i++) {
     assertEquals(buf.position(), 0);
     DoubleBuffer ret = buf.put(i, (double) i);
     assertEquals(buf.get(i), (double) i, 0.0);
     assertSame(ret, buf);
   }
   try {
     buf.put(-1, 0);
     fail("Should throw Exception"); // $NON-NLS-1$
   } catch (IndexOutOfBoundsException e) {
     // expected
   }
   try {
     buf.put(buf.limit(), 0);
     fail("Should throw Exception"); // $NON-NLS-1$
   } catch (IndexOutOfBoundsException e) {
     // expected
   }
 }
 private static double[] loadRawDouble(String source) throws Exception {
   System.out.println("Loading data...");
   long time = System.nanoTime();
   RandomAccessFile raf = new RandomAccessFile(source, "r");
   FileChannel inChannel = raf.getChannel();
   MappedByteBuffer buffer = inChannel.map(FileChannel.MapMode.READ_ONLY, 0, inChannel.size());
   DoubleBuffer dbuf = buffer.asDoubleBuffer();
   double[] dest = new double[dbuf.remaining()];
   dbuf.get(dest);
   long elapsed = System.nanoTime() - time;
   System.out.println("Load complete... " + (elapsed / 1000000) + "ms");
   raf.close();
   return dest;
 }
  private static void bulkPut(VertexBuffer.Format format, Buffer buf1, Buffer buf2) {
    switch (format) {
      case Byte:
      case Half:
      case UnsignedByte:
        ((ByteBuffer) buf1).put((ByteBuffer) buf2);
        break;
      case Short:
      case UnsignedShort:
        ((ShortBuffer) buf1).put((ShortBuffer) buf2);
        break;

      case Int:
      case UnsignedInt:
        ((IntBuffer) buf1).put((IntBuffer) buf2);
        break;
      case Float:
        ((FloatBuffer) buf1).put((FloatBuffer) buf2);
        break;
      case Double:
        ((DoubleBuffer) buf1).put((DoubleBuffer) buf2);
        break;

      default:
        throw new UnsupportedOperationException("Unrecoginized buffer format: " + format);
    }
  }
示例#20
0
 public static void glWeightARB(DoubleBuffer pWeights) {
   ContextCapabilities caps = GLContext.getCapabilities();
   long function_pointer = caps.glWeightdvARB;
   BufferChecks.checkFunctionAddress(function_pointer);
   BufferChecks.checkDirect(pWeights);
   nglWeightdvARB(pWeights.remaining(), MemoryUtil.getAddress(pWeights), function_pointer);
 }
  private static void putValue(VertexBuffer.Format format, Buffer buf1, Buffer buf2, int index) {
    switch (format) {
      case Byte:
      case Half:
      case UnsignedByte:
        byte b = ((ByteBuffer) buf2).get(index);
        ((ByteBuffer) buf1).put(b);
        break;
      case Short:
      case UnsignedShort:
        short s = ((ShortBuffer) buf2).get(index);
        ((ShortBuffer) buf1).put(s);
        break;

      case Int:
      case UnsignedInt:
        int i = ((IntBuffer) buf2).get(index);
        ((IntBuffer) buf1).put(i);
        break;
      case Float:
        float f = ((FloatBuffer) buf2).get(index);
        ((FloatBuffer) buf1).put(f);
        break;
      case Double:
        double d = ((DoubleBuffer) buf2).get(index);
        ((DoubleBuffer) buf1).put(d);
        break;
      default:
        throw new UnsupportedOperationException("Unrecoginized buffer format: " + format);
    }
  }
示例#22
0
  protected final void enableClipping(int yTop, int yBottom) {
    if (doubleBuffer == null) {
      doubleBuffer = BufferUtils.createByteBuffer(32).asDoubleBuffer();
    }

    doubleBuffer.clear();
    doubleBuffer.put(0).put(1).put(0).put(-yTop).flip();
    glClipPlane(GL_CLIP_PLANE0, doubleBuffer);

    doubleBuffer.clear();
    doubleBuffer.put(0).put(-1).put(0).put(yBottom).flip();
    glClipPlane(GL_CLIP_PLANE1, doubleBuffer);

    glEnable(GL_CLIP_PLANE0);
    glEnable(GL_CLIP_PLANE1);
  }
示例#23
0
 @Override
 public DoubleBuffer asNioDouble() {
   if (wrappedBuffer == null) {
     return DoubleBuffer.wrap(doubleData);
   }
   return wrappedBuffer.asDoubleBuffer();
 }
 @TestTargetNew(
     level = TestLevel.PARTIAL_COMPLETE,
     notes = "",
     method = "order",
     args = {})
 public void testOrder() {
   assertEquals(ByteOrder.nativeOrder(), buf.order());
 }
示例#25
0
 private void assertContentLikeTestData1(
     DoubleBuffer buf, int startIndex, double startValue, int length) {
   double value = startValue;
   for (int i = 0; i < length; i++) {
     assertEquals(buf.get(startIndex + i), value, 0.01);
     value = value + 1.0;
   }
 }
示例#26
0
 public float compute(
     java.nio.DoubleBuffer coords, int stride, int count, float shrink, float shrinkClamp) {
   assert coords.isDirect() : "Buffer must be allocated direct.";
   {
     return LinearMathJNI.btConvexHullComputer_compute__SWIG_1(
         swigCPtr, this, coords, stride, count, shrink, shrinkClamp);
   }
 }
示例#27
0
 public void readFile(File file) {
   try {
     FileChannel channel = new FileInputStream(file).getChannel();
     MappedByteBuffer bb = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
     IntBuffer ib = bb.asIntBuffer();
     _nx = ib.get();
     _ny = ib.get();
     _nz = ib.get();
     bb.position(4 * ib.position());
     DoubleBuffer db = bb.asDoubleBuffer();
     if (_a == null || _a.length != _nx * _ny * _nz) _a = new double[_nx * _ny * _nz];
     db.get(_a);
     channel.close();
   } catch (IOException e) {
     System.out.println(e.getMessage());
   }
 }
示例#28
0
 private void init() throws IOException {
   channel.read(byteBuffer);
   intBuffer.position(0);
   doubleBuffer.position(0);
   byteBuffer.position(0);
   positionInBytes = 0;
   initialized = true;
 }
  @NotNull
  public static IndexedCollection<Double> ofDouble(@NotNull ByteBuffer byteBuffer) {
    int magic = byteBuffer.getInt();
    if (magic != MAGIC) {
      throw new IllegalArgumentException("bad magic number");
    }
    int version = byteBuffer.getInt();
    if (version != VERSION) {
      throw new IllegalArgumentException("bad version number");
    }

    int size = byteBuffer.getInt();
    DoubleBuffer values = byteBuffer.asDoubleBuffer();
    values.limit(size);
    byteBuffer.position(byteBuffer.position() + size * Integer.BYTES);
    return new DoubleBufferCollection(values.slice());
  }
 @TestTargetNew(
     level = TestLevel.PARTIAL_COMPLETE,
     notes = "Abstract method.",
     method = "isReadOnly",
     args = {})
 public void testIsReadOnly() {
   assertFalse(buf.isReadOnly());
 }