1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
|
#include <mystdlib.h>
#include <myadt.hpp>
#include <occgeom.hpp>
#define OCCGEOMETRY 1
namespace nglib {
#include "nglib.h"
}
namespace netgen
{
inline void NOOP_Deleter(void *) { ; }
extern MeshingParameters mparam;
DLL_HEADER extern OCCParameters occparam;
} // namespace netgen
using namespace netgen;
namespace nglib
{
// --------------------- OCC Geometry / Meshing Utility Functions -------------------
// Create new OCC Geometry Object
NGLIB_API Ng_OCC_Geometry * Ng_OCC_NewGeometry ()
{
return (Ng_OCC_Geometry*)(void*)new OCCGeometry;
}
// Delete the OCC Geometry Object
NGLIB_API 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
NGLIB_API Ng_OCC_Geometry * Ng_OCC_Load_STEP (const char * filename)
{
// Call the STEP File Load function. Note.. the geometry class
// is created and instantiated within the load function
OCCGeometry * occgeo = LoadOCC_STEP(filename);
return ((Ng_OCC_Geometry *)occgeo);
}
// Loads geometry from IGES File
NGLIB_API Ng_OCC_Geometry * Ng_OCC_Load_IGES (const char * filename)
{
// Call the IGES File Load function. Note.. the geometry class
// is created and instantiated within the load function
OCCGeometry * occgeo = LoadOCC_IGES(filename);
return ((Ng_OCC_Geometry *)occgeo);
}
// Loads geometry from BREP File
NGLIB_API Ng_OCC_Geometry * Ng_OCC_Load_BREP (const char * filename)
{
// Call the BREP File Load function. Note.. the geometry class
// is created and instantiated within the load function
OCCGeometry * occgeo = LoadOCC_BREP(filename);
return ((Ng_OCC_Geometry *)occgeo);
}
// Locally limit the size of the mesh to be generated at various points
// based on the topology of the geometry
NGLIB_API Ng_Result Ng_OCC_SetLocalMeshSize (Ng_OCC_Geometry * geom,
Ng_Mesh * mesh,
Ng_Meshing_Parameters * mp)
{
OCCGeometry * occgeom = (OCCGeometry*)geom;
Mesh * me = (Mesh*)mesh;
me->SetGeometry( shared_ptr<NetgenGeometry>(occgeom, &NOOP_Deleter) );
me->geomtype = Mesh::GEOM_OCC;
mp->Transfer_Parameters();
if(mp->closeedgeenable)
mparam.closeedgefac = mp->closeedgefact;
// Delete the mesh structures in order to start with a clean
// slate
me->DeleteMesh();
OCCSetLocalMeshSize(*occgeom, *me, mparam, occparam);
return(NG_OK);
}
// Mesh the edges and add Face descriptors to prepare for surface meshing
NGLIB_API Ng_Result Ng_OCC_GenerateEdgeMesh (Ng_OCC_Geometry * geom,
Ng_Mesh * mesh,
Ng_Meshing_Parameters * mp)
{
OCCGeometry * occgeom = (OCCGeometry*)geom;
Mesh * me = (Mesh*)mesh;
me->SetGeometry( shared_ptr<NetgenGeometry>(occgeom, &NOOP_Deleter) );
mp->Transfer_Parameters();
occgeom->FindEdges(*me, mparam);
if((me->GetNP()))
{
return NG_OK;
}
else
{
return NG_ERROR;
}
}
// Mesh the edges and add Face descriptors to prepare for surface meshing
NGLIB_API Ng_Result Ng_OCC_GenerateSurfaceMesh (Ng_OCC_Geometry * geom,
Ng_Mesh * mesh,
Ng_Meshing_Parameters * mp)
{
int numpoints = 0;
OCCGeometry * occgeom = (OCCGeometry*)geom;
Mesh * me = (Mesh*)mesh;
me->SetGeometry( shared_ptr<NetgenGeometry>(occgeom, &NOOP_Deleter) );
// Set the internal meshing parameters structure from the nglib meshing
// parameters structure
mp->Transfer_Parameters();
numpoints = me->GetNP();
// Initially set up only for surface meshing without any optimisation
// int perfstepsend = MESHCONST_MESHSURFACE;
// Check and if required, enable surface mesh optimisation step
/*
if(mp->optsurfmeshenable)
{
perfstepsend = MESHCONST_OPTSURFACE;
}
*/
occgeom->MeshSurface(*me, mparam);
occgeom->OptimizeSurface(*me, mparam);
me->CalcSurfacesOfNode();
if(me->GetNP() <= numpoints)
return NG_ERROR;
if(me->GetNSE() <= 0)
return NG_ERROR;
return NG_OK;
}
// Extract the face map from the OCC geometry
// The face map basically gives an index to each face in the geometry,
// which can be used to access a specific face
NGLIB_API Ng_Result Ng_OCC_GetFMap(Ng_OCC_Geometry * geom,
Ng_OCC_TopTools_IndexedMapOfShape * FMap)
{
OCCGeometry* occgeom = (OCCGeometry*)geom;
TopTools_IndexedMapOfShape *occfmap = (TopTools_IndexedMapOfShape *)FMap;
// Copy the face map from the geometry to the given variable
occfmap->Assign(occgeom->fmap);
if(occfmap->Extent())
{
return NG_OK;
}
else
{
return NG_ERROR;
}
}
// ------------------ End - OCC Geometry / Meshing Utility Functions ----------------
NGLIB_API void Ng_OCC_Generate_SecondOrder (Ng_OCC_Geometry * geom,
Ng_Mesh * mesh)
{
((OCCGeometry*)geom )->GetRefinement().MakeSecondOrder(*(Mesh*) mesh);
}
NGLIB_API void Ng_OCC_Uniform_Refinement (Ng_OCC_Geometry * geom,
Ng_Mesh * mesh)
{
( (OCCGeometry*)geom ) -> GetRefinement().Refine ( * (Mesh*) mesh );
}
} // namespace nglib
|