* Added function to explicitly delete OCC Geometry in nglib

* Removed unnecessary "BRepMesh_IncrementalMesh" call in nglib which was causing a Memory Leak
* Miscellaneous streamlining of the nglib OCC functions
This commit is contained in:
Philippose Rajan 2010-05-05 18:42:51 +00:00
parent a585af7eb9
commit 8f59f8bdf8
2 changed files with 43 additions and 33 deletions

View File

@ -97,7 +97,17 @@ namespace nglib
// Delete an existing netgen mesh object // Delete an existing netgen mesh object
DLL_HEADER void Ng_DeleteMesh (Ng_Mesh * mesh) DLL_HEADER void Ng_DeleteMesh (Ng_Mesh * mesh)
{ {
if(mesh != NULL)
{
// Delete the Mesh structures
((Mesh*)mesh)->DeleteMesh();
// Now delete the Mesh class itself
delete (Mesh*)mesh; delete (Mesh*)mesh;
// Set the Ng_Mesh pointer to NULL
mesh = NULL;
}
} }
@ -650,20 +660,29 @@ namespace nglib
// Delete the OCC Geometry Object
DLL_HEADER Ng_Result Ng_OCC_DeleteGeometry(Ng_OCC_Geometry * geom)
{
if (geom != NULL)
{
delete (OCCGeometry*)geom;
geom = NULL;
return NG_OK;
}
return NG_ERROR;
}
// Loads geometry from STEP File // Loads geometry from STEP File
DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_STEP (const char * filename) DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_STEP (const char * filename)
{ {
Ng_OCC_Geometry * geo = Ng_OCC_NewGeometry(); // Call the STEP File Load function. Note.. the geometry class
// is created and instantiated within the load function
OCCGeometry * occgeo = LoadOCC_STEP(filename); OCCGeometry * occgeo = LoadOCC_STEP(filename);
// Create the initial triangulation for the OCC return ((Ng_OCC_Geometry *)occgeo);
// BRepMesh_IncrementalMesh::
BRepMesh_IncrementalMesh(occgeo->shape,0.1);
geo = (Ng_OCC_Geometry *)occgeo;
return (geo);
} }
@ -671,17 +690,11 @@ namespace nglib
// Loads geometry from IGES File // Loads geometry from IGES File
DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_IGES (const char * filename) DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_IGES (const char * filename)
{ {
Ng_OCC_Geometry * geo = Ng_OCC_NewGeometry(); // Call the IGES File Load function. Note.. the geometry class
// is created and instantiated within the load function
OCCGeometry * occgeo = LoadOCC_IGES(filename); OCCGeometry * occgeo = LoadOCC_IGES(filename);
// Create the initial triangulation for the OCC return ((Ng_OCC_Geometry *)occgeo);
// BRepMesh_IncrementalMesh::
BRepMesh_IncrementalMesh(occgeo->shape,0.1);
geo = (Ng_OCC_Geometry *)occgeo;
return (geo);
} }
@ -689,22 +702,17 @@ namespace nglib
// Loads geometry from BREP File // Loads geometry from BREP File
DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_BREP (const char * filename) DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_BREP (const char * filename)
{ {
Ng_OCC_Geometry * geo = Ng_OCC_NewGeometry(); // Call the BREP File Load function. Note.. the geometry class
// is created and instantiated within the load function
OCCGeometry * occgeo = LoadOCC_BREP(filename); OCCGeometry * occgeo = LoadOCC_BREP(filename);
// Create the initial triangulation for the OCC return ((Ng_OCC_Geometry *)occgeo);
// BRepMesh_IncrementalMesh::
BRepMesh_IncrementalMesh(occgeo->shape,0.1);
geo = (Ng_OCC_Geometry *)occgeo;
return (geo);
} }
// // Locally limit the size of the mesh to be generated at various points
// based on the topology of the geometry
DLL_HEADER Ng_Result Ng_OCC_SetLocalMeshSize (Ng_OCC_Geometry * geom, DLL_HEADER Ng_Result Ng_OCC_SetLocalMeshSize (Ng_OCC_Geometry * geom,
Ng_Mesh * mesh, Ng_Mesh * mesh,
Ng_Meshing_Parameters * mp) Ng_Meshing_Parameters * mp)
@ -728,9 +736,8 @@ namespace nglib
occparam.resthcloseedgeenable = mp->closeedgeenable; occparam.resthcloseedgeenable = mp->closeedgeenable;
occparam.resthcloseedgefac = mp->closeedgefact; occparam.resthcloseedgefac = mp->closeedgefact;
// delete me; // Delete the mesh structures in order to start with a clean
// me = new Mesh; // slate
me->DeleteMesh(); me->DeleteMesh();
OCCSetLocalMeshSize(*occgeom, *me); OCCSetLocalMeshSize(*occgeom, *me);

View File

@ -601,6 +601,9 @@ DLL_HEADER Ng_Result Ng_ACIS_GenerateSurfaceMesh (Ng_ACIS_Geometry * geom,
// Create new OCC Geometry Object // Create new OCC Geometry Object
DLL_HEADER Ng_OCC_Geometry * Ng_OCC_NewGeometry (); DLL_HEADER Ng_OCC_Geometry * Ng_OCC_NewGeometry ();
// Delete an OCC Geometry Object
DLL_HEADER Ng_Result Ng_OCC_DeleteGeometry (Ng_OCC_Geometry * geom);
// Loads geometry from STEP file // Loads geometry from STEP file
DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_STEP (const char * filename); DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_STEP (const char * filename);