Exemplo n.º 1
0
DBL BicubicPatch::determine_subpatch_flatness(const ControlPoints *Patch)
{
    int i, j;
    DBL d, dist, temp1;
    Vector3d n;
    Vector3d TempV;
    Vector3d vertices[3];

    vertices[0] = (*Patch)[0][0];
    vertices[1] = (*Patch)[0][3];

    TempV = vertices[0] - vertices[1];

    temp1 = TempV.length();

    if (fabs(temp1) < EPSILON)
    {
        /*
         * Degenerate in the V direction for U = 0. This is ok if the other
         * two corners are distinct from the lower left corner - I'm sure there
         * are cases where the corners coincide and the middle has good values,
         * but that is somewhat pathalogical and won't be considered.
         */

        vertices[1] = (*Patch)[3][3];

        TempV = vertices[0] - vertices[1];

        temp1 = TempV.length();

        if (fabs(temp1) < EPSILON)
        {
            return (-1.0);
        }

        vertices[2] = (*Patch)[3][0];

        TempV = vertices[0] - vertices[1];

        temp1 = TempV.length();

        if (fabs(temp1) < EPSILON)
        {
            return (-1.0);
        }

        TempV = vertices[1] - vertices[2];

        temp1 = TempV.length();

        if (fabs(temp1) < EPSILON)
        {
            return (-1.0);
        }
    }
    else
    {
        vertices[2] = (*Patch)[3][0];

        TempV = vertices[0] - vertices[1];

        temp1 = TempV.length();

        if (fabs(temp1) < EPSILON)
        {
            vertices[2] = (*Patch)[3][3];

            TempV = vertices[0] - vertices[2];

            temp1 = TempV.length();

            if (fabs(temp1) < EPSILON)
            {
                return (-1.0);
            }

            TempV = vertices[1] - vertices[2];

            temp1 = TempV.length();

            if (fabs(temp1) < EPSILON)
            {
                return (-1.0);
            }
        }
        else
        {
            TempV = vertices[1] - vertices[2];

            temp1 = TempV.length();

            if (fabs(temp1) < EPSILON)
            {
                return (-1.0);
            }
        }
    }

    /*
     * Now that a good set of candidate points has been found,
     * find the plane equations for the patch.
     */

    if (subpatch_normal(vertices[0], vertices[1], vertices[2], n, &d))
    {
        /*
         * Step through all vertices and see what the maximum
         * distance from the plane happens to be.
         */

        dist = 0.0;

        for (i = 0; i < 4; i++)
        {
            for (j = 0; j < 4; j++)
            {
                temp1 = fabs(point_plane_distance((*Patch)[i][j], n, d));

                if (temp1 > dist)
                {
                    dist = temp1;
                }
            }
        }

        return (dist);
    }
    else
    {
/*
        Debug_Info("Subpatch normal failed in determine_subpatch_flatness\n");
*/

        return (-1.0);
    }
}
Exemplo n.º 2
0
static DBL determine_subpatch_flatness(VECTOR (*Patch)[4][4])
{
  int i, j;
  DBL d, dist, temp1;
  VECTOR n, TempV;
  VECTOR vertices[4];

  Assign_Vector(vertices[0], (*Patch)[0][0]);
  Assign_Vector(vertices[1], (*Patch)[0][3]);

  VSub(TempV, vertices[0], vertices[1]);

  VLength(temp1, TempV);

  if (fabs(temp1) < EPSILON)
  {
    /*
     * Degenerate in the V direction for U = 0. This is ok if the other
     * two corners are distinct from the lower left corner - I'm sure there
     * are cases where the corners coincide and the middle has good values,
     * but that is somewhat pathalogical and won't be considered.
     */

    Assign_Vector(vertices[1], (*Patch)[3][3]);

    VSub(TempV, vertices[0], vertices[1]);

    VLength(temp1, TempV);

    if (fabs(temp1) < EPSILON)
    {
      return (-1.0);
    }

    Assign_Vector(vertices[2], (*Patch)[3][0]);

    VSub(TempV, vertices[0], vertices[1]);

    VLength(temp1, TempV);

    if (fabs(temp1) < EPSILON)
    {
      return (-1.0);
    }

    VSub(TempV, vertices[1], vertices[2]);

    VLength(temp1, TempV);

    if (fabs(temp1) < EPSILON)
    {
      return (-1.0);
    }
  }
  else
  {
    Assign_Vector(vertices[2], (*Patch)[3][0]);

    VSub(TempV, vertices[0], vertices[1]);

    VLength(temp1, TempV);

    if (fabs(temp1) < EPSILON)
    {
      Assign_Vector(vertices[2], (*Patch)[3][3]);

      VSub(TempV, vertices[0], vertices[2]);

      VLength(temp1, TempV);

      if (fabs(temp1) < EPSILON)
      {
        return (-1.0);
      }

      VSub(TempV, vertices[1], vertices[2]);

      VLength(temp1, TempV);

      if (fabs(temp1) < EPSILON)
      {
        return (-1.0);
      }
    }
    else
    {
      VSub(TempV, vertices[1], vertices[2]);

      VLength(temp1, TempV);

      if (fabs(temp1) < EPSILON)
      {
        return (-1.0);
      }
    }
  }

  /*
   * Now that a good set of candidate points has been found,
   * find the plane equations for the patch.
   */

  if (subpatch_normal(vertices[0], vertices[1], vertices[2], n, &d))
  {
    /*
     * Step through all vertices and see what the maximum
     * distance from the plane happens to be.
     */

    dist = 0.0;

    for (i = 0; i < 4; i++)
    {
      for (j = 0; j < 4; j++)
      {
        temp1 = fabs(point_plane_distance(((*Patch)[i][j]), n, &d));

        if (temp1 > dist)
        {
          dist = temp1;
        }
      }
    }

    return (dist);
  }
  else
  {
/*
    Debug_Info("Subpatch normal failed in determine_subpatch_flatness\n");
*/

    return (-1.0);
  }
}