示例#1
0
ON_Surface::ISO
ON_Surface::IsIsoparametric( const ON_Curve& curve, const ON_Interval* subdomain ) const
{
  ISO iso = not_iso;

  if ( subdomain )
  {
    ON_Interval cdom = curve.Domain();
    double t0 = cdom.NormalizedParameterAt(subdomain->Min());
    double t1 = cdom.NormalizedParameterAt(subdomain->Max());
    if ( t0 < t1-ON_SQRT_EPSILON )
    {
      if ( (t0 > ON_SQRT_EPSILON && t0 < 1.0-ON_SQRT_EPSILON) || (t1 > ON_SQRT_EPSILON && t1 < 1.0-ON_SQRT_EPSILON) )
      {
        cdom.Intersection(*subdomain);
        if ( cdom.IsIncreasing() )
        {
          ON_NurbsCurve nurbs_curve;
          if ( curve.GetNurbForm( nurbs_curve, 0.0,&cdom) )
          {
            return IsIsoparametric( nurbs_curve, 0 );
          }
        }
      }
    }
  }


  ON_BoundingBox bbox;
  double tolerance = 0.0;
  const int dim = curve.Dimension();
  if ( (dim == 2 || dim==3) && curve.GetBoundingBox(bbox) ) 
  {
    iso = IsIsoparametric( bbox );
    switch (iso) {
    case x_iso:
    case W_iso:
    case E_iso:
      // make sure curve is a (nearly) vertical line
      // and weed out vertical scribbles
      tolerance = bbox.m_max.x - bbox.m_min.x;
      if ( tolerance < ON_ZERO_TOLERANCE && ON_ZERO_TOLERANCE*1024.0 <= (bbox.m_max.y-bbox.m_min.y) )
      {
        // 26 March 2007 Dale Lear
        //    If tolerance is tiny, then use ON_ZERO_TOLERANCE
        //    This fixes cases where iso curves where not getting
        //    the correct flag because tol=1e-16 and the closest
        //    point to line had calculation errors of 1e-15.
        tolerance = ON_ZERO_TOLERANCE;
      }
      if ( !curve.IsLinear( tolerance ) )
        iso = not_iso;
      break;
    case y_iso:
    case S_iso:
    case N_iso:
      // make sure curve is a (nearly) horizontal line
      // and weed out horizontal scribbles
      tolerance = bbox.m_max.y - bbox.m_min.y;
      if ( tolerance < ON_ZERO_TOLERANCE && ON_ZERO_TOLERANCE*1024.0 <= (bbox.m_max.x-bbox.m_min.x) )
      {
        // 26 March 2007 Dale Lear
        //    If tolerance is tiny, then use ON_ZERO_TOLERANCE
        //    This fixes cases where iso curves where not getting
        //    the correct flag because tol=1e-16 and the closest
        //    point to line had calculation errors of 1e-15.
        tolerance = ON_ZERO_TOLERANCE;
      }
      if ( !curve.IsLinear( tolerance ) )
        iso = not_iso;
      break;
    default:
      // nothing here
      break;
    }
  }
  return iso;
}
示例#2
0
int
main(int, char**)
{
    srand(time(0));

    ON_3dPoint center(0.0, 0.0, 0.0);
    double radius = 10.0;
    ON_Sphere sphere(center, radius);
    ON_Brep *brep = ON_BrepSphere(sphere);

    ON_3dPoint p1(0.0, 0.0, 0.0);
    ON_3dPoint p2(0.0, 0.0, radius);

    // Point-point intersection
    bu_log("*** Point-point intersection ***\n");
    test_ppi(p1, p1);
    test_ppi(p1, p2);

    // Point-curve intersection
    bu_log("*** Point-curve intersection ***\n");
    // brep->m_C3[0] is an arc curve that starts from (0, 0, -R)
    // to (0, 0, R) through (R, 0, 0) which forms a semicircle.
    ON_Curve *curve = brep->m_C3[0];

    ON_3dPoint mid = curve->PointAt(curve->Domain().Mid());
    bu_log("debug: %f %f %f\n", mid[0], mid[1], mid[2]);

    bu_log("** Part 1 **\n");
    test_pci(p1, *curve);
    test_pci(p2, *curve);

    // Now we use some randomized points (should intersect)
    bu_log("** Part 2 **\n");
    for (int i = 0; i < 10; i++) {
	double x = rand_f(0.0, radius);
	double y = 0.0;
	double z = sqrt(radius*radius-x*x);
	if (rand() % 2) z = -z; // sometimes we have it negative
	ON_3dPoint test_pt(x, y, z);
	test_pci(test_pt, *curve);
    }

    // More randomize points (maybe no intersection)
    bu_log("** Part 3 **\n");
    for (int i = 0; i < 10; i++) {
	// We use test points randomly distributed inside a cube
	// from (-R, -R, -R) to (R, R, R)
	double x = rand_f(-radius, radius);
	double y = rand_f(-radius, radius);
	double z = rand_f(-radius, radius);
	ON_3dPoint test_pt(x, y, z);
	test_pci(test_pt, *curve);
    }

    // Point-surface intersection
    bu_log("*** Point-surface intersection ***\n");
    bu_log("** Part 1 **\n");
    ON_Surface *surf = brep->m_S[0];
    test_psi(p1, *surf);
    test_psi(p2, *surf);

    // Now we use some randomized points (should intersect)
    bu_log("** Part 2 **\n");
    for (int i = 0; i < 10; i++) {
	double x = rand_f(-radius, radius);
	double y_range = sqrt(radius*radius-x*x);
	double y = rand_f(-y_range, y_range);
	double z = sqrt(y_range*y_range-y*y);
	if (rand() % 2) z = -z; // sometimes we have it negative
	ON_3dPoint test_pt(x, y, z);
	test_psi(test_pt, *surf);
    }

    // More randomize points (maybe no intersection)
    bu_log("** Part 3 **\n");
    for (int i = 0; i < 10; i++) {
	// We use test points randomly distributed inside a cube
	// from (-R, -R, -R) to (R, R, R)
	double x = rand_f(-radius, radius);
	double y = rand_f(-radius, radius);
	double z = rand_f(-radius, radius);
	ON_3dPoint test_pt(x, y, z);
	test_psi(test_pt, *surf);
    }

    delete brep;
    bu_log("All finished.\n");
    return 0;
}