예제 #1
0
  public static SphericalRegion getEnclosingSphere(RectangularBox box) {
    Point3f centre =
        new Point3f(
            (box.getHighestXValue() + box.getLowestXValue()) / 2,
            (box.getHighestYValue() + box.getLowestYValue()) / 2,
            (box.getHighestZValue() + box.getLowestZValue()) / 2);

    float radius =
        centre.distance(
            new Point3f(box.getLowestXValue(), box.getLowestYValue(), box.getLowestZValue()));

    SphericalRegion newSphere = new SphericalRegion(centre.x, centre.y, centre.z, radius);

    return newSphere;
  }
예제 #2
0
  /**
   * Compute the vertex positions for the four voxels in the current slice to be bilinearly
   * interpolated.
   *
   * @param i0 the current permuted indices of the upper left voxel in the 2x2 block of voxels in
   *     the slice
   * @param i1 DOCUMENT ME!
   * @param i2 DOCUMENT ME!
   */
  protected final void computePositions(int i0, int i1, int i2) {

    switch (m_iPermute) {
      case 0:
        m_kP00.x = i0 - (0.5f * m_aiBound[0]);
        m_kP00.y = i1 - (0.5f * m_aiBound[1]);
        m_kP00.z = i2 - (0.5f * m_aiBound[2]);
        m_kP10.x = m_kP00.x + 1.0f;
        m_kP10.y = m_kP00.y;
        m_kP10.z = m_kP00.z;
        m_kP01.x = m_kP00.x;
        m_kP01.y = m_kP00.y + 1.0f;
        m_kP01.z = m_kP00.z;
        m_kP11.x = m_kP10.x;
        m_kP11.y = m_kP01.y;
        m_kP11.z = m_kP00.z;
        break;

      case 1:
        m_kP00.y = i0 - (0.5f * m_aiBound[1]);
        m_kP00.z = i1 - (0.5f * m_aiBound[2]);
        m_kP00.x = i2 - (0.5f * m_aiBound[0]);
        m_kP10.y = m_kP00.y + 1.0f;
        m_kP10.z = m_kP00.z;
        m_kP10.x = m_kP00.x;
        m_kP01.y = m_kP00.y;
        m_kP01.z = m_kP00.z + 1.0f;
        m_kP01.x = m_kP00.x;
        m_kP11.y = m_kP10.y;
        m_kP11.z = m_kP01.z;
        m_kP11.x = m_kP00.x;
        break;

      case 2:
        m_kP00.z = i0 - (0.5f * m_aiBound[2]);
        m_kP00.x = i1 - (0.5f * m_aiBound[0]);
        m_kP00.y = i2 - (0.5f * m_aiBound[1]);
        m_kP10.z = m_kP00.z + 1.0f;
        m_kP10.x = m_kP00.x;
        m_kP10.y = m_kP00.y;
        m_kP01.z = m_kP00.z;
        m_kP01.x = m_kP00.x + 1.0f;
        m_kP01.y = m_kP00.y;
        m_kP11.z = m_kP10.z;
        m_kP11.x = m_kP01.x;
        m_kP11.y = m_kP00.y;
        break;
    }
  }
  /**
   * Computes the new transform for this interpolator for a given alpha value.
   *
   * @param alphaValue alpha value between 0.0 and 1.0
   * @param transform object that receives the computed transform for the specified alpha value
   * @since Java 3D 1.3
   */
  public void computeTransform(float alphaValue, Transform3D transform) {
    // compute the current value of u from alpha and the
    // determine lower and upper knot points
    computePathInterpolation(alphaValue);

    // Determine the segment within which we will be interpolating
    currentSegmentIndex = this.lowerKnot - 1;

    // if we are at the start of the curve
    if (currentSegmentIndex == 0 && currentU == 0f) {
      iHeading = keyFrames[1].heading;
      iPitch = keyFrames[1].pitch;
      iBank = keyFrames[1].bank;
      iPos.set(keyFrames[1].position);
      iScale.set(keyFrames[1].scale);

      // if we are at the end of the curve
    } else if (currentSegmentIndex == (numSegments - 1) && currentU == 1.0) {
      iHeading = keyFrames[upperKnot].heading;
      iPitch = keyFrames[upperKnot].pitch;
      iBank = keyFrames[upperKnot].bank;
      iPos.set(keyFrames[upperKnot].position);
      iScale.set(keyFrames[upperKnot].scale);

      // if we are somewhere in between the curve
    } else {
      // Get a reference to the current spline segment i.e. the
      // one bounded by lowerKnot and upperKnot
      currentSegment = cubicSplineCurve.getSegment(currentSegmentIndex);

      // interpolate quaternions
      iHeading = currentSegment.getInterpolatedHeading(currentU);
      iPitch = currentSegment.getInterpolatedPitch(currentU);
      iBank = currentSegment.getInterpolatedBank(currentU);

      // interpolate position
      currentSegment.getInterpolatedPositionVector(currentU, iPos);

      // interpolate position
      currentSegment.getInterpolatedScale(currentU, iScale);
      // System.out.println("Pos :" + iPos);
    }

    // Modification by ReubenDB

    if (colorRampingInterpolate == true) {
      float[] curPos = new float[3];
      iPos.get(curPos);

      myColorRamp.getColor(curPos[1], histColor);
      // System.out.println("SETING COLOR:" + histColor + " CurPos: " + curPos[0] + ", " + curPos[1]
      // + ", " + curPos[2]);
      objectCA.setColor(histColor);
      // System.out.println("CurrentAlpha = " + myAlpha.value());
    }

    if (timeDisplayInterpolate == true) {
      myTimeDisplay.updateDisplayFromAlpha(myAlpha.value());
      // System.out.println(myAlpha.value());
    }

    // Generate a transformation matrix in tMat using interpolated
    // heading, pitch and bank
    pitchMat.setIdentity();
    pitchMat.rotX(-iPitch);
    bankMat.setIdentity();
    bankMat.rotZ(iBank);
    tMat.setIdentity();
    tMat.rotY(-iHeading);
    tMat.mul(pitchMat);
    tMat.mul(bankMat);

    // TODO: Vijay - Handle Non-Uniform scale
    // Currently this interpolator does not handle non uniform scale
    // We cheat by just taking the x scale component

    // Scale the transformation matrix
    sMat.set((double) iScale.x);
    tMat.mul(sMat);

    // Set the translation components.
    tMat.m03 = iPos.x;
    tMat.m13 = iPos.y;
    tMat.m23 = iPos.z;
    rotation.set(tMat);

    // construct a Transform3D from:  axis * rotation * axisInverse
    transform.mul(axis, rotation);
    transform.mul(transform, axisInverse);
  }