For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings


Need to speed up your development?
Have a look at our:

Samples & Tools


Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

OCC + nglib: unv mesh with boundaries

Víctor SV's picture

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's picture

Sorry for the poor explanation... what i want to do is something similar to "Explode" in Salome platform.

Thanks again :)

Hugues Delorme's picture

Hello Victor,

Maybe class TopExp_Explorer can help here.

Víctor SV's picture

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's picture

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 p1 = netgen::Point (x1,y1,z1);
netgen::Point p2 = netgen::Point (x2,y2,z2);
occgeo.boundingbox = netgen::Box (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 err = 1;

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

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

Poly_Array1OfTriangle Tri(1,ngMesh->GetNSE());
for (int i=1; iGetNSE(); 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's picture

:O! Oh thanks!

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

Best regards!

Víctor SV's picture

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's picture

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 :)