Salome HOME
Fix compilation errors using gcc-5.X relating to explicit stream::operator bool()
[modules/smesh.git] / src / StdMeshers / StdMeshers_Adaptive1D.cxx
index 55d5d00b48efb02fd29c996e0ca3910b5bc96499..8ffcc0ce255b21818cd42c9fc905a41763123887 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 
 #include <BRepAdaptor_Curve.hxx>
 #include <BRepAdaptor_Surface.hxx>
+#include <BRepBndLib.hxx>
 #include <BRepMesh_IncrementalMesh.hxx>
 #include <BRep_Tool.hxx>
 #include <Bnd_B3d.hxx>
+#include <Bnd_Box.hxx>
 #include <GCPnts_AbscissaPoint.hxx>
 #include <GeomAdaptor_Curve.hxx>
 #include <Geom_Curve.hxx>
@@ -278,28 +280,6 @@ namespace // internal utils
     vector< int > _elementIDs;
   };
   //================================================================================
-  /*!
-   * \brief BRepMesh_IncrementalMesh with access to its protected Bnd_Box
-   */
-  struct IncrementalMesh : public BRepMesh_IncrementalMesh
-  {
-    IncrementalMesh(const TopoDS_Shape& shape,
-                    const Standard_Real deflection,
-                    const bool          relative):
-      BRepMesh_IncrementalMesh( shape, deflection, relative )
-    {
-    }
-    Bnd_B3d GetBox() const
-    {
-      Standard_Real TXmin, TYmin, TZmin, TXmax, TYmax, TZmax;
-      myBox.Get(TXmin, TYmin, TZmin, TXmax, TYmax, TZmax);
-      Bnd_B3d bb;
-      bb.Add( gp_XYZ( TXmin, TYmin, TZmin ));
-      bb.Add( gp_XYZ( TXmax, TYmax, TZmax ));
-      return bb;
-    }
-  };
-  //================================================================================
   /*!
    * \brief Link of two nodes
    */
@@ -555,7 +535,7 @@ namespace // internal utils
         for ( int i = 0; i < 3; ++i )
         {
           const gp_Pnt& pn = myNodes->Value(n[i]);
-          if ( avoidTria = ( pn.SquareDistance( *avoidPnt ) <= tol2 ))
+          if (( avoidTria = ( pn.SquareDistance( *avoidPnt ) <= tol2 )))
             break;
           if ( !projectedOnly )
             minD2 = Min( minD2, pn.SquareDistance( p ));
@@ -723,7 +703,7 @@ namespace // internal utils
   void ElementBndBoxTree::buildChildrenData()
   {
     ElemTreeData* data = GetElemData();
-    for ( int i = 0; i < _elementIDs.size(); ++i )
+    for ( size_t i = 0; i < _elementIDs.size(); ++i )
     {
       const Bnd_B3d* elemBox = data->GetBox( _elementIDs[i] );
       for (int j = 0; j < 8; j++)
@@ -738,7 +718,7 @@ namespace // internal utils
     {
       ElementBndBoxTree* child = static_cast<ElementBndBoxTree*>( myChildren[j] );
       child->_elementIDs = data->myWorkIDs[ j ];
-      if ( child->_elementIDs.size() <= theMaxNbElemsInLeaf )
+      if ((int) child->_elementIDs.size() <= theMaxNbElemsInLeaf )
         child->myIsLeaf = true;
       data->myWorkIDs[ j ].clear();
     }
@@ -761,7 +741,7 @@ namespace // internal utils
       if ( isLeaf() )
       {
         ElemTreeData* data = GetElemData();
-        for ( int i = 0; i < _elementIDs.size(); ++i )
+        for ( size_t i = 0; i < _elementIDs.size(); ++i )
           if ( !data->GetBox( _elementIDs[i] )->IsOut( center, radius ))
             foundElemIDs.push_back( _elementIDs[i] );
       }
@@ -942,7 +922,6 @@ StdMeshers_Adaptive1D::StdMeshers_Adaptive1D(int         hypId,
   myMinSize       = 1e-10;
   myMaxSize       = 1e+10;
   myDeflection    = 1e-2;
-  myGrading       = 1e-2;
   myAlgo          = NULL;
   _name           = "Adaptive1D";
   _param_algo_dim = 1; // is used by SMESH_Regular_1D
@@ -969,20 +948,6 @@ void StdMeshers_Adaptive1D::SetDeflection(double value)
   }
 }
 //=======================================================================
-//function : SetGrading
-//purpose  :
-void StdMeshers_Adaptive1D::SetGrading(double value)
-  throw(SALOME_Exception)
-{
-  if (value <= std::numeric_limits<double>::min() )
-    throw SALOME_Exception("Grading must be greater that zero");
-  if (myGrading != value)
-  {
-    myGrading = value;
-    NotifySubMeshesHypothesisModification();
-  }
-}
-//=======================================================================
 //function : SetMinSize
 //purpose  : Sets minimal allowed segment length
 void StdMeshers_Adaptive1D::SetMinSize(double minSize)
@@ -1017,7 +982,7 @@ void StdMeshers_Adaptive1D::SetMaxSize(double maxSize)
 //purpose  : Persistence
 ostream & StdMeshers_Adaptive1D::SaveTo(ostream & save)
 {
-  save << myMinSize << " " << myMaxSize << " " << myDeflection << " " << myGrading;
+  save << myMinSize << " " << myMaxSize << " " << myDeflection;
   save << " " << -1 << " " << -1; // preview addition of parameters
   return save;
 }
@@ -1027,7 +992,7 @@ ostream & StdMeshers_Adaptive1D::SaveTo(ostream & save)
 istream & StdMeshers_Adaptive1D::LoadFrom(istream & load)
 {
   int dummyParam;
-  bool isOK = (load >> myMinSize >> myMaxSize >> myDeflection >> myGrading >> dummyParam >> dummyParam);
+  bool isOK = static_cast<bool>(load >> myMinSize >> myMaxSize >> myDeflection >> dummyParam >> dummyParam);
   if (!isOK)
     load.clear(ios::badbit | load.rdstate());
   return load;
@@ -1097,7 +1062,6 @@ bool StdMeshers_Adaptive1D::SetParametersByDefaults(const TDefaults&  dflts,
   myMinSize = dflts._elemLength / 10;
   myMaxSize = dflts._elemLength * 2;
   myDeflection = myMinSize / 7;
-  myGrading = 0.7;
   return true;
 }
 
@@ -1161,17 +1125,26 @@ bool AdaptiveAlgo::Compute(SMESH_Mesh &         theMesh,
 
   myMesh = &theMesh;
   SMESH_MesherHelper helper( theMesh );
-  const double grading = myHyp->GetGrading();
+  const double grading = 0.7;
 
   TopTools_IndexedMapOfShape edgeMap, faceMap;
   TopExp::MapShapes( theShape,                 TopAbs_EDGE, edgeMap );
   TopExp::MapShapes( theMesh.GetShapeToMesh(), TopAbs_FACE, faceMap );
 
   // Triangulate the shape with the given deflection ?????????
+  {
+    BRepMesh_IncrementalMesh im( theMesh.GetShapeToMesh(), myHyp->GetDeflection(), /*isRelatif=*/0);
+  }
+
+  // get a bnd box
   Bnd_B3d box;
   {
-    IncrementalMesh im( theMesh.GetShapeToMesh(), myHyp->GetDeflection(), /*Relatif=*/false);
-    box = im.GetBox();
+    Bnd_Box aBox;
+    BRepBndLib::Add( theMesh.GetShapeToMesh(), aBox);
+    Standard_Real TXmin, TYmin, TZmin, TXmax, TYmax, TZmax;
+    aBox.Get(TXmin, TYmin, TZmin, TXmax, TYmax, TZmax);
+    box.Add( gp_XYZ( TXmin, TYmin, TZmin ));
+    box.Add( gp_XYZ( TXmax, TYmax, TZmax ));
   }
   // *theProgress = 0.3;
 
@@ -1206,6 +1179,7 @@ bool AdaptiveAlgo::Compute(SMESH_Mesh &         theMesh,
       eData.AddPoint( eData.myPoints.end(), eData.myC3d.LastParameter() );
     }
   }
+  if ( myEdges.empty() ) return true;
   if ( _computeCanceled ) return false;
 
   // Take into account size of already existing segments
@@ -1223,7 +1197,7 @@ bool AdaptiveAlgo::Compute(SMESH_Mesh &         theMesh,
   StdMeshers_Regular_1D::_value[ DEFLECTION_IND ] = myHyp->GetDeflection();
 
   list< double > params;
-  for ( int iE = 0; iE < myEdges.size(); ++iE )
+  for ( size_t iE = 0; iE < myEdges.size(); ++iE )
   {
     EdgeData& eData = myEdges[ iE ];
     //cout << "E " << theMesh.GetMeshDS()->ShapeToIndex( eData.Edge() ) << endl;
@@ -1269,7 +1243,7 @@ bool AdaptiveAlgo::Compute(SMESH_Mesh &         theMesh,
 
     triaSearcher->SetSizeByTrias( sizeTree, myHyp->GetDeflection() );
 
-    for ( int iE = 0; iE < myEdges.size(); ++iE )
+    for ( size_t iE = 0; iE < myEdges.size(); ++iE )
     {
       EdgeData& eData = myEdges[ iE ];
 
@@ -1316,6 +1290,7 @@ bool AdaptiveAlgo::Compute(SMESH_Mesh &         theMesh,
         //cout << "E " << theMesh.GetMeshDS()->ShapeToIndex( eData.Edge() ) << endl;
         sizeDecreased = false;
         const gp_Pnt* avoidPnt = & eData.First().myP;
+        EdgeData::TPntIter pItLast = --eData.myPoints.end(), pItFirst = eData.myPoints.begin();
         for ( pIt1 = eData.myPoints.begin(); pIt1 != eData.myPoints.end();  )
         {
           double distToFace =
@@ -1333,19 +1308,16 @@ bool AdaptiveAlgo::Compute(SMESH_Mesh &         theMesh,
               //      << "\t SetSize " << allowedSize << " at "
               //      << pIt1->myP.X() <<", "<< pIt1->myP.Y()<<", "<<pIt1->myP.Z() << endl;
               pIt2 = pIt1;
-              if ( --pIt2 != eData.myPoints.end() && pIt2->mySegSize > allowedSize )
+              if ( pIt1 != pItFirst && ( --pIt2 )->mySegSize > allowedSize )
                 sizeTree.SetSize( eData.myC3d.Value( 0.6*pIt2->myU + 0.4*pIt1->myU ), allowedSize );
               pIt2 = pIt1;
-              if ( ++pIt2 != eData.myPoints.end() && pIt2->mySegSize > allowedSize )
+              if ( pIt1 != pItLast  && ( ++pIt2 )->mySegSize > allowedSize )
                 sizeTree.SetSize( eData.myC3d.Value( 0.6*pIt2->myU + 0.4*pIt1->myU ), allowedSize );
             }
             pIt1->mySegSize = allowedSize;
           }
           ++pIt1;
-          if ( & (*pIt1) == & eData.Last() )
-            avoidPnt = & eData.Last().myP;
-          else
-            avoidPnt = NULL;
+          avoidPnt = ( pIt1 == pItLast ) ? & eData.Last().myP : NULL;
 
           if ( iLoop > 20 )
           {
@@ -1382,7 +1354,7 @@ bool AdaptiveAlgo::makeSegments()
 
   vector< double > nbSegs, params;
 
-  for ( int iE = 0; iE < myEdges.size(); ++iE )
+  for ( size_t iE = 0; iE < myEdges.size(); ++iE )
   {
     EdgeData& eData = myEdges[ iE ];
 
@@ -1393,13 +1365,13 @@ bool AdaptiveAlgo::makeSegments()
       edgeMinSize = Min( edgeMinSize,
                          Min( pIt1->mySegSize, mySizeTree->GetSize( pIt1->myP )));
 
-    const double f = eData.myC3d.FirstParameter(), l = eData.myC3d.LastParameter();
+    const double      f = eData.myC3d.FirstParameter(), l = eData.myC3d.LastParameter();
     const double parLen = l - f;
     const int  nbDivSeg = 5;
-    int           nbDiv = Max( 1, int ( eData.myLength / edgeMinSize * nbDivSeg ));
+    size_t        nbDiv = Max( 1, int ( eData.myLength / edgeMinSize * nbDivSeg ));
 
     // compute nb of segments
-    bool toRecompute = true;
+    bool  toRecompute = true;
     double maxSegSize = 0;
     size_t i = 1, segCount;
     //cout << "E " << theMesh.GetMeshDS()->ShapeToIndex( eData.Edge() ) << endl;
@@ -1457,7 +1429,7 @@ bool AdaptiveAlgo::makeSegments()
     }
 
     // compute parameters of nodes
-    int nbSegFinal = Max( 1, int(floor( nbSegs.back() + 0.5 )));
+    size_t nbSegFinal = Max( 1, int(floor( nbSegs.back() + 0.5 )));
     double fact = nbSegFinal / nbSegs.back();
     if ( maxSegSize / fact > myHyp->GetMaxSize() )
       fact = ++nbSegFinal / nbSegs.back();
@@ -1530,7 +1502,7 @@ bool AdaptiveAlgo::Evaluate(SMESH_Mesh &         theMesh,
 
   for ( ; edExp.More(); edExp.Next() )
   {
-    const TopoDS_Edge & edge = TopoDS::Edge( edExp.Current() );
+    //const TopoDS_Edge & edge = TopoDS::Edge( edExp.Current() );
     StdMeshers_Regular_1D::Evaluate( theMesh, theShape, theResMap );
   }
   return true;