+ //================================================================================
+ /*!
+ * \brief Restrict size of elements on the given edge
+ */
+ //================================================================================
+
+ void setLocalSize(const TopoDS_Edge& edge,
+ double size,
+ netgen::Mesh& mesh,
+ const bool overrideMinH = true)
+ {
+ if ( size <= std::numeric_limits<double>::min() )
+ return;
+ Standard_Real u1, u2;
+ Handle(Geom_Curve) curve = BRep_Tool::Curve(edge, u1, u2);
+ if ( curve.IsNull() )
+ {
+ TopoDS_Iterator vIt( edge );
+ if ( !vIt.More() ) return;
+ gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( vIt.Value() ));
+ NETGENPlugin_Mesher::RestrictLocalSize( mesh, p.XYZ(), size, overrideMinH );
+ }
+ else
+ {
+ const int nb = (int)( 1.5 * SMESH_Algo::EdgeLength( edge ) / size );
+ Standard_Real delta = (u2-u1)/nb;
+ for(int i=0; i<nb; i++)
+ {
+ Standard_Real u = u1 + delta*i;
+ gp_Pnt p = curve->Value(u);
+ NETGENPlugin_Mesher::RestrictLocalSize( mesh, p.XYZ(), size, overrideMinH );
+ netgen::Point3d pi(p.X(), p.Y(), p.Z());
+ double resultSize = mesh.GetH(pi);
+ if ( resultSize - size > 0.1*size )
+ // netgen does restriction iff oldH/newH > 1.2 (localh.cpp:136)
+ NETGENPlugin_Mesher::RestrictLocalSize( mesh, p.XYZ(), resultSize/1.201, overrideMinH );
+ }
+ }
+ }
+
+ //================================================================================
+ /*!
+ * \brief Return triangle size for a given chordalError and radius of curvature
+ */
+ //================================================================================
+
+ double elemSizeForChordalError( double chordalError, double radius )
+ {
+ if ( 2 * radius < chordalError )
+ return 1.5 * radius;
+ return Sqrt( 3 ) * Sqrt( chordalError * ( 2 * radius - chordalError ));
+ }
+
+ //=============================================================================
+ /*!
+ *
+ */
+ //=============================================================================
+
+ void setLocalSize(const TopoDS_Shape& GeomShape, double LocalSize)
+ {
+ if ( GeomShape.IsNull() ) return;
+ TopAbs_ShapeEnum GeomType = GeomShape.ShapeType();
+ if (GeomType == TopAbs_COMPOUND) {
+ for (TopoDS_Iterator it (GeomShape); it.More(); it.Next()) {
+ setLocalSize(it.Value(), LocalSize);
+ }
+ return;
+ }
+ int key;
+ if (! ShapesWithLocalSize.Contains(GeomShape))
+ key = ShapesWithLocalSize.Add(GeomShape);
+ else
+ key = ShapesWithLocalSize.FindIndex(GeomShape);
+ if (GeomType == TopAbs_VERTEX) {
+ VertexId2LocalSize[key] = LocalSize;
+ } else if (GeomType == TopAbs_EDGE) {
+ EdgeId2LocalSize[key] = LocalSize;
+ } else if (GeomType == TopAbs_FACE) {
+ FaceId2LocalSize[key] = LocalSize;
+ } else if (GeomType == TopAbs_SOLID) {
+ SolidId2LocalSize[key] = LocalSize;
+ }
+ return;
+ }
+
+ //================================================================================
+ /*!
+ * \brief Return faceNgID or faceNgID-1 depending on side the given proxy face lies
+ * \param [in] f - proxy face
+ * \param [in] solidSMDSIDs - IDs of SOLIDs sharing the FACE on which face lies
+ * \param [in] faceNgID - NETGEN ID of the FACE
+ * \return int - NETGEN ID of the FACE
+ */
+ //================================================================================
+
+ int getFaceNgID( const SMDS_MeshElement* face,
+ const int * solidSMDSIDs,
+ const int faceNgID )
+ {
+ for ( int i = 0; i < 3; ++i )
+ {
+ const SMDS_MeshNode* n = face->GetNode( i );
+ const int shapeID = n->GetShapeID();
+ if ( shapeID == solidSMDSIDs[0] )
+ return faceNgID - 1;
+ if ( shapeID == solidSMDSIDs[1] )
+ return faceNgID;
+ }
+ std::vector<const SMDS_MeshNode*> fNodes( face->begin_nodes(), face->end_nodes() );
+ std::vector<const SMDS_MeshElement*> vols;
+ if ( SMDS_Mesh::GetElementsByNodes( fNodes, vols, SMDSAbs_Volume ))
+ for ( size_t i = 0; i < vols.size(); ++i )
+ {
+ const int shapeID = vols[i]->GetShapeID();
+ if ( shapeID == solidSMDSIDs[0] )
+ return faceNgID - 1;
+ if ( shapeID == solidSMDSIDs[1] )
+ return faceNgID;
+ }
+ return faceNgID;
+ }
+
+} // namespace
+
+
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+NETGENPlugin_Mesher::NETGENPlugin_Mesher (SMESH_Mesh* mesh,
+ const TopoDS_Shape& aShape,
+ const bool isVolume)
+ : _mesh (mesh),
+ _shape (aShape),
+ _isVolume(isVolume),
+ _optimize(true),
+ _fineness(NETGENPlugin_Hypothesis::GetDefaultFineness()),
+ _isViscousLayers2D(false),
+ _chordalError(-1), // means disabled
+ _ngMesh(NULL),
+ _occgeom(NULL),
+ _curShapeIndex(-1),
+ _progressTic(1),
+ _totalTime(1.0),
+ _simpleHyp(NULL),
+ _viscousLayersHyp(NULL),
+ _ptrToMe(NULL)
+{
+ SetDefaultParameters();
+ ShapesWithLocalSize.Clear();
+ VertexId2LocalSize.clear();
+ EdgeId2LocalSize.clear();
+ FaceId2LocalSize.clear();
+ SolidId2LocalSize.clear();
+ ControlPoints.clear();
+ ShapesWithControlPoints.clear();
+}
+
+//================================================================================
+/*!
+ * Destructor
+ */
+//================================================================================
+
+NETGENPlugin_Mesher::~NETGENPlugin_Mesher()
+{
+ if ( _ptrToMe )
+ *_ptrToMe = NULL;
+ _ptrToMe = 0;
+ _ngMesh = NULL;
+}
+
+//================================================================================
+/*!
+ * Set pointer to NETGENPlugin_Mesher* field of the holder, that will be
+ * nullified at destruction of this
+ */
+//================================================================================
+
+void NETGENPlugin_Mesher::SetSelfPointer( NETGENPlugin_Mesher ** ptr )
+{
+ if ( _ptrToMe )
+ *_ptrToMe = NULL;
+
+ _ptrToMe = ptr;
+
+ if ( _ptrToMe )
+ *_ptrToMe = this;
+}
+
+//================================================================================
+/*!
+ * \brief Initialize global NETGEN parameters with default values
+ */
+//================================================================================
+
+void NETGENPlugin_Mesher::SetDefaultParameters()
+{
+ netgen::MeshingParameters& mparams = netgen::mparam;
+ mparams = netgen::MeshingParameters();
+ // maximal mesh edge size
+ mparams.maxh = 0;//NETGENPlugin_Hypothesis::GetDefaultMaxSize();
+ mparams.minh = 0;
+ // minimal number of segments per edge
+ mparams.segmentsperedge = NETGENPlugin_Hypothesis::GetDefaultNbSegPerEdge();
+ // rate of growth of size between elements
+ mparams.grading = NETGENPlugin_Hypothesis::GetDefaultGrowthRate();
+ // safety factor for curvatures (elements per radius)
+ mparams.curvaturesafety = NETGENPlugin_Hypothesis::GetDefaultNbSegPerRadius();
+ // create elements of second order
+ mparams.secondorder = NETGENPlugin_Hypothesis::GetDefaultSecondOrder();
+ // quad-dominated surface meshing
+ if (_isVolume)
+ mparams.quad = 0;
+ else
+ mparams.quad = NETGENPlugin_Hypothesis_2D::GetDefaultQuadAllowed();
+ _fineness = NETGENPlugin_Hypothesis::GetDefaultFineness();
+ mparams.uselocalh = NETGENPlugin_Hypothesis::GetDefaultSurfaceCurvature();
+ netgen::merge_solids = NETGENPlugin_Hypothesis::GetDefaultFuseEdges();
+ // Unused argument but set 0 to initialise it
+ mparams.elementorder = 0;
+
+#ifdef NETGEN_V6
+
+ mparams.nthreads = NETGENPlugin_Hypothesis::GetDefaultNbThreads();
+
+ if ( getenv( "SALOME_NETGEN_DISABLE_MULTITHREADING" ))
+ {
+ mparams.nthreads = 1;
+ mparams.parallel_meshing = false;
+ }
+#endif
+}
+