コード例 #1
0
// ANSWER:
// An ON_BrepEdge is connector for joining ON_BrepTrim objects and representing
// a 3-D location of the seam they form.  An Edge can connect 1 or more trims.
// In the case of a simple "joined edge" there will be 2 trims, one from each
// adjacent face. In a closed face, like a cylinder, the trims will be different
// on each side of the face, and they will both be in the same loop and belong to
// the same face.
static const ON_BrepFace* GetOtherFace(const ON_BrepTrim* trim)
{
  ON_BrepFace* face = 0;
  if (0 == trim)  
    return 0;

  ON_Brep* brep = trim->Brep();
  if (0 == brep)
    return 0;

  const ON_BrepEdge* edge = trim->Edge();
  if (0 == edge)
    return 0;

  // Trim count on a proper joined edge should be 2.
  const int trim_count = edge->TrimCount();
  if (trim_count < 2)
    return 0;  // Not joined
  if (trim_count > 2)
    return 0;  // Joined to more than one other surface (non-manifold)

  for (int i = 0; i < trim_count; i++)
  {
    // Look for a trim that's not the same as the input one
    // edge->m_ti is an array of indexes of the trims connected to an edge
    const ON_BrepTrim* other_trim = brep->Trim(edge->m_ti[i]);
    if (0 != other_trim && trim != other_trim)
    {
      // There is another trim on the edge, and its not the same as the input one.
      // So get the face it belonge to.
      face = other_trim->Face();

      // You can also get the loop on the other side of the edge
      //const ON_BrepLoop* other_loop = other_trim->Loop();

      // Or the surface geometry of the face
      //const ON_Surface* srf = face->SurfaceOf();

      break;
    }
  }

  return face;
}
コード例 #2
0
static
bool ChangeTrimBdryToSing( ON_Brep& brep, ON_BrepTrim& trim, 
                           ON_BrepTrim* prevtrim, ON_BrepTrim* nexttrim )
{
  if ( trim.m_vi[0] == trim.m_vi[1] )
    return false;
  if ( trim.m_type == ON_BrepTrim::singular )
    return false;
  if ( trim.m_ei < 0 )
    return false;

  int vi0 = trim.m_vi[0];
  int vi1 = trim.m_vi[1];

  int sing_vi = vi0;

  ON_BrepVertex* v0 = brep.Vertex(vi0);
  if ( v0 )
    v0->m_tolerance = ON_UNSET_VALUE;
  ON_BrepVertex* v1 = brep.Vertex(vi1);
  if ( v1 )
    v1->m_tolerance = ON_UNSET_VALUE;

  ON_BrepEdge* edge = brep.Edge(trim.m_ei);
  if ( edge )
  {
    for ( int eti = 0; eti < edge->m_ti.Count(); eti++ )
    {
      if ( edge->m_ti[eti] == trim.m_trim_index )
      {
        edge->m_ti.Remove(eti);
        break;
      }
    }

    trim.m_ei = -1;
    if ( 0 == edge->m_ti.Count() )
    {
      brep.DeleteEdge( *edge, true );
    }
    else if ( 1 == edge->m_ti.Count() && ON_BrepTrim::seam == trim.m_type )
    {
      // change neighbor trim type
      ON_BrepTrim* other_trim = brep.Trim(edge->m_ti[0]);
      if ( 0 != other_trim && ON_BrepTrim::seam == other_trim->m_type )
      {
        other_trim->m_type = ON_BrepTrim::boundary;
        int j = (trim.m_bRev3d == other_trim->m_bRev3d) ? 0 : 1;
        if (    trim.m_vi[0] == other_trim->m_vi[j] 
             && trim.m_vi[1] == other_trim->m_vi[1-j] )
        {
          // we need a new singular vertex
          sing_vi = brep.NewVertex(ON_UNSET_POINT).m_vertex_index;
        }
      }
    }
  }

  trim.m_vi[0] = sing_vi;
  trim.m_vi[1] = sing_vi;
  trim.m_type = ON_BrepTrim::singular;
  trim.m_bRev3d = false;

  if ( nexttrim )
    ChangeTrimVertex( brep,*nexttrim,0,vi1,sing_vi,true,true);
  if ( prevtrim )
    ChangeTrimVertex( brep,*prevtrim,1,vi0,sing_vi,true,true);

  return true;
}
コード例 #3
0
static
bool ChangeEdgeVertex( 
         ON_Brep& brep,
         ON_BrepEdge& edge,
         int edge_end,
         int old_vi,
         int new_vi,
         bool bUpdateTrims
         )
{
  // used by ON_Brep::ReplaceSurface() to change edge ends

  if ( edge_end != 0 && edge_end != 1 )
    return false;
  if ( edge.m_vi[edge_end] != old_vi )
    return false;
  if ( old_vi == new_vi )
    return true;

  ON_BrepVertex* old_v = brep.Vertex(old_vi);
  if ( old_vi >= 0 && 0 == old_v )
    return false;
  if ( old_v )
    old_v->m_tolerance = ON_UNSET_VALUE;
  
  ON_BrepVertex* new_v = brep.Vertex(new_vi);
  if ( new_vi >= 0 && 0 == new_v )
    return false;
  if ( new_v )
    old_v->m_tolerance = ON_UNSET_VALUE;

  // disconnect edge from old vertex
  if ( old_vi >= 0 )
  {
    for ( int vei = 0; vei < old_v->m_ei.Count(); vei++ )
    {
      if ( old_v->m_ei[vei] == edge.m_edge_index )
      {
        old_v->m_ei.Remove(vei);
        break;
      }
    }
  }

  edge.m_vi[edge_end] = new_vi;
  new_v->m_ei.Append(edge.m_edge_index);

  if ( bUpdateTrims )
  {
    for ( int eti = 0; eti < edge.m_ti.Count(); eti++ )
    {
      ON_BrepTrim* trim = brep.Trim(edge.m_ti[eti]);
      if ( 0 == trim )
        continue;
      int trim_end = trim->m_bRev3d ? 1-edge_end : edge_end;
      if ( trim->m_vi[trim_end] == old_vi )
        trim->m_vi[trim_end] = new_vi;
    }
  }

  return true;
}