// Created by: Peter KURNEV // Copyright (c) 2010-2014 OPEN CASCADE SAS // Copyright (c) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE // Copyright (c) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, // EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // // This file is part of Open CASCADE Technology software library. // // This library is free software; you can redistribute it and/or modify it under // the terms of the GNU Lesser General Public License version 2.1 as published // by the Free Software Foundation, with special exception defined in the file // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT // distribution for complete text of the license and disclaimer of any warranty. // // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. // #include // #include // #include #include // #include #include // #include #include #include #include #include #include #include #include #include #include // #include #include // #include #include #include #include // #include #include #include #include #include #include #include #include #include // #include // #include #include // #include #include #include #include // #include #include #include #include static void OwnInternalShapes(const TopoDS_Shape& , BOPCol_IndexedMapOfShape& ); static void TreatCompound(const TopoDS_Shape& theS, BOPCol_MapOfShape& aMFence, BOPCol_ListOfShape& theLS); //======================================================================= // BOPAlgo_BuilderSolid // typedef BOPCol_NCVector BOPAlgo_VectorOfBuilderSolid; // typedef BOPCol_Functor BOPAlgo_BuilderSolidFunctor; // typedef BOPCol_Cnt BOPAlgo_BuilderSolidCnt; // //======================================================================= // class: BOPAlgo_ShapeBox // //======================================================================= //class : BOPAlgo_ShapeBox //purpose : Auxiliary class //======================================================================= class BOPAlgo_ShapeBox { public: BOPAlgo_ShapeBox() { }; // ~BOPAlgo_ShapeBox() { }; // void SetShape(const TopoDS_Shape& aS) { myShape=aS; }; // const TopoDS_Shape& Shape()const { return myShape; }; // void SetBox(const Bnd_Box& aBox) { myBox=aBox; }; // const Bnd_Box& Box()const { return myBox; }; // protected: TopoDS_Shape myShape; Bnd_Box myBox; }; // typedef BOPCol_NCVector BOPAlgo_VectorOfShapeBox; // //======================================================================= // class: BOPAlgo_FillIn3DParts // //======================================================================= //class : BOPAlgo_FillIn3DParts //purpose : //======================================================================= class BOPAlgo_FillIn3DParts : public BOPAlgo_Algo { public: DEFINE_STANDARD_ALLOC BOPAlgo_FillIn3DParts(){ myHasImage=Standard_False; myBBTree=NULL; myVSB=NULL; }; // virtual ~BOPAlgo_FillIn3DParts(){ }; // void SetSolid(const TopoDS_Solid& aS) { mySolid=aS; }; // const TopoDS_Solid& Solid()const { return mySolid; }; // void SetDraftSolid(const TopoDS_Solid& aS) { myDraftSolid=aS; }; // const TopoDS_Solid& DraftSolid()const { return myDraftSolid; }; // void SetHasImage(const Standard_Boolean bFlag) { myHasImage=bFlag; }; // Standard_Boolean HasImage()const { return myHasImage; }; // void SetBoxS(const Bnd_Box& aBox) { myBoxS=aBox; }; // const Bnd_Box& BoxS()const { return myBoxS; }; // void SetLIF(const BOPCol_ListOfShape& aLIF) { myLIF=aLIF; }; // const BOPCol_ListOfShape& LIF()const { return myLIF; }; // void SetBBTree(const BOPCol_BoxBndTree& aBBTree) { myBBTree=(BOPCol_BoxBndTree*)&aBBTree; }; // void SetVSB(const BOPAlgo_VectorOfShapeBox& aVSB) { myVSB=(BOPAlgo_VectorOfShapeBox*)&aVSB; }; // // void SetContext(const Handle(IntTools_Context)& aContext) { myContext=aContext; } // const Handle(IntTools_Context)& Context()const { return myContext; } // virtual void Perform(); // // const BOPCol_ListOfShape& LFIN()const { return myLFIN; }; protected: void MapEdgesAndFaces (const TopoDS_Shape& , BOPCol_IndexedDataMapOfShapeListOfShape& , const Handle(NCollection_BaseAllocator)& ); void MakeConnexityBlock (const BOPCol_ListOfShape& , const BOPCol_IndexedMapOfShape& , const BOPCol_MapOfShape& , const BOPCol_IndexedDataMapOfShapeListOfShape& , BOPCol_ListOfShape& , const Handle(NCollection_BaseAllocator)& ); // protected: TopoDS_Solid mySolid; TopoDS_Solid myDraftSolid; Standard_Boolean myHasImage; Bnd_Box myBoxS; BOPCol_ListOfShape myLIF; BOPCol_ListOfShape myLFIN; // BOPCol_BoxBndTree* myBBTree; BOPAlgo_VectorOfShapeBox* myVSB; // TopoDS_Iterator myItF; TopoDS_Iterator myItW; Handle(IntTools_Context) myContext; }; //======================================================================= //function : BOPAlgo_FillIn3DParts::Perform //purpose : //======================================================================= void BOPAlgo_FillIn3DParts::Perform() { Handle(NCollection_IncAllocator) aAlr1; BOPAlgo_Algo::UserBreak(); // Standard_Integer aNbFP, k, nFP, iIsIN; Standard_Real aTolPC; BOPCol_ListIteratorOfListOfInteger aItLI, aItLI1; BOPCol_ListIteratorOfListOfShape aItLS; BOPCol_BoxBndTreeSelector aSelector; // aAlr1=new NCollection_IncAllocator(); // BOPCol_ListOfShape aLFP(aAlr1); BOPCol_ListOfShape aLCBF(aAlr1); BOPCol_MapOfShape aMFDone(100, aAlr1); BOPCol_IndexedMapOfShape aME(100, aAlr1); BOPCol_IndexedMapOfShape aMF(100, aAlr1); BOPCol_IndexedDataMapOfShapeListOfShape aMEFP(100, aAlr1); BOPCol_IndexedDataMapOfShapeListOfShape aMEF(100, aAlr1); // aTolPC=Precision::Confusion(); myLFIN.Clear(); BOPAlgo_VectorOfShapeBox& aVSB=*myVSB; // // 1. aMEF - EF map for myDraftSolid BOPTools::MapShapesAndAncestors(myDraftSolid, TopAbs_EDGE, TopAbs_FACE, aMEF); // // 2. Faces from myDraftSolid and its own internal faces => aMF BOPTools::MapShapes(myDraftSolid, TopAbs_FACE, aMF); aItLS.Initialize(myLIF); for (; aItLS.More(); aItLS.Next()) { const TopoDS_Shape& aFI=aItLS.Value(); aMF.Add(aFI); } // aME - Edges from DraftSolid [i.e. edges to stop] BOPTools::MapShapes(myDraftSolid, TopAbs_EDGE, aME); // // 3. Select boxes of faces that are not out of aBoxS aSelector.Clear(); aSelector.SetBox(myBoxS); // aNbFP=myBBTree->Select(aSelector); const BOPCol_ListOfInteger& aLIFPx=aSelector.Indices(); // // 4. aIVec, aLIFP - faces to process BOPCol_ListOfInteger aLIFP(aAlr1); BOPCol_NCVector aIVec(256, aAlr1); // k=0; aItLI.Initialize(aLIFPx); for (; aItLI.More(); aItLI.Next()) { nFP=aItLI.Value(); const TopoDS_Shape& aFP=aVSB(nFP).Shape(); if (!aMF.Contains(aFP)) { MapEdgesAndFaces(aFP, aMEFP, aAlr1); aLIFP.Append(nFP); aIVec.Append1()=nFP; ++k; } } aNbFP=k; // // sort indices std::sort(aIVec.begin(), aIVec.end()); // // 5. Collect faces that are IN mySolid [ myLFIN ] for (k=0; k \ BOPAlgo_VectorOfFillIn3DParts; // typedef BOPCol_ContextFunctor BOPCol_FillIn3DPartsFunctor; // typedef BOPCol_ContextCnt BOPAlgo_FillIn3DPartsCnt; // //======================================================================= // class: BOPAlgo_Builder // //======================================================================= //function : FillImagesSolids //purpose : //======================================================================= void BOPAlgo_Builder::FillImagesSolids() { Standard_Boolean bHasSolids; Standard_Integer i, aNbS; // myErrorStatus=0; // bHasSolids=Standard_False; aNbS=myDS->NbSourceShapes(); for (i=0; iShapeInfo(i); if (aSI.ShapeType()==TopAbs_SOLID) { bHasSolids=!bHasSolids; break; } } // if (!bHasSolids) { return; } // Handle(NCollection_IncAllocator) aAlr; // aAlr=new NCollection_IncAllocator(); BOPCol_DataMapOfShapeListOfShape theInParts(100, aAlr); BOPCol_DataMapOfShapeShape theDraftSolids(100, aAlr); // FillIn3DParts(theInParts, theDraftSolids, aAlr); BuildSplitSolids(theInParts, theDraftSolids, aAlr); FillInternalShapes(); // theInParts.Clear(); theDraftSolids.Clear(); } //======================================================================= //function : FillIn3DParts //purpose : //======================================================================= void BOPAlgo_Builder::FillIn3DParts (BOPCol_DataMapOfShapeListOfShape& theInParts, BOPCol_DataMapOfShapeShape& theDraftSolids, const BOPCol_BaseAllocator& ) { Standard_Boolean bHasImage; Standard_Integer i, k, aNbS, aNbLIF, aNbFIN, aNbVSB, aNbVFIP; Handle(NCollection_IncAllocator) aAlr0; TopoDS_Solid aSD; TopoDS_Iterator aIt; BRep_Builder aBB; // BOPCol_ListIteratorOfListOfInteger aItLI, aItLI1; BOPCol_ListIteratorOfListOfShape aItLS; // aAlr0=new NCollection_IncAllocator(); // BOPCol_MapOfShape aMFence(100, aAlr0); BOPAlgo_VectorOfShapeBox aVSB(256, aAlr0); // myErrorStatus=0; theDraftSolids.Clear(); // // 1. aVSB vector Index/FaceBox aNbS=myDS->NbSourceShapes(); for (i=0; iShapeInfo(i); if (aSI.ShapeType()!=TopAbs_FACE) { continue; } // const TopoDS_Shape& aS=aSI.Shape(); // if (myImages.IsBound(aS)) { const BOPCol_ListOfShape& aLS=myImages.Find(aS); aItLS.Initialize(aLS); for (; aItLS.More(); aItLS.Next()) { const TopoDS_Shape& aSx=aItLS.Value(); if (!aMFence.Add(aSx)) { continue; } Bnd_Box aBox; BRepBndLib::Add(aSx, aBox); // BOPAlgo_ShapeBox& aSB=aVSB.Append1(); aSB.SetShape(aSx); aSB.SetBox(aBox); } } else { const Bnd_Box& aBox=aSI.Box(); // BOPAlgo_ShapeBox& aSB=aVSB.Append1(); aSB.SetShape(aS); aSB.SetBox(aBox); } }//for (i=0; i aTreeFiller(aBBTree); // aNbVSB=aVSB.Extent(); for (k=0; kShapeInfo(i); if (aSI.ShapeType()!=TopAbs_SOLID) { continue; } // const TopoDS_Shape& aS=aSI.Shape(); const TopoDS_Solid& aSolid=(*(TopoDS_Solid*)(&aS)); // // 2.0 Flag bHasImage bHasImage=Standard_False; aIt.Initialize(aS); for (; aIt.More(); aIt.Next()) { const TopoDS_Shape& aShell=aIt.Value(); bHasImage=myImages.IsBound(aShell); if (bHasImage){ break; } } // // 2.1 Bounding box for the solid aS [ aBoxS ] Bnd_Box aBoxS; aBoxS=aSI.Box(); // // 2.2 Build Draft Solid [aSD] BOPCol_ListOfShape aLIF; // aBB.MakeSolid(aSD); BuildDraftSolid(aSolid, aSD, aLIF); // BOPAlgo_FillIn3DParts& aFIP=aVFIP.Append1(); // aFIP.SetSolid(aSolid); aFIP.SetDraftSolid(aSD); aFIP.SetHasImage(bHasImage); aFIP.SetBoxS(aBoxS); aFIP.SetLIF(aLIF); aFIP.SetBBTree(aBBTree); aFIP.SetVSB(aVSB); }//for (i=0; iNbSourceShapes(); for (i=0; iShapeInfo(i); // if (aSI.ShapeType()!=TopAbs_SOLID) { continue; } // const TopoDS_Shape& aS=aSI.Shape(); if (!aMFence.Add(aS)) { continue; } if(theDraftSolids.IsBound(aS)) { continue; } // BOPTools_Set aST; // aST.Add(aS, TopAbs_FACE); aMST.Add(aST); // } //for (i=1; i<=aNbS; ++i) // // 1. Build solids for interferred source solids for (i=0; iShapeInfo(i); // if (aSI.ShapeType()!=TopAbs_SOLID) { continue; } // const TopoDS_Shape& aS=aSI.Shape(); const TopoDS_Solid& aSolid=(*(TopoDS_Solid*)(&aS)); if(!theDraftSolids.IsBound(aS)) { continue; } const TopoDS_Shape& aSD=theDraftSolids.Find(aS); const BOPCol_ListOfShape& aLFIN= (theInParts.IsBound(aS)) ? theInParts.Find(aS) : aLSEmpty; // // 1.1 Fill Shell Faces Set aSFS.Clear(); aExp.Init(aSD, TopAbs_FACE); for (; aExp.More(); aExp.Next()) { const TopoDS_Shape& aF=aExp.Current(); aSFS.Append(aF); } // aIt.Initialize(aLFIN); for (; aIt.More(); aIt.Next()) { TopoDS_Shape aF=aIt.Value(); // aF.Orientation(TopAbs_FORWARD); aSFS.Append(aF); aF.Orientation(TopAbs_REVERSED); aSFS.Append(aF); } // // 1.3 Build new solids Handle(NCollection_IncAllocator) aAlr1; aAlr1=new NCollection_IncAllocator(); // BOPAlgo_BuilderSolid& aBS=aVBS.Append1(); aBS.SetSolid(aSolid); aBS.SetShapes(aSFS); aBS.SetRunParallel(myRunParallel); aBS.SetProgressIndicator(myProgressIndicator); }//for (i=0; iArguments(); aIt.Initialize(aArguments); for (; aIt.More(); aIt.Next()) { const TopoDS_Shape& aS=aIt.Value(); TreatCompound(aS, aMFence, aLSC); } aIt.Initialize(aLSC); for (; aIt.More(); aIt.Next()) { const TopoDS_Shape& aS=aIt.Value(); aType=aS.ShapeType(); if (aType==TopAbs_WIRE) { aItS.Initialize(aS); for(; aItS.More(); aItS.Next()) { const TopoDS_Shape& aE=aItS.Value(); if (aMFence.Add(aE)) { aLArgs.Append(aE); } } } else if (aType==TopAbs_VERTEX || aType==TopAbs_EDGE){ aLArgs.Append(aS); } } aMFence.Clear(); // aIt.Initialize(aLArgs); for (; aIt.More(); aIt.Next()) { const TopoDS_Shape& aS=aIt.Value(); aType=aS.ShapeType(); if (aType==TopAbs_VERTEX || aType==TopAbs_EDGE || aType==TopAbs_WIRE) { if (aMFence.Add(aS)) { if (myImages.IsBound(aS)) { const BOPCol_ListOfShape &aLSp=myImages.Find(aS); aIt1.Initialize(aLSp); for (; aIt1.More(); aIt1.Next()) { const TopoDS_Shape& aSp=aIt1.Value(); aMSI.Add(aSp); } } else { aMSI.Add(aS); } } } } aNbSI=aMSI.Extent(); // // 2. Internal vertices, edges from source solids aMFence.Clear(); aLSd.Clear(); // aNbS=myDS->NbSourceShapes(); for (i=0; iShapeInfo(i); // if (aSI.ShapeType()!=TopAbs_SOLID) { continue; } // UserBreak(); // const TopoDS_Shape& aS=aSI.Shape(); // aMx.Clear(); OwnInternalShapes(aS, aMx); // aNbSx=aMx.Extent(); for (j=1; j<=aNbSx; ++j) { const TopoDS_Shape& aSi=aMx(j); if (myImages.IsBound(aSi)) { const BOPCol_ListOfShape &aLSp=myImages.Find(aSi); aIt1.Initialize(aLSp); for (; aIt1.More(); aIt1.Next()) { const TopoDS_Shape& aSp=aIt1.Value(); aMSI.Add(aSp); } } else { aMSI.Add(aSi); } } // // build aux map from splits of solids if (myImages.IsBound(aS)) { const BOPCol_ListOfShape &aLSp=myImages.Find(aS); aIt.Initialize(aLSp); for (; aIt.More(); aIt.Next()) { const TopoDS_Shape& aSp=aIt.Value(); if (aMFence.Add(aSp)) { BOPTools::MapShapesAndAncestors(aSp, TopAbs_VERTEX, TopAbs_EDGE, aMSx); BOPTools::MapShapesAndAncestors(aSp, TopAbs_VERTEX, TopAbs_FACE, aMSx); BOPTools::MapShapesAndAncestors(aSp, TopAbs_EDGE , TopAbs_FACE, aMSx); aLSd.Append(aSp); } } } else { if (aMFence.Add(aS)) { BOPTools::MapShapesAndAncestors(aS, TopAbs_VERTEX, TopAbs_EDGE, aMSx); BOPTools::MapShapesAndAncestors(aS, TopAbs_VERTEX, TopAbs_FACE, aMSx); BOPTools::MapShapesAndAncestors(aS, TopAbs_EDGE , TopAbs_FACE, aMSx); aLSd.Append(aS); aMSOr.Add(aS); } } }// for (i=0; i