Salome HOME
NPAL15298: geompy.KindOfShape(aShape) first version implemented.
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_Gluer.cxx
index b63e99eea9c94b7e75bbfb7c9d8a5408ea914834..9c27ede442c09280fd084daecf518600df92129d 100755 (executable)
@@ -1,3 +1,22 @@
+// Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// 
+// 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.
+// 
+// This library is distributed in the hope that it will be useful 
+// but WITHOUT ANY WARRANTY; without even the implied warranty of 
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public  
+// License along with this library; if not, write to the Free Software 
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 // File:       GEOMAlgo_Gluer.cxx
 // Created:    Sat Dec 04 12:45:53 2004
 // Author:     Peter KURNEV
@@ -6,6 +25,11 @@
 
 #include <GEOMAlgo_Gluer.ixx>
 
+#include <NMTDS_BoxBndTree.hxx>
+#include <NCollection_UBTreeFiller.hxx>
+
+#include <TColStd_MapIteratorOfMapOfInteger.hxx>
+#include <TColStd_MapOfInteger.hxx>
 #include <TColStd_ListOfInteger.hxx>
 #include <TColStd_ListIteratorOfListOfInteger.hxx>
 
@@ -58,8 +82,8 @@
 
 #include <GEOMAlgo_IndexedDataMapOfIntegerShape.hxx>
 #include <GEOMAlgo_IndexedDataMapOfShapeBox.hxx>
-#include <GEOMAlgo_IndexedDataMapOfPassKeyListOfShape.hxx>
-#include <GEOMAlgo_PassKey.hxx>
+#include <GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape.hxx> 
+#include <GEOMAlgo_PassKeyShape.hxx>
 #include <GEOMAlgo_Tools.hxx>
 //
 
@@ -160,11 +184,9 @@ void GEOMAlgo_Gluer::MakeVertices()
 {
   myErrorStatus=0;
   //
-  Standard_Integer j, i, aNbV, aIndex, aNbVSD;
+  Standard_Integer j, i, aNbV, aNbVSD;
   TColStd_ListIteratorOfListOfInteger aIt;
-  Handle(Bnd_HArray1OfBox) aHAB;
-  Bnd_BoundSortBox aBSB;
-  TopoDS_Shape aSTmp, aVF;
+  TopoDS_Shape aVF;
   TopoDS_Vertex aVnew;
   TopTools_IndexedMapOfShape aMV, aMVProcessed;
   TopTools_ListIteratorOfListOfShape aItS;
@@ -173,6 +195,11 @@ void GEOMAlgo_Gluer::MakeVertices()
   GEOMAlgo_IndexedDataMapOfIntegerShape aMIS;
   GEOMAlgo_IndexedDataMapOfShapeBox aMSB;
   //
+  NMTDS_BoxBndTreeSelector aSelector;
+  NMTDS_BoxBndTree aBBTree;
+  NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
+  //
+  //
   TopExp::MapShapes(myShape, TopAbs_VERTEX, aMV);
   aNbV=aMV.Extent();
   if (!aNbV) {
@@ -180,21 +207,23 @@ void GEOMAlgo_Gluer::MakeVertices()
     return;
   }
   //
-  aHAB=new Bnd_HArray1OfBox(1, aNbV);
-  //
   for (i=1; i<=aNbV; ++i) {
     const TopoDS_Shape& aV=aMV(i);
     Bnd_Box aBox;
     //
     aBox.SetGap(myTol); 
     BRepBndLib::Add(aV, aBox);
-    aHAB->SetValue(i, aBox);
+    //
+    aTreeFiller.Add(i, aBox);
+    //
     aMIS.Add(i, aV);
     aMSB.Add(aV, aBox); 
   }
   //
-  aBSB.Initialize(aHAB);
+  aTreeFiller.Fill();
   //
+  //------------------------------
+  // Chains
   for (i=1; i<=aNbV; ++i) {
     const TopoDS_Shape& aV=aMV(i);
     //
@@ -202,31 +231,86 @@ void GEOMAlgo_Gluer::MakeVertices()
       continue;
     }
     //
-    const Bnd_Box& aBoxV=aMSB.FindFromKey(aV);
-    const TColStd_ListOfInteger& aLI=aBSB.Compare(aBoxV);
-    aNbVSD=aLI.Extent();
-    if (!aNbVSD) {
-      myErrorStatus=3; // it must not be 
-      return;
-    }
+    Standard_Integer aNbIP, aIP, aNbIP1, aIP1;
+    TopTools_ListOfShape aLVSD;
+    TColStd_MapOfInteger aMIP, aMIP1, aMIPC;
+    TColStd_MapIteratorOfMapOfInteger aIt1;
     //
-    // Images
+    aMIP.Add(i);
+    while(1) {
+      aNbIP=aMIP.Extent();
+      aIt1.Initialize(aMIP);
+      for(; aIt1.More(); aIt1.Next()) {
+       aIP=aIt1.Key();
+       if (aMIPC.Contains(aIP)) {
+         continue;
+       }
+       //
+       const TopoDS_Shape& aVP=aMIS.FindFromKey(aIP);
+       const Bnd_Box& aBoxVP=aMSB.FindFromKey(aVP);
+       //
+       aSelector.Clear();
+       aSelector.SetBox(aBoxVP);
+       //
+       aNbVSD=aBBTree.Select(aSelector);
+       if (!aNbVSD) {
+         continue;  // it must not be 
+       }
+       //
+       const TColStd_ListOfInteger& aLI=aSelector.Indices();
+       aIt.Initialize(aLI);
+       for (; aIt.More(); aIt.Next()) {
+         aIP1=aIt.Value();
+         if (aMIP.Contains(aIP1)) {
+           continue;
+         }
+         aMIP1.Add(aIP1);
+       } //for (; aIt.More(); aIt.Next()) {
+      }//for(; aIt1.More(); aIt1.Next()) {
+      //
+      aNbIP1=aMIP1.Extent();
+      if (!aNbIP1) {
+       break;
+      }
+      //
+      aIt1.Initialize(aMIP);
+      for(; aIt1.More(); aIt1.Next()) {
+       aIP=aIt1.Key();
+       aMIPC.Add(aIP);
+      }
+      //
+      aMIP.Clear();
+      aIt1.Initialize(aMIP1);
+      for(; aIt1.More(); aIt1.Next()) {
+       aIP=aIt1.Key();
+       aMIP.Add(aIP);
+      }
+      aMIP1.Clear();
+    }// while(1)
     //
-    TopTools_ListOfShape aLVSD;
+    // Fill myImages
+    aNbIP=aMIPC.Extent();
     //
-    aIt.Initialize(aLI);
-    for (j=0; aIt.More(); aIt.Next(), ++j) {
-      aIndex=aIt.Value();
-      const TopoDS_Shape& aVx=aMIS.FindFromKey(aIndex);
-      if(!j) {
-       aVF=aVx;
+    if (!aNbIP) {// no SD vertices founded
+      aVF=aV;
+      aLVSD.Append(aV);
+      aMVProcessed.Add(aV);
+    }
+    else { // SD vertices founded [ aMIPC ]
+      aIt1.Initialize(aMIPC);
+      for(j=0; aIt1.More(); aIt1.Next(), ++j) {
+       aIP=aIt1.Key();
+       const TopoDS_Shape& aVP=aMIS.FindFromKey(aIP);
+       if (!j) {
+         aVF=aVP;
+       }
+       aLVSD.Append(aVP);
+       aMVProcessed.Add(aVP);
       }
-      aLVSD.Append(aVx);
-      aMVProcessed.Add(aVx);
     }
-    //
     myImages.Bind(aVF, aLVSD);
-  }
+  }// for (i=1; i<=aNbV; ++i) {
+  //------------------------------
   //
   // Make new vertices
   aMV.Clear();
@@ -262,7 +346,6 @@ void GEOMAlgo_Gluer::MakeVertices()
   for (; aItIm.More(); aItIm.Next()) {
     const TopoDS_Shape& aV=aItIm.Key();
     const TopTools_ListOfShape& aLVSD=aItIm.Value();
-    //
     aItS.Initialize(aLVSD);
     for (; aItS.More(); aItS.Next()) {
       const TopoDS_Shape& aVSD=aItS.Value();
@@ -324,7 +407,7 @@ void GEOMAlgo_Gluer::MakeSolids()
   //
   aNbS=aMS.Extent();
   if (aNbS) {
-    //Standard_Real aTol=1.e-7;
+    Standard_Real aTol=1.e-7;
     BOP_CorrectTolerances::CorrectCurveOnSurface(myResult);
   }
 }
@@ -405,8 +488,8 @@ void GEOMAlgo_Gluer::MakeShapes(const TopAbs_ShapeEnum aType)
   TopoDS_Shape aNewShape;
   TopTools_IndexedMapOfShape aMF;
   TopTools_ListIteratorOfListOfShape aItS;
-  GEOMAlgo_PassKey aPKF;
-  GEOMAlgo_IndexedDataMapOfPassKeyListOfShape aMPKLF;
+  GEOMAlgo_PassKeyShape aPKF;
+  GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape aMPKLF;
   //
   TopExp::MapShapes(myShape, aType, aMF);
   //
@@ -414,7 +497,6 @@ void GEOMAlgo_Gluer::MakeShapes(const TopAbs_ShapeEnum aType)
   for (i=1; i<=aNbF; ++i) {
     const TopoDS_Shape& aS=aMF(i);
     // 
-    aPKF.Clear();
     if (aType==TopAbs_FACE) {
       const TopoDS_Face& aF=TopoDS::Face(aS);
       FacePassKey(aF, aPKF);
@@ -460,8 +542,6 @@ void GEOMAlgo_Gluer::MakeShapes(const TopAbs_ShapeEnum aType)
     //
     const TopoDS_Shape& aS1=aLSDF.First();
     //
-    //modified by NIZNHY-PKV Fri Jan 21 15:34:00 2005 f
-    //
     bHasNewSubShape=Standard_True;
     // prevent creation of a new shape if there are not
     // new subshapes of aSS among the originals
@@ -472,9 +552,8 @@ void GEOMAlgo_Gluer::MakeShapes(const TopAbs_ShapeEnum aType)
        aNewShape.Orientation(TopAbs_FORWARD);
       }
     }
-    //modified by NIZNHY-PKV Fri Jan 21 15:34:05 2005 t
     //
-    if (bHasNewSubShape) {//modified by NIZNHY-PKV Fri Jan 21 15:34:10 2005ft 
+    if (bHasNewSubShape) { 
       if (aType==TopAbs_FACE) {
        TopoDS_Face aNewFace;
        //
@@ -604,19 +683,14 @@ void GEOMAlgo_Gluer::InnerTolerance()
 //purpose  : 
 //=======================================================================
 void GEOMAlgo_Gluer::FacePassKey(const TopoDS_Face& aF, 
-                                GEOMAlgo_PassKey& aPK)
+                                GEOMAlgo_PassKeyShape& aPK)
 {
-  Standard_Integer i, aNbE, aNbMax;
+  Standard_Integer i, aNbE;
   TopTools_ListOfShape aLE;
   TopTools_IndexedMapOfShape aME;
   //
   TopExp::MapShapes(aF, TopAbs_EDGE, aME);
   aNbE=aME.Extent();
-  aNbMax=aPK.NbMax();
-  if (!aNbE || aNbE>aNbMax) {
-     myErrorStatus=101; // temprorary
-     return;
-  }
   //
   for (i=1; i<=aNbE; ++i) {
     const TopoDS_Shape& aE=aME(i);
@@ -627,14 +701,14 @@ void GEOMAlgo_Gluer::FacePassKey(const TopoDS_Face& aF,
     const TopoDS_Shape& aER=myOrigins.Find(aE);
     aLE.Append(aER);
   }
-  aPK.SetIds(aLE);
+  aPK.SetShapes(aLE);
 }
 //=======================================================================
 //function : EdgePassKey
 //purpose  : 
 //=======================================================================
 void GEOMAlgo_Gluer::EdgePassKey(const TopoDS_Edge& aE, 
-                                GEOMAlgo_PassKey& aPK)
+                                GEOMAlgo_PassKeyShape& aPK)
 {
   TopoDS_Vertex aV1, aV2;
   //
@@ -646,7 +720,7 @@ void GEOMAlgo_Gluer::EdgePassKey(const TopoDS_Edge& aE,
   }
   const TopoDS_Shape& aVR1=myOrigins.Find(aV1);
   const TopoDS_Shape& aVR2=myOrigins.Find(aV2);
-  aPK.SetIds(aVR1, aVR2);
+  aPK.SetShapes(aVR1, aVR2);
 }
 //=======================================================================
 //function : MakeVertex
@@ -748,7 +822,6 @@ void GEOMAlgo_Gluer::MakeEdge(const TopoDS_Edge& aE,
     BOPTools_Tools::MakeSplitEdge(aEx, aVR1, aT1, aVR2, aT2, aNewEdge); 
   }
 }
-//
 //=======================================================================
 //function : MakeFace
 //purpose  : 
@@ -808,6 +881,13 @@ void GEOMAlgo_Gluer::MakeFace(const TopoDS_Face& aF,
       //
       aBB.Add(newWire, aER);
     }
+    // xf
+    TopTools_ListOfShape aLW;
+    //
+    aLW.Append(aW);
+    myImages.Bind(newWire, aLW);
+    myOrigins.Bind(aW, newWire);
+    // xt
     aBB.Add(newFace, newWire);
   }
   aNewFace=newFace;
@@ -858,8 +938,6 @@ Standard_Boolean GEOMAlgo_Gluer::IsToReverse(const TopoDS_Face& aFR,
   }
   return bRet;
 }
-//
-//modified by NIZNHY-PKV Fri Jan 21 10:55:42 2005 f
 //=======================================================================
 //function : HasNewSubShape
 //purpose  : 
@@ -928,9 +1006,12 @@ const TopTools_ListOfShape& GEOMAlgo_Gluer::Modified (const TopoDS_Shape& aS)
   myGenerated.Clear();
   //
   aType=aS.ShapeType();
-  if (aType==TopAbs_FACE || 
-      aType==TopAbs_EDGE || 
-      aType==TopAbs_VERTEX) {
+  if (aType==TopAbs_VERTEX ||
+      aType==TopAbs_EDGE   || 
+      aType==TopAbs_WIRE   || 
+      aType==TopAbs_FACE   || 
+      aType==TopAbs_SHELL  || 
+      aType==TopAbs_SOLID) {  
     if(myOrigins.IsBound(aS)) {
       const TopoDS_Shape& aSnew=myOrigins.Find(aS);
       if (!aSnew.IsSame(aS)) {
@@ -963,7 +1044,6 @@ Standard_Boolean GEOMAlgo_Gluer::IsDeleted (const TopoDS_Shape& aS)
   //
   return bRet;
 }
-//modified by NIZNHY-PKV Fri Jan 21 10:59:21 2005 t
 //
 // ErrorStatus
 //