| 1 | // Created by: Peter KURNEV |
| 2 | // Copyright (c) 2010-2014 OPEN CASCADE SAS |
| 3 | // Copyright (c) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE |
| 4 | // Copyright (c) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, |
| 5 | // EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS |
| 6 | // |
| 7 | // This file is part of Open CASCADE Technology software library. |
| 8 | // |
| 9 | // This library is free software; you can redistribute it and/or modify it under |
| 10 | // the terms of the GNU Lesser General Public License version 2.1 as published |
| 11 | // by the Free Software Foundation, with special exception defined in the file |
| 12 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
| 13 | // distribution for complete text of the license and disclaimer of any warranty. |
| 14 | // |
| 15 | // Alternatively, this file may be used under the terms of Open CASCADE |
| 16 | // commercial license or contractual agreement. |
| 17 | |
| 18 | #include <BOPAlgo_Builder.ixx> |
| 19 | |
| 20 | #include <NCollection_IncAllocator.hxx> |
| 21 | |
| 22 | #include <TopoDS_Shape.hxx> |
| 23 | #include <TopoDS_Face.hxx> |
| 24 | #include <TopoDS_Edge.hxx> |
| 25 | #include <TopoDS_Vertex.hxx> |
| 26 | #include <TopoDS_Compound.hxx> |
| 27 | |
| 28 | #include <BRep_Tool.hxx> |
| 29 | #include <BRep_Builder.hxx> |
| 30 | |
| 31 | #include <TopExp_Explorer.hxx> |
| 32 | |
| 33 | #include <BOPCol_ListOfShape.hxx> |
| 34 | #include <BOPCol_ListOfInteger.hxx> |
| 35 | #include <BOPCol_MapOfInteger.hxx> |
| 36 | #include <BOPCol_DataMapOfIntegerListOfShape.hxx> |
| 37 | #include <BOPCol_DataMapOfShapeShape.hxx> |
| 38 | |
| 39 | #include <BOPInt_Context.hxx> |
| 40 | |
| 41 | #include <BOPDS_PaveBlock.hxx> |
| 42 | #include <BOPDS_ShapeInfo.hxx> |
| 43 | #include <BOPDS_DS.hxx> |
| 44 | #include <BOPDS_FaceInfo.hxx> |
| 45 | #include <BOPDS_MapOfPaveBlock.hxx> |
| 46 | #include <BOPDS_VectorOfInterfFF.hxx> |
| 47 | #include <BOPDS_Interf.hxx> |
| 48 | #include <BOPDS_VectorOfCurve.hxx> |
| 49 | #include <BOPDS_VectorOfPoint.hxx> |
| 50 | |
| 51 | #include <BOPTools.hxx> |
| 52 | #include <BOPTools_AlgoTools.hxx> |
| 53 | #include <BOPTools_AlgoTools2D.hxx> |
| 54 | #include <BOPTools_AlgoTools3D.hxx> |
| 55 | #include <BOPAlgo_BuilderFace.hxx> |
| 56 | #include <BOPTools_CoupleOfShape.hxx> |
| 57 | #include <BOPTools_ListOfCoupleOfShape.hxx> |
| 58 | #include <BOPTools_MapOfSet.hxx> |
| 59 | #include <BOPTools_DataMapOfShapeSet.hxx> |
| 60 | #include <BOPAlgo_Builder_2Cnt.hxx> |
| 61 | |
| 62 | static |
| 63 | Standard_Boolean HasPaveBlocksOnIn(const BOPDS_FaceInfo& aFI1, |
| 64 | const BOPDS_FaceInfo& aFI2); |
| 65 | static |
| 66 | void FillMap(const TopoDS_Shape& aS1, |
| 67 | const TopoDS_Shape& aS2, |
| 68 | BOPCol_IndexedDataMapOfShapeListOfShape& aDMSLS, |
| 69 | Handle(NCollection_IncAllocator)& aAllocator); |
| 70 | static |
| 71 | void MakeBlocksCnx(const BOPCol_IndexedDataMapOfShapeListOfShape& aMILI, |
| 72 | BOPCol_DataMapOfIntegerListOfShape& aMBlocks, |
| 73 | Handle(NCollection_IncAllocator)& aAllocator); |
| 74 | |
| 75 | |
| 76 | //======================================================================= |
| 77 | //function : FillImagesFaces |
| 78 | //purpose : |
| 79 | //======================================================================= |
| 80 | void BOPAlgo_Builder::FillImagesFaces() |
| 81 | { |
| 82 | myErrorStatus=0; |
| 83 | // |
| 84 | BuildSplitFaces(); |
| 85 | FillSameDomainFaces(); |
| 86 | FillImagesFaces1(); |
| 87 | } |
| 88 | //======================================================================= |
| 89 | //function : BuildSplitFaces |
| 90 | //purpose : |
| 91 | //======================================================================= |
| 92 | void BOPAlgo_Builder::BuildSplitFaces() |
| 93 | { |
| 94 | Standard_Boolean bHasFaceInfo, bIsClosed, bIsDegenerated, bToReverse; |
| 95 | Standard_Integer i, j, k, aNbS, aNbPBIn, aNbPBOn, aNbPBSc, aNbAV, nSp; |
| 96 | Standard_Size aNbBF; |
| 97 | TopoDS_Face aFF, aFSD; |
| 98 | TopoDS_Edge aSp, aEE; |
| 99 | TopAbs_Orientation anOriF, anOriE; |
| 100 | TopExp_Explorer aExp; |
| 101 | BOPCol_ListIteratorOfListOfShape aIt; |
| 102 | BOPCol_ListOfInteger aLIAV; |
| 103 | BOPCol_MapOfShape aMFence; |
| 104 | Handle(NCollection_BaseAllocator) aAllocator; |
| 105 | BOPCol_ListOfShape aLFIm(myAllocator); |
| 106 | BOPCol_MapIteratorOfMapOfShape aItMS; |
| 107 | BOPAlgo_VectorOfBuilderFace aVBF; |
| 108 | // |
| 109 | myErrorStatus=0; |
| 110 | // |
| 111 | //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~scope f |
| 112 | aAllocator=new NCollection_IncAllocator(); |
| 113 | // |
| 114 | BOPCol_ListOfShape aLE(aAllocator); |
| 115 | BOPCol_MapOfShape aMDE(100, aAllocator); |
| 116 | // |
| 117 | aNbS=myDS->NbSourceShapes(); |
| 118 | // |
| 119 | for (i=0; i<aNbS; ++i) { |
| 120 | const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i); |
| 121 | if (aSI.ShapeType()!=TopAbs_FACE) { |
| 122 | continue; |
| 123 | } |
| 124 | // |
| 125 | const TopoDS_Face& aF=(*(TopoDS_Face*)(&aSI.Shape())); |
| 126 | // |
| 127 | bHasFaceInfo=myDS->HasFaceInfo(i); |
| 128 | if(!bHasFaceInfo) { |
| 129 | continue; |
| 130 | } |
| 131 | // |
| 132 | const BOPDS_FaceInfo& aFI=myDS->FaceInfo(i); |
| 133 | // |
| 134 | const BOPDS_IndexedMapOfPaveBlock& aMPBIn=aFI.PaveBlocksIn(); |
| 135 | const BOPDS_IndexedMapOfPaveBlock& aMPBOn=aFI.PaveBlocksOn(); |
| 136 | const BOPDS_IndexedMapOfPaveBlock& aMPBSc=aFI.PaveBlocksSc(); |
| 137 | aLIAV.Clear(); |
| 138 | myDS->AloneVertices(i, aLIAV); |
| 139 | |
| 140 | aNbPBIn=aMPBIn.Extent(); |
| 141 | aNbPBOn=aMPBOn.Extent(); |
| 142 | aNbPBSc=aMPBSc.Extent(); |
| 143 | aNbAV=aLIAV.Extent(); |
| 144 | if (!aNbPBIn && !aNbPBOn && !aNbPBSc && !aNbAV) { // not compete |
| 145 | continue; |
| 146 | } |
| 147 | // |
| 148 | aMFence.Clear(); |
| 149 | // |
| 150 | anOriF=aF.Orientation(); |
| 151 | aFF=aF; |
| 152 | aFF.Orientation(TopAbs_FORWARD); |
| 153 | // |
| 154 | |
| 155 | // |
| 156 | // 1. Fill the egdes set for the face aFF -> LE |
| 157 | aLE.Clear(); |
| 158 | // |
| 159 | // |
| 160 | // 1.1 Bounding edges |
| 161 | aExp.Init(aFF, TopAbs_EDGE); |
| 162 | for (; aExp.More(); aExp.Next()) { |
| 163 | const TopoDS_Edge& aE=(*(TopoDS_Edge*)(&aExp.Current())); |
| 164 | anOriE=aE.Orientation(); |
| 165 | bIsDegenerated=BRep_Tool::Degenerated(aE); |
| 166 | bIsClosed=BRep_Tool::IsClosed(aE, aF); |
| 167 | // |
| 168 | if (!myImages.IsBound(aE)) { |
| 169 | if (anOriE==TopAbs_INTERNAL) { |
| 170 | aEE=aE; |
| 171 | aEE.Orientation(TopAbs_FORWARD); |
| 172 | aLE.Append(aEE); |
| 173 | aEE.Orientation(TopAbs_REVERSED); |
| 174 | aLE.Append(aEE); |
| 175 | } |
| 176 | else { |
| 177 | aLE.Append(aE); |
| 178 | } |
| 179 | } |
| 180 | else {//else 1 |
| 181 | const BOPCol_ListOfShape& aLIE=myImages.Find(aE); |
| 182 | aIt.Initialize(aLIE); |
| 183 | for (; aIt.More(); aIt.Next()) { |
| 184 | aSp=(*(TopoDS_Edge*)(&aIt.Value())); |
| 185 | if (bIsDegenerated) { |
| 186 | aSp.Orientation(anOriE); |
| 187 | aLE.Append(aSp); |
| 188 | continue; |
| 189 | } |
| 190 | // |
| 191 | if (anOriE==TopAbs_INTERNAL) { |
| 192 | aSp.Orientation(TopAbs_FORWARD); |
| 193 | aLE.Append(aSp); |
| 194 | aSp.Orientation(TopAbs_REVERSED); |
| 195 | aLE.Append(aSp); |
| 196 | continue; |
| 197 | } |
| 198 | // |
| 199 | if (bIsClosed) { |
| 200 | if (aMFence.Add(aSp)) { |
| 201 | if (!BRep_Tool::IsClosed(aSp, aF)){ |
| 202 | BOPTools_AlgoTools3D::DoSplitSEAMOnFace(aSp, aF); |
| 203 | } |
| 204 | // |
| 205 | aSp.Orientation(TopAbs_FORWARD); |
| 206 | aLE.Append(aSp); |
| 207 | aSp.Orientation(TopAbs_REVERSED); |
| 208 | aLE.Append(aSp); |
| 209 | }// if (aMFence.Add(aSp)) |
| 210 | continue; |
| 211 | }// if (bIsClosed){ |
| 212 | // |
| 213 | aSp.Orientation(anOriE); |
| 214 | bToReverse=BOPTools_AlgoTools::IsSplitToReverse(aSp, aE, myContext); |
| 215 | if (bToReverse) { |
| 216 | aSp.Reverse(); |
| 217 | } |
| 218 | aLE.Append(aSp); |
| 219 | }// for (; aIt.More(); aIt.Next()) { |
| 220 | }// else 1 |
| 221 | }// for (; aExp.More(); aExp.Next()) { |
| 222 | // |
| 223 | // |
| 224 | // 1.2 In edges |
| 225 | for (j=1; j<=aNbPBIn; ++j) { |
| 226 | const Handle(BOPDS_PaveBlock)& aPB=aMPBIn(j); |
| 227 | nSp=aPB->Edge(); |
| 228 | aSp=(*(TopoDS_Edge*)(&myDS->Shape(nSp))); |
| 229 | // |
| 230 | aSp.Orientation(TopAbs_FORWARD); |
| 231 | aLE.Append(aSp); |
| 232 | aSp.Orientation(TopAbs_REVERSED); |
| 233 | aLE.Append(aSp); |
| 234 | } |
| 235 | // |
| 236 | // |
| 237 | // 1.3 Section edges |
| 238 | for (j=1; j<=aNbPBSc; ++j) { |
| 239 | const Handle(BOPDS_PaveBlock)& aPB=aMPBSc(j); |
| 240 | nSp=aPB->Edge(); |
| 241 | aSp=(*(TopoDS_Edge*)(&myDS->Shape(nSp))); |
| 242 | // |
| 243 | aSp.Orientation(TopAbs_FORWARD); |
| 244 | aLE.Append(aSp); |
| 245 | aSp.Orientation(TopAbs_REVERSED); |
| 246 | aLE.Append(aSp); |
| 247 | } |
| 248 | // |
| 249 | BOPTools_AlgoTools2D::BuildPCurveForEdgesOnPlane (aLE, aFF); |
| 250 | // |
| 251 | // 3 Build split faces |
| 252 | BOPAlgo_BuilderFace& aBF=aVBF.Append1(); |
| 253 | aBF.SetFace(aF); |
| 254 | aBF.SetShapes(aLE); |
| 255 | aBF.SetRunParallel(myRunParallel); |
| 256 | // |
| 257 | }// for (i=0; i<aNbS; ++i) { |
| 258 | // |
| 259 | aNbBF=aVBF.Extent(); |
| 260 | // |
| 261 | //=================================================== |
| 262 | BOPAlgo_BuilderFaceCnt::Perform(myRunParallel, aVBF); |
| 263 | //=================================================== |
| 264 | // |
| 265 | for (k=0; k<(Standard_Integer)aNbBF; ++k) { |
| 266 | aLFIm.Clear(); |
| 267 | // |
| 268 | BOPAlgo_BuilderFace& aBF=aVBF(k); |
| 269 | TopoDS_Face aF=aBF.Face(); |
| 270 | anOriF=aBF.Orientation(); |
| 271 | aF.Orientation(anOriF); |
| 272 | // |
| 273 | const BOPCol_ListOfShape& aLFR=aBF.Areas(); |
| 274 | aIt.Initialize(aLFR); |
| 275 | for (; aIt.More(); aIt.Next()) { |
| 276 | TopoDS_Shape& aFR=aIt.ChangeValue(); |
| 277 | if (anOriF==TopAbs_REVERSED) { |
| 278 | aFR.Orientation(TopAbs_REVERSED); |
| 279 | } |
| 280 | //aFR.Orientation(anOriF); |
| 281 | aLFIm.Append(aFR); |
| 282 | } |
| 283 | // |
| 284 | mySplits.Bind(aF, aLFIm); |
| 285 | }// for (k=0; k<aNbBF; ++k) { |
| 286 | // |
| 287 | aAllocator.Nullify(); |
| 288 | //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~scope t |
| 289 | } |
| 290 | //======================================================================= |
| 291 | //function : FillSameDomainFaces |
| 292 | //purpose : |
| 293 | //======================================================================= |
| 294 | void BOPAlgo_Builder::FillSameDomainFaces() |
| 295 | { |
| 296 | Standard_Boolean bFlag; |
| 297 | Standard_Integer i, j, k, aNbFFs, aNbCurves, aNbPoints, nF1, nF2, aNbS; |
| 298 | Handle(NCollection_IncAllocator) aAllocator; |
| 299 | BOPCol_ListIteratorOfListOfShape aItF; |
| 300 | BOPCol_MapOfShape aMFence; |
| 301 | BOPAlgo_IndexedDataMapOfSetInteger aIDMSS; |
| 302 | BOPAlgo_VectorOfVectorOfShape aVVS; |
| 303 | // |
| 304 | myErrorStatus=0; |
| 305 | // |
| 306 | const BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF(); |
| 307 | // |
| 308 | aNbFFs=aFFs.Extent(); |
| 309 | if (!aNbFFs) { |
| 310 | return; |
| 311 | } |
| 312 | // |
| 313 | for (i=0; i<aNbFFs; ++i) { |
| 314 | const BOPDS_InterfFF& aFF=aFFs(i); |
| 315 | aFF.Indices(nF1, nF2); |
| 316 | // |
| 317 | const BOPDS_VectorOfCurve& aCurves=aFF.Curves(); |
| 318 | aNbCurves=aCurves.Extent(); |
| 319 | if (aNbCurves) { |
| 320 | // |
| 321 | bFlag=Standard_False; |
| 322 | for (j=0; j<aNbCurves; ++j) { |
| 323 | const BOPDS_Curve& aNC=aCurves.Value(j); |
| 324 | bFlag=aNC.HasEdge(); |
| 325 | if (bFlag) { |
| 326 | break; |
| 327 | } |
| 328 | } |
| 329 | if (bFlag) { |
| 330 | continue; |
| 331 | } |
| 332 | //continue; |
| 333 | } |
| 334 | // |
| 335 | const BOPDS_VectorOfPoint& aPoints=aFF.Points(); |
| 336 | aNbPoints=aPoints.Extent(); |
| 337 | if (aNbPoints) { |
| 338 | continue; |
| 339 | } |
| 340 | // |
| 341 | if (!myDS->HasFaceInfo(nF1) || !myDS->HasFaceInfo(nF2) ) { |
| 342 | continue; |
| 343 | } |
| 344 | // |
| 345 | const BOPDS_FaceInfo& aFI1=myDS->FaceInfo(nF1); |
| 346 | const BOPDS_FaceInfo& aFI2=myDS->FaceInfo(nF2); |
| 347 | // |
| 348 | const TopoDS_Shape& aF1=myDS->Shape(nF1); |
| 349 | const TopoDS_Shape& aF2=myDS->Shape(nF2); |
| 350 | // |
| 351 | bFlag=HasPaveBlocksOnIn(aFI1, aFI2); |
| 352 | bFlag=bFlag && (mySplits.IsBound(aF1) && mySplits.IsBound(aF2)); |
| 353 | // |
| 354 | if (bFlag) { |
| 355 | for (k=0; k<2; ++k) { |
| 356 | const TopoDS_Shape& aF=(!k) ? aF1 : aF2; |
| 357 | const BOPCol_ListOfShape& aLF=mySplits.Find(aF); |
| 358 | // |
| 359 | aItF.Initialize(aLF); |
| 360 | for (; aItF.More(); aItF.Next()) { |
| 361 | const TopoDS_Shape& aFx=aItF.Value(); |
| 362 | // |
| 363 | if (aMFence.Add(aFx)) { |
| 364 | BOPTools_Set aSTx; |
| 365 | // |
| 366 | aSTx.AddEdges(aFx); |
| 367 | // |
| 368 | if (!aIDMSS.Contains(aSTx)) { |
| 369 | BOPAlgo_VectorOfShape& aVS=aVVS.Append1(); |
| 370 | aVS.Append(aFx); |
| 371 | // |
| 372 | j=aVVS.Extent()-1; |
| 373 | aIDMSS.Add (aSTx, j); |
| 374 | } |
| 375 | else { |
| 376 | j=aIDMSS.ChangeFromKey(aSTx); |
| 377 | BOPAlgo_VectorOfShape& aVS=aVVS(j); |
| 378 | aVS.Append(aFx); |
| 379 | } |
| 380 | } |
| 381 | } |
| 382 | } |
| 383 | }// if (bFlag) { |
| 384 | else {// if (!bFlag) |
| 385 | BOPTools_Set aST1, aST2; |
| 386 | // |
| 387 | aST1.AddEdges(aF1); |
| 388 | aST2.AddEdges(aF2); |
| 389 | // |
| 390 | if (aST1.IsEqual(aST2)) { |
| 391 | if (!aIDMSS.Contains(aST1)) { |
| 392 | BOPAlgo_VectorOfShape& aVS=aVVS.Append1(); |
| 393 | if (aMFence.Add(aF1)) { |
| 394 | aVS.Append(aF1); |
| 395 | } |
| 396 | if (aMFence.Add(aF2)) { |
| 397 | aVS.Append(aF2); |
| 398 | } |
| 399 | // |
| 400 | k=aVVS.Extent()-1; |
| 401 | aIDMSS.Add (aST1, k); |
| 402 | } |
| 403 | else { |
| 404 | k=aIDMSS.ChangeFromKey(aST1); |
| 405 | BOPAlgo_VectorOfShape& aVS=aVVS(k); |
| 406 | if (aMFence.Add(aF1)) { |
| 407 | aVS.Append(aF1); |
| 408 | } |
| 409 | if (aMFence.Add(aF2)) { |
| 410 | aVS.Append(aF2); |
| 411 | } |
| 412 | } |
| 413 | }//if (aST1.IsEqual(aST2)) { |
| 414 | }// else {// if (!bFlag) |
| 415 | // |
| 416 | }// for (i=0; i<aNbFFs; ++i) { |
| 417 | // |
| 418 | aIDMSS.Clear(); |
| 419 | // |
| 420 | Standard_Boolean bFlagSD; |
| 421 | Standard_Integer aNbVPSB, aNbVVS, aNbF, aNbF1; |
| 422 | BOPAlgo_VectorOfPairOfShapeBoolean aVPSB; |
| 423 | // |
| 424 | aNbVVS=aVVS.Extent(); |
| 425 | for (i=0; i<aNbVVS; ++i) { |
| 426 | const BOPAlgo_VectorOfShape& aVS=aVVS(i); |
| 427 | aNbF=aVS.Extent(); |
| 428 | if (aNbF<2) { |
| 429 | continue; |
| 430 | } |
| 431 | // |
| 432 | aNbF1=aNbF-1; |
| 433 | for (j=0; j<aNbF1; ++j) { |
| 434 | const TopoDS_Shape& aFj=aVS(j); |
| 435 | for (k=j+1; k<aNbF; ++k) { |
| 436 | const TopoDS_Shape& aFk=aVS(k); |
| 437 | BOPAlgo_PairOfShapeBoolean& aPSB=aVPSB.Append1(); |
| 438 | aPSB.Shape1()=aFj; |
| 439 | aPSB.Shape2()=aFk; |
| 440 | } |
| 441 | } |
| 442 | } |
| 443 | //==================================================== |
| 444 | BOPAlgo_BuilderSDFaceCnt::Perform(myRunParallel, aVPSB); |
| 445 | //==================================================== |
| 446 | aAllocator=new NCollection_IncAllocator(); |
| 447 | BOPCol_IndexedDataMapOfShapeListOfShape aDMSLS(100, aAllocator); |
| 448 | BOPCol_DataMapOfIntegerListOfShape aMBlocks(100, aAllocator); |
| 449 | // |
| 450 | aNbVPSB=aVPSB.Extent(); |
| 451 | for (i=0; i<aNbVPSB; ++i) { |
| 452 | BOPAlgo_PairOfShapeBoolean& aPSB=aVPSB(i); |
| 453 | bFlagSD=aPSB.Flag(); |
| 454 | if (bFlagSD) { |
| 455 | const TopoDS_Shape& aFj=aPSB.Shape1(); |
| 456 | const TopoDS_Shape& aFk=aPSB.Shape2(); |
| 457 | FillMap(aFj, aFk, aDMSLS, aAllocator); |
| 458 | } |
| 459 | } |
| 460 | aVPSB.Clear(); |
| 461 | // |
| 462 | // 2. Make blocks |
| 463 | MakeBlocksCnx(aDMSLS, aMBlocks, aAllocator); |
| 464 | // |
| 465 | // 3. Fill same domain faces map -> aMSDF |
| 466 | aNbS = aMBlocks.Extent(); |
| 467 | for (i=0; i<aNbS; ++i) { |
| 468 | const BOPCol_ListOfShape& aLSD=aMBlocks.Find(i); |
| 469 | if (aLSD.IsEmpty()) { |
| 470 | continue; |
| 471 | } |
| 472 | // |
| 473 | const TopoDS_Shape& aFSD1=aLSD.First(); |
| 474 | aItF.Initialize(aLSD); |
| 475 | for (; aItF.More(); aItF.Next()) { |
| 476 | const TopoDS_Shape& aFSD=aItF.Value(); |
| 477 | myShapesSD.Bind(aFSD, aFSD1); |
| 478 | // |
| 479 | // If the face has no splits but are SD face, |
| 480 | // it is considered as splitted face |
| 481 | if (!mySplits.IsBound(aFSD)) { |
| 482 | BOPCol_ListOfShape aLS; |
| 483 | aLS.Append(aFSD); |
| 484 | mySplits.Bind(aFSD, aLS); |
| 485 | } |
| 486 | } |
| 487 | } |
| 488 | aMBlocks.Clear(); |
| 489 | aDMSLS.Clear(); |
| 490 | aAllocator.Nullify(); |
| 491 | } |
| 492 | //======================================================================= |
| 493 | // function: FillImagesFaces1 |
| 494 | // purpose: |
| 495 | //======================================================================= |
| 496 | void BOPAlgo_Builder::FillImagesFaces1() |
| 497 | { |
| 498 | Standard_Integer i, aNbS, iSense; |
| 499 | TopoDS_Face aFSD; |
| 500 | BOPCol_ListOfInteger aLIAV; |
| 501 | BOPCol_ListOfShape aLFIm; |
| 502 | BOPCol_ListIteratorOfListOfShape aItLS; |
| 503 | // |
| 504 | aNbS=myDS->NbSourceShapes(); |
| 505 | for (i=0; i<aNbS; ++i) { |
| 506 | const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i); |
| 507 | if (aSI.ShapeType()!=TopAbs_FACE) { |
| 508 | continue; |
| 509 | } |
| 510 | // |
| 511 | const TopoDS_Face& aF=(*(TopoDS_Face*)(&aSI.Shape())); |
| 512 | // |
| 513 | if (!mySplits.IsBound(aF)) { |
| 514 | continue; |
| 515 | } |
| 516 | // |
| 517 | aLIAV.Clear(); |
| 518 | myDS->AloneVertices(i, aLIAV); |
| 519 | aLFIm.Clear(); |
| 520 | // |
| 521 | const BOPCol_ListOfShape& aLSp=mySplits.Find(aF); |
| 522 | aItLS.Initialize(aLSp); |
| 523 | for (; aItLS.More(); aItLS.Next()) { |
| 524 | const TopoDS_Face& aFSp=(*(TopoDS_Face*)(&aItLS.Value())); |
| 525 | if (!myShapesSD.IsBound(aFSp)) { |
| 526 | aLFIm.Append(aFSp); |
| 527 | } |
| 528 | else { |
| 529 | aFSD=(*(TopoDS_Face*)(&myShapesSD.Find(aFSp))); |
| 530 | iSense=BOPTools_AlgoTools::Sense(aFSp, aFSD); |
| 531 | if (iSense<0) { |
| 532 | aFSD.Reverse(); |
| 533 | } |
| 534 | aLFIm.Append(aFSD); |
| 535 | } |
| 536 | } |
| 537 | // |
| 538 | FillInternalVertices(aLFIm, aLIAV); |
| 539 | // |
| 540 | myImages.Bind(aF, aLFIm); |
| 541 | // |
| 542 | //fill myOrigins |
| 543 | aItLS.Initialize(aLFIm); |
| 544 | for (; aItLS.More(); aItLS.Next()) { |
| 545 | const TopoDS_Face& aFSp=(*(TopoDS_Face*)(&aItLS.Value())); |
| 546 | myOrigins.Bind(aFSp, aF); |
| 547 | } |
| 548 | }// for (i=0; i<aNbS; ++i) { |
| 549 | } |
| 550 | //======================================================================= |
| 551 | // function: FillInternalVertices |
| 552 | // purpose: |
| 553 | //======================================================================= |
| 554 | void BOPAlgo_Builder::FillInternalVertices(BOPCol_ListOfShape& aLFIm, |
| 555 | BOPCol_ListOfInteger& aLIAV) |
| 556 | { |
| 557 | Standard_Integer nV, iFlag; |
| 558 | Standard_Real aU1, aU2; |
| 559 | TopoDS_Vertex aV; |
| 560 | BRep_Builder aBB; |
| 561 | BOPCol_ListIteratorOfListOfInteger aItV; |
| 562 | BOPCol_ListIteratorOfListOfShape aItF; |
| 563 | // |
| 564 | aItV.Initialize(aLIAV); |
| 565 | for (; aItV.More(); aItV.Next()) { |
| 566 | nV=aItV.Value(); |
| 567 | aV=(*(TopoDS_Vertex*)(&myDS->Shape(nV))); |
| 568 | aV.Orientation(TopAbs_INTERNAL); |
| 569 | // |
| 570 | aItF.Initialize(aLFIm); |
| 571 | for (; aItF.More(); aItF.Next()) { |
| 572 | TopoDS_Face& aF=(*(TopoDS_Face*)(&aItF.Value())); |
| 573 | iFlag=myContext->ComputeVF(aV, aF, aU1, aU2); |
| 574 | if (!iFlag) { |
| 575 | aBB.Add(aF, aV); |
| 576 | break; |
| 577 | } |
| 578 | } |
| 579 | } |
| 580 | } |
| 581 | //======================================================================= |
| 582 | //function : MakeBlocksCnx |
| 583 | //purpose : |
| 584 | //======================================================================= |
| 585 | void MakeBlocksCnx(const BOPCol_IndexedDataMapOfShapeListOfShape& aMILI, |
| 586 | BOPCol_DataMapOfIntegerListOfShape& aMBlocks, |
| 587 | Handle(NCollection_IncAllocator)& aAllocator) |
| 588 | { |
| 589 | Standard_Integer aNbV, aNbVS, aNbVP, aNbEC, k, i, j; |
| 590 | BOPCol_ListIteratorOfListOfShape aItLI; |
| 591 | // |
| 592 | BOPCol_MapOfShape aMVS(100, aAllocator); |
| 593 | BOPCol_IndexedMapOfShape aMEC(100, aAllocator); |
| 594 | BOPCol_IndexedMapOfShape aMVP(100, aAllocator); |
| 595 | BOPCol_IndexedMapOfShape aMVAdd(100, aAllocator); |
| 596 | // |
| 597 | aNbV=aMILI.Extent(); |
| 598 | // |
| 599 | for (k=0,i=1; i<=aNbV; ++i) { |
| 600 | aNbVS=aMVS.Extent(); |
| 601 | if (aNbVS==aNbV) { |
| 602 | break; |
| 603 | } |
| 604 | // |
| 605 | const TopoDS_Shape& nV=aMILI.FindKey(i); |
| 606 | if (aMVS.Contains(nV)){ |
| 607 | continue; |
| 608 | } |
| 609 | aMVS.Add(nV); |
| 610 | // |
| 611 | aMEC.Clear(); |
| 612 | aMVP.Clear(); |
| 613 | aMVAdd.Clear(); |
| 614 | // |
| 615 | aMVP.Add(nV); |
| 616 | for(;;) { |
| 617 | aNbVP=aMVP.Extent(); |
| 618 | for (j=1; j<=aNbVP; ++j) { |
| 619 | const TopoDS_Shape& nVP=aMVP(j); |
| 620 | const BOPCol_ListOfShape& aLV=aMILI.FindFromKey(nVP); |
| 621 | aItLI.Initialize(aLV); |
| 622 | for (; aItLI.More(); aItLI.Next()) { |
| 623 | const TopoDS_Shape& nVx=aItLI.Value(); |
| 624 | if (aMEC.Contains(nVx)) { |
| 625 | continue; |
| 626 | } |
| 627 | // |
| 628 | aMVS.Add(nVx); |
| 629 | aMEC.Add(nVx); |
| 630 | aMVAdd.Add(nVx); |
| 631 | } |
| 632 | } |
| 633 | // |
| 634 | aNbVP=aMVAdd.Extent(); |
| 635 | if (!aNbVP) { |
| 636 | break; // from while(1) |
| 637 | } |
| 638 | // |
| 639 | aMVP.Clear(); |
| 640 | for (j=1; j<=aNbVP; ++j) { |
| 641 | aMVP.Add(aMVAdd(j)); |
| 642 | } |
| 643 | aMVAdd.Clear(); |
| 644 | }//while(1) { |
| 645 | // |
| 646 | BOPCol_ListOfShape aLIx(aAllocator); |
| 647 | // |
| 648 | aNbEC = aMEC.Extent(); |
| 649 | for (j=1; j<=aNbEC; ++j) { |
| 650 | const TopoDS_Shape& nVx=aMEC(j); |
| 651 | aLIx.Append(nVx); |
| 652 | } |
| 653 | // |
| 654 | aMBlocks.Bind(k, aLIx); |
| 655 | ++k; |
| 656 | }//for (k=0,i=1; i<=aNbV; ++i) |
| 657 | aMVAdd.Clear(); |
| 658 | aMVP.Clear(); |
| 659 | aMEC.Clear(); |
| 660 | aMVS.Clear(); |
| 661 | } |
| 662 | |
| 663 | //======================================================================= |
| 664 | //function : FillMap |
| 665 | //purpose : |
| 666 | //======================================================================= |
| 667 | void FillMap(const TopoDS_Shape& aS1, |
| 668 | const TopoDS_Shape& aS2, |
| 669 | BOPCol_IndexedDataMapOfShapeListOfShape& aDMSLS, |
| 670 | Handle(NCollection_IncAllocator)& aAllocator) |
| 671 | { |
| 672 | if (aDMSLS.Contains(aS1)) { |
| 673 | BOPCol_ListOfShape& aLS=aDMSLS.ChangeFromKey(aS1); |
| 674 | aLS.Append(aS2); |
| 675 | } |
| 676 | else { |
| 677 | BOPCol_ListOfShape aLS(aAllocator); |
| 678 | aLS.Append(aS2); |
| 679 | aDMSLS.Add(aS1, aLS); |
| 680 | } |
| 681 | // |
| 682 | if (aDMSLS.Contains(aS2)) { |
| 683 | BOPCol_ListOfShape& aLS=aDMSLS.ChangeFromKey(aS2); |
| 684 | aLS.Append(aS1); |
| 685 | } |
| 686 | else { |
| 687 | BOPCol_ListOfShape aLS(aAllocator); |
| 688 | aLS.Append(aS1); |
| 689 | aDMSLS.Add(aS2, aLS); |
| 690 | } |
| 691 | } |
| 692 | //======================================================================= |
| 693 | //function :HasPaveBlocksOnIn |
| 694 | //purpose : |
| 695 | //======================================================================= |
| 696 | Standard_Boolean HasPaveBlocksOnIn(const BOPDS_FaceInfo& aFI1, |
| 697 | const BOPDS_FaceInfo& aFI2) |
| 698 | { |
| 699 | Standard_Boolean bRet; |
| 700 | BOPDS_MapIteratorOfMapOfPaveBlock aItMPB; |
| 701 | // |
| 702 | bRet=Standard_False; |
| 703 | const BOPDS_IndexedMapOfPaveBlock& aMPBOn1=aFI1.PaveBlocksOn(); |
| 704 | const BOPDS_IndexedMapOfPaveBlock& aMPBIn1=aFI1.PaveBlocksIn(); |
| 705 | // |
| 706 | const BOPDS_IndexedMapOfPaveBlock& aMPBOn2=aFI2.PaveBlocksOn(); |
| 707 | aItMPB.Initialize(aMPBOn2); |
| 708 | for (; aItMPB.More(); aItMPB.Next()) { |
| 709 | const Handle(BOPDS_PaveBlock)& aPB=aItMPB.Value(); |
| 710 | bRet=aMPBOn1.Contains(aPB) || aMPBIn1.Contains(aPB); |
| 711 | if (bRet) { |
| 712 | return bRet; |
| 713 | } |
| 714 | } |
| 715 | // |
| 716 | const BOPDS_IndexedMapOfPaveBlock& aMPBIn2=aFI2.PaveBlocksIn(); |
| 717 | aItMPB.Initialize(aMPBIn2); |
| 718 | for (; aItMPB.More(); aItMPB.Next()) { |
| 719 | const Handle(BOPDS_PaveBlock)& aPB=aItMPB.Value(); |
| 720 | bRet=aMPBOn1.Contains(aPB) || aMPBIn1.Contains(aPB); |
| 721 | if (bRet) { |
| 722 | return bRet; |
| 723 | } |
| 724 | } |
| 725 | return bRet; |
| 726 | } |
| 727 | /* |
| 728 | //DEBf |
| 729 | { |
| 730 | TopoDS_Compound aCx; |
| 731 | BRep_Builder aBBx; |
| 732 | BOPCol_ListIteratorOfListOfShape aItx; |
| 733 | // |
| 734 | aBBx.MakeCompound(aCx); |
| 735 | aBBx.Add(aCx, aFF); |
| 736 | aItx.Initialize(aLE); |
| 737 | for (; aItx.More(); aItx.Next()) { |
| 738 | const TopoDS_Shape& aEx=aItx.Value(); |
| 739 | aBBx.Add(aCx, aEx); |
| 740 | } |
| 741 | int a=0; |
| 742 | } |
| 743 | //DEBt |
| 744 | */ |