Edge Surfaces

Hi Everyone. I need to read the index of edge elements (surfaces) into a vector and get to know which elements are at the edge of my sharped edge geometry. Could anyone help me how could I do it in opennurbs library?Thanks

Hi @Omid1,

What kind of geometry is this?

Brep edges are stored in the ON_Brep::m_E array.

– Dale

Hi @dale ,

Thanks for the reply. It is a Brep and I am trying to get the nurb surfaces from it in c++. Do you mean the edges of all those surfaces or the bounding elements of the geometry? because what I am asking is to find out which nurbs are located at the bounding or the edges of the geometry. I need it to solve the singularity of current on those patches. I hope it makes sense. Thanks.

I have a recursive split bezier code that extracts quadrilateral beziers from the model and store them in an array to find the interaction between them. Now, after doing this splitting process, I need to know which one of those beziers are located at the edge of the geometry to do some more mitigations for singularity on them. I mean if there is any flag to check if it is located at the boundary of the geometry or not as I attached the pic.

Hi @Omid1,

I assume you are splitting the Brep faces (ON_BrepFace) and not the underlying surface geometry. If you Brep is untrimmed then the face and the underlying surface are basically one in the same, however.

You’ll want to deal with Brep faces as they are topological elements and provides access to associated trims, edges, and loops. Brep surfaces are not topological elements.

If you have a surface, then you’ll need to search through the ON_Brep::m_F array until you find the surface’s owning face. Once you have the face, you can begin your topological search.

– Dale

Hi @dale,

Actually, I am doing convert span to bezier and splitting the ON_BezierSurface comparing to the maxLength I am giving to the solver in input file. Thanks

Hi @Omid1,

So what are you splitting? Surface you’ve created on your own, or Breps you’ve read from 3dm files?

Do you even have a Brep.

– Dale

Hi @dale,

This is the part of my code reading a brep for the 3dm model from rhino and extracting surfaces from it and splitting them:

 if (mybrep)
    {
      ON_Brep brep = *mybrep;
      bool flipBool = brep.FlipReversedSurfaces();
      int numberOfSufaces = brep.m_S.Count();
      for (int si = 0; si < numberOfSufaces; si++)
      {
        const ON_Surface *surf = brep.m_S[si];
        if (surf)
        {
          numberOfSurfaces++;
          const ON_NurbsSurface *nurbs_surf;
          nurbs_surf = ON_NurbsSurface::Cast(surf);
          if (!nurbs_surf)
          {
            ON_NurbsSurface nurbs_surf2;
            surf->GetNurbForm(nurbs_surf2, TOL_geometry);
            nurbs_surf = &nurbs_surf2;
          }
          if (nurbs_surf)
          {
            numberOfNURBS++;
            count = 0;
            maxErr = 0;
            double err;
            for (int span_index0 = 0; span_index0 <= nurbs_surf->m_cv_count[0] -
                                                         nurbs_surf->m_order[0];
                 span_index0++)
            {
              for (int span_index1 = 0;
                   span_index1 <=
                   nurbs_surf->m_cv_count[1] - nurbs_surf->m_order[1];
                   span_index1++)
              {
                count++;
                ON_BezierSurface bezier_surface_orig;
                if (nurbs_surf->ConvertSpanToBezier(span_index0, span_index1,
                                                    bezier_surface_orig))
                {

Then I am spitting U and V recursively for those bezier surfaces comparing to the maxLength given in input file.Thanks

Hi @Omid1,

Maybe something like this will help?

typedef struct tagBEZIERFACEMAP
{
  ON_BezierSurface m_bezier;
  int m_faceIndex;
}
BEZIERFACEMAP, * PBEZIERFACEMAP;

int GetBezierSpans(const ON_Brep* pBrep, double tol, ON_SimpleArray<BEZIERFACEMAP>& map)
{
  if (nullptr == pBrep)
    return 0;

  const int mapCount = map.Count();

  const int faceCount = pBrep->m_F.Count();
  for (int fi = 0; fi < faceCount; fi++)
  {
    const ON_BrepFace& face = pBrep->m_F[fi];
  
    const ON_Surface* srf = face.SurfaceOf();
    if (nullptr == srf)
      continue;

    ON_NurbsSurface ns;
    if (!srf->GetNurbForm(ns, tol))
      continue;

    for (int j = 0; j <= ns.CVCount(0) - ns.Order(0); j++)
    {
      for (int k = 0; k <= ns.CVCount(1) - ns.Order(1); k++)
      {
        BEZIERFACEMAP bez;
        if (ns.ConvertSpanToBezier(j, k, bez.m_bezier))
        {
          bez.m_faceIndex = face.m_face_index;
          map.Append(bez);
        }
      }
    }
  }

  return map.Count() - mapCount;
}

The function returns a map of Bezier surface and the index of the Brep face which it came from. With this index, you can walk the Brep topology and find what you need.

– Dale