Salome HOME
23491: EDF 15591 - Duplicate Elements / Nodes
[modules/smesh.git] / src / SMESHUtils / SMESH_MeshAlgos.hxx
index fe5074eb5aa7b6245a148e5cf30f5848a98bb0c6..0bf9c49b5adbb4bdf3f90b83e1fd5b425fe2e8f4 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  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
@@ -58,6 +58,7 @@ struct SMESHUtils_EXPORT SMESH_NodeSearcher
   virtual int  FindNearPoint(const gp_Pnt&                        point,
                              const double                         tolerance,
                              std::vector< const SMDS_MeshNode* >& foundNodes) = 0;
+  virtual ~SMESH_NodeSearcher() {}
 };
 
 //=======================================================================
@@ -88,6 +89,13 @@ struct SMESHUtils_EXPORT SMESH_ElementSearcher
   virtual void GetElementsNearLine( const gp_Ax1&                           line,
                                     SMDSAbs_ElementType                     type,
                                     std::vector< const SMDS_MeshElement* >& foundElems) = 0;
+  /*!
+   * \brief Return elements whose bounding box intersects a sphere
+   */
+  virtual void GetElementsInSphere( const gp_XYZ&                           center,
+                                    const double                            radius,
+                                    SMDSAbs_ElementType                     type,
+                                    std::vector< const SMDS_MeshElement* >& foundElems) = 0;
   /*!
    * \brief Find out if the given point is out of closed 2D mesh.
    */
@@ -146,20 +154,116 @@ namespace SMESH_MeshAlgos
   std::vector< const SMDS_MeshNode*> GetCommonNodes(const SMDS_MeshElement* e1,
                                                     const SMDS_MeshElement* e2);
 
+  /*!
+   * \brief Mark elements given by SMDS_Iterator
+   */
+  template< class ElemIter >
+  void MarkElems( ElemIter it, const bool isMarked )
+  {
+    while ( it->more() ) it->next()->setIsMarked( isMarked );
+  }
+  /*!
+   * \brief Mark elements given by std iterators
+   */
+  template< class ElemIter >
+  void MarkElems( ElemIter it, ElemIter end, const bool isMarked )
+  {
+    for ( ; it != end; ++it ) (*it)->setIsMarked( isMarked );
+  }
+  /*!
+   * \brief Mark nodes of elements given by SMDS_Iterator
+   */
+  template< class ElemIter >
+  void MarkElemNodes( ElemIter it, const bool isMarked, const bool markElem = false )
+  {
+    if ( markElem )
+      while ( it->more() ) {
+        const SMDS_MeshElement* e = it->next();
+        e->setIsMarked( isMarked );
+        MarkElems( e->nodesIterator(), isMarked );
+      }
+    else
+      while ( it->more() )
+        MarkElems( it->next()->nodesIterator(), isMarked );
+  }
+  /*!
+   * \brief Mark elements given by std iterators
+   */
+  template< class ElemIter >
+  void MarkElemNodes( ElemIter it, ElemIter end, const bool isMarked, const bool markElem = false )
+  {
+    if ( markElem )
+      for ( ; it != end; ++it ) {
+        (*it)->setIsMarked( isMarked );
+        MarkElems( (*it)->nodesIterator(), isMarked );
+      }
+    else
+      for ( ; it != end; ++it )
+        MarkElems( (*it)->nodesIterator(), isMarked );
+  }
+
   /*!
    * \brief Return SMESH_NodeSearcher. The caller is responsible for deleteing it
    */
   SMESHUtils_EXPORT
   SMESH_NodeSearcher* GetNodeSearcher( SMDS_Mesh& mesh );
 
+  SMESHUtils_EXPORT
+  SMESH_NodeSearcher* GetNodeSearcher( SMDS_ElemIteratorPtr elemIt );
+
   /*!
    * \brief Return SMESH_ElementSearcher. The caller is responsible for deleting it
    */
   SMESHUtils_EXPORT
-  SMESH_ElementSearcher* GetElementSearcher( SMDS_Mesh& mesh );
+  SMESH_ElementSearcher* GetElementSearcher( SMDS_Mesh& mesh,
+                                             double     tolerance=-1.);
   SMESHUtils_EXPORT
   SMESH_ElementSearcher* GetElementSearcher( SMDS_Mesh& mesh,
-                                             SMDS_ElemIteratorPtr elemIt );
-}
+                                             SMDS_ElemIteratorPtr elemIt,
+                                             double     tolerance=-1. );
+
+
+
+  typedef std::vector<const SMDS_MeshNode*> TFreeBorder;
+  typedef std::vector<TFreeBorder>          TFreeBorderVec;
+  struct TFreeBorderPart
+  {
+    int _border; // border index within a TFreeBorderVec
+    int _node1;  // node index within the border-th TFreeBorder
+    int _node2;
+    int _nodeLast;
+  };
+  typedef std::vector<TFreeBorderPart>  TCoincidentGroup;
+  typedef std::vector<TCoincidentGroup> TCoincidentGroupVec;
+  struct CoincidentFreeBorders
+  {
+    TFreeBorderVec      _borders;          // nodes of all free borders
+    TCoincidentGroupVec _coincidentGroups; // groups of coincident parts of borders
+  };
+
+  /*!
+   * Returns TFreeBorder's coincident within the given tolerance.
+   * If the tolerance <= 0.0 then one tenth of an average size of elements adjacent
+   * to free borders being compared is used.
+   *
+   * (Implemented in ./SMESH_FreeBorders.cxx)
+   */
+  SMESHUtils_EXPORT
+  void FindCoincidentFreeBorders(SMDS_Mesh&              mesh,
+                                 double                  tolerance,
+                                 CoincidentFreeBorders & foundFreeBordes);
+  
+
+  /*!
+   * \brief Find nodes whose merge makes the element invalid
+   *
+   * (Implemented in SMESH_DeMerge.cxx)
+   */
+  SMESHUtils_EXPORT
+  void DeMerge(const SMDS_MeshElement*              elem,
+               std::vector< const SMDS_MeshNode* >& newNodes,
+               std::vector< const SMDS_MeshNode* >& noMergeNodes);
+
+} // namespace SMESH_MeshAlgos
 
 #endif