What kind of Brep-surfaces excist in openNURBS?


#1

Hello friends! I am new to OpenNURBS and would like to start of by thanking the creators for this fantastic tool!

What im trying to do is to read data from a .3dm file and investigate what kind of geometry is in it, pretty similar to the example_read.cpp file.

Im reading the content of the file into a ONX_Model class named “model” after which i do the following:

for (int i = 0; i  < model.m_object_table.Count(); ++i) {
  const ON_Geometry* pGeometry = ON_Geometry::Cast(model.m_object_table[i].m_object);
  if ( pGeometry ) {
    if ( ON_Brep::Cast(model.m_object_table[i].m_object) )
    {
      ON_Brep* brep = ON_Brep::Cast(model.m_object_table[i].m_object)
      for (int i = 0; i < brep->m_S.Count(); ++i) {
        if (ON_NurbsSurface::Cast(brep->m_S[i]))
        {
          std::cout << "Got a Brep taht was a NurbsSurface." << std::endl;
         }
       }
}

so basically im investigateing wether or not the object is a NurbsSurface or not.

My question is: What other kind of surfaces can excist in the brep->m_S? i would ofc like to investigate all kinds of surfaces supported in m_S.

Thnx for your answer!

/Alexander


(Dale Fugier) #2

Hi Alexander,

You might find this useful:

Anything derived from ON_Surface can be found on ON_Brep::m_S, including:

ON_NurbsSurface
ON_PlaneSurface
ON_RevSurface
ON_SumSurface
other


#3

Dale! Thank you so much for your answer. It did indeed help me to investigate what kind of surfaces was included in the BREP i was investigating.

I do have another question for you:

At the moment, im trying to go through the source-code to find out wether or not there excist functions to convert planesurfaces and revsurfaces into nurbssurfaces. Me beeing fairly new to c++ and to opennurbs, im haveing some difficulty to get a good grap on the code so to say. Would u be able to point me in the right direction?

Basically what i wanna find out is if i can take a ex. RevSurface and put it into a function and the function gives me back the same surface but in NurbSurface form.


(Dale Fugier) #4

Use ON_PlaneSurface::GetNurbForm() and ON_RevSurface::GetNurbForm().


#5

Thankyou Dale, your answers sure is helpful!

I have another question to you, this one about writing to a .3dm.

As stated before, im reading a .3dm file similar to the example_read.cpp file in openNurbs. After that i loop through the ON_Model model and check each object (e.i. model.m_object_table[l].m_object).

for each loop i do the following:

ON_Brep* brep = ON_Brep::New();
      brep->CopyFrom(model.m_object_table[l].m_object);
        
      bool rc = true;
      for (int l = 0; l < brep->m_F.Count(); ++l) 
      { 
        ON_BrepFace& face = brep->m_F[l];
        ON_NurbsSurface* nurbssurface = ON_NurbsSurface::Cast(&face);

        if( nurbssurface == NULL)
        {
          nurbssurface = new ON_NurbsSurface();

          int nurb_form_rc = face.GetNurbForm( *nurbssurface );
          if (nurb_form_rc == 0)
            rc = false;
          else 
          {
            int si = brep->AddSurface(nurbssurface);
            if(si<0)
              rc = false;
            else
            {
              if( nurb_form_rc==2)
                brep->RebuildTrimsForV2(face, *nurbssurface);
              face.ChangeSurface(si);
            }
          }
        }
      }

      if(rc)
        rc = brep->Compact();        
      
      const char* filename;
      bool ok = false;
      filename = "My_file.3dm";
      FILE* fp = ON::OpenFile( filename, "wb" );
      
      const ON_Brep* newconstBrep = ON_Brep::New();
      newconstBrep->Cast(brep);     

      ON_TextLog error_log;
      std::cout << i << std::endl;
      if (brep->IsValid (&error_log) )
      {
        ON_BinaryFile archive(ON::write3dm, fp);
        ok = ON_WriteOneObjectArchive( archive, 0, *ON_Object::Cast(newconstBrep) );
        std::cout << "success! " << std::endl;
      }
      
      ON::CloseFile( fp );

So basically i want to read a .3dm file, convert all faces in each brep to nurbfaces, and then save this as a new .3dm file.

My problems atm is the following:

  • in some occasions i get errormessages from the error_log saying “ON_Brep has no faces, edges, or vertices”
  • the bigger problem is that (as i understand it) a complicated geometry can consist of several objects/breps and that i atm just looping through each object/brep and saveing that to the file. E.i. i would rather like to save all objects/breps in a .3dm file. My initial thought is that i should be able to do the revese process from reading the file. When reading the file i save all content of the file in an ONX_Model. Would the right way to go about saveing on a .3dm file be to save each constructed Brep/object on a new ONX_Model and then write this ONX_Model into a .3dm file? If yes, could you point me in the right direction for how to do this? (have tried but haveing trubble)

Thanks again and thanks in advance for your answer!

/Alexander


(Dale Fugier) #6

Hi Alexander,

Why do you want to convert all the underlying surfaces to NURBS surfaces? What problem are you trying to solve?


#7

My goal is to be able to perform physics simulations like collision detection on the entire geometry (BREP), and since i already figured out how to do collision detection with NURBS surfaces i thought it would be most convenient to have all surfaces as NURBS surfaces.


(Dale Fugier) #8

Many of the features of a Brep are calculated from the underlying surfaces. So, if you swap out the underlying surfaces, then you will have to recalculate the edge curves, trims, loops, etc. Sounds like a lot of work to me.

How are you calculating collisions? Why does it only work with NURBS surfaces?


#9

Hi Dale!

After creating several 3dm models i want to be able to perform collision detection on, i noticed the following:

  • They consisted of about 45% ON_PlaneSurface, 45% ON_RevSurface and 10% ON_NurbsSurface
  • The 2d trimcurves and 3d edgecurves consisted ONLY of ON_NurbsCurves
  • The curves defining the shape of the RevSurfaces were about 85% LineCurves and 15% ArcCurves

For NurbsSurfaces, finding the 3D coordinate P of an intersection in parameteric coordinate p in uv-space an iterative search for P by estimateing p is done using Newtons Method. For PlaneSurfaces a method for collision detection has already been adapted, and for RevSurfaces im guessing an approach similar to NurbsSurface collisions would work.

Haveing an “universal” colission detection algorithm for the entire brep would (i think) be a intuitive and easyer-to-implement way of dealing with several contact points.

Im intrested however in compairing how computationally expensive the two approaches is. One being when reading the 3dm file, convert all surfaces etc to nurbssurfaces while still maintaining all Brep features, the other being keeping the Brep as it is, and implementing collision detection on RevSurfaces.