Open CASCADE, the 3D modelling kernel
3D modeling & numerical simulation

Search the Forums
See All Topics

OCC + nglib: unv mesh with boundaries

OCC + nglib: unv mesh with boundaries
Víctor SV 2013/02/06 22:32
Hi all,

i'm a newbie. I'm trying to read a STEP geometry, mesh it and export to UNV file format; i use a simple STEP cube and i get the expected result.

Now i want to identify solids, faces, edges and vertices and save it as groups in the mesh, but... i'm lost.

Can anyone guide me in the steps i should follow?

Víctor SV 2013/02/06 22:41
Sorry for the poor explanation... what i want to do is something similar to "Explode" in Salome platform.

Thanks again :)
Hugues Delorme 2013/02/08 15:38
Hello Victor,

Maybe class TopExp_Explorer can help here.
Víctor SV 2013/02/08 17:24
Hello Hugues,

thanks for the response :)

I have allready cheked this class, but my problem comes later...
To narrow down the issue, i wonder how i can get a Ng_OCC_Geometry from a TopoDS_Shape or a Geom_[...] (Ex. Geom_Surface).
I don't know if it's possible to mesh a topology or geometry with Netgen. Is it possible?

François Lauzon 2013/02/08 17:59
Hello Victor,
we are using Netgen at our company, here is some code snippet of how we use it to produce a mesh from a TopoDS_Shape, it might not work as is but should be pretty close to working (I extract this code from a C++ class we use):

// setting of meshing parameters, tolerance,...
netgen::mparam.maxh = 1.; // some max edge length
netgen::mparam.minh = 1.; // some min edge length
netgen::mparam.optimize2d = "smsmsmSmSmSm";
netgen::mparam.grading = 0.3;


     // -------------------------
     // Prepare OCC geometry
     // -------------------------
     TopoDS_Shape _shape=...;
     netgen::OCCGeometry occgeo;
     occgeo.shape = _shape;
     occgeo.changed = 1;
// the shape need to have a starting mesh
     if (!BRepTools::Triangulation(_shape,1)) {

     Bnd_Box bb;
     BRepBndLib::Add (_shape, bb);
     double x1,y1,z1,x2,y2,z2;
     bb.Get (x1,y1,z1,x2,y2,z2);
     netgen::Point<3> p1 = netgen::Point<3> (x1,y1,z1);
     netgen::Point<3> p2 = netgen::Point<3> (x2,y2,z2);
     occgeo.boundingbox = netgen::Box<3> (p1,p2);

     // -------------------------
     // Generate the mesh
     // -------------------------
     netgen::Mesh *ngMesh = NULL;
     // we start always with ANALYSE,
     // but end depending on _optimize and _isVolume
     int startWith = netgen::MESHCONST_ANALYSE;
     int endWith = netgen::MESHCONST_OPTSURFACE;
     char *optstr=NULL;
     int err = 0;
     try {
          err = netgen::OCCGenerateMesh(occgeo, ngMesh,netgen::mparam, startWith, endWith);
          if (!err && netgen::mparam.secondorder > 0) {
               netgen::OCCRefinementSurfaces ref (occgeo);
               ref.MakeSecondOrder (*ngMesh);
     catch (netgen::NgException exc) {
          std::cout <<"Exception in NETGEN: " << exc.What()<<std::endl;
          err = 1;

// create the triangulation
Handle_Poly_Triangulation aTriangulation;
if (isOK && ngMesh->GetNP()>0) {

TColgp_Array1OfPnt pts(1,ngMesh->GetNP());
for (int i=1; i<=ngMesh->GetNP(); i++) {
netgen::MeshPoint pt=ngMesh->Point(i);

Poly_Array1OfTriangle Tri(1,ngMesh->GetNSE());
for (int i=1; i<=ngMesh->GetNSE(); i++) {
// get surface element
netgen::Element2d elem=ngMesh->SurfaceElement(i);
if (elem.GetNP()>=3) {
Standard_Integer N1=elem[0].GetInt();
Standard_Integer N2=elem[1].GetInt();
Standard_Integer N3=elem[2].GetInt();

aTriangulation=new Poly_Triangulation(pts,Tri);

Víctor SV 2013/02/08 18:49
:O! Oh thanks!

i thinks this is really what i need. I will try and coment my experience :)

Best regards!
Víctor SV 2013/02/11 18:22
Hi again,

now i have a problem, i think is related to my poor knowledge on C++. when i try to generate the mesh i get the following error:

undefined reference to `netgen::OCCGenerateMesh(netgen::OCCGeometry&, netgen::Mesh*&, netgen::MeshingParameters&, int, int)'

Someone know how can i fix this?

Víctor SV 2013/02/19 12:09
Hi again,

I try some of your code "exploding" a cube and it works well for solid and shells but i get an error when i try to mesh the last face, and the edges. With the face i get this output:

Creating Edge Mesh.....
Edge Mesh successfully created.....
Number of points = 8
Creating Surface Mesh.....
load internal triangle rules
Face 1 / 1 (parameter space projection)
Surface meshing done
Optimize Surface 1
Error creating Surface Mesh..... Aborting!! -1

Maybe something wrong with some parameters?

Thanks :)
Latest news
  • New features to enhance the development process
  • Open CASCADE Technology 6.7.1 is available for download!
  • Open CASCADE Technology 6.7.0 is available for download!

  • © OPEN CASCADE 2000 - 2014  |  Search  |  Contacts   |  Site map