void OCCRegion::replaceFacesInternal(std::list<GFace*> &new_faces) { // we simply replace old faces by new faces in the structure TopExp_Explorer aExpS, aExpF; BRep_Builder aBB; TopoDS_Compound aCmp; aBB.MakeCompound(aCmp); TopoDS_Solid _s_replacement; aBB.MakeSolid(_s_replacement); _s_replacement.Orientation(s.Orientation()); aExpS.Init(s, TopAbs_SHELL); for (; aExpS.More(); aExpS.Next()) { const TopoDS_Shell& _shell=TopoDS::Shell(aExpS.Current()); TopoDS_Shell _shell_replacement; aBB.MakeShell(_shell_replacement); _shell_replacement.Orientation(_shell.Orientation()); aExpF.Init(_shell, TopAbs_FACE); for (; aExpF.More(); aExpF.Next()) { const TopoDS_Face& _face=TopoDS::Face(aExpF.Current()); TopoDS_Face _face_replacement; std::list<GFace*>::iterator it = l_faces.begin(); std::list<GFace*>::iterator it2 = new_faces.begin(); for ( ; it != l_faces.end() ; ++it,++it2){ OCCFace *occF = dynamic_cast<OCCFace*>(*it); if (occF){ TopoDS_Face oldf = occF->getTopoDS_Face(); if (oldf.IsSame(_face)){ _face_replacement = *((TopoDS_Face*)(*it2)->getNativePtr()); } else { oldf = occF->getTopoDS_FaceOld(); if (oldf.IsSame(_face)){ _face_replacement = *((TopoDS_Face*)(*it2)->getNativePtr()); } } } } if (_face_replacement.IsNull()){ Msg::Error("cannot find an face for gluing a region"); } if (_face_replacement.IsSame(_face)) { aBB.Add(_shell_replacement, _face); } else { if(FaceHaveDifferentOrientations(_face, _face_replacement)) _face_replacement.Reverse(); aBB.Add(_shell_replacement, _face_replacement); } } aBB.Add(_s_replacement, _shell_replacement); } s = _s_replacement; setup(); }
Standard_Boolean ShHealOper_RemoveFace::removeFaces(const TopoDS_Solid& theShape, TopoDS_Shape& theNewShape) { Standard_Boolean isDone = Standard_False; TopoDS_Solid aSol; BRep_Builder aB; aB.MakeSolid(aSol); TopoDS_Compound aComp; aB.MakeCompound(aComp); Standard_Boolean isAddSol = Standard_False, isAddComp = Standard_False; //firslty faces will be deleted from each shell. TopoDS_Iterator aItSol(theShape,Standard_False); for( ; aItSol.More(); aItSol.Next()) { TopoDS_Shape aSh = aItSol.Value(); TopoDS_Shape aNewShape; if(removeFaces(aSh,aNewShape)) isDone = Standard_True; if(aNewShape.IsNull()) continue; else if(aNewShape.ShapeType() == TopAbs_SHELL ) { aB.Add(aSol,aNewShape); isAddSol = Standard_True; } else { aB.Add(aComp,aNewShape); isAddComp = Standard_True; } } if(isDone) { //for getting correct solids class ShapeFix_Solid will be used. if(isAddSol) { Handle(ShapeFix_Solid) aSfSol = new ShapeFix_Solid(aSol); aSfSol->FixShellMode()= Standard_False; aSfSol->Perform(); TopoDS_Shape aresSol = aSfSol->Shape(); if(!isAddComp) theNewShape = aresSol; else aB.Add(aComp,aresSol); } else if(isAddComp) theNewShape = aComp; else theNewShape.Nullify(); } else theNewShape = theShape; return isDone; }
//======================================================================= // function: MakeContainer // purpose: //======================================================================= void GEOMAlgo_Tools3D::MakeContainer(const TopAbs_ShapeEnum theType, TopoDS_Shape& theC) { BRep_Builder aBB; // switch(theType) { case TopAbs_COMPOUND:{ TopoDS_Compound aC; aBB.MakeCompound(aC); theC=aC; } break; // case TopAbs_COMPSOLID:{ TopoDS_CompSolid aCS; aBB.MakeCompSolid(aCS); theC=aCS; } break; // case TopAbs_SOLID:{ TopoDS_Solid aSolid; aBB.MakeSolid(aSolid); theC=aSolid; } break; // // case TopAbs_SHELL:{ TopoDS_Shell aShell; aBB.MakeShell(aShell); theC=aShell; } break; // case TopAbs_WIRE: { TopoDS_Wire aWire; aBB.MakeWire(aWire); theC=aWire; } break; // default: break; } }
//////////////////////////////////////////////////////////////////////////////// // Construct TopoDS from BRL-CAD data //////////////////////////////////////////////////////////////////////////////// BRLTopo::BRLTopo(struct rt_arb_internal *arb) { TopoDS_Vertex v[8]; for(int i=0;i<8;i++) v[i]=BRepBuilderAPI_MakeVertex( gp_Pnt( scale*arb->pt[i][0], scale*arb->pt[i][1], scale*arb->pt[i][2] ) ); int arbn; if(!BRepTools::Compare(v[6],v[7])) arbn=8; else if(!BRepTools::Compare(v[4],v[5])) arbn=7; else if(!BRepTools::Compare(v[5],v[6])) arbn=6; else if(!BRepTools::Compare(v[0],v[3])) arbn=5; else arbn=4; switch(arbn) { case 8: { TopoDS_Edge e[12]; for(int i=0;i<4;i++) { e[i]=BRepBuilderAPI_MakeEdge(v[i],v[(i+1)%4]); e[i+4]=BRepBuilderAPI_MakeEdge(v[i+4],v[(i+1)%4+4]); e[i+8]=BRepBuilderAPI_MakeEdge(v[i],v[(i+4)%8]); } TopoDS_Wire w[6]; w[0]=BRepBuilderAPI_MakeWire(e[0],e[1],e[2],e[3]); w[1]=BRepBuilderAPI_MakeWire(e[4],e[5],e[6],e[7]); w[2]=BRepBuilderAPI_MakeWire(e[0],e[9],e[4],e[8]); w[3]=BRepBuilderAPI_MakeWire(e[1],e[10],e[5],e[9]); w[4]=BRepBuilderAPI_MakeWire(e[2],e[11],e[6],e[10]); w[5]=BRepBuilderAPI_MakeWire(e[3],e[8],e[7],e[11]); BRep_Builder BB; TopoDS_Shell shell; BB.MakeShell(shell); for(int i=0;i<6;i++) { TopoDS_Face f=BRepBuilderAPI_MakeFace(w[i]); BB.Add(shell,i? f.Reversed():f); } TopoDS_Solid solid; BB.MakeSolid(solid); BB.Add(solid,shell); ShapeFix_Solid sf(solid); sf.Perform(); shape=sf.Solid(); } break; case 6: { TopoDS_Edge e[9]; e[0]=BRepBuilderAPI_MakeEdge(v[0],v[1]); e[1]=BRepBuilderAPI_MakeEdge(v[1],v[2]); e[2]=BRepBuilderAPI_MakeEdge(v[2],v[3]); e[3]=BRepBuilderAPI_MakeEdge(v[3],v[0]); e[4]=BRepBuilderAPI_MakeEdge(v[0],v[4]); e[5]=BRepBuilderAPI_MakeEdge(v[1],v[4]); e[6]=BRepBuilderAPI_MakeEdge(v[2],v[6]); e[7]=BRepBuilderAPI_MakeEdge(v[3],v[6]); e[8]=BRepBuilderAPI_MakeEdge(v[4],v[6]); TopoDS_Wire w[5]; w[0]=BRepBuilderAPI_MakeWire(e[0],e[1],e[2],e[3]); w[1]=BRepBuilderAPI_MakeWire(e[0],e[4],e[5]); w[2]=BRepBuilderAPI_MakeWire(e[2],e[6],e[7]); w[3]=BRepBuilderAPI_MakeWire(e[3],e[4],e[8],e[7]); w[4]=BRepBuilderAPI_MakeWire(e[1],e[5],e[8],e[6]); BRep_Builder BB; #if 0 TopoDS_Compound result; BB.MakeCompound(result); for(int i=0;i<5;i++) { BB.Add(result,BRepBuilderAPI_MakeFace(w[i])); } shape=result; #else TopoDS_Shell shell; BB.MakeShell(shell); for(int i=0;i<5;i++) { TopoDS_Face f=BRepBuilderAPI_MakeFace(w[i]); BB.Add(shell,f); //i? f:f.Reversed()); } TopoDS_Solid solid; BB.MakeSolid(solid); BB.Add(solid,shell); ShapeFix_Solid sf(solid); sf.Perform(); shape=sf.Solid(); #endif } break; default: cerr << "Unhandled arb8 type n=" << arbn << '\n'; } }
//======================================================================= //function : MakeScaledPrism //purpose : //======================================================================= TopoDS_Shape GEOMImpl_PrismDriver::MakeScaledPrism (const TopoDS_Shape& theShapeBase, const gp_Vec& theVector, const Standard_Real theScaleFactor, const gp_Pnt& theCDG, bool isCDG) { TopoDS_Shape aShape; BRep_Builder B; // 1. aCDG = geompy.MakeCDG(theBase) gp_Pnt aCDG = theCDG; if (!isCDG) { gp_Ax3 aPos = GEOMImpl_IMeasureOperations::GetPosition(theShapeBase); aCDG = aPos.Location(); } TopoDS_Shape aShapeCDG_1 = BRepBuilderAPI_MakeVertex(aCDG).Shape(); // Process case of several given shapes if (theShapeBase.ShapeType() == TopAbs_COMPOUND || theShapeBase.ShapeType() == TopAbs_SHELL) { int nbSub = 0; TopoDS_Shape aShapeI; TopoDS_Compound aCompound; B.MakeCompound(aCompound); TopoDS_Iterator It (theShapeBase, Standard_True, Standard_True); for (; It.More(); It.Next()) { nbSub++; aShapeI = MakeScaledPrism(It.Value(), theVector, theScaleFactor, aCDG, true); B.Add(aCompound, aShapeI); } if (nbSub == 1) aShape = aShapeI; else if (nbSub > 1) aShape = GEOMImpl_GlueDriver::GlueFaces(aCompound, Precision::Confusion(), Standard_True); return aShape; } // 2. Scale = geompy.MakeScaleTransform(theBase, aCDG, theScaleFactor) // Bug 6839: Check for standalone (not included in faces) degenerated edges TopTools_IndexedDataMapOfShapeListOfShape aEFMap; TopExp::MapShapesAndAncestors(theShapeBase, TopAbs_EDGE, TopAbs_FACE, aEFMap); Standard_Integer i, nbE = aEFMap.Extent(); for (i = 1; i <= nbE; i++) { TopoDS_Shape anEdgeSh = aEFMap.FindKey(i); if (BRep_Tool::Degenerated(TopoDS::Edge(anEdgeSh))) { const TopTools_ListOfShape& aFaces = aEFMap.FindFromIndex(i); if (aFaces.IsEmpty()) Standard_ConstructionError::Raise ("Scaling aborted : cannot scale standalone degenerated edge"); } } // Perform Scaling gp_Trsf aTrsf; aTrsf.SetScale(aCDG, theScaleFactor); BRepBuilderAPI_Transform aBRepTrsf (theShapeBase, aTrsf, Standard_False); TopoDS_Shape aScale = aBRepTrsf.Shape(); // 3. aBase2 = geompy.MakeTranslationVectorDistance(Scale, theVec, theH) gp_Trsf aTrsf3; aTrsf3.SetTranslation(theVector); TopLoc_Location aLocOrig = aScale.Location(); gp_Trsf aTrsfOrig = aLocOrig.Transformation(); TopLoc_Location aLocRes (aTrsf3 * aTrsfOrig); TopoDS_Shape aBase2 = aScale.Located(aLocRes); // 4. aCDG_2 = geompy.MakeTranslationVectorDistance(aCDG, theVec, theH) gp_Pnt aCDG_2 = aCDG.Translated(theVector); TopoDS_Shape aShapeCDG_2 = BRepBuilderAPI_MakeVertex(aCDG_2).Shape(); // 5. Vector = geompy.MakeVector(aCDG, aCDG_2) TopoDS_Shape aShapeVec = BRepBuilderAPI_MakeEdge(aCDG, aCDG_2).Shape(); TopoDS_Edge anEdge = TopoDS::Edge(aShapeVec); TopoDS_Wire aWirePath = BRepBuilderAPI_MakeWire(anEdge); // 6. aPrism = geompy.MakePipeWithDifferentSections([theBase, aBase2], [aCDG, aCDG_2], Vector, False, False) Handle(TopTools_HSequenceOfShape) aBases = new TopTools_HSequenceOfShape; aBases->Append(theShapeBase); aBases->Append(aBase2); Handle(TopTools_HSequenceOfShape) aLocs = new TopTools_HSequenceOfShape; aLocs->Append(aShapeCDG_1); aLocs->Append(aShapeCDG_2); aShape = GEOMImpl_PipeDriver::CreatePipeWithDifferentSections(aWirePath, aBases, aLocs, false, false); // 7. Make a solid, if possible if (theShapeBase.ShapeType() == TopAbs_FACE) { BRepBuilderAPI_Sewing aSewing (Precision::Confusion()*10.0); TopExp_Explorer expF (aShape, TopAbs_FACE); Standard_Integer ifa = 0; for (; expF.More(); expF.Next()) { aSewing.Add(expF.Current()); ifa++; } if (ifa > 0) { aSewing.Perform(); TopoDS_Shape aShell; TopoDS_Shape sh = aSewing.SewedShape(); if (sh.ShapeType() == TopAbs_FACE && ifa == 1) { // case for creation of shell from one face TopoDS_Shell ss; B.MakeShell(ss); B.Add(ss,sh); aShell = ss; } else { TopExp_Explorer exp (sh, TopAbs_SHELL); Standard_Integer ish = 0; for (; exp.More(); exp.Next()) { aShell = exp.Current(); ish++; } if (ish != 1) aShell = sh; } BRepCheck_Shell chkShell (TopoDS::Shell(aShell)); if (chkShell.Closed() == BRepCheck_NoError) { TopoDS_Solid Sol; B.MakeSolid(Sol); B.Add(Sol, aShell); BRepClass3d_SolidClassifier SC (Sol); SC.PerformInfinitePoint(Precision::Confusion()); if (SC.State() == TopAbs_IN) { B.MakeSolid(Sol); B.Add(Sol, aShell.Reversed()); } aShape = Sol; } } } return aShape; }
//======================================================================= //function :FillInternalShapes //purpose : //======================================================================= void GEOMAlgo_Builder::FillInternalShapes() { myErrorStatus=0; // const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS(); NMTTools_PaveFiller* pPF=myPaveFiller; const Handle(IntTools_Context)& aCtx= pPF->Context(); // //Standard_Boolean bHasImage; Standard_Integer i, j, jT, aNbS, aNbSI, aNbSx, aNbSd; TopAbs_ShapeEnum aType, aT[]={ TopAbs_VERTEX, TopAbs_EDGE }; TopAbs_State aState; TopTools_ListIteratorOfListOfShape aIt, aIt1; TopTools_IndexedDataMapOfShapeListOfShape aMSx; TopTools_IndexedMapOfShape aMx; TopTools_MapOfShape aMSI, aMFence, aMSOr; TopTools_MapIteratorOfMapOfShape aItM; TopTools_ListOfShape aLSI, aLSd; TopoDS_Iterator aItS; BRep_Builder aBB; // // 1. Shapes to process // // 1.1 Shapes from pure arguments aMSI // 1.1.1 vertex, edge for (i=0; i<2; ++i) { jT=(Standard_Integer)aT[i]; const TopTools_ListOfShape &aLS=myShapes1[jT]; aIt.Initialize(aLS); for (; aIt.More(); aIt.Next()) { const TopoDS_Shape& aS=aIt.Value(); if (aMFence.Add(aS)) { aLSI.Append(aS); } } } // 1.1.2 wire { jT=(Standard_Integer)TopAbs_WIRE; const TopTools_ListOfShape &aLW=myShapes1[jT]; aIt.Initialize(aLW); for (; aIt.More(); aIt.Next()) { const TopoDS_Shape& aW=aIt.Value(); aItS.Initialize(aW); for (; aItS.More(); aItS.Next()) { const TopoDS_Shape& aE=aItS.Value(); if (aMFence.Add(aE)) { aLSI.Append(aE); } } } } // 1.1.3 theirs images/sources aIt1.Initialize(aLSI); for (; aIt1.More(); aIt1.Next()) { const TopoDS_Shape& aS=aIt1.Value(); if (myImages.HasImage(aS)) { const TopTools_ListOfShape &aLSp=myImages.Image(aS); aIt.Initialize(aLSp); for (; aIt.More(); aIt.Next()) { const TopoDS_Shape& aSI=aIt.Value(); aMSI.Add(aSI); } } else { aMSI.Add(aS); } } aLSI.Clear(); aNbSI=aMSI.Extent(); // // 2. Internal vertices, edges from source solids aMFence.Clear(); aLSd.Clear(); // aNbS=aDS.NumberOfShapesOfTheObject(); for (i=1; i<=aNbS; ++i) { const TopoDS_Shape& aS=aDS.Shape(i); aType=aS.ShapeType(); if (aType==TopAbs_SOLID) { // aMx.Clear(); OwnInternalShapes(aS, aMx); // aNbSx=aMx.Extent(); for (j=1; j<=aNbSx; ++j) { const TopoDS_Shape& aSI=aMx(j); if (myImages.HasImage(aSI)) { const TopTools_ListOfShape &aLSp=myImages.Image(aSI); aIt.Initialize(aLSp); for (; aIt.More(); aIt.Next()) { const TopoDS_Shape& aSp=aIt.Value(); aMSI.Add(aSp); } } else { aMSI.Add(aSI); } } // // build aux map from splits of solids if (myImages.HasImage(aS)) { const TopTools_ListOfShape &aLSp=myImages.Image(aS); aIt.Initialize(aLSp); for (; aIt.More(); aIt.Next()) { const TopoDS_Shape& aSp=aIt.Value(); if (aMFence.Add(aSp)) { TopExp::MapShapesAndAncestors(aSp, TopAbs_VERTEX, TopAbs_EDGE, aMSx); TopExp::MapShapesAndAncestors(aSp, TopAbs_VERTEX, TopAbs_FACE, aMSx); TopExp::MapShapesAndAncestors(aSp, TopAbs_EDGE , TopAbs_FACE, aMSx); aLSd.Append(aSp); } } } else { if (aMFence.Add(aS)) { TopExp::MapShapesAndAncestors(aS, TopAbs_VERTEX, TopAbs_EDGE, aMSx); TopExp::MapShapesAndAncestors(aS, TopAbs_VERTEX, TopAbs_FACE, aMSx); TopExp::MapShapesAndAncestors(aS, TopAbs_EDGE , TopAbs_FACE, aMSx); aLSd.Append(aS); aMSOr.Add(aS); } } }//if (aType==TopAbs_SOLID) } // aNbSd=aLSd.Extent(); // // 3. Some shapes of aMSI can be already tied with faces of // split solids aItM.Initialize(aMSI); for (; aItM.More(); aItM.Next()) { const TopoDS_Shape& aSI=aItM.Key(); if (aMSx.Contains(aSI)) { const TopTools_ListOfShape &aLSx=aMSx.FindFromKey(aSI); aNbSx=aLSx.Extent(); if (aNbSx) { aMSI.Remove(aSI); } } } // // 4. Just check it aNbSI=aMSI.Extent(); if (!aNbSI) { return; } // // 5 Settle internal vertices and edges into solids aMx.Clear(); aIt.Initialize(aLSd); for (; aIt.More(); aIt.Next()) { TopoDS_Solid aSd=TopoDS::Solid(aIt.Value()); // aItM.Initialize(aMSI); for (; aItM.More(); aItM.Next()) { TopoDS_Shape aSI=aItM.Key(); aSI.Orientation(TopAbs_INTERNAL); // aState=GEOMAlgo_Tools3D::ComputeStateByOnePoint(aSI, aSd, 1.e-11, aCtx); if (aState==TopAbs_IN) { // if(aMSOr.Contains(aSd)) { // TopoDS_Solid aSdx; // aBB.MakeSolid(aSdx); aItS.Initialize(aSd); for (; aItS.More(); aItS.Next()) { const TopoDS_Shape& aSh=aItS.Value(); aBB.Add(aSdx, aSh); } // aBB.Add(aSdx, aSI); // myImages.Bind(aSd, aSdx); aMSOr.Remove(aSd); aSd=aSdx; } else { aBB.Add(aSd, aSI); } // aMSI.Remove(aSI); } //if (aState==TopAbs_IN) { }// for (; aItM.More(); aItM.Next()) { }//for (; aIt1.More(); aIt1.Next()) { }
//======================================================================= //function : FillIn3DParts //purpose : //======================================================================= void GEOMAlgo_Builder::FillIn3DParts() { myErrorStatus=0; // const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS(); NMTTools_PaveFiller* pPF=myPaveFiller; const Handle(IntTools_Context)& aCtx= pPF->Context(); // Standard_Boolean bIsIN, bHasImage; Standard_Integer aNbS, aNbSolids, i, j, aNbFaces, aNbFP, aNbFPx, aNbFIN, aNbLIF; TopAbs_ShapeEnum aType; TopAbs_State aState; TopTools_IndexedMapOfShape aMSolids, aMS, aMFaces, aMFIN; TopTools_MapOfShape aMFDone; TopTools_IndexedDataMapOfShapeListOfShape aMEF; TopTools_ListIteratorOfListOfShape aItS; TopoDS_Iterator aIt, aItF; BRep_Builder aBB; TopoDS_Solid aSolidSp; TopoDS_Face aFP; // myDraftSolids.Clear(); // aNbS=aDS.NumberOfShapesOfTheObject(); for (i=1; i<=aNbS; ++i) { const TopoDS_Shape& aS=aDS.Shape(i); // aType=aS.ShapeType(); if (aType==TopAbs_SOLID) { // all solids from DS aMSolids.Add(aS); } else if (aType==TopAbs_FACE) { // all faces (originals from DS or theirs images) if (myImages.HasImage(aS)) { const TopTools_ListOfShape& aLS=myImages.Image(aS); aItS.Initialize(aLS); for (; aItS.More(); aItS.Next()) { const TopoDS_Shape& aFx=aItS.Value(); // if (mySameDomainShapes.Contains(aFx)) { const TopoDS_Shape& aFSDx=mySameDomainShapes.FindFromKey(aFx); aMFaces.Add(aFSDx); } else { aMFaces.Add(aFx); } } } else { if (mySameDomainShapes.Contains(aS)) { const TopoDS_Shape& aFSDx=mySameDomainShapes.FindFromKey(aS); aMFaces.Add(aFSDx); } else { aMFaces.Add(aS); } } } } // aNbFaces=aMFaces.Extent(); aNbSolids=aMSolids.Extent(); // for (i=1; i<=aNbSolids; ++i) { const TopoDS_Solid& aSolid=TopoDS::Solid(aMSolids(i)); aMFDone.Clear(); aMFIN.Clear(); aMEF.Clear(); // aBB.MakeSolid(aSolidSp); // TopTools_ListOfShape aLIF; // BuildDraftSolid(aSolid, aSolidSp, aLIF); aNbLIF=aLIF.Extent(); // // 1 all faces/edges from aSolid [ aMS ] bHasImage=Standard_False; aMS.Clear(); aIt.Initialize(aSolid); for (; aIt.More(); aIt.Next()) { const TopoDS_Shape& aShell=aIt.Value(); // if (myImages.HasImage(aShell)) { bHasImage=Standard_True; // const TopTools_ListOfShape& aLS=myImages.Image(aShell); aItS.Initialize(aLS); for (; aItS.More(); aItS.Next()) { const TopoDS_Shape& aSx=aItS.Value(); aMS.Add(aSx); TopExp::MapShapes(aSx, TopAbs_FACE, aMS); TopExp::MapShapes(aSx, TopAbs_EDGE, aMS); TopExp::MapShapesAndAncestors(aSx, TopAbs_EDGE, TopAbs_FACE, aMEF); } } else { //aMS.Add(aShell); TopExp::MapShapes(aShell, TopAbs_FACE, aMS); //modified by NIZNHY-PKV Fri Dec 03 11:18:45 2010f TopExp::MapShapes(aShell, TopAbs_EDGE, aMS); //modified by NIZNHY-PKV Fri Dec 03 11:18:51 2010t TopExp::MapShapesAndAncestors(aShell, TopAbs_EDGE, TopAbs_FACE, aMEF); } } // // 2 all faces that are not from aSolid [ aLFP1 ] Standard_Integer aNbEFP; TopTools_IndexedDataMapOfShapeListOfShape aMEFP; TopTools_ListIteratorOfListOfShape aItFP, aItEx; TopTools_MapOfShape aMFence; TopTools_ListOfShape aLFP1, aLFP2, aLFP, aLCBF, aLFIN, aLEx;//*pLFP, // // for all non-solid faces build EF map [ aMEFP ] for (j=1; j<=aNbFaces; ++j) { const TopoDS_Shape& aFace=aMFaces(j); if (!aMS.Contains(aFace)) { TopExp::MapShapesAndAncestors(aFace, TopAbs_EDGE, TopAbs_FACE, aMEFP); } } // // among all faces from aMEFP select these that have same edges // with the solid (i.e aMEF). These faces will be treated first // to prevent the usage of 3D classifier. // The full list of faces to process is aLFP1. aNbEFP=aMEFP.Extent(); for (j=1; j<=aNbEFP; ++j) { const TopoDS_Shape& aE=aMEFP.FindKey(j); // if (aMEF.Contains(aE)) { // !! const TopTools_ListOfShape& aLF=aMEFP(j); aItFP.Initialize(aLF); for (; aItFP.More(); aItFP.Next()) { const TopoDS_Shape& aF=aItFP.Value(); if (aMFence.Add(aF)) { aLFP1.Append(aF); } } } else { aLEx.Append(aE); } } // aItEx.Initialize(aLEx); for (; aItEx.More(); aItEx.Next()) { const TopoDS_Shape& aE=aItEx.Value(); const TopTools_ListOfShape& aLF=aMEFP.FindFromKey(aE); aItFP.Initialize(aLF); for (; aItFP.More(); aItFP.Next()) { const TopoDS_Shape& aF=aItFP.Value(); if (aMFence.Add(aF)) { aLFP2.Append(aF); } } } aLFP1.Append(aLFP2); //========== // // 3 Process faces aLFP1 aNbFP=aLFP1.Extent(); aItFP.Initialize(aLFP1); for (; aItFP.More(); aItFP.Next()) { const TopoDS_Shape& aSP=aItFP.Value(); if (!aMFDone.Add(aSP)) { continue; } // // first face to process aFP=TopoDS::Face(aSP); bIsIN= GEOMAlgo_Tools3D::IsInternalFace(aFP, aSolidSp, aMEF, 1.e-14, aCtx); aState=(bIsIN) ? TopAbs_IN : TopAbs_OUT; // // collect faces to process [ aFP is the first ] aLFP.Clear(); aLFP.Append(aFP); aItS.Initialize(aLFP1); for (; aItS.More(); aItS.Next()) { const TopoDS_Shape& aSk=aItS.Value(); if (!aMFDone.Contains(aSk)) { aLFP.Append(aSk); } } // // Connexity Block that spreads from aFP the Bound // or till the end of the block itself aLCBF.Clear(); GEOMAlgo_Tools3D::MakeConnexityBlock(aLFP, aMS, aLCBF); // // fill states for the Connexity Block aItS.Initialize(aLCBF); for (; aItS.More(); aItS.Next()) { const TopoDS_Shape& aSx=aItS.Value(); aMFDone.Add(aSx); if (aState==TopAbs_IN) { aMFIN.Add(aSx); } } // aNbFPx=aMFDone.Extent(); if (aNbFPx==aNbFP) { break; } }//for (; aItFP.More(); aItFP.Next()) // // faces Inside aSolid aLFIN.Clear(); aNbFIN=aMFIN.Extent(); if (aNbFIN || aNbLIF) { for (j=1; j<=aNbFIN; ++j) { const TopoDS_Shape& aFIN=aMFIN(j); aLFIN.Append(aFIN); } // aItS.Initialize(aLIF); for (; aItS.More(); aItS.Next()) { const TopoDS_Shape& aFIN=aItS.Value(); aLFIN.Append(aFIN); } // myInParts.Add(aSolid, aLFIN); } if (aNbFIN || bHasImage) { myDraftSolids.Add(aSolid, aSolidSp); } }//for (i=1; i<=aNbSolids; ++i) { // next solid }
Standard_Boolean ShHealOper_RemoveFace::removeFaces(const TopoDS_Shape& theShape, TopoDS_Shape& theNewShape) { Standard_Boolean isDone = Standard_False; TopAbs_ShapeEnum aType = theShape.ShapeType(); theNewShape = theShape; if(!myMapFaces.Extent()) return isDone; if( aType == TopAbs_WIRE || aType == TopAbs_EDGE || aType == TopAbs_VERTEX) return isDone; if(aType == TopAbs_FACE && myMapFaces.Contains(theShape)) { removePCurve(TopoDS::Face(theShape)); myContext->Remove(theShape); myMapFaces.Remove(theShape); //theNewShape = TopoDS_Shape(); theNewShape.Nullify(); isDone = Standard_True; } else if(aType == TopAbs_SHELL) { isDone = removeFaces(TopoDS::Shell(theShape),theNewShape); return isDone; } else if(aType == TopAbs_SOLID) { isDone = removeFaces(TopoDS::Solid(theShape),theNewShape); myContext->Replace(theShape,theNewShape); } else if(aType == TopAbs_COMPSOLID) { //in the case of compsolid method for removing faces for solid //will be used. TopExp_Explorer aExpShell(theShape,TopAbs_SHELL); TopoDS_Solid aSol; BRep_Builder aB; aB.MakeSolid(aSol); for( ; aExpShell.More(); aExpShell.Next()) { aB.Add(aSol,aExpShell.Current()); } TopoDS_Shape aNewShape; isDone = removeFaces(aSol,aNewShape); if(isDone) myContext->Replace(theShape,theNewShape); } else if(aType == TopAbs_COMPOUND) { //in the case of compounf faces will be removed from each part of compound separately TopoDS_Compound aComp; TopoDS_Iterator aItShape(theShape,Standard_False); BRep_Builder aB; aB.MakeCompound(aComp); Standard_Integer nbs =0; for( ; aItShape.More() ; aItShape.Next()) { TopoDS_Shape aNShape; if( removeFaces(aItShape.Value(),aNShape)) { isDone = Standard_True; myContext->Replace(aItShape.Value(),aNShape); } if(!aNShape.IsNull()) { aB.Add(aComp,aNShape); nbs++; } } if(isDone) { if(nbs) theNewShape = aComp; else theNewShape =TopoDS_Shape(); myContext->Replace(theShape,theNewShape); } } return isDone; }