Salome HOME
Copyright update 2022
[modules/smesh.git] / src / StdMeshers / StdMeshers_HexaFromSkin_3D.cxx
index 58a90931c73d32924e057b65e8d2cf16bf66de48..e91c8806cb7a5c7272cecb4a7cc442a3f00b1751 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 #include "SMDS_VolumeOfNodes.hxx"
 #include "SMDS_VolumeTool.hxx"
+#include "SMESHDS_Mesh.hxx"
 #include "SMESH_Block.hxx"
+#include "SMESH_Indexer.hxx"
+#include "SMESH_Mesh.hxx"
+#include "SMESH_MeshAlgos.hxx"
 #include "SMESH_MesherHelper.hxx"
 
 #include <gp_Ax2.hxx>
 
-//#include "utilities.h"
 #include <limits>
 
+using namespace std;
+
 // Define error message and _MYDEBUG_ if needed
 #ifdef _DEBUG_
 #define BAD_MESH_ERR \
 
 namespace
 {
+  // typedefs for struct's moved to SMESHUtils
+  typedef SMESH_Indexer         _Indexer;
+  typedef SMESH_OrientedIndexer _OrientedIndexer;
+
   enum EBoxSides //!< sides of the block
     {
       B_BOTTOM=0, B_RIGHT, B_TOP, B_LEFT, B_FRONT, B_BACK, NB_BLOCK_SIDES
@@ -107,14 +116,14 @@ namespace
       return true;
 
     set<const SMDS_MeshNode*> nodesInInverseFaces;
-    SMDS_ElemIteratorPtr fIt = n->GetInverseElementIterator(SMDSAbs_Face );
+    SMDS_ElemIteratorPtr fIt = n->GetInverseElementIterator( SMDSAbs_Face );
     while ( fIt->more() )
     {
       const SMDS_MeshElement* face = fIt->next();
       nodesInInverseFaces.insert( face->begin_nodes(), face->end_nodes() );
     }
 
-    return nodesInInverseFaces.size() != ( 6 + (nbF/2-1)*3 );
+    return (int)nodesInInverseFaces.size() != ( 6 + (nbF/2-1)*3 );
   }
 
   //================================================================================
@@ -139,67 +148,6 @@ namespace
     return quad->GetNode( (iNode+2) % 4 );
   }
 
-  //================================================================================
-  /*!
-   * \brief Convertor of a pair of integers to a sole index
-   */
-  struct _Indexer
-  {
-    int _xSize, _ySize;
-    _Indexer( int xSize=0, int ySize=0 ): _xSize(xSize), _ySize(ySize) {}
-    int size() const { return _xSize * _ySize; }
-    int operator()(int x, int y) const { return y * _xSize + x; }
-  };
-  //================================================================================
-  /*!
-   * \brief Oriented convertor of a pair of integers to a sole index 
-   */
-  class _OrientedIndexer : public _Indexer
-  {
-  public:
-    enum OriFlags //!< types of block side orientation
-      {
-        REV_X = 1, REV_Y = 2, SWAP_XY = 4, MAX_ORI = REV_X|REV_Y|SWAP_XY
-      };
-    _OrientedIndexer( const _Indexer& indexer, const int oriFlags ):
-      _Indexer( indexer._xSize, indexer._ySize ),
-      _xSize (indexer._xSize), _ySize(indexer._ySize),
-      _xRevFun((oriFlags & REV_X) ? & reverse : & lazy),
-      _yRevFun((oriFlags & REV_Y) ? & reverse : & lazy),
-      _swapFun((oriFlags & SWAP_XY ) ? & swap : & lazy)
-    {
-      (*_swapFun)( _xSize, _ySize );
-    }
-    //!< Return index by XY
-    int operator()(int x, int y) const
-    {
-      (*_xRevFun)( x, const_cast<int&>( _xSize ));
-      (*_yRevFun)( y, const_cast<int&>( _ySize ));
-      (*_swapFun)( x, y );
-      return _Indexer::operator()(x,y);
-    }
-    //!< Return index for a corner
-    int corner(bool xMax, bool yMax) const
-    {
-      int x = xMax, y = yMax, size = 2;
-      (*_xRevFun)( x, size );
-      (*_yRevFun)( y, size );
-      (*_swapFun)( x, y );
-      return _Indexer::operator()(x ? _Indexer::_xSize-1 : 0 , y ? _Indexer::_ySize-1 : 0);
-    }
-    int xSize() const { return _xSize; }
-    int ySize() const { return _ySize; }
-  private:
-    _Indexer _indexer;
-    int _xSize, _ySize;
-
-    typedef void (*TFun)(int& x, int& y);
-    TFun _xRevFun, _yRevFun, _swapFun;
-    
-    static void lazy   (int&, int&) {}
-    static void reverse(int& x, int& size) { x = size - x - 1; }
-    static void swap   (int& x, int& y) { std::swap(x,y); }
-  };
   //================================================================================
   /*!
    * \brief Structure corresponding to the meshed side of block
@@ -269,8 +217,8 @@ namespace
     //!< safely return a node by XY
     const SMDS_MeshNode* node(int x, int y) const
     {
-      int i = _index( x, y );
-      return ( i < 0 || i >= _side->_grid.size()) ? 0 : _side->_grid[i];
+      size_t i = _index( x, y );
+      return ( i >= _side->_grid.size() ) ? 0 : _side->_grid[i];
     }
     //!< Return an edge
     SMESH_OrientedLink edge(EQuadEdge edge) const
@@ -372,7 +320,7 @@ namespace
 
   //================================================================================
   /*!
-   * \brief Find and return number of submeshes corresponding to blocks
+   * \brief Find blocks and return their number
    */
   //================================================================================
 
@@ -382,7 +330,7 @@ namespace
 
     // Find a node at any block corner
 
-    SMDS_NodeIteratorPtr nIt = meshDS->nodesIterator(/*idInceasingOrder=*/true);
+    SMDS_NodeIteratorPtr nIt = meshDS->nodesIterator();
     if ( !nIt->more() ) return error("Empty mesh");
 
     const SMDS_MeshNode* nCorner = 0;
@@ -401,7 +349,7 @@ namespace
     // Find all block sides starting from mesh faces sharing the corner node
     // --------------------------------------------------------------------
 
-    int nbFacesOnSides = 0;
+    smIdType nbFacesOnSides = 0;
     TIDSortedElemSet cornerFaces; // corner faces of found _BlockSide's
     list< const SMDS_MeshNode* > corners( 1, nCorner );
     list< const SMDS_MeshNode* >::iterator corner = corners.begin();
@@ -421,7 +369,7 @@ namespace
           _allSides.push_back( _BlockSide() );
 
         _BlockSide& side = _allSides.back();
-        if ( !fillSide( side, face, *corner ) )
+        if ( !fillSide( side, face, *corner ))
         {
           if ( !_error.empty() )
             return false;
@@ -522,7 +470,7 @@ namespace
             ok = block.setSide( i, findBlockSide( B_FRONT, edgeOfFront[i], edgeOfAdj[i],
                                                   advAnalys, sidesAround));
         // try to find a BACK side by a TOP one
-        if ( ok || !advAnalys)
+        if ( ok || !advAnalys )
           if ( !block._side[B_BACK] && block._side[B_TOP] )
             ok = block.setSide( B_BACK, findBlockSide( B_TOP, Q_TOP, Q_TOP,
                                                        advAnalys, sidesAround ));
@@ -533,7 +481,7 @@ namespace
       {
         // check if just found block is same as one of previously found blocks
         bool isSame = false;
-        for ( int i = 1; i < _blocks.size() && !isSame; ++i )
+        for ( size_t i = 1; i < _blocks.size() && !isSame; ++i )
           isSame = ( block._corners == _blocks[i-1]._corners );
         ok = !isSame;
       }
@@ -584,7 +532,7 @@ namespace
                         const SMDS_MeshElement* cornerQuad,
                         const SMDS_MeshNode*    nCorner)
   {
-    // Find out size of block side mesured in nodes and by the way find two rows
+    // Find out size of block side measured in nodes and by the way find two rows
     // of nodes in two directions.
 
     int x, y, nbX, nbY;
@@ -606,12 +554,12 @@ namespace
       side._index._ySize = verRow1.size();
       side._grid.resize( side._index.size(), NULL );
 
-      for ( x = 0; x < horRow1.size(); ++x )
+      for ( x = 0; x < nbX; ++x )
       {
         side.setNode( x, 0, horRow1[x] );
         side.setNode( x, 1, horRow2[x] );
       }
-      for ( y = 0; y < verRow1.size(); ++y )
+      for ( y = 0; y < nbY; ++y )
       {
         side.setNode( 0, y, verRow1[y] );
         side.setNode( 1, y, verRow2[y] );
@@ -635,7 +583,7 @@ namespace
       const SMDS_MeshNode* n1down = side.getNode( 0, y-1 );
       const SMDS_MeshNode* n2down = side.getNode( 1, y-1 );
       avoidSet.clear(); avoidSet.insert( firstQuad );
-      firstQuad = SMESH_MeshEditor::FindFaceInSet( n1down, n2down, emptySet, avoidSet,
+      firstQuad = SMESH_MeshAlgos::FindFaceInSet( n1down, n2down, emptySet, avoidSet,
                                                    &i1down, &i2down);
       if ( !isQuadrangle( firstQuad ))
         return BAD_MESH_ERR;
@@ -648,7 +596,7 @@ namespace
       x = 1; 
       while ( ++x < nbX )
       {
-        const SMDS_MeshElement* quad = SMESH_MeshEditor::FindFaceInSet( n2up, n2down, emptySet,
+        const SMDS_MeshElement* quad = SMESH_MeshAlgos::FindFaceInSet( n2up, n2down, emptySet,
                                                                         avoidSet, &i2up, &i2down);
         if ( !isQuadrangle( quad ))
           return BAD_MESH_ERR;
@@ -725,7 +673,9 @@ namespace
       if ( !n ) return false;
 
       prevSide = nextSide;
-      nbChainLinks++;
+
+      if ( ++nbChainLinks > NB_QUAD_SIDES )
+        return false;
     }
 
     return ( n == n2 && nbChainLinks == NB_QUAD_SIDES );
@@ -942,7 +892,7 @@ namespace
     while ( !isCornerNode( n2 ) )
     {
       avoidSet.clear(); avoidSet.insert( quad );
-      quad = SMESH_MeshEditor::FindFaceInSet( n1, n2, emptySet, avoidSet, &i1, &i2 );
+      quad = SMESH_MeshAlgos::FindFaceInSet( n1, n2, emptySet, avoidSet, &i1, &i2 );
       if ( !isQuadrangle( quad ))
         return BAD_MESH_ERR;
 
@@ -1003,6 +953,9 @@ namespace
       SMESH_OrientedLink eAdja = _side[ adjacent[i] ].edge( edgeAdj[i] );
       ok = ( eBack == eAdja );
     }
+    ok = ok && ( _side[ B_BOTTOM ]._index.size() == _side[ B_TOP  ]._index.size() &&
+                 _side[ B_RIGHT  ]._index.size() == _side[ B_LEFT ]._index.size() &&
+                 _side[ B_FRONT  ]._index.size() == _side[ B_BACK ]._index.size() );
     return ok;
   }
 
@@ -1013,16 +966,14 @@ namespace
 //purpose  : 
 //=======================================================================
 
-StdMeshers_HexaFromSkin_3D::StdMeshers_HexaFromSkin_3D(int hypId, int studyId, SMESH_Gen* gen)
-  :SMESH_3D_Algo(hypId, studyId, gen)
+StdMeshers_HexaFromSkin_3D::StdMeshers_HexaFromSkin_3D(int hypId, SMESH_Gen* gen)
+  :SMESH_3D_Algo(hypId, gen)
 {
-  MESSAGE("StdMeshers_HexaFromSkin_3D::StdMeshers_HexaFromSkin_3D");
   _name = "HexaFromSkin_3D";
 }
 
 StdMeshers_HexaFromSkin_3D::~StdMeshers_HexaFromSkin_3D()
 {
-  MESSAGE("StdMeshers_HexaFromSkin_3D::~StdMeshers_HexaFromSkin_3D");
 }
 
 //================================================================================
@@ -1249,8 +1200,8 @@ bool StdMeshers_HexaFromSkin_3D::Evaluate(SMESH_Mesh &         aMesh,
   bool secondOrder = aMesh.NbFaces( ORDER_QUADRATIC );
 
   int entity = secondOrder ? SMDSEntity_Quad_Hexa : SMDSEntity_Hexa;
-  vector<int>& nbByType = aResMap[ aMesh.GetSubMesh( aShape )];
-  if ( entity >= nbByType.size() )
+  vector<smIdType>& nbByType = aResMap[ aMesh.GetSubMesh( aShape )];
+  if ( entity >= (int) nbByType.size() )
     nbByType.resize( SMDSEntity_Last, 0 );
 
   for ( int i = 0; i < nbBlocks; ++i )