I would like to use netgen to mesh OpenCascade geometry. I know that netgen can use OpenCascade as a tool for loading geometry files, but can netgen also be used as a tool in OpenCascade for meshing OpenCascade geometry without reading and writing the data from/to files?
Probably this is possible by modifying the netgen code a litte bit, but is there someone who has already collected some experience how to approach this task?
Thank you very much!
Now I am able to answer my own question.
Yes, netgen can quite easily be used as an OpenCascade mesher. To achieve this I have modified four netgen files: libsrc/occ/occgeom.cpp, libsrc/occ/occgeom.hpp, nglib/nglib.cpp and nglib/nglib.h. The main task is to add a method to occgeom to initialize this class using an OpenCascade shape instead of a file name. Afterwards the interface in nglib should be added.
I hope that nobody minds, if I paste the patch here for those who would like to do the same:
# HG changeset patch
# User Benjamin Bihler <firstname.lastname@example.org>
# Date 1367330436 -7200
# Node ID 7274265016fa8ec24f32725882e86a43226cd41f
# Parent 72885796f4aa933d0d814f30adf28843593c4484
Added methods to mesh OpenCascade shapes
diff -git a/libsrc/occ/occgeom.cpp b/libsrc/occ/occgeom.cpp
@@ -1201,6 +1201,25 @@
+ OCCGeometry * UseOCCGeometry ( TopoDS_Shape* shape )
+ OCCGeometry * occgeo;
+ occgeo = new OCCGeometry;
+ occgeo->shape = *shape;
+ // We do not use colour data right now.
+ // Hence, the face_colours Handle needs to be created as a NULL handle.
+ occgeo->face_colours = Handle_XCAFDoc_ColorTool();
+ occgeo->changed = 1;
+ PrintContents (occgeo);
+ return occgeo;
OCCGeometry *LoadOCC_BREP (const char *filename)
diff -git a/libsrc/occ/occgeom.hpp b/libsrc/occ/occgeom.hpp
@@ -428,6 +428,7 @@
OCCGeometry * LoadOCC_IGES (const char * filename);
OCCGeometry * LoadOCC_STEP (const char * filename);
OCCGeometry * LoadOCC_BREP (const char * filename);
+ OCCGeometry * UseOCCGeometry ( TopoDS_Shape* shape );
extern OCCParameters occparam;
diff -git a/nglib/nglib.cpp b/nglib/nglib.cpp
@@ -789,6 +789,14 @@
+ DLL_HEADER Ng_OCC_Geometry * Ng_UseOCCGeometry ( Ng_OCC_Shape shape )
+ // Call the function to use OCC shape. Note.. the geometry class
+ // is created and instantiated within that function
+ OCCGeometry * occgeo = UseOCCGeometry( (TopoDS_Shape*) shape );
+ return ((Ng_OCC_Geometry *)occgeo);
// Loads geometry from STEP File
diff -git a/nglib/nglib.h b/nglib/nglib.h
@@ -61,6 +61,7 @@
/// Data type for NETGEN OpenCascade geometry
typedef void * Ng_OCC_Geometry;
typedef void * Ng_OCC_TopTools_IndexedMapOfShape;
+typedef void * Ng_OCC_Shape;
@@ -658,6 +659,9 @@
// Delete an OCC Geometry Object
DLL_HEADER Ng_Result Ng_OCC_DeleteGeometry (Ng_OCC_Geometry * geom);
+// Use OpenCascade TopoDS_Shape shape as geometry
+DLL_HEADER Ng_OCC_Geometry * Ng_UseOCCGeometry ( Ng_OCC_Shape shape );
// Loads geometry from STEP file
DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_STEP (const char * filename);
Log in to post a comment.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.