]> OCCT Git - occt-copy.git/commitdiff
0032254: Refactor frontierAdjust function CR0032254
authorDzmitry Razmyslovich <razmyslovich@volumegraphics.com>
Sat, 27 Mar 2021 19:29:35 +0000 (20:29 +0100)
committerDzmitry Razmyslovich <razmyslovich@volumegraphics.com>
Sat, 27 Mar 2021 19:29:35 +0000 (20:29 +0100)
src/BRepMesh/BRepMesh_Delaun.cxx
src/BRepMesh/BRepMesh_Delaun.hxx

index 799d0367c68a40745e02226adaf7c61dff2af924..abafc53b274f823d0607ef4e03a425eda9eb18a3 100644 (file)
@@ -377,7 +377,7 @@ void BRepMesh_Delaun::compute(IMeshData::VectorOfInteger& theVertexIndexes)
     createTriangles( theVertexIndexes( anVertexIdx ), aLoopEdges );
 
     // Add other nodes to the mesh
-    createTrianglesOnNewVertices (theVertexIndexes, Message_ProgressRange());
+    createTrianglesOnNewVertices (theVertexIndexes, Message_ProgressRange(), Standard_True);
   }
 
   RemoveAuxElements ();
@@ -544,7 +544,8 @@ void BRepMesh_Delaun::createTriangles(const Standard_Integer          theVertexI
 //=======================================================================
 void BRepMesh_Delaun::createTrianglesOnNewVertices(
   IMeshData::VectorOfInteger&   theVertexIndexes,
-  const Message_ProgressRange& theRange)
+  const Message_ProgressRange& theRange, 
+  Standard_Boolean doFrontierAdjust)
 {
   Handle(NCollection_IncAllocator) aAllocator =
     new NCollection_IncAllocator(IMeshData::MEMORY_BLOCK_SIZE_HUGE);
@@ -633,7 +634,13 @@ void BRepMesh_Delaun::createTrianglesOnNewVertices(
     }
   }
 
-  ProcessConstraints();
+  insertInternalEdges ();
+
+  if (doFrontierAdjust)
+  {
+    // Adjustment of meshes to boundary edges
+    frontierAdjust ();
+  }
 }
 
 //=======================================================================
@@ -869,67 +876,85 @@ void BRepMesh_Delaun::frontierAdjust()
   IMeshData::MapOfIntegerInteger  aLoopEdges(10, aAllocator);
   Handle(IMeshData::MapOfInteger) aIntFrontierEdges = new IMeshData::MapOfInteger;
 
-  for ( Standard_Integer aPass = 1; aPass <= 2; ++aPass )
-  {      
-    // 1 pass): find external triangles on boundary edges;
-    // 2 pass): find external triangles on boundary edges appeared 
-    //          during triangles replacement.
-    
-    IMeshData::IteratorOfMapOfInteger aFrontierIt( *aFrontier );
-    for ( ; aFrontierIt.More(); aFrontierIt.Next() )
+  IMeshData::MapOfInteger aTrianglesList;
+  Standard_Boolean isModified = Standard_True;
+
+  Standard_Integer aPass = 1;
+
+  for ( ; isModified; ++aPass )
+  {
+    isModified = Standard_False;
+    aFailedFrontiers.Clear ();
+
+    IMeshData::IteratorOfMapOfInteger aFrontierIt (*aFrontier);
+    for (; aFrontierIt.More (); aFrontierIt.Next ())
     {
-      Standard_Integer aFrontierId = aFrontierIt.Key();
-      const BRepMesh_PairOfIndex& aPair = myMeshData->ElementsConnectedTo( aFrontierId );
-      Standard_Integer aNbElem = aPair.Extent();
-      for( Standard_Integer aElemIt = 1; aElemIt <= aNbElem; ++aElemIt )
+      Standard_Integer aFrontierId = aFrontierIt.Key ();
+      const BRepMesh_PairOfIndex& aPair = myMeshData->ElementsConnectedTo (aFrontierId);
+
+      for( Standard_Integer j = 1, jn = aPair.Extent(); j <= jn; ++j )
       {
-        const Standard_Integer aPriorElemId = aPair.Index( aElemIt );
+        const Standard_Integer aPriorElemId = aPair.Index(j);
         if( aPriorElemId < 0 )
-          continue;
+            continue;
             
-        const BRepMesh_Triangle& aElement = GetTriangle(aPriorElemId);
-        const Standard_Integer(&e)[3] = aElement.myEdges;
-        const Standard_Boolean(&o)[3] = aElement.myOrientations;
+        Standard_Integer e[3];
+        Standard_Boolean o[3];
+        GetTriangle( aPriorElemId ).Edges( e, o );
 
-        Standard_Boolean isTriangleFound = Standard_False;
         for ( Standard_Integer n = 0; n < 3; ++n )
         {
-          if ( aFrontierId == e[n] && !o[n] )
+          if ( aFrontierIt.Key() == e[n] && !o[n] )
           {
-            // Destruction  of external triangles on boundary edges
-            isTriangleFound = Standard_True;
-            deleteTriangle( aPriorElemId, aLoopEdges );
+            if ( !aTrianglesList.Contains(aPriorElemId) )
+              aTrianglesList.Add( aPriorElemId );
             break;
           }
         }
-
-        if ( isTriangleFound )
-          break;
       }
     }
 
+    // destruction of external triangles on boundary edges
+    IMeshData::IteratorOfMapOfInteger anTriangleIt( aTrianglesList );
+    for ( ; anTriangleIt.More(); anTriangleIt.Next() )
+      deleteTriangle( anTriangleIt.Key(), aLoopEdges );
+    aTrianglesList.Clear();
+
     // destrucrion of remaining hanging edges :
-    IMeshData::MapOfIntegerInteger::Iterator aLoopEdgesIt( aLoopEdges );
-    for ( ; aLoopEdgesIt.More(); aLoopEdgesIt.Next() )
+    IMeshData::MapOfIntegerInteger::Iterator aLoopEdgesIt (aLoopEdges);
+    for (; aLoopEdgesIt.More (); aLoopEdgesIt.Next ())
     {
-      Standard_Integer aLoopEdgeId = aLoopEdgesIt.Key();
-      if (myMeshData->ElementsConnectedTo( aLoopEdgeId ).IsEmpty() )
-        myMeshData->RemoveLink( aLoopEdgeId );
+      Standard_Integer aLoopEdgeId = aLoopEdgesIt.Key ();
+      if (myMeshData->ElementsConnectedTo (aLoopEdgeId).IsEmpty ())
+        myMeshData->RemoveLink (aLoopEdgeId);
     }
+    aLoopEdges.Clear ();
 
-    // destruction of triangles crossing the boundary edges and 
-    // their replacement by makeshift triangles
-    for ( aFrontierIt.Reset(); aFrontierIt.More(); aFrontierIt.Next() )
+    cleanupMesh();
+
+    // Now analyze the frontier and build the missing triangles
+    aFrontierIt.Reset ();
+    for ( ; aFrontierIt.More(); aFrontierIt.Next() )
     {
-      Standard_Integer aFrontierId = aFrontierIt.Key();
-      if ( !myMeshData->ElementsConnectedTo( aFrontierId ).IsEmpty() )
-        continue;
+      Standard_Integer aFrontierId = aFrontierIt.Key ();
+      const BRepMesh_Edge& anEdge = GetEdge(aFrontierId);
+
+      if ( myMeshData->ElementsConnectedTo(aFrontierId).IsEmpty() && (anEdge.FirstNode() != anEdge.LastNode())) // we fix mesh only for non-zero edges
+      {
+        Standard_Boolean isSuccess =
+          meshLeftPolygonOf (aFrontierId, Standard_True, aIntFrontierEdges);
+        
+        if (!isSuccess)
+          aFailedFrontiers.Append (aFrontierId);
+        else
+          isModified = Standard_True;
+      }
+    }
 
-      Standard_Boolean isSuccess = 
-        meshLeftPolygonOf( aFrontierId, Standard_True, aIntFrontierEdges );
+    aIntFrontierEdges->Clear ();
 
-      if ( aPass == 2 && !isSuccess )
-        aFailedFrontiers.Append( aFrontierId );
+    if ( aPass > 1 ) {
+      isModified = Standard_False;
     }
   }
 
index 04c7df1fdc8b24134988f2449ce306dda8b2b189..51541aa47cf06f1579f1e4dc297bfca1f1e83e6b 100755 (executable)
@@ -298,7 +298,8 @@ private:
   
   //! Creates the triangles on new nodes.
   void createTrianglesOnNewVertices (IMeshData::VectorOfInteger&  theVertexIndices,
-                                     const Message_ProgressRange& theRange);
+                                     const Message_ProgressRange& theRange,
+                                     Standard_Boolean doFrontierAdjust = Standard_False);
 
   //! Cleanup mesh from the free triangles.
   void cleanupMesh();