Salome HOME
PAL16217 (3D Extrusion produces degenerated hexahedrons)
authoreap <eap@opencascade.com>
Mon, 18 Jun 2007 13:44:24 +0000 (13:44 +0000)
committereap <eap@opencascade.com>
Mon, 18 Jun 2007 13:44:24 +0000 (13:44 +0000)
    fix face association in a block (avoid taking far propagation edge)

src/StdMeshers/StdMeshers_ProjectionUtils.cxx
src/StdMeshers/StdMeshers_ProjectionUtils.hxx

index 25f2399cdc8ab2d9991677a3cfa93be26f68f9ee..1452599ed08ddc7c25eaf5c8c838ff0d43458aa0 100644 (file)
@@ -160,7 +160,7 @@ namespace {
     {
       list< TopoDS_Edge >::iterator eIt2 = ++edges2.begin(); // 2nd edge of the 2nd face
       TopoDS_Edge edge2 =
     {
       list< TopoDS_Edge >::iterator eIt2 = ++edges2.begin(); // 2nd edge of the 2nd face
       TopoDS_Edge edge2 =
-        StdMeshers_ProjectionUtils::GetPropagationEdge( theMesh1, *eIt2, edges1.front() );
+        StdMeshers_ProjectionUtils::GetPropagationEdge( theMesh1, *eIt2, edges1.front() ).second;
       if ( !edge2.IsNull() ) { // propagation found for the second edge
         Reverse( edges2, nbEdges );
         return true;
       if ( !edge2.IsNull() ) { // propagation found for the second edge
         Reverse( edges2, nbEdges );
         return true;
@@ -382,7 +382,7 @@ bool StdMeshers_ProjectionUtils::FindSubShapeAssociation(const TopoDS_Shape& the
     TopoDS_Edge edge2 = TopoDS::Edge( theShape2 );
     if ( IsPropagationPossible( theMesh1, theMesh2 ))
     {
     TopoDS_Edge edge2 = TopoDS::Edge( theShape2 );
     if ( IsPropagationPossible( theMesh1, theMesh2 ))
     {
-      TopoDS_Edge prpEdge = GetPropagationEdge( theMesh1, edge2, edge1 );
+      TopoDS_Edge prpEdge = GetPropagationEdge( theMesh1, edge2, edge1 ).second;
       if ( !prpEdge.IsNull() )
       {
         TopoDS_Vertex VV1[2], VV2[2];
       if ( !prpEdge.IsNull() )
       {
         TopoDS_Vertex VV1[2], VV2[2];
@@ -415,40 +415,46 @@ bool StdMeshers_ProjectionUtils::FindSubShapeAssociation(const TopoDS_Shape& the
     {
       TopoDS_Face face1 = TopoDS::Face(theShape1);
       TopoDS_Face face2 = TopoDS::Face(theShape2);
     {
       TopoDS_Face face1 = TopoDS::Face(theShape1);
       TopoDS_Face face2 = TopoDS::Face(theShape2);
+      TopoDS_Edge edge1, edge2;
       // get outer edge of theShape1
       // get outer edge of theShape1
-      TopoDS_Edge edge1 = TopoDS::Edge( OuterShape( face1, TopAbs_EDGE ));
+      edge1 = TopoDS::Edge( OuterShape( face1, TopAbs_EDGE ));
       // find out if any edge of face2 is a propagation edge of outer edge1
       // find out if any edge of face2 is a propagation edge of outer edge1
+      map<int,TopoDS_Edge> propag_edges; // use map to find the closest propagation edge
       for ( TopExp_Explorer exp( face2, TopAbs_EDGE ); exp.More(); exp.Next() ) {
       for ( TopExp_Explorer exp( face2, TopAbs_EDGE ); exp.More(); exp.Next() ) {
-        TopoDS_Edge edge2 = TopoDS::Edge( exp.Current() );
-        edge2 = GetPropagationEdge( theMesh1, edge2, edge1 );
-        if ( !edge2.IsNull() ) // propagation found
+        edge2 = TopoDS::Edge( exp.Current() );
+        pair<int,TopoDS_Edge> step_edge = GetPropagationEdge( theMesh1, edge2, edge1 );
+        if ( !step_edge.second.IsNull() ) { // propagation found
+          propag_edges.insert( step_edge );
+        }
+      }
+      if ( !propag_edges.empty() ) // propagation found
+      {
+        edge2 = propag_edges.begin()->second;
+        TopoDS_Vertex VV1[2], VV2[2];
+        TopExp::Vertices( edge1, VV1[0], VV1[1], true );
+        TopExp::Vertices( edge2, VV2[0], VV2[1], true );
+        list< TopoDS_Edge > edges1, edges2;
+        int nbE = FindFaceAssociation( face1, VV1, face2, VV2, edges1, edges2 );
+        if ( !nbE ) RETURN_BAD_RESULT("FindFaceAssociation() failed");
+        if ( nbE == 2 ) // only 2 edges
         {
         {
-          TopoDS_Vertex VV1[2], VV2[2];
-          TopExp::Vertices( edge1, VV1[0], VV1[1], true );
-          TopExp::Vertices( edge2, VV2[0], VV2[1], true );
-          list< TopoDS_Edge > edges1, edges2;
-          int nbE = FindFaceAssociation( face1, VV1, face2, VV2, edges1, edges2 );
-          if ( !nbE ) RETURN_BAD_RESULT("FindFaceAssociation() failed");
-          if ( nbE == 2 ) // only 2 edges
-          {
-            // take care of proper association of propagated edges
-            bool same1 = edge1.IsSame( edges1.front() );
-            bool same2 = edge2.IsSame( edges2.front() );
-            if ( same1 != same2 )
-              Reverse(edges2, nbE);
-          }
-          // store association
-          list< TopoDS_Edge >::iterator eIt1 = edges1.begin();
-          list< TopoDS_Edge >::iterator eIt2 = edges2.begin();
-          for ( ; eIt1 != edges1.end(); ++eIt1, ++eIt2 )
-          {
-            InsertAssociation( *eIt1, *eIt2, theMap, bidirect);
-            VV1[0] = TopExp::FirstVertex( *eIt1, true );
-            VV2[0] = TopExp::FirstVertex( *eIt2, true );
-            InsertAssociation( VV1[0], VV2[0], theMap, bidirect);
-          }
-          return true;
+          // take care of proper association of propagated edges
+          bool same1 = edge1.IsSame( edges1.front() );
+          bool same2 = edge2.IsSame( edges2.front() );
+          if ( same1 != same2 )
+            Reverse(edges2, nbE);
         }
         }
+        // store association
+        list< TopoDS_Edge >::iterator eIt1 = edges1.begin();
+        list< TopoDS_Edge >::iterator eIt2 = edges2.begin();
+        for ( ; eIt1 != edges1.end(); ++eIt1, ++eIt2 )
+        {
+          InsertAssociation( *eIt1, *eIt2, theMap, bidirect);
+          VV1[0] = TopExp::FirstVertex( *eIt1, true );
+          VV2[0] = TopExp::FirstVertex( *eIt2, true );
+          InsertAssociation( VV1[0], VV2[0], theMap, bidirect);
+        }
+        return true;
       }
     }
     break; // try by vertex closeness
       }
     }
     break; // try by vertex closeness
@@ -772,23 +778,25 @@ TopoDS_Face StdMeshers_ProjectionUtils::GetNextFace( SMESH_Mesh*        mesh,
  * \param aMesh - mesh
  * \param theEdge - edge to find by propagation
  * \param fromEdge - start edge for propagation
  * \param aMesh - mesh
  * \param theEdge - edge to find by propagation
  * \param fromEdge - start edge for propagation
- * \retval TopoDS_Edge - found edge
+ * \retval pair<int,TopoDS_Edge> - propagation step and found edge
  */
 //================================================================================
 
  */
 //================================================================================
 
-TopoDS_Edge StdMeshers_ProjectionUtils::GetPropagationEdge( SMESH_Mesh*        aMesh,
-                                                            const TopoDS_Edge& theEdge,
-                                                            const TopoDS_Edge& fromEdge)
+pair<int,TopoDS_Edge>
+StdMeshers_ProjectionUtils::GetPropagationEdge( SMESH_Mesh*        aMesh,
+                                                const TopoDS_Edge& theEdge,
+                                                const TopoDS_Edge& fromEdge)
 {
   SMESH_IndexedMapOfShape aChain;
 {
   SMESH_IndexedMapOfShape aChain;
-  //aChain.Add(fromEdge);
+  int step = 0;
 
   // List of edges, added to chain on the previous cycle pass
   TopTools_ListOfShape listPrevEdges;
 
   // List of edges, added to chain on the previous cycle pass
   TopTools_ListOfShape listPrevEdges;
-  listPrevEdges.Append(fromEdge/*.Oriented( TopAbs_FORWARD )*/);
+  listPrevEdges.Append(fromEdge);
 
   // Collect all edges pass by pass
   while (listPrevEdges.Extent() > 0) {
 
   // Collect all edges pass by pass
   while (listPrevEdges.Extent() > 0) {
+    step++;
     // List of edges, added to chain on this cycle pass
     TopTools_ListOfShape listCurEdges;
 
     // List of edges, added to chain on this cycle pass
     TopTools_ListOfShape listCurEdges;
 
@@ -833,7 +841,7 @@ TopoDS_Edge StdMeshers_ProjectionUtils::GetPropagationEdge( SMESH_Mesh*        a
                 ori = TopAbs::Reverse( ori );
               anOppE.Orientation( ori );
               if ( anOppE.IsSame( theEdge ))
                 ori = TopAbs::Reverse( ori );
               anOppE.Orientation( ori );
               if ( anOppE.IsSame( theEdge ))
-                return TopoDS::Edge( anOppE );
+                return make_pair( step, TopoDS::Edge( anOppE ));
               aChain.Add(anOppE);
               listCurEdges.Append(anOppE);
             }
               aChain.Add(anOppE);
               listCurEdges.Append(anOppE);
             }
@@ -845,7 +853,7 @@ TopoDS_Edge StdMeshers_ProjectionUtils::GetPropagationEdge( SMESH_Mesh*        a
     listPrevEdges = listCurEdges;
   } // while (listPrevEdges.Extent() > 0)
 
     listPrevEdges = listCurEdges;
   } // while (listPrevEdges.Extent() > 0)
 
-  return TopoDS_Edge();
+  return make_pair( INT_MAX, TopoDS_Edge());
 }
 
 //================================================================================
 }
 
 //================================================================================
index 5071209cd233f7cac8ba9798229a9c2a2cdbdae7..2990e533f962887924eb91c3fa5245bcb8013cd1 100644 (file)
@@ -137,11 +137,11 @@ class StdMeshers_ProjectionUtils
    * \brief Return an oriented propagation edge
     * \param aMesh - mesh
     * \param fromEdge - start edge for propagation
    * \brief Return an oriented propagation edge
     * \param aMesh - mesh
     * \param fromEdge - start edge for propagation
-    * \retval TopoDS_Edge - found edge
+    * \retval pair<int,TopoDS_Edge> - propagation step and found edge
    */
    */
-  static TopoDS_Edge GetPropagationEdge( SMESH_Mesh*        aMesh,
-                                         const TopoDS_Edge& anEdge,
-                                         const TopoDS_Edge& fromEdge);
+  static std::pair<int,TopoDS_Edge> GetPropagationEdge( SMESH_Mesh*        aMesh,
+                                                        const TopoDS_Edge& anEdge,
+                                                        const TopoDS_Edge& fromEdge);
 
   /*!
    * \brief Find corresponding nodes on two faces
 
   /*!
    * \brief Find corresponding nodes on two faces