-// namespace
-// {
-// void limitVolumeSize( netgen::Mesh* ngMesh,
-// double maxh )
-// {
-// // get average h of faces
-// double faceh = 0;
-// int nbh = 0;
-// for (int i = 1; i <= ngMesh->GetNSE(); i++)
-// {
-// const netgen::Element2d& face = ngMesh->SurfaceElement(i);
-// for (int j=1; j <= face.GetNP(); ++j)
-// {
-// const netgen::PointIndex & i1 = face.PNumMod(j);
-// const netgen::PointIndex & i2 = face.PNumMod(j+1);
-// if ( i1 < i2 )
-// {
-// const netgen::Point3d & p1 = ngMesh->Point( i1 );
-// const netgen::Point3d & p2 = ngMesh->Point( i2 );
-// faceh += netgen::Dist2( p1, p2 );
-// nbh++;
-// }
-// }
-// }
-// faceh = Sqrt( faceh / nbh );
-
-// double compareh;
-// if ( faceh < 0.5 * maxh ) compareh = -1;
-// else if ( faceh > 1.5 * maxh ) compareh = 1;
-// else compareh = 0;
-// // cerr << "faceh " << faceh << endl;
-// // cerr << "init maxh " << maxh << endl;
-// // cerr << "compareh " << compareh << endl;
-
-// if ( compareh > 0 )
-// maxh *= 1.2;
-// else
-// maxh *= 0.8;
-// // cerr << "maxh " << maxh << endl;
-
-// // get bnd box
-// netgen::Point3d pmin, pmax;
-// ngMesh->GetBox( pmin, pmax, 0 );
-// const double dx = pmax.X() - pmin.X();
-// const double dy = pmax.Y() - pmin.Y();
-// const double dz = pmax.Z() - pmin.Z();
-
-// if ( ! & ngMesh->LocalHFunction() )
-// ngMesh->SetLocalH( pmin, pmax, compareh <= 0 ? 0.1 : 0.5 );
-
-// // adjusted by SALOME_TESTS/Grids/smesh/bugs_08/I8
-// const int nbX = Max( 2, int( dx / maxh * 2 ));
-// const int nbY = Max( 2, int( dy / maxh * 2 ));
-// const int nbZ = Max( 2, int( dz / maxh * 2 ));
-
-// netgen::Point3d p;
-// for ( int i = 0; i <= nbX; ++i )
-// {
-// p.X() = pmin.X() + i * dx / nbX;
-// for ( int j = 0; j <= nbY; ++j )
-// {
-// p.Y() = pmin.Y() + j * dy / nbY;
-// for ( int k = 0; k <= nbZ; ++k )
-// {
-// p.Z() = pmin.Z() + k * dz / nbZ;
-// ngMesh->RestrictLocalH( p, maxh );
-// }
-// }
-// }
-// }
-// }
+bool NETGENPlugin_NETGEN_3D::computeRunMesher(
+ netgen::OCCGeometry &occgeo,
+ vector< const SMDS_MeshNode* > &nodeVec,
+ netgen::Mesh* ngMesh,
+ NETGENPlugin_NetgenLibWrapper &ngLib,
+ netgen_params &aParams,
+ int &startWith, int &endWith)
+{
+ int err = 1;
+
+ try
+ {
+ OCC_CATCH_SIGNALS;
+
+ ngLib.CalcLocalH(ngMesh);
+ err = ngLib.GenerateMesh(occgeo, startWith, endWith);
+
+ if(netgen::multithread.terminate)
+ return false;
+ if ( err ){
+ aParams._comment = SMESH_Comment("Error in netgen::OCCGenerateMesh() at ") << netgen::multithread.task;
+ return true;
+ }
+ }
+ catch (Standard_Failure& ex)
+ {
+ SMESH_Comment str("Exception in netgen::OCCGenerateMesh()");
+ str << " at " << netgen::multithread.task
+ << ": " << ex.DynamicType()->Name();
+ if ( ex.GetMessageString() && strlen( ex.GetMessageString() ))
+ str << ": " << ex.GetMessageString();
+ aParams._comment = str;
+ return true;
+ }
+ catch (netgen::NgException& exc)
+ {
+ SMESH_Comment str("NgException");
+ if ( strlen( netgen::multithread.task ) > 0 )
+ str << " at " << netgen::multithread.task;
+ str << ": " << exc.What();
+ aParams._comment = str;
+ return true;
+ }
+ catch (...)
+ {
+ SMESH_Comment str("Exception in netgen::OCCGenerateMesh()");
+ if ( strlen( netgen::multithread.task ) > 0 )
+ str << " at " << netgen::multithread.task;
+ aParams._comment = str;
+ return true;
+ }
+
+ if ( err )
+ {
+ SMESH_ComputeErrorPtr ce = NETGENPlugin_Mesher::ReadErrors(nodeVec);
+ if ( ce && ce->HasBadElems() ){
+ aParams._error = ce->myName;
+ aParams._comment = ce->myComment;
+ return true;
+ }
+ }
+
+ return false;
+}
+
+bool NETGENPlugin_NETGEN_3D::computeFillMesh(
+ vector< const SMDS_MeshNode* > &nodeVec,
+ NETGENPlugin_NetgenLibWrapper &ngLib,
+ SMESH_MesherHelper &helper,
+ int &Netgen_NbOfNodes
+ )
+{
+ Ng_Mesh* Netgen_mesh = ngLib.ngMesh();
+
+ int Netgen_NbOfNodesNew = Ng_GetNP(Netgen_mesh);
+ int Netgen_NbOfTetra = Ng_GetNE(Netgen_mesh);
+
+ bool isOK = ( /*status == NG_OK &&*/ Netgen_NbOfTetra > 0 );// get whatever built
+ if ( isOK )
+ {
+ double Netgen_point[3];
+ int Netgen_tetrahedron[4];
+
+ // create and insert new nodes into nodeVec
+ nodeVec.resize( Netgen_NbOfNodesNew + 1, 0 );
+ int nodeIndex = Netgen_NbOfNodes + 1;
+ for ( ; nodeIndex <= Netgen_NbOfNodesNew; ++nodeIndex )
+ {
+ Ng_GetPoint( Netgen_mesh, nodeIndex, Netgen_point );
+ nodeVec.at(nodeIndex) = helper.AddNode(Netgen_point[0], Netgen_point[1], Netgen_point[2]);
+ }
+
+ // create tetrahedrons
+ for ( int elemIndex = 1; elemIndex <= Netgen_NbOfTetra; ++elemIndex )
+ {
+ Ng_GetVolumeElement(Netgen_mesh, elemIndex, Netgen_tetrahedron);
+ try
+ {
+ helper.AddVolume (nodeVec.at( Netgen_tetrahedron[0] ),
+ nodeVec.at( Netgen_tetrahedron[1] ),
+ nodeVec.at( Netgen_tetrahedron[2] ),
+ nodeVec.at( Netgen_tetrahedron[3] ));
+ }
+ catch (...)
+ {
+ }
+ }
+ }
+ return false;
+}
+
+bool NETGENPlugin_NETGEN_3D::Compute(
+ SMESH_Mesh& aMesh,
+ const TopoDS_Shape& aShape)
+{
+ if(aMesh.IsParallel())
+ return RemoteCompute(aMesh, aShape);
+
+ // vector of nodes in which node index == netgen ID
+ vector< const SMDS_MeshNode* > nodeVec;
+ NETGENPlugin_NetgenLibWrapper ngLib;
+ SMESH_MesherHelper helper(aMesh);
+ int startWith = netgen::MESHCONST_MESHVOLUME;
+ int endWith = netgen::MESHCONST_OPTVOLUME;
+ int Netgen_NbOfNodes;
+
+ netgen_params aParams;
+
+ aParams._hypParameters = const_cast<NETGENPlugin_Hypothesis*>(_hypParameters);
+ aParams._hypMaxElementVolume = const_cast<StdMeshers_MaxElementVolume*>(_hypMaxElementVolume);
+ aParams.maxElementVolume = _maxElementVolume;
+ aParams._progressByTic = _progressByTic;
+ aParams._quadraticMesh = _quadraticMesh;
+ aParams._viscousLayersHyp = const_cast<StdMeshers_ViscousLayers*>(_viscousLayersHyp);
+
+ bool ret;
+ ret = computeFillNgMesh(aMesh, aShape, nodeVec, ngLib, helper, aParams, Netgen_NbOfNodes);
+ if(ret)
+ return error( aParams._error, aParams._comment);
+
+ netgen::OCCGeometry occgeo;
+ computePrepareParam(aMesh, ngLib, occgeo, helper, aParams, endWith);
+ ret = computeRunMesher(occgeo, nodeVec, ngLib._ngMesh, ngLib, aParams, startWith, endWith);
+ if(ret){
+ if(aParams._error)
+ return error(aParams._error, aParams._comment);
+
+ error(aParams._comment);
+ return true;
+ }
+ computeFillMesh(nodeVec, ngLib, helper, Netgen_NbOfNodes);
+
+ return false;
+
+}