Salome HOME
ObjectPool and SMDS_Position
[modules/smesh.git] / src / StdMeshers / StdMeshers_MEFISTO_2D.cxx
index f842eb87b01bc6bd88d813f90ffeebfbc6202084..f4ef0198d114575598259d6a3759533eec7cac06 100644 (file)
@@ -53,6 +53,7 @@
 #include <Geom_Curve.hxx>
 #include <Geom2d_Curve.hxx>
 #include <Geom_Surface.hxx>
+#include <Precision.hxx>
 #include <TopExp.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
@@ -303,7 +304,7 @@ bool StdMeshers_MEFISTO_2D::Evaluate(SMESH_Mesh & aMesh,
   TopoDS_Face F = TopoDS::Face(aShape.Oriented(TopAbs_FORWARD));
 
   double aLen = 0.0;
-  double NbSeg = 0;
+  int NbSeg = 0;
   bool IsQuadratic = false;
   bool IsFirst = true;
   TopExp_Explorer exp(F,TopAbs_EDGE);
@@ -312,10 +313,10 @@ bool StdMeshers_MEFISTO_2D::Evaluate(SMESH_Mesh & aMesh,
     MapShapeNbElemsItr anIt = aResMap.find( aMesh.GetSubMesh(E) );
     if( anIt == aResMap.end() ) continue;
     std::vector<int> aVec = (*anIt).second;
-    int nbe = Max(aVec[1],aVec[2]);
+    int nbe = Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
     NbSeg += nbe;
     if(IsFirst) {
-      IsQuadratic = ( aVec[2] > aVec[1] );
+      IsQuadratic = ( aVec[SMDSEntity_Quad_Edge] > aVec[SMDSEntity_Edge] );
       IsFirst = false;
     }
     double a,b;
@@ -331,27 +332,38 @@ bool StdMeshers_MEFISTO_2D::Evaluate(SMESH_Mesh & aMesh,
       P1 = P2;
     }
   }
+  if(NbSeg<1) {
+    std::vector<int> aResVec(SMDSEntity_Last);
+    for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
+    SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
+    aResMap.insert(std::make_pair(sm,aResVec));
+    SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
+    smError.reset( new SMESH_ComputeError(COMPERR_ALGO_FAILED,
+                                          "Submesh can not be evaluated",this));
+    return false;
+  }
   aLen = aLen/NbSeg; // middle length
 
-  _edgeLength = DBL_MAX;
+  _edgeLength = Precision::Infinite();
   double tmpLength = Min( _edgeLength, aLen );
 
   GProp_GProps G;
   BRepGProp::SurfaceProperties(aShape,G);
   double anArea = G.Mass();
 
-  int nbFaces = (int) anArea/(tmpLength*tmpLength*sqrt(3)/4);
+  int nbFaces = Precision::IsInfinite( tmpLength ) ? 0 :
+    (int)( anArea/(tmpLength*tmpLength*sqrt(3.)/4) );
   int nbNodes = (int) ( nbFaces*3 - (NbSeg-1)*2 ) / 6;
 
-  std::vector<int> aVec(17);
-  for(int i=0; i<17; i++) aVec[i] = 0;
+  std::vector<int> aVec(SMDSEntity_Last);
+  for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aVec[i] = 0;
   if(IsQuadratic) {
-    aVec[4] = nbFaces;
-    aVec[0] = nbNodes + nbFaces*3 - (NbSeg-1);
+    aVec[SMDSEntity_Quad_Triangle] = nbFaces;
+    aVec[SMDSEntity_Node] = (int)( nbNodes + nbFaces*3 - (NbSeg-1) );
   }
   else {
-    aVec[0] = nbNodes;
-    aVec[3] = nbFaces;
+    aVec[SMDSEntity_Node] = nbNodes;
+    aVec[SMDSEntity_Triangle] = nbFaces;
   }
   SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
   aResMap.insert(std::make_pair(sm,aVec));
@@ -499,7 +511,7 @@ static bool fixCommonVertexUV (R2 &                 theUV,
         if ( theCreateQuadratic && SMESH_MesherHelper::IsMedium( node, SMDSAbs_Edge ))
           continue;
         const SMDS_EdgePosition* epos =
-          static_cast<const SMDS_EdgePosition*>(node->GetPosition().get());
+          static_cast<const SMDS_EdgePosition*>(node->GetPosition());
         double u = epos->GetUParameter();
         if ( u < umin )
           umin = u;