static void MakeTwistedCubeFace( ON_Brep& brep,
     int si,      // index of 3d surface
     int s_dir,   // orientation of surface with respect to brep
     //int vSWi, int vSEi, int vNEi, int vNWi, // Indices of corner vertices listed in SW,SE,NW,NE order
     int eSi,     // index of edge on south side of surface
     int eS_dir,  // orientation of edge with respect to surface trim
     int eEi,     // index of edge on south side of surface
     int eE_dir,  // orientation of edge with respect to surface trim
     int eNi,     // index of edge on south side of surface
     int eN_dir,  // orientation of edge with respect to surface trim
     int eWi,     // index of edge on south side of surface
     int eW_dir   // orientation of edge with respect to surface trim
                                )
{
  ON_BrepFace& face = brep.NewFace(si);

  MakeTwistedCubeTrimmingLoop( brep, face,
                //vSWi, vSEi, vNEi, vNWi, 
                eSi, eS_dir, 
                eEi, eE_dir, 
                eNi, eN_dir, 
                eWi, eW_dir 
                );

  face.m_bRev = (s_dir == -1);
}
static void MakeTrimmedFace( ON_Brep& brep,
     int si,      // index of 3d surface
     int s_dir,   // orientation of surface with respect to surfce
     int v0, int v1, int v2, // Indices of corner vertices
     int e0,     // index of first edge
     int e0_dir,  // orientation of edge
     int e1,     // index of second edge
     int e1_dir,  // orientation of edge
     int e2,     // index of third edge
     int e2_dir  // orientation of edge
                           )
{
	//Add new face to brep
  ON_BrepFace& face = brep.NewFace(si);

	//Create loop and trims for the face
  MakeTrimmingLoop( brep, face,
                v0, v1, v2, 
                e0, e0_dir, 
                e1, e1_dir, 
                e2, e2_dir 
                );

	//Set face direction relative to surface direction
  face.m_bRev = (s_dir == -1);
}
Ejemplo n.º 3
0
static
bool ON_BrepExtrudeHelper_MakeCap(
          ON_Brep& brep,
          int bottom_loop_index,
          const ON_3dVector path_vector,
          const int* side_face_index
          )
{
  bool bCap = true;
  // make cap
  if ( !ON_BrepExtrudeHelper_CheckLoop( brep, bottom_loop_index ) )
    return false;
  brep.m_F.Reserve(brep.m_F.Count() + 1);
  brep.m_L.Reserve(brep.m_L.Count() + 1);
  const ON_BrepLoop& bottom_loop = brep.m_L[bottom_loop_index];
  const ON_BrepFace& bottom_face = brep.m_F[bottom_loop.m_fi];
  const ON_Surface* bottom_surface = bottom_face.SurfaceOf();
  ON_Surface* top_surface = bottom_surface->Duplicate();
  top_surface->Translate( path_vector );
  int top_surface_index = brep.AddSurface( top_surface );
  ON_BrepFace& top_face = brep.NewFace( top_surface_index );

  bCap = ON_BrepExtrudeHelper_MakeTopLoop( brep, top_face, bottom_loop_index, path_vector, side_face_index );
  if ( bCap )
  {
    ON_BrepLoop& top_loop = brep.m_L[brep.m_L.Count()-1];
    if ( bottom_loop.m_type == ON_BrepLoop::inner )
    {
      // we capped an inner boundary
      // top_loop.m_type = ON_BrepLoop::outer; // done in ON_BrepExtrudeHelper_MakeTopLoop
      brep.FlipLoop(top_loop);
    }
    else if ( bottom_loop.m_type == ON_BrepLoop::outer )
    {
      // we capped an outer boundary
      // top_loop.m_type = ON_BrepLoop::outer; // done in ON_BrepExtrudeHelper_MakeTopLoop
      brep.FlipFace(top_face);
    }
  }
  else
  {
    // delete partially made cap face
    brep.DeleteFace( top_face, false );
    delete brep.m_S[top_surface_index];
    brep.m_S[top_surface_index] = 0;
  }
  return bCap;
}
Ejemplo n.º 4
0
int ON_BrepExtrudeEdge( 
          ON_Brep& brep,
          int edge_index,
          const ON_Curve& path_curve
          )
{
  ON_3dVector path_vector;

  if ( edge_index < 0 && edge_index >= brep.m_E.Count() )
    return false;

  if ( !ON_BrepExtrudeHelper_CheckPathCurve(path_curve,path_vector) )
    return false;


  // make sides
  bool bRev = false;
  ON_SumSurface* sum_srf = ON_BrepExtrudeHelper_MakeSumSrf( 
                              path_curve, brep.m_E[edge_index], bRev );

  if ( !sum_srf )
    return false;

  int vid[4], eid[4], bRev3d[4];

  vid[0] = brep.m_E[edge_index].m_vi[bRev?0:1];
  vid[1] = brep.m_E[edge_index].m_vi[bRev?1:0];
  vid[2] = -1;
  vid[3] = -1;

  eid[0] = edge_index; // "south side edge"
  eid[1] = -1;
  eid[2] = -1;
  eid[3] = -1;

  bRev3d[0] = bRev?0:1;
  bRev3d[1] = 0;
  bRev3d[2] = 0;
  bRev3d[3] = 0;

  return brep.NewFace( sum_srf, vid, eid, bRev3d ) ? true : false;
}
Ejemplo n.º 5
0
void
MakeTwistedCubeFace(ON_Brep& brep,
		    int surf,
		    int orientation,
		    int v0, int v1, int v2, int v3, // the indices of corner vertices
		    int e0, int eo0, // edge index + orientation
		    int e1, int eo1,
		    int e2, int eo2,
		    int e3, int eo3)
{
    ON_BrepFace& face = brep.NewFace(surf);
    MakeTwistedCubeTrimmingLoop(brep,
				face,
				v0, v1, v2, v3,
				e0, eo0,
				e1, eo1,
				e2, eo2,
				e3, eo3);
    // should the normal be reversed?
    face.m_bRev = (orientation == -1);
}
Ejemplo n.º 6
0
/* TODO - Need to find a more compact, efficient way to
 * do this - shouldn't need 24 3d curves... */
ON_Brep *
Cobb_Sphere(double UNUSED(radius), ON_3dPoint *UNUSED(origin))
{
    ON_Brep *b = ON_Brep::New();

    // Patch 1 of 6
    ON_BezierSurface *b1 = ON_CobbSphereFace(0, 0);
    ON_NurbsSurface *p1_nurb = ON_NurbsSurface::New();
    b1->GetNurbForm(*p1_nurb);
    b->NewFace(*p1_nurb);

    // Patch 2 of 6
    ON_BezierSurface *b2 = ON_CobbSphereFace(90, 0);
    ON_NurbsSurface *p2_nurb = ON_NurbsSurface::New();
    b2->GetNurbForm(*p2_nurb);
    b->NewFace(*p2_nurb);

    // Patch 3 of 6
    ON_BezierSurface *b3 = ON_CobbSphereFace(180, 0);
    ON_NurbsSurface *p3_nurb = ON_NurbsSurface::New();
    b3->GetNurbForm(*p3_nurb);
    b->NewFace(*p3_nurb);

    // Patch 4 of 6
    ON_BezierSurface *b4 = ON_CobbSphereFace(270, 0);
    ON_NurbsSurface *p4_nurb = ON_NurbsSurface::New();
    b4->GetNurbForm(*p4_nurb);
    b->NewFace(*p4_nurb);

    // Patch 5 of 6
    ON_BezierSurface *b5 = ON_CobbSphereFace(90, 90);
    ON_NurbsSurface *p5_nurb = ON_NurbsSurface::New();
    b5->GetNurbForm(*p5_nurb);
    b->NewFace(*p5_nurb);

    // Patch 6 of 6
    ON_BezierSurface *b6 = ON_CobbSphereFace(90, 270);
    ON_NurbsSurface *p6_nurb = ON_NurbsSurface::New();
    b6->GetNurbForm(*p6_nurb);
    b->NewFace(*p6_nurb);


    b->Standardize();
    b->Compact();

    return b;
}
Ejemplo n.º 7
0
int ON_BrepConeEdge( 
          ON_Brep& brep,
          int edge_index,
          ON_3dPoint apex_point
          )
{
  //ON_3dVector path_vector;

  if ( edge_index < 0 && edge_index >= brep.m_E.Count() )
    return false;

  // make sides
  ON_NurbsSurface* cone_srf = ON_BrepExtrudeHelper_MakeConeSrf( 
                              apex_point, brep.m_E[edge_index], false );

  if ( !cone_srf )
    return false;

  int vid[4], eid[4], bRev3d[4];

  vid[0] = brep.m_E[edge_index].m_vi[0];
  vid[1] = brep.m_E[edge_index].m_vi[1];
  vid[2] = -1;
  vid[3] = -1;

  eid[0] = edge_index;
  eid[1] = -1;
  eid[2] = -1;
  eid[3] = -1;

  bRev3d[0] = 0;
  bRev3d[1] = 0;
  bRev3d[2] = 0;
  bRev3d[3] = 0;

  return brep.NewFace( cone_srf, vid, eid, bRev3d ) ? true : false;
}
Ejemplo n.º 8
0
static ON_Brep *
generate_brep(int count, ON_3dPoint *points)
{
    ON_Brep *brep = new ON_Brep();

    /* make an arb8 */

    // VERTICES

    for (int i=0; i<count; i++) {
	brep->NewVertex(points[i], SMALL_FASTF);
    }

    ON_3dPoint p8 = ON_3dPoint(-1.0, 0.0, -1.0);
    ON_3dPoint p9 = ON_3dPoint(2.0, 0.0, -1.0);
    ON_3dPoint p10 = ON_3dPoint(2.0, 0.0, 3.5);
    ON_3dPoint p11 = ON_3dPoint(-1.0, 0.0, 3.5);

    brep->NewVertex(p8, SMALL_FASTF); // 8
    brep->NewVertex(p9, SMALL_FASTF); // 9
    brep->NewVertex(p10, SMALL_FASTF); // 10
    brep->NewVertex(p11, SMALL_FASTF); // 11

    // LEFT SEGMENTS

    // 0
    ON_Curve* segment01 = new ON_LineCurve(points[0], points[1]);
    segment01->SetDomain(0.0, 1.0);
    brep->m_C3.Append(segment01);

    // 1
    ON_Curve* segment12 = new ON_LineCurve(points[1], points[2]);
    segment12->SetDomain(0.0, 1.0);
    brep->m_C3.Append(segment12);

    // 2
    ON_Curve* segment23 = new ON_LineCurve(points[2], points[3]);
    segment23->SetDomain(0.0, 1.0);
    brep->m_C3.Append(segment23);

    // 3
    ON_Curve* segment30 = new ON_LineCurve(points[3], points[0]);
    segment30->SetDomain(0.0, 1.0);
    brep->m_C3.Append(segment30);

    // RIGHT SEGMENTS

    // 4
    ON_Curve* segment45 = new ON_LineCurve(points[5], points[4]);
    segment45->SetDomain(0.0, 1.0);
    brep->m_C3.Append(segment45);

    // 5
    ON_Curve* segment56 = new ON_LineCurve(points[6], points[5]);
    segment56->SetDomain(0.0, 1.0);
    brep->m_C3.Append(segment56);

    // 6
    ON_Curve* segment67 = new ON_LineCurve(points[7], points[6]);
    segment67->SetDomain(0.0, 1.0);
    brep->m_C3.Append(segment67);

    // 7
    ON_Curve* segment74 = new ON_LineCurve(points[4], points[7]);
    segment74->SetDomain(0.0, 1.0);
    brep->m_C3.Append(segment74);

    // HORIZONTAL SEGMENTS

    // 8
    ON_Curve* segment04 = new ON_LineCurve(points[0], points[4]);
    segment04->SetDomain(0.0, 1.0);
    brep->m_C3.Append(segment04);

    // 9
    ON_Curve* segment51 = new ON_LineCurve(points[5], points[1]);
    segment51->SetDomain(0.0, 1.0);
    brep->m_C3.Append(segment51);

    // 10
    ON_Curve* segment26 = new ON_LineCurve(points[2], points[6]);
    segment26->SetDomain(0.0, 1.0);
    brep->m_C3.Append(segment26);

    // 11
    ON_Curve* segment73 = new ON_LineCurve(points[7], points[3]);
    segment73->SetDomain(0.0, 1.0);
    brep->m_C3.Append(segment73);

    /* XXX */

    // 12
    ON_Curve* segment01prime = new ON_LineCurve(p8, p9);
    segment01prime->SetDomain(0.0, 1.0);
    brep->m_C3.Append(segment01prime);

    // 13
    ON_Curve* segment12prime = new ON_LineCurve(p9, p10);
    segment12prime->SetDomain(0.0, 1.0);
    brep->m_C3.Append(segment12prime);

    // 14
    ON_Curve* segment23prime = new ON_LineCurve(p10, p11);
    segment23prime->SetDomain(0.0, 1.0);
    brep->m_C3.Append(segment23prime);

    // 15
    ON_Curve* segment30prime = new ON_LineCurve(p11, p8);
    segment30prime->SetDomain(0.0, 1.0);
    brep->m_C3.Append(segment30prime);

    // SURFACES
    ON_NurbsSurface* surf0123 = new ON_NurbsSurface(3 /*dimension*/, 0 /*nonrational*/, 2 /*u*/, 2 /*v*/, 2 /*#u*/, 2 /*#v*/);
    surf0123->SetKnot(0, 0, 0.0); surf0123->SetKnot(0, 1, 1.0); surf0123->SetKnot(1, 0, 0.0); surf0123->SetKnot(1, 1, 1.0);
    surf0123->SetCV(0, 0, points[0]);
    surf0123->SetCV(1, 0, points[1]);
    surf0123->SetCV(1, 1, points[2]);
    surf0123->SetCV(0, 1, points[3]);
    brep->m_S.Append(surf0123); /* 0 */

    ON_NurbsSurface* surf4765 = new ON_NurbsSurface(3 /*dimension*/, 0 /*nonrational*/, 2 /*u*/, 2 /*v*/, 2 /*#u*/, 2 /*#v*/);
    surf4765->SetKnot(0, 0, 0.0); surf4765->SetKnot(0, 1, 1.0); surf4765->SetKnot(1, 0, 0.0); surf4765->SetKnot(1, 1, 1.0);
    surf4765->SetCV(0, 0, points[4]);
    surf4765->SetCV(1, 0, points[7]);
    surf4765->SetCV(1, 1, points[6]);
    surf4765->SetCV(0, 1, points[5]);
    brep->m_S.Append(surf4765); /* 1 */

    ON_NurbsSurface* surf0451 = new ON_NurbsSurface(3 /*dimension*/, 0 /*nonrational*/, 2 /*u*/, 2 /*v*/, 2 /*#u*/, 2 /*#v*/);
    surf0451->SetKnot(0, 0, 0.0); surf0451->SetKnot(0, 1, 1.0); surf0451->SetKnot(1, 0, 0.0); surf0451->SetKnot(1, 1, 1.0);
    surf0451->SetCV(0, 0, points[0]);
    surf0451->SetCV(1, 0, points[4]);
    surf0451->SetCV(1, 1, points[5]);
    surf0451->SetCV(0, 1, points[1]);
    brep->m_S.Append(surf0451); /* 2 */

    ON_NurbsSurface* surf2673 = new ON_NurbsSurface(3 /*dimension*/, 0 /*nonrational*/, 2 /*u*/, 2 /*v*/, 2 /*#u*/, 2 /*#v*/);
    surf2673->SetKnot(0, 0, 0.0); surf2673->SetKnot(0, 1, 1.0); surf2673->SetKnot(1, 0, 0.0); surf2673->SetKnot(1, 1, 1.0);
    surf2673->SetCV(0, 0, points[2]);
    surf2673->SetCV(1, 0, points[6]);
    surf2673->SetCV(1, 1, points[7]);
    surf2673->SetCV(0, 1, points[3]);
    brep->m_S.Append(surf2673); /* 3 */

    ON_NurbsSurface* surf1562 = new ON_NurbsSurface(3 /*dimension*/, 0 /*nonrational*/, 2 /*u*/, 2 /*v*/, 2 /*#u*/, 2 /*#v*/);
    surf1562->SetKnot(0, 0, 0.0); surf1562->SetKnot(0, 1, 1.0); surf1562->SetKnot(1, 0, 0.0); surf1562->SetKnot(1, 1, 1.0);
    surf1562->SetCV(0, 0, points[1]);
    surf1562->SetCV(1, 0, points[5]);
    surf1562->SetCV(1, 1, points[6]);
    surf1562->SetCV(0, 1, points[2]);
    brep->m_S.Append(surf1562); /* 4 */

    ON_NurbsSurface* surf0374 = new ON_NurbsSurface(3 /*dimension*/, 0 /*nonrational*/, 2 /*u*/, 2 /*v*/, 2 /*#u*/, 2 /*#v*/);
    surf0374->SetKnot(0, 0, 0.0); surf0374->SetKnot(0, 1, 1.0); surf0374->SetKnot(1, 0, 0.0); surf0374->SetKnot(1, 1, 1.0);
    surf0374->SetCV(0, 0, points[0]);
    surf0374->SetCV(1, 0, points[3]);
    surf0374->SetCV(1, 1, points[7]);
    surf0374->SetCV(0, 1, points[4]);
    brep->m_S.Append(surf0374); /* 5 */


    // TRIM CURVES

    ON_Curve* trimcurve01 = new ON_LineCurve(ON_2dPoint(0, 0), ON_2dPoint(1, 0));
    trimcurve01->SetDomain(0.0, 1.0);
    brep->m_C2.Append(trimcurve01); /* 0 */

    ON_Curve* trimcurve12 = new ON_LineCurve(ON_2dPoint(1, 0), ON_2dPoint(1, 1));
    trimcurve12->SetDomain(0.0, 1.0);
    brep->m_C2.Append(trimcurve12); /* 1 */

    ON_Curve* trimcurve23 = new ON_LineCurve(ON_2dPoint(1, 1), ON_2dPoint(0, 1));
    trimcurve23->SetDomain(0.0, 1.0);
    brep->m_C2.Append(trimcurve23); /* 2 */

    ON_Curve* trimcurve30 = new ON_LineCurve(ON_2dPoint(0, 1), ON_2dPoint(0, 0));
    trimcurve30->SetDomain(0.0, 1.0);
    brep->m_C2.Append(trimcurve30); /* 3 */

    // EDGES

    /* C3 curve */
    // left face edges
    brep->NewEdge(brep->m_V[0], brep->m_V[1], 0, NULL, SMALL_FASTF); /* 0 */
    brep->NewEdge(brep->m_V[1], brep->m_V[2], 1, NULL, SMALL_FASTF); /* 1 */
    brep->NewEdge(brep->m_V[2], brep->m_V[3], 2, NULL, SMALL_FASTF); /* 2 */
    brep->NewEdge(brep->m_V[3], brep->m_V[0], 3, NULL, SMALL_FASTF); /* 3 */

    // right face edges
    brep->NewEdge(brep->m_V[5], brep->m_V[4], 4, NULL, SMALL_FASTF); /* 4 */
    brep->NewEdge(brep->m_V[6], brep->m_V[5], 5, NULL, SMALL_FASTF); /* 5 */
    brep->NewEdge(brep->m_V[7], brep->m_V[6], 6, NULL, SMALL_FASTF); /* 6 */
    brep->NewEdge(brep->m_V[4], brep->m_V[7], 7, NULL, SMALL_FASTF); /* 7 */

    // horizontal face edges
    brep->NewEdge(brep->m_V[0], brep->m_V[4], 8, NULL, SMALL_FASTF); /* 8 */
    brep->NewEdge(brep->m_V[5], brep->m_V[1], 9, NULL, SMALL_FASTF); /* 9 */
    brep->NewEdge(brep->m_V[2], brep->m_V[6], 10, NULL, SMALL_FASTF); /* 10 */
    brep->NewEdge(brep->m_V[7], brep->m_V[3], 11, NULL, SMALL_FASTF); /* 11 */

    // XXX
    brep->NewEdge(brep->m_V[8], brep->m_V[9], 12, NULL, SMALL_FASTF); /* 12 */
    brep->NewEdge(brep->m_V[9], brep->m_V[10], 13, NULL, SMALL_FASTF); /* 13 */
    brep->NewEdge(brep->m_V[10], brep->m_V[11], 14, NULL, SMALL_FASTF); /* 14 */
    brep->NewEdge(brep->m_V[11], brep->m_V[8], 15, NULL, SMALL_FASTF); /* 15 */

    // FACES

    ON_BrepFace& face0123 = brep->NewFace(0);
    ON_BrepLoop& loop0123 = brep->NewLoop(ON_BrepLoop::outer, face0123); /* 0 */
    ON_BrepTrim& trim01 = brep->NewTrim(brep->m_E[0], false, loop0123, 0 /* trim */); /* m_T[0] */
    trim01.m_iso = ON_Surface::S_iso;
    trim01.m_type = ON_BrepTrim::mated;
    trim01.m_tolerance[0] = SMALL_FASTF;
    trim01.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim12 = brep->NewTrim(brep->m_E[1], false, loop0123, 1 /* trim */); /* 1 */
    trim12.m_iso = ON_Surface::E_iso;
    trim12.m_type = ON_BrepTrim::mated;
    trim12.m_tolerance[0] = SMALL_FASTF;
    trim12.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim23 = brep->NewTrim(brep->m_E[2], false, loop0123, 2 /* trim */); /* 2 */
    trim23.m_iso = ON_Surface::N_iso;
    trim23.m_type = ON_BrepTrim::mated;
    trim23.m_tolerance[0] = SMALL_FASTF;
    trim23.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim30 = brep->NewTrim(brep->m_E[3], false, loop0123, 3 /* trim */); /* 3 */
    trim30.m_iso = ON_Surface::W_iso;
    trim30.m_type = ON_BrepTrim::mated;
    trim30.m_tolerance[0] = SMALL_FASTF;
    trim30.m_tolerance[1] = SMALL_FASTF;

    ON_BrepFace& face4765 = brep->NewFace(1 /* surfaceID */);
    ON_BrepLoop& loop4765 = brep->NewLoop(ON_BrepLoop::outer, face4765); /* 1 */
    ON_BrepTrim& trim47 = brep->NewTrim(brep->m_E[7], false, loop4765, 0 /* trim */); /* 4 */
    trim47.m_iso = ON_Surface::S_iso;
    trim47.m_type = ON_BrepTrim::mated;
    trim47.m_tolerance[0] = SMALL_FASTF;
    trim47.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim76 = brep->NewTrim(brep->m_E[6], false, loop4765, 1 /* trim */); /* 5 */
    trim76.m_iso = ON_Surface::E_iso;
    trim76.m_type = ON_BrepTrim::mated;
    trim76.m_tolerance[0] = SMALL_FASTF;
    trim76.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim65 = brep->NewTrim(brep->m_E[5], false, loop4765, 2 /* trim */); /* 6 */
    trim65.m_iso = ON_Surface::N_iso;
    trim65.m_type = ON_BrepTrim::mated;
    trim65.m_tolerance[0] = SMALL_FASTF;
    trim65.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim54 = brep->NewTrim(brep->m_E[4], false, loop4765, 3 /* trim */); /* 7 */
    trim54.m_iso = ON_Surface::W_iso;
    trim54.m_type = ON_BrepTrim::mated;
    trim54.m_tolerance[0] = SMALL_FASTF;
    trim54.m_tolerance[1] = SMALL_FASTF;

    ON_BrepFace& face0451 = brep->NewFace(2);
    ON_BrepLoop& loop0451 = brep->NewLoop(ON_BrepLoop::outer, face0451); /* 2 */
    ON_BrepTrim& trim04 = brep->NewTrim(brep->m_E[8], false, loop0451, 0 /* trim */); /* 8 */
    trim04.m_iso = ON_Surface::S_iso;
    trim04.m_type = ON_BrepTrim::mated;
    trim04.m_tolerance[0] = SMALL_FASTF;
    trim04.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim45 = brep->NewTrim(brep->m_E[4], true, loop0451, 1 /* trim */); /* 9 */
    trim45.m_iso = ON_Surface::E_iso;
    trim45.m_type = ON_BrepTrim::mated;
    trim45.m_tolerance[0] = SMALL_FASTF;
    trim45.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim51 = brep->NewTrim(brep->m_E[9], false, loop0451, 2 /* trim */); /* 10 */
    trim51.m_iso = ON_Surface::N_iso;
    trim51.m_type = ON_BrepTrim::mated;
    trim51.m_tolerance[0] = SMALL_FASTF;
    trim51.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim10 = brep->NewTrim(brep->m_E[0], true, loop0451, 3 /* trim */); /* 11 */
    trim10.m_iso = ON_Surface::W_iso;
    trim10.m_type = ON_BrepTrim::mated;
    trim10.m_tolerance[0] = SMALL_FASTF;
    trim10.m_tolerance[1] = SMALL_FASTF;

    ON_BrepFace& face2673 = brep->NewFace(3);
    ON_BrepLoop& loop2673 = brep->NewLoop(ON_BrepLoop::outer, face2673); /* 3 */
    ON_BrepTrim& trim26 = brep->NewTrim(brep->m_E[10], false, loop2673, 0 /* trim */); /* 12 */
    trim26.m_iso = ON_Surface::S_iso;
    trim26.m_type = ON_BrepTrim::mated;
    trim26.m_tolerance[0] = SMALL_FASTF;
    trim26.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim67 = brep->NewTrim(brep->m_E[6], true, loop2673, 1 /* trim */); /* 13 */
    trim67.m_iso = ON_Surface::E_iso;
    trim67.m_type = ON_BrepTrim::mated;
    trim67.m_tolerance[0] = SMALL_FASTF;
    trim67.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim73 = brep->NewTrim(brep->m_E[11], false, loop2673, 2 /* trim */); /* 14 */
    trim73.m_iso = ON_Surface::N_iso;
    trim73.m_type = ON_BrepTrim::mated;
    trim73.m_tolerance[0] = SMALL_FASTF;
    trim73.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim32 = brep->NewTrim(brep->m_E[2], true, loop2673, 3 /* trim */); /* 15 */
    trim32.m_iso = ON_Surface::W_iso;
    trim32.m_type = ON_BrepTrim::mated;
    trim32.m_tolerance[0] = SMALL_FASTF;
    trim32.m_tolerance[1] = SMALL_FASTF;

    ON_BrepFace& face1562 = brep->NewFace(4);
    ON_BrepLoop& loop1562 = brep->NewLoop(ON_BrepLoop::outer, face1562); /* 4 */
    ON_BrepTrim& trim15 = brep->NewTrim(brep->m_E[9], true, loop1562, 0 /* trim */); /* 16 */
    trim15.m_iso = ON_Surface::S_iso;
    trim15.m_type = ON_BrepTrim::mated;
    trim15.m_tolerance[0] = SMALL_FASTF;
    trim15.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim56 = brep->NewTrim(brep->m_E[5], true, loop1562, 1 /* trim */); /* 17 */
    trim56.m_iso = ON_Surface::E_iso;
    trim56.m_type = ON_BrepTrim::mated;
    trim56.m_tolerance[0] = SMALL_FASTF;
    trim56.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim62 = brep->NewTrim(brep->m_E[10], true, loop1562, 2 /* trim */); /* 18 */
    trim62.m_iso = ON_Surface::N_iso;
    trim62.m_type = ON_BrepTrim::mated;
    trim62.m_tolerance[0] = SMALL_FASTF;
    trim62.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim21 = brep->NewTrim(brep->m_E[1], true, loop1562, 3 /* trim */); /* 19 */
    trim21.m_iso = ON_Surface::W_iso;
    trim21.m_type = ON_BrepTrim::mated;
    trim21.m_tolerance[0] = SMALL_FASTF;
    trim21.m_tolerance[1] = SMALL_FASTF;

    ON_BrepFace& face0374 = brep->NewFace(5);
    ON_BrepLoop& loop0374 = brep->NewLoop(ON_BrepLoop::outer, face0374); /* 5 */
    ON_BrepTrim& trim03 = brep->NewTrim(brep->m_E[3], true, loop0374, 0 /* trim */); /* 20 */
    trim03.m_iso = ON_Surface::S_iso;
    trim03.m_type = ON_BrepTrim::mated;
    trim03.m_tolerance[0] = SMALL_FASTF;
    trim03.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim37 = brep->NewTrim(brep->m_E[11], true, loop0374, 1 /* trim */); /* 21 */
    trim37.m_iso = ON_Surface::E_iso;
    trim37.m_type = ON_BrepTrim::mated;
    trim37.m_tolerance[0] = SMALL_FASTF;
    trim37.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim74 = brep->NewTrim(brep->m_E[7], true, loop0374, 2 /* trim */); /* 22 */
    trim74.m_iso = ON_Surface::N_iso;
    trim74.m_type = ON_BrepTrim::mated;
    trim74.m_tolerance[0] = SMALL_FASTF;
    trim74.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim40 = brep->NewTrim(brep->m_E[8], true, loop0374, 3 /* trim */); /* 23 */
    trim40.m_iso = ON_Surface::W_iso;
    trim40.m_type = ON_BrepTrim::mated;
    trim40.m_tolerance[0] = SMALL_FASTF;
    trim40.m_tolerance[1] = SMALL_FASTF;

    return brep;
}
Ejemplo n.º 9
0
bool ON_BrepExtrude( 
          ON_Brep& brep,
          const ON_Curve& path_curve,
          bool bCap
          )
{
  ON_Workspace ws;
  const int vcount0 = brep.m_V.Count();
  const int tcount0 = brep.m_T.Count();
  const int lcount0 = brep.m_L.Count();
  const int ecount0 = brep.m_E.Count();
  const int fcount0 = brep.m_F.Count();

  const ON_3dPoint PathStart = path_curve.PointAtStart();
  ON_3dPoint P = path_curve.PointAtEnd();
  if ( !PathStart.IsValid() || !P.IsValid() )
    return false;
  const ON_3dVector height = P - PathStart;
  if ( !height.IsValid() || height.Length() <= ON_ZERO_TOLERANCE )
    return false;

  ON_Xform tr;
  tr.Translation(height);

  // count number of new sides
  int side_count = 0;
  int i, vi, ei, fi;
  bool* bSideEdge = (bool*)ws.GetIntMemory(ecount0*sizeof(bSideEdge[0]));
  for ( ei = 0; ei < ecount0; ei++ )
  {
    const ON_BrepEdge& e = brep.m_E[ei];
    if ( 1 == e.m_ti.Count() )
    {
      side_count++;
      bSideEdge[ei] = true;
    }
    else
    {
      bSideEdge[ei] = false;
    }
  }

  brep.m_V.Reserve( 2*vcount0 );
  i = 4*side_count + (bCap?tcount0:0);
  brep.m_T.Reserve( tcount0 + i );
  brep.m_C2.Reserve( brep.m_C2.Count() + i );
  brep.m_L.Reserve( lcount0 + side_count + (bCap?lcount0:0) );
  i = side_count + (bCap?ecount0:side_count);
  brep.m_E.Reserve( ecount0 + i );
  brep.m_C3.Reserve( brep.m_C3.Count() + i );
  i = side_count + (bCap?fcount0:0);
  brep.m_F.Reserve( fcount0 + i );
  brep.m_S.Reserve( brep.m_S.Count() + i );

  bool bOK = true;

  // build top vertices
  int* topvimap = ws.GetIntMemory(vcount0);
  memset(topvimap,0,vcount0*sizeof(topvimap[0]));
  if ( bCap )
  {
    for ( vi = 0; vi < vcount0; vi++ )
    {
      const ON_BrepVertex& bottomv = brep.m_V[vi];
      ON_BrepVertex& topv = brep.NewVertex(bottomv.point+height,bottomv.m_tolerance);
      topvimap[vi] = topv.m_vertex_index;
    }
  }
  else
  {
    for ( ei = 0; ei < ecount0; ei++ )
    {
      if ( bSideEdge[ei] )
      {
        const ON_BrepEdge& bottome = brep.m_E[ei];
        int bottomvi0 = bottome.m_vi[0];
        if ( bottomvi0 < 0 || bottomvi0 >= vcount0 )
        {
          bOK = false;
          break;
        }
        int bottomvi1 = bottome.m_vi[1];
        if ( bottomvi1 < 0 || bottomvi1 >= vcount0 )
        {
          bOK = false;
          break;
        }
        if ( !topvimap[bottomvi0] )
        {
          const ON_BrepVertex& bottomv = brep.m_V[bottomvi0];
          ON_BrepVertex& topv = brep.NewVertex(bottomv.point+height,bottomv.m_tolerance);
          topvimap[bottomvi0] = topv.m_vertex_index;
        }
        if ( !topvimap[bottomvi1] )
        {
          const ON_BrepVertex& bottomv = brep.m_V[bottomvi1];
          ON_BrepVertex& topv = brep.NewVertex(bottomv.point+height,bottomv.m_tolerance);
          topvimap[bottomvi1] = topv.m_vertex_index;
        }
      }
    }
  }

  // build top edges
  int* topeimap = ws.GetIntMemory(ecount0);
  memset(topeimap,0,ecount0*sizeof(topeimap[0]));
  if ( bOK ) for ( ei = 0; ei < ecount0; ei++ )
  {
    if ( bCap || bSideEdge[ei] )
    {
      const ON_BrepEdge& bottome = brep.m_E[ei];
      ON_BrepVertex& topv0 = brep.m_V[topvimap[bottome.m_vi[0]]];
      ON_BrepVertex& topv1 = brep.m_V[topvimap[bottome.m_vi[1]]];
      ON_Curve* c3 = bottome.DuplicateCurve();
      if ( !c3 )
      {
        bOK = false;
        break;
      }
      c3->Transform(tr);
      int c3i = brep.AddEdgeCurve(c3);
      ON_BrepEdge& tope = brep.NewEdge(topv0,topv1,c3i,0,bottome.m_tolerance);
      topeimap[ei] = tope.m_edge_index;
    }
  }

  // build side edges
  int* sideveimap = ws.GetIntMemory(vcount0);
  memset(sideveimap,0,vcount0*sizeof(sideveimap[0]));
  if ( bOK ) for ( vi = 0; vi < vcount0; vi++ )
  {
    ON_BrepVertex& bottomv = brep.m_V[vi];
    for ( int vei = 0; vei < bottomv.m_ei.Count(); vei++ )
    {
      if ( bSideEdge[bottomv.m_ei[vei]] && topvimap[vi] )
      {
        ON_BrepVertex& topv = brep.m_V[topvimap[vi]];
        ON_Curve* c3 = path_curve.DuplicateCurve();
        if ( !c3 )
        {
          bOK = false;
        }
        else
        {
          ON_3dVector D = bottomv.point - PathStart;
          c3->Translate(D);
          int c3i = brep.AddEdgeCurve(c3);
          const ON_BrepEdge& e = brep.NewEdge(bottomv,topv,c3i,0,0.0);
          sideveimap[vi] = e.m_edge_index;
        }
        break;
      }
    }
  }

  if ( bOK && bCap )
  {
    // build top faces
    for (fi = 0; fi < fcount0; fi++ )
    {
      const ON_BrepFace& bottomf = brep.m_F[fi];
      ON_Surface* srf = bottomf.DuplicateSurface();
      if ( !srf )
      {
        bOK = false;
        break;
      }
      srf->Transform(tr);
      int si = brep.AddSurface(srf);
      ON_BrepFace& topf = brep.NewFace(si);
      topf.m_bRev = !bottomf.m_bRev;
      const int loop_count = bottomf.m_li.Count();
      topf.m_li.Reserve(loop_count);
      for ( int fli = 0; fli < loop_count; fli++ )
      {
        const ON_BrepLoop& bottoml = brep.m_L[bottomf.m_li[fli]];
        ON_BrepLoop& topl = brep.NewLoop(bottoml.m_type,topf);
        const int loop_trim_count = bottoml.m_ti.Count();
        topl.m_ti.Reserve(loop_trim_count);
        for ( int lti = 0; lti < loop_trim_count; lti++ )
        {
          const ON_BrepTrim& bottomt = brep.m_T[bottoml.m_ti[lti]];
          ON_NurbsCurve* c2 = ON_NurbsCurve::New();
          if ( !bottomt.GetNurbForm(*c2) )
          {
            delete c2;
            bOK = false;
            break;
          }
          int c2i = brep.AddTrimCurve(c2);
          ON_BrepTrim* topt = 0;
          if ( bottomt.m_ei >= 0 )
          {
            ON_BrepEdge& tope = brep.m_E[topeimap[bottomt.m_ei]];
            topt = &brep.NewTrim(tope,bottomt.m_bRev3d,topl,c2i);
          }
          else
          {
            // singular trim
            ON_BrepVertex& topv = brep.m_V[topvimap[bottomt.m_vi[0]]];
            topt = &brep.NewSingularTrim(topv,topl,bottomt.m_iso,c2i);
          }
          topt->m_tolerance[0] = bottomt.m_tolerance[0];
          topt->m_tolerance[1] = bottomt.m_tolerance[1];
          topt->m_pbox = bottomt.m_pbox;
          topt->m_type = bottomt.m_type;
          topt->m_iso = bottomt.m_iso;
        }
        topl.m_pbox = bottoml.m_pbox;
      }
    }
  }

  // build sides
  int bRev3d[4] = {0,0,1,1};
  int vid[4], eid[4];
  if( bOK ) for ( ei = 0; ei < ecount0; ei++ )
  {
    if ( bSideEdge[ei] && topeimap[ei] )
    {
      ON_BrepEdge& bottome = brep.m_E[ei];
      ON_BrepEdge& tope = brep.m_E[topeimap[ei]];
      vid[0] = bottome.m_vi[0];
      vid[1] = bottome.m_vi[1];
      vid[2] = topvimap[vid[1]];
      vid[3] = topvimap[vid[0]];
      if ( sideveimap[vid[0]] && sideveimap[vid[1]] )
      {
        ON_BrepEdge& leftedge = brep.m_E[sideveimap[vid[0]]];
        ON_BrepEdge& rightedge = brep.m_E[sideveimap[vid[1]]];
        ON_Curve* cx = bottome.DuplicateCurve();
        if ( !cx )
        {
          bOK = false;
          break;
        }
        ON_Curve* cy = leftedge.DuplicateCurve();
        if ( !cy )
        {
          delete cx;
          bOK = false;
          break;
        }
        ON_SumSurface* srf = new ON_SumSurface();
        srf->m_curve[0] = cx;
        srf->m_curve[1] = cy;
        srf->m_basepoint = srf->m_curve[1]->PointAtStart();
        srf->m_basepoint.x = -srf->m_basepoint.x;
        srf->m_basepoint.y = -srf->m_basepoint.y;
        srf->m_basepoint.z = -srf->m_basepoint.z;
        eid[0] = bottome.m_edge_index;
        eid[1] = rightedge.m_edge_index;
        eid[2] = tope.m_edge_index;
        eid[3] = leftedge.m_edge_index;
        ON_BrepFace* face = brep.NewFace(srf,vid,eid,bRev3d);
        if ( !face )
        {
          bOK = false;
          break;
        }
        else if ( bottome.m_ti.Count() == 2 )
        {
          const ON_BrepTrim& trim0 = brep.m_T[bottome.m_ti[0]];
          const ON_BrepTrim& trim1 = brep.m_T[bottome.m_ti[1]];
          const ON_BrepLoop& loop0 = brep.m_L[trim0.m_li];
          const ON_BrepLoop& loop1 = brep.m_L[trim1.m_li];
          bool bBottomFaceRev = brep.m_F[(loop0.m_fi != face->m_face_index) ? loop0.m_fi : loop1.m_fi].m_bRev;
          bool bSideFaceRev = ( trim0.m_bRev3d != trim1.m_bRev3d ) 
                            ? bBottomFaceRev 
                            : !bBottomFaceRev;
          face->m_bRev = bSideFaceRev;
        }
      }
    }
  }

  if ( !bOK )
  {
    for ( vi = brep.m_V.Count(); vi >= vcount0; vi-- )
    {
      brep.DeleteVertex(brep.m_V[vi]);
    }
  }

  return bOK;
}
Ejemplo n.º 10
0
bool ON_BrepConeLoop( 
          ON_Brep& brep,
          int loop_index,
          ON_3dPoint apex_point
          )
{
  if ( loop_index < 0 && loop_index >= brep.m_L.Count() )
    return false;

  int lti, ti, i, vid[4], eid[4], bRev3d[4];

  // indices of new faces appended to the side_face_index[] array 
  // (1 face index for each trim, -1 is used for singular trims)

  // count number of new objects so we can grow arrays
  // efficiently and use refs to dynamic array elements.
  const int loop_trim_count = brep.m_L[loop_index].m_ti.Count();
  if ( loop_trim_count == 0 )
    return false;

  // save input trim and edge counts for use below
  const int trim_count0 = brep.m_T.Count();
  const int edge_count0 = brep.m_E.Count();

  ON_BrepExtrudeHelper_ReserveSpace( brep, loop_trim_count, 0 );

  int prev_face_index = -1;
  int first_face_east_trim_index = -1;

  ON_BrepVertex& apex_vertex = brep.NewVertex( apex_point, 0.0 );

  for ( lti = 0; lti < loop_trim_count; lti++ )
  {
    ON_NurbsSurface* cone_srf = 0;
    ti = brep.m_L[loop_index].m_ti[lti];
    if ( ti < 0 || ti >= trim_count0 )
      continue;

    for ( i = 0; i < 4; i++ )
    {
      vid[i] = -1;
      eid[i] = -1;
    }
    bRev3d[0] = false;
    bRev3d[1] = false;
    bRev3d[2] = false;
    bRev3d[3] = false;

    // get side surface for new face
    // get side surface for new face
    {
      ON_BrepTrim& trim = brep.m_T[ti];
      if ( trim.m_ei >= 0 &&  trim.m_ei < edge_count0 )
      {
        const ON_BrepEdge& base_edge = brep.m_E[trim.m_ei];

        // connect new face to existing topology on trim
        vid[0] = trim.m_vi[1];
        vid[1] = trim.m_vi[0];
        eid[0] = base_edge.m_edge_index;
        bRev3d[0] = (trim.m_bRev3d?false:true);
        cone_srf = ON_BrepExtrudeHelper_MakeConeSrf( apex_point, base_edge, bRev3d[0] );
      }
    }
    if ( !cone_srf )
      continue;
    vid[2] = apex_vertex.m_vertex_index;
    vid[3] = apex_vertex.m_vertex_index;

    if ( prev_face_index >= 0 )
    {
      const ON_BrepTrim& prev_west_trim = brep.m_T[ brep.m_L[ brep.m_F[prev_face_index].m_li[0]].m_ti[3] ];
      vid[2] = prev_west_trim.m_vi[0];
      eid[1] = prev_west_trim.m_ei;
      bRev3d[1] = (prev_west_trim.m_bRev3d?false:true);
    }
    if ( first_face_east_trim_index >= 0 && brep.m_T[first_face_east_trim_index].m_vi[0] == vid[0] )
    {
      const ON_BrepTrim& first_face_east_trim = brep.m_T[first_face_east_trim_index];
      vid[3] = first_face_east_trim.m_vi[1];
      eid[3] = first_face_east_trim.m_ei;
      bRev3d[3] = (first_face_east_trim.m_bRev3d?false:true);
    }
    const ON_BrepFace* side_face = brep.NewFace(cone_srf,vid,eid,bRev3d);
    if ( side_face )
    {
      prev_face_index = side_face->m_face_index;
      if ( first_face_east_trim_index < 0 )
        first_face_east_trim_index = brep.m_L[ side_face->m_li[0] ].m_ti[1];
    }
  }

  return true;
}
Ejemplo n.º 11
0
static
ON_BOOL32 ON_BrepExtrudeHelper_MakeSides(
          ON_Brep& brep,
          int loop_index,
          const ON_Curve& path_curve,
          ON_BOOL32 bCap,
          ON_SimpleArray<int>& side_face_index
          )
{
  int lti, ti, i, vid[4], eid[4], bRev3d[4];

  // indices of new faces appended to the side_face_index[] array 
  // (1 face index for each trim, -1 is used for singular trims)

  // count number of new objects so we can grow arrays
  // efficiently and use refs to dynamic array elements.
  const int loop_trim_count = brep.m_L[loop_index].m_ti.Count();
  if ( loop_trim_count == 0 )
    return false;

  // save input trim and edge counts for use below
  const int trim_count0 = brep.m_T.Count();
  const int edge_count0 = brep.m_E.Count();

  ON_BrepExtrudeHelper_ReserveSpace( brep, loop_trim_count, bCap?1:0 );

  side_face_index.Reserve( side_face_index.Count() + loop_trim_count); // index of new face above brep.m_L[loop_index].m_ti[lti]
  int prev_face_index = -1;
  int first_face_east_trim_index = -1;

  for ( lti = 0; lti < loop_trim_count; lti++ )
  {
    ON_SumSurface* sum_srf = 0;
    side_face_index.Append(-1);
    ti = brep.m_L[loop_index].m_ti[lti];
    if ( ti < 0 || ti >= trim_count0 )
      continue;

    for ( i = 0; i < 4; i++ )
    {
      vid[i] = -1;
      eid[i] = -1;
    }
    bRev3d[0] = false;
    bRev3d[1] = false;
    bRev3d[2] = false;
    bRev3d[3] = false;

    // get side surface for new face
    {
      ON_BrepTrim& trim = brep.m_T[ti];
      if ( trim.m_ei >= 0 &&  trim.m_ei < edge_count0 )
      {
        const ON_BrepEdge& base_edge = brep.m_E[trim.m_ei];

        // 5 September, 2003 Dale Lear
        //   do not extrude seams - fixes rectangle slabe bug
        if ( trim.m_type == ON_BrepTrim::seam )
        {
          prev_face_index = -1;
          continue;
        }

        // connect new face to existing topology on trim
        vid[0] = trim.m_vi[1];
        vid[1] = trim.m_vi[0];
        eid[0] = base_edge.m_edge_index;
        bRev3d[0] = (trim.m_bRev3d?false:true);
        sum_srf = ON_BrepExtrudeHelper_MakeSumSrf( path_curve, base_edge, trim.m_bRev3d );
      }
    }
    if ( !sum_srf )
      continue;

    if ( prev_face_index >= 0 )
    {
      const ON_BrepTrim& prev_west_trim = brep.m_T[ brep.m_L[ brep.m_F[prev_face_index].m_li[0]].m_ti[3] ];
      vid[2] = prev_west_trim.m_vi[0];
      eid[1] = prev_west_trim.m_ei;
      bRev3d[1] = (prev_west_trim.m_bRev3d?false:true);
    }
    if ( first_face_east_trim_index >= 0 && brep.m_T[first_face_east_trim_index].m_vi[0] == vid[0] )
    {
      const ON_BrepTrim& first_face_east_trim = brep.m_T[first_face_east_trim_index];
      vid[3] = first_face_east_trim.m_vi[1];
      eid[3] = first_face_east_trim.m_ei;
      bRev3d[3] = (first_face_east_trim.m_bRev3d?false:true);
    }
    const ON_BrepFace* side_face = brep.NewFace(sum_srf,vid,eid,bRev3d);
    if ( side_face )
    {
      *side_face_index.Last() = side_face->m_face_index;
      prev_face_index = side_face->m_face_index;
      if ( first_face_east_trim_index < 0 )
        first_face_east_trim_index = brep.m_L[ side_face->m_li[0] ].m_ti[1];
    }
  }

  return true;
}