0029715: Mesh - Estimate the grid size of the acceleration structure by the complexit...
[occt.git] / src / BRepMesh / BRepMesh_Delaun.cxx
index 62ff759..a6aec38 100644 (file)
@@ -106,7 +106,9 @@ BRepMesh_Delaun::BRepMesh_Delaun(
   myCircles ( theVertices.Length(), theOldMesh->Allocator() )
 {
   if ( theVertices.Length() > 2 )
+  {
     Init( theVertices );
+  }
 }
 
 //=======================================================================
@@ -119,16 +121,21 @@ BRepMesh_Delaun::BRepMesh_Delaun(
 : myMeshData( theOldMesh ),
   myCircles ( theVertexIndices.Length(), theOldMesh->Allocator() )
 {
-  if ( theVertexIndices.Length() > 2 )
-  {
-    Bnd_Box2d aBox;
-    Standard_Integer anIndex = theVertexIndices.Lower();
-    Standard_Integer anUpper = theVertexIndices.Upper();
-    for ( ; anIndex <= anUpper; ++anIndex )
-      aBox.Add( gp_Pnt2d( GetVertex( theVertexIndices( anIndex) ).Coord() ) );
+  perform( theVertexIndices );
+}
 
-    perform( aBox, theVertexIndices );
-  }
+//=======================================================================
+//function : BRepMesh_Delaun
+//purpose  : Creates the triangulation with and existent Mesh data structure
+//=======================================================================
+BRepMesh_Delaun::BRepMesh_Delaun (const Handle (BRepMesh_DataStructureOfDelaun)& theOldMesh,
+                                  BRepMesh::Array1OfInteger&                     theVertexIndices,
+                                  const Standard_Integer                         theCellsCountU,
+                                  const Standard_Integer                         theCellsCountV)
+  : myMeshData (theOldMesh),
+  myCircles (theVertexIndices.Length (), theOldMesh->Allocator ())
+{
+  perform (theVertexIndices, theCellsCountU, theCellsCountV);
 }
 
 //=======================================================================
@@ -137,7 +144,6 @@ BRepMesh_Delaun::BRepMesh_Delaun(
 //=======================================================================
 void BRepMesh_Delaun::Init(BRepMesh::Array1OfVertexOfDelaun& theVertices)
 {
-  Bnd_Box2d aBox;
   Standard_Integer aLowerIdx  = theVertices.Lower();
   Standard_Integer anUpperIdx = theVertices.Upper();
   BRepMesh::Array1OfInteger aVertexIndexes( aLowerIdx, anUpperIdx );
@@ -145,35 +151,62 @@ void BRepMesh_Delaun::Init(BRepMesh::Array1OfVertexOfDelaun& theVertices)
   Standard_Integer anIndex = aLowerIdx;
   for ( ; anIndex <= anUpperIdx; ++anIndex )
   {
-    aBox.Add( gp_Pnt2d( theVertices( anIndex ).Coord() ) );
     aVertexIndexes( anIndex ) = myMeshData->AddNode( theVertices( anIndex ) );
   }
 
-  perform( aBox, aVertexIndexes );
+  perform( aVertexIndexes );
 }
 
 //=======================================================================
 //function : perform
 //purpose  : Create super mesh and run triangulation procedure
 //=======================================================================
-void BRepMesh_Delaun::perform(Bnd_Box2d&                 theBndBox,
-                              BRepMesh::Array1OfInteger& theVertexIndexes)
+void BRepMesh_Delaun::perform (BRepMesh::Array1OfInteger& theVertexIndices,
+                               const Standard_Integer     theCellsCountU /* = -1 */,
+                               const Standard_Integer     theCellsCountV /* = -1 */)
 {
-  theBndBox.Enlarge( Precision );
-  superMesh( theBndBox );
+  if (theVertexIndices.Length () <= 2)
+  {
+    return;
+  }
+
+  Bnd_Box2d aBox;
+  Standard_Integer anIndex = theVertexIndices.Lower ();
+  Standard_Integer anUpper = theVertexIndices.Upper ();
+  for (; anIndex <= anUpper; ++anIndex)
+  {
+    aBox.Add (gp_Pnt2d (GetVertex (theVertexIndices (anIndex)).Coord ()));
+  }
+
+  aBox.Enlarge (Precision);
+
+  Standard_Integer aScaler = 2;
+  if ( myMeshData->NbNodes() > 100 )
+  {
+    aScaler = 5;
+  }
+  else if( myMeshData->NbNodes() > 1000 )
+  {
+    aScaler = 7;
+  }
+
+  superMesh (aBox, Max (theCellsCountU, aScaler),
+                   Max (theCellsCountV, aScaler));
 
   ComparatorOfIndexedVertexOfDelaun aCmp(myMeshData);
-  std::make_heap(theVertexIndexes.begin(), theVertexIndexes.end(), aCmp);
-  std::sort_heap(theVertexIndexes.begin(), theVertexIndexes.end(), aCmp);
+  std::make_heap(theVertexIndices.begin(), theVertexIndices.end(), aCmp);
+  std::sort_heap(theVertexIndices.begin(), theVertexIndices.end(), aCmp);
 
-  compute( theVertexIndexes );
+  compute( theVertexIndices );
 }
 
 //=======================================================================
 //function : superMesh
 //purpose  : Build the super mesh
 //=======================================================================
-void BRepMesh_Delaun::superMesh( const Bnd_Box2d& theBox )
+void BRepMesh_Delaun::superMesh (const Bnd_Box2d&       theBox,
+                                 const Standard_Integer theCellsCountU,
+                                 const Standard_Integer theCellsCountV)
 {
   Standard_Real aMinX, aMinY, aMaxX, aMaxY;
   theBox.Get( aMinX, aMinY, aMaxX, aMaxY );
@@ -185,15 +218,7 @@ void BRepMesh_Delaun::superMesh( const Bnd_Box2d& theBox )
   Standard_Real aDelta    = aDeltaX + aDeltaY;
   
   myCircles.SetMinMaxSize( gp_XY( aMinX, aMinY ), gp_XY( aMaxX, aMaxY ) );
-
-  Standard_Integer aScaler = 2;
-  if ( myMeshData->NbNodes() > 100 )
-    aScaler = 5;
-  else if( myMeshData->NbNodes() > 1000 )
-    aScaler = 7;
-
-  myCircles.SetCellSize( aDeltaX / aScaler,
-                         aDeltaY / aScaler );
+  myCircles.SetCellSize( aDeltaX / theCellsCountU, aDeltaY / theCellsCountV);
 
   mySupVert[0] = myMeshData->AddNode(
     BRepMesh_Vertex( ( aMinX + aMaxX ) / 2, aMaxY + aDeltaMax, BRepMesh_Free ) );