#include <meshing.hpp>
//#include <ngexception.hpp>
namespace netgen {
-#ifdef NETGEN_V5
- extern int OCCGenerateMesh (OCCGeometry&, Mesh*&, MeshingParameters&, int, int);
-#else
- extern int OCCGenerateMesh (OCCGeometry&, Mesh*&, int, int, char*);
-#endif
- //extern void OCCSetLocalMeshSize(OCCGeometry & geom, Mesh & mesh);
NETGENPLUGIN_DLL_HEADER
extern MeshingParameters mparam;
namespace
{
+ inline void NOOP_Deleter(void *) { ; }
+
//=============================================================================
/*!
* Link - a pair of integer numbers
mparams.checkchartboundary = hyp->GetCheckChartBoundary();
_simpleHyp = NULL;
// mesh size file
+#ifdef NETGEN_V6
+ // std::string
+ mparams.meshsizefilename = hyp->GetMeshSizeFile();
+#else
+ // const char*
mparams.meshsizefilename= hyp->GetMeshSizeFile().empty() ? 0 : hyp->GetMeshSizeFile().c_str();
-
+#endif
const NETGENPlugin_Hypothesis::TLocalSize& localSizes = hyp->GetLocalSizesAndEntries();
if ( !localSizes.empty() )
{
int faceNgID = occgeo.fmap.FindIndex(shape);
if ( faceNgID >= 1 )
{
+#ifdef NETGEN_V6
+ occgeo.SetFaceMaxH(faceNgID-1, val);
+#else
occgeo.SetFaceMaxH(faceNgID, val);
+#endif
for ( TopExp_Explorer edgeExp( shape, TopAbs_EDGE ); edgeExp.More(); edgeExp.Next() )
setLocalSize( TopoDS::Edge( edgeExp.Current() ), val, ngMesh );
}
surfProp.SetParameters( 0, 0 );
double maxCurv = Max( Abs( surfProp.MaxCurvature()), Abs( surfProp.MinCurvature() ));
double size = elemSizeForChordalError( _chordalError, 1 / maxCurv );
+#ifdef NETGEN_V6
+ occgeo.SetFaceMaxH( i-1, size * sizeCoef );
+#else
occgeo.SetFaceMaxH( i, size * sizeCoef );
+#endif
// limit size one edges
TopTools_MapOfShape edgeMap;
for ( TopExp_Explorer eExp( face, TopAbs_EDGE ); eExp.More(); eExp.Next() )
occgeo.face_maxh = mparams.maxh;
// Let netgen create _ngMesh and calculate element size on not meshed shapes
-#ifndef NETGEN_V5
- char *optstr = 0;
-#endif
int startWith = netgen::MESHCONST_ANALYSE;
int endWith = netgen::MESHCONST_ANALYSE;
try
{
OCC_CATCH_SIGNALS;
-#ifdef NETGEN_V5
- err = netgen::OCCGenerateMesh(occgeo, _ngMesh, mparams, startWith, endWith);
-#else
- err = netgen::OCCGenerateMesh(occgeo, _ngMesh, startWith, endWith, optstr);
-#endif
+
+ err = ngLib.GenerateMesh(occgeo, startWith, endWith, _ngMesh);
+
if(netgen::multithread.terminate)
return false;
catch (netgen::NgException & ex)
{
comment << text(ex);
- if ( mparams.meshsizefilename )
+#ifdef NETGEN_V6
+ bool hasSizeFile = !mparams.meshsizefilename.empty();
+#else
+ bool hasSizeFile = mparams.meshsizefilename;
+#endif
+ if ( hasSizeFile )
throw SMESH_ComputeError(COMPERR_BAD_PARMETERS, comment );
}
err = 0; //- MESHCONST_ANALYSE isn't so important step
//OCCSetLocalMeshSize(intOccgeo, *_ngMesh); it deletes _ngMesh->localH
// let netgen create a temporary mesh
-#ifdef NETGEN_V5
- netgen::OCCGenerateMesh(intOccgeo, tmpNgMesh, mparams, startWith, endWith);
-#else
- netgen::OCCGenerateMesh(intOccgeo, tmpNgMesh, startWith, endWith, optstr);
-#endif
- if(netgen::multithread.terminate)
+ ngLib.GenerateMesh(intOccgeo, startWith, endWith, tmpNgMesh);
+
+ if ( netgen::multithread.terminate )
return false;
// copy LocalH from the main to temporary mesh
// compute mesh on internal edges
startWith = endWith = netgen::MESHCONST_MESHEDGES;
-#ifdef NETGEN_V5
- err = netgen::OCCGenerateMesh(intOccgeo, tmpNgMesh, mparams, startWith, endWith);
-#else
- err = netgen::OCCGenerateMesh(intOccgeo, tmpNgMesh, startWith, endWith, optstr);
-#endif
+ err = ngLib.GenerateMesh(intOccgeo, startWith, endWith, tmpNgMesh);
+
comment << text(err);
}
catch (Standard_Failure& ex)
try
{
OCC_CATCH_SIGNALS;
-#ifdef NETGEN_V5
- err = netgen::OCCGenerateMesh(occgeo, _ngMesh, mparams, startWith, endWith);
-#else
- err = netgen::OCCGenerateMesh(occgeo, _ngMesh, startWith, endWith, optstr);
-#endif
- if(netgen::multithread.terminate)
+
+ err = ngLib.GenerateMesh(occgeo, startWith, endWith);
+
+ if ( netgen::multithread.terminate )
return false;
comment << text(err);
try
{
OCC_CATCH_SIGNALS;
-#ifdef NETGEN_V5
- err = netgen::OCCGenerateMesh(occgeo, _ngMesh, mparams, startWith, endWith);
-#else
- err = netgen::OCCGenerateMesh(occgeo, _ngMesh, startWith, endWith, optstr);
-#endif
- if(netgen::multithread.terminate)
+
+ err = ngLib.GenerateMesh(occgeo, startWith, endWith);
+
+ if ( netgen::multithread.terminate )
return false;
comment << text (err);
}
_ngMesh->SetGlobalH (mparams.maxh);
mparams.grading = 0.4;
-#ifdef NETGEN_V5
- _ngMesh->CalcLocalH(mparams.grading);
-#else
- _ngMesh->CalcLocalH();
-#endif
+ ngLib.CalcLocalH( ngLib._ngMesh );
}
// Care of vertices internal in solids and internal faces (issue 0020676)
if ( internals.hasInternalVertexInSolid() || internals.hasInternalFaces() )
try
{
OCC_CATCH_SIGNALS;
-#ifdef NETGEN_V5
- err = netgen::OCCGenerateMesh(occgeo, _ngMesh, mparams, startWith, endWith);
-#else
- err = netgen::OCCGenerateMesh(occgeo, _ngMesh, startWith, endWith, optstr);
-#endif
- if(netgen::multithread.terminate)
+
+ err = ngLib.GenerateMesh(occgeo, startWith, endWith);
+
+ if ( netgen::multithread.terminate )
return false;
if ( comment.empty() ) // do not overwrite a previous error
try
{
OCC_CATCH_SIGNALS;
-#ifdef NETGEN_V5
- err = netgen::OCCGenerateMesh(occgeo, _ngMesh, mparams, startWith, endWith);
-#else
- err = netgen::OCCGenerateMesh(occgeo, _ngMesh, startWith, endWith, optstr);
-#endif
- if(netgen::multithread.terminate)
+
+ err = ngLib.GenerateMesh(occgeo, startWith, endWith);
+
+ if ( netgen::multithread.terminate )
return false;
if ( comment.empty() ) // do not overwrite a previous error
_ngMesh->Compress();
}
// convert to quadratic
- netgen::OCCRefinementSurfaces ref (occgeo);
- ref.MakeSecondOrder (*_ngMesh);
+#ifdef NETGEN_V6
+ occgeo.GetRefinement().MakeSecondOrder(*_ngMesh);
+#else
+ netgen::OCCRefinementSurfaces(occgeo).MakeSecondOrder(*_ngMesh);
+#endif
// care of elements already loaded to SMESH
// if ( initState._nbSegments > 0 )
// let netgen create _ngMesh and calculate element size on not meshed shapes
NETGENPlugin_NetgenLibWrapper ngLib;
netgen::Mesh *ngMesh = NULL;
-#ifndef NETGEN_V5
- char *optstr = 0;
-#endif
int startWith = netgen::MESHCONST_ANALYSE;
int endWith = netgen::MESHCONST_MESHEDGES;
-#ifdef NETGEN_V5
- int err = netgen::OCCGenerateMesh(occgeo, ngMesh, mparams, startWith, endWith);
-#else
- int err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr);
-#endif
+ int err = ngLib.GenerateMesh(occgeo, startWith, endWith, ngMesh);
if(netgen::multithread.terminate)
return false;
{
if ( !fromMesh->LocalHFunctionGenerated() ) return;
if ( !toMesh->LocalHFunctionGenerated() )
-#ifdef NETGEN_V5
- toMesh->CalcLocalH(netgen::mparam.grading);
-#else
- toMesh->CalcLocalH();
-#endif
+ NETGENPlugin_NetgenLibWrapper::CalcLocalH( toMesh );
const size_t size = sizeof( netgen::LocalH );
_copyOfLocalH = new char[ size ];
*/
//================================================================================
-NETGENPlugin_NetgenLibWrapper::NETGENPlugin_NetgenLibWrapper()
+NETGENPlugin_NetgenLibWrapper::NETGENPlugin_NetgenLibWrapper():
+ _ngMesh(0)
{
if ( instanceCounter() == 0 )
+ {
Ng_Init();
+ if ( !netgen::testout )
+ netgen::testout = new ofstream( "test.out" );
+ }
++instanceCounter();
#endif
}
- _ngMesh = Ng_NewMesh();
+ setMesh( Ng_NewMesh() );
}
//================================================================================
{
--instanceCounter();
- Ng_DeleteMesh( _ngMesh );
+ Ng_DeleteMesh( ngMesh() );
Ng_Exit();
RemoveTmpFiles();
if ( _coutBuffer )
void NETGENPlugin_NetgenLibWrapper::setMesh( Ng_Mesh* mesh )
{
if ( _ngMesh )
- Ng_DeleteMesh( _ngMesh );
- _ngMesh = mesh;
+ Ng_DeleteMesh( ngMesh() );
+ _ngMesh = (netgen::Mesh*) mesh;
+}
+
+//================================================================================
+/*!
+ * \brief Perform a step of mesh generation
+ * \param [inout] occgeo - geometry to mesh
+ * \param [inout] startWith - start step
+ * \param [inout] endWith - end step
+ * \param [inout] ngMesh - netgen mesh
+ * \return int - is error
+ */
+//================================================================================
+
+int NETGENPlugin_NetgenLibWrapper::GenerateMesh( netgen::OCCGeometry& occgeo,
+ int startWith, int endWith,
+ netgen::Mesh* & ngMesh )
+{
+ int err = 0;
+#ifdef NETGEN_V6
+
+ if ( !ngMesh )
+ ngMesh = new netgen::Mesh;
+ ngMesh->SetGeometry( shared_ptr<netgen::NetgenGeometry>( &occgeo, &NOOP_Deleter ));
+
+ netgen::mparam.perfstepsstart = startWith;
+ netgen::mparam.perfstepsend = endWith;
+ std::shared_ptr<netgen::Mesh> meshPtr( ngMesh, &NOOP_Deleter );
+ err = occgeo.GenerateMesh( meshPtr, netgen::mparam );
+
+#else
+ #ifdef NETGEN_V5
+
+ err = netgen::OCCGenerateMesh(occgeo, ngMesh, netgen::mparam, startWith, endWith);
+
+ #else
+
+ char *optstr = 0;
+ err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr);
+
+ #endif
+#endif
+ return err;
+}
+
+//================================================================================
+/*!
+ * \brief Create a mesh size tree
+ */
+//================================================================================
+
+void NETGENPlugin_NetgenLibWrapper::CalcLocalH( netgen::Mesh * ngMesh )
+{
+#if defined( NETGEN_V5 ) || defined( NETGEN_V6 )
+ ngMesh->CalcLocalH(netgen::mparam.grading);
+#else
+ ngMesh->CalcLocalH();
+#endif
}
//================================================================================
{
std::string aTmpDir = SALOMEDS_Tool::GetTmpDir();
- TCollection_AsciiString aGenericName = (char*)aTmpDir.c_str();
+ TCollection_AsciiString aGenericName = aTmpDir.c_str();
aGenericName += "NETGEN_";
#ifndef WIN32
aGenericName += getpid();
#define OCCGEOMETRY
#endif
#include <occgeom.hpp>
+
+#ifdef NETGEN_V5
#include <ngexception.hpp>
+#endif
+#ifdef NETGEN_V6
+#include <exception.hpp>
+#endif
+
namespace nglib {
#include <nglib.h>
}
int Netgen_triangle[3];
NETGENPlugin_NetgenLibWrapper ngLib;
- Ng_Mesh * Netgen_mesh = ngLib._ngMesh;
+ Ng_Mesh * Netgen_mesh = (Ng_Mesh*)ngLib._ngMesh;
// vector of nodes in which node index == netgen ID
vector< const SMDS_MeshNode* > nodeVec;
// Generate the volume mesh
// -------------------------
- return ( ngLib._isComputeOk = compute( aMesh, helper, nodeVec, Netgen_mesh));
+ return ( ngLib._isComputeOk = compute( aMesh, helper, nodeVec, ngLib ));
}
// namespace
bool NETGENPlugin_NETGEN_3D::compute(SMESH_Mesh& aMesh,
SMESH_MesherHelper& helper,
vector< const SMDS_MeshNode* >& nodeVec,
- Ng_Mesh * Netgen_mesh)
+ NETGENPlugin_NetgenLibWrapper& ngLib)
{
netgen::multithread.terminate = 0;
- netgen::Mesh* ngMesh = (netgen::Mesh*)Netgen_mesh;
- int Netgen_NbOfNodes = Ng_GetNP(Netgen_mesh);
+ netgen::Mesh* ngMesh = ngLib._ngMesh;
+ Ng_Mesh* Netgen_mesh = ngLib.ngMesh();
+ int Netgen_NbOfNodes = Ng_GetNP( Netgen_mesh );
-#ifndef NETGEN_V5
- char *optstr = 0;
-#endif
int startWith = netgen::MESHCONST_MESHVOLUME;
int endWith = netgen::MESHCONST_OPTVOLUME;
int err = 1;
{
OCC_CATCH_SIGNALS;
-#ifdef NETGEN_V5
- ngMesh->CalcLocalH(netgen::mparam.grading);
- err = netgen::OCCGenerateMesh(occgeo, ngMesh, netgen::mparam, startWith, endWith);
-#else
- ngMesh->CalcLocalH();
- err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr);
-#endif
+ ngLib.CalcLocalH(ngMesh);
+ err = ngLib.GenerateMesh(occgeo, startWith, endWith);
+
if(netgen::multithread.terminate)
return false;
if ( err )
int Netgen_triangle[3];
NETGENPlugin_NetgenLibWrapper ngLib;
- Ng_Mesh * Netgen_mesh = ngLib._ngMesh;
+ Ng_Mesh * Netgen_mesh = ngLib.ngMesh();
SMESH_ProxyMesh::Ptr proxyMesh( new SMESH_ProxyMesh( aMesh ));
if ( aMesh.NbQuadrangles() > 0 )
// Generate the volume mesh
// -------------------------
- return ( ngLib._isComputeOk = compute( aMesh, *aHelper, nodeVec, Netgen_mesh));
+ return ( ngLib._isComputeOk = compute( aMesh, *aHelper, nodeVec, ngLib ));
}
void NETGENPlugin_NETGEN_3D::CancelCompute()
namespace netgen {
+ NETGENPLUGIN_DLL_HEADER
+ extern MeshingParameters mparam;
+
NETGENPLUGIN_DLL_HEADER
extern STLParameters stlparam;
netgen::stlparam.resthchartdistenable = hyp->GetRestHChartDistEnable();
netgen::stlparam.resthlinelengthfac = hyp->GetRestHLineLengthFactor();
netgen::stlparam.resthlinelengthenable = hyp->GetRestHLineLengthEnable();
+#ifndef NETGEN_V6
netgen::stlparam.resthcloseedgefac = hyp->GetRestHCloseEdgeFactor();
netgen::stlparam.resthcloseedgeenable = hyp->GetRestHCloseEdgeEnable();
+#endif
netgen::stlparam.resthsurfcurvfac = hyp->GetRestHSurfCurvFactor();
netgen::stlparam.resthsurfcurvenable = hyp->GetRestHSurfCurvEnable();
netgen::stlparam.resthedgeanglefac = hyp->GetRestHEdgeAngleFactor();
netgen::STLGeometry* stlGeom = (netgen::STLGeometry*)ngStlGeo;
// the following code is taken from STLMeshing() method
+#ifdef NETGEN_V6
+ stlGeom->Clear();
+ stlGeom->BuildEdges( netgen::stlparam );
+ stlGeom->MakeAtlas( *ngMesh, netgen::mparam, netgen::stlparam );
+ stlGeom->CalcFaceNums();
+ stlGeom->AddFaceEdges();
+ fixNodes( fixedEdges->GetGroupDS(), stlGeom );
+ stlGeom->LinkEdges( netgen::stlparam );
+#else
stlGeom->Clear();
stlGeom->BuildEdges();
stlGeom->MakeAtlas( *ngMesh );
stlGeom->AddFaceEdges();
fixNodes( fixedEdges->GetGroupDS(), stlGeom );
stlGeom->LinkEdges();
-
+#endif
ngMesh->ClearFaceDescriptors();
for (int i = 1; i <= stlGeom->GetNOFaces(); i++)
ngMesh->AddFaceDescriptor (netgen::FaceDescriptor (i, 1, 0, 0));
}
else
{
- Ng_STL_MakeEdges( ngStlGeo, ngLib._ngMesh, &ngParams );
+ Ng_STL_MakeEdges( ngStlGeo, ngLib.ngMesh(), &ngParams );
}
netgen::mparam = savedParams;
netgen::OCCGeometry occgeo;
mesher.SetLocalSize( occgeo, *ngMesh );
- // const char* optStr = "SmSmSm";//"smsmsmSmSmSm";
- // netgen::mparam.optimize2d = optStr;
-
// meshing
try
{
- ng_res = Ng_STL_GenerateSurfaceMesh( ngStlGeo, ngLib._ngMesh, &ngParams );
+ ng_res = Ng_STL_GenerateSurfaceMesh( ngStlGeo, ngLib.ngMesh(), &ngParams );
}
catch (netgen::NgException & ex)
{