Exemple #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");
    }
  }
Exemple #2
0
  private Vector3f interpolate_vertex(final Vector3f vertex0, final Vector3f vertex1) {
    float value0 = this.substitute_plane_equation(vertex0);
    float value1 = this.substitute_plane_equation(vertex1);
    float ratio = kvs.core.util.Math.abs(value0 / (value1 - value0));

    return (vertex0.mul(1.0f - ratio).add(vertex1.mul(ratio)));
  }
Exemple #3
0
  private double interpolate_value(
      final StructuredVolumeObject volume, final Vector3f vertex0, final Vector3f vertex1)
      throws KVSException {
    Buffer buf = volume.values();

    final int line_size = volume.nnodesPerLine();
    final int slice_size = volume.nnodesPerSlice();

    final float value0 = this.substitute_plane_equation(vertex0);
    final float value1 = this.substitute_plane_equation(vertex1);
    final float ratio = kvs.core.util.Math.abs(value0 / (value1 - value0));

    final int index0 =
        (int) (vertex0.getX() + vertex0.getY() * line_size + vertex0.getZ() * slice_size);
    final int index1 =
        (int) (vertex1.getX() + vertex1.getY() * line_size + vertex1.getZ() * slice_size);

    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");
    }
  }
Exemple #4
0
  public final void combine_projection_and_modelview(double[] projection, double[] modelview) {
    /* Calculate a combined matrix PM in order to project the point in the
     * object coordinate system onto the image plane in the window coordinate
     * system. The matrix PM is composed of a modelview marix M and a projection
     * matrix P. It is possible to calculate the efficiently by taking advantage
     * of zero-elements in the M and P.
     *
     * Modelview matrix M:   [ m0, m4, m8,  m12 ]   [ m0, m4, m8,  m12 ]
     *                       [ m1, m5, m9,  m13 ] = [ m1, m5, m9,  m13 ]
     *                       [ m2, m6, m10, m14 ]   [ m2, m6, m10, m14 ]
     *                       [ m3, m7, m11, m15 ]   [  0,  0,   0,   1 ]
     *
     * Projection matrix P:  [ p0, p4, p8,  p12 ]   [ p0,  0, p8,    0 ] (Pers.)
     *                       [ p1, p5, p9,  p13 ] = [  0, p5, p9,    0 ]
     *                       [ p2, p6, p10, p14 ]   [  0,  0, p10, p14 ]
     *                       [ p3, p7, p11, p15 ]   [  0,  0,  -1,   0 ]
     *
     *                                              [ p0,  0,   0, p12 ] (Orth.)
     *                                            = [  0, p5,   0, p13 ]
     *                                              [  0,  0, p10, p14 ]
     *                                              [  0,  0,   0,   1 ]
     *
     * if 'r == -l' in the view volume, P is denoted as follows:
     *
     *       [ p0,  0,   0,   0 ] (Pers.)     [ p0,  0,   0,   0 ] (Orth.)
     *       [  0, p5,   0,   0 ]             [  0, p5,   0,   0 ]
     *       [  0,  0, p10, p14 ]             [  0,  0, p10, p14 ]
     *       [  0,  0,  -1,   0 ]             [  0,  0,   0,   1 ]
     *
     * Combined matrix PM:
     *
     *         [ p0  m0,   p0  m4,   p0  m8,    p0  m12       ] (Pers.)
     *         [ p5  m1,   p5  m5,   p5  m9,    p5  m13       ]
     *         [ p10 m2,   p10 m6,   p10 m10,   p10 m14 + p14 ]
     *         [    -m2,      -m6,      -m10,            -m14 ]
     *
     *         [ p0  m0,   p0  m4,   p0  m8,    p0  m12       ] (Orth.)
     *         [ p5  m1,   p5  m5,   p5  m9,    p5  m13       ]
     *         [ p10 m2,   p10 m6,   p10 m10,   p10 m14 + p14 ]
     *         [      0,        0,         0,               1 ]
     */

    // Row 1.
    Vector4f row1 =
        new Vector4f(
            (float) (projection[0] * modelview[0]),
            (float) (projection[0] * modelview[4]),
            (float) (projection[0] * modelview[8]),
            (float) (projection[0] * modelview[12]));

    // Row 2.
    Vector4f row2 =
        new Vector4f(
            (float) (projection[5] * modelview[1]),
            (float) (projection[5] * modelview[5]),
            (float) (projection[5] * modelview[9]),
            (float) (projection[5] * modelview[13]));

    // Row 3.
    Vector4f row3 =
        new Vector4f(
            (float) (projection[10] * modelview[2]),
            (float) (projection[10] * modelview[6]),
            (float) (projection[10] * modelview[10]),
            (float) (projection[10] * modelview[14] + projection[14]));

    // Row 4.
    Vector4f row4;
    // Perspective.
    if (kvs.core.util.Math.isZero(projection[15])) {
      row4 =
          new Vector4f(
              (float) (-modelview[2]),
              (float) (-modelview[6]),
              (float) (-modelview[10]),
              (float) (-modelview[14]));
    }
    // Orthogonal.
    else {
      row4 = new Vector4f(0.0f, 0.0f, 0.0f, 1.0f);
    }

    m_combined = new Matrix44f(row1, row2, row3, row4);

    // Calculate the inverse of the PM matrix.
    m_inverse = m_combined.inverse();
  }