//======================================================================= // function: FillImagesFaces1 // purpose: //======================================================================= void GEOMAlgo_Builder::FillImagesFaces1() { Standard_Integer i, aNb, iSense, aNbLFx; TopoDS_Face aF, aFSp, aFSD; TopTools_ListOfShape aLFx; TopTools_ListIteratorOfListOfShape aIt; // const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS(); // aNb=aDS.NumberOfShapesOfTheObject(); for (i=1; i<=aNb; ++i) { const TopoDS_Shape& aS=aDS.Shape(i); if (aS.ShapeType()!=TopAbs_FACE) { continue; } // if (!mySplitFaces.HasImage(aS)) { continue; } // aF=*((TopoDS_Face*)&aS); // aLFx.Clear(); const TopTools_ListOfShape& aLF=mySplitFaces.Image(aF); aIt.Initialize(aLF); for (; aIt.More(); aIt.Next()) { aFSp=*((TopoDS_Face*)(&aIt.Value())); if (!mySameDomainShapes.Contains(aFSp)) { aLFx.Append(aFSp); } else { const TopoDS_Shape& aSx=mySameDomainShapes.FindFromKey(aFSp); aFSD=*((TopoDS_Face*)(&aSx)); iSense=GEOMAlgo_Tools3D::Sense(aFSp, aFSD); if (iSense<0) { aFSD.Reverse(); } aLFx.Append(aFSD); } } // if (!myImages.HasImage(aF)) { aNbLFx=aLFx.Extent(); if (aNbLFx==1) { const TopoDS_Shape& aFx=aLFx.First(); if (aF.IsSame(aFx)) { continue; } } myImages.Bind(aF, aLFx); } } }
//======================================================================= // function: FillIn2DParts // purpose: //======================================================================= void GEOMAlgo_Builder::FillIn2DParts() { const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS(); NMTTools_PaveFiller* pPF=myPaveFiller; NMTDS_InterfPool* pIP=pPF->IP(); BOPTools_CArray1OfSSInterference& aFFs=pIP->SSInterferences(); NMTTools_CommonBlockPool& aCBP=pPF->ChangeCommonBlockPool(); // Standard_Integer j, nSpIn, nSpSc, aNbCurves; Standard_Integer aNbS, nF, aNbCBP, n1, n2, aNbFFs, aNbSpIn; TopTools_MapOfShape aMFence; TopTools_ListOfShape aLSpIn; TopoDS_Face aF; NMTTools_ListIteratorOfListOfCommonBlock aItCB; BOPTools_ListIteratorOfListOfPaveBlock aItPB; // myInParts.Clear(); // aNbFFs=aFFs.Extent(); aNbCBP=aCBP.Extent(); // aNbS=aDS.NumberOfShapesOfTheObject(); for (nF=1; nF<=aNbS; ++nF) { if (aDS.GetShapeType(nF)!=TopAbs_FACE) { continue; } // aF=TopoDS::Face(aDS.Shape(nF)); // aMFence.Clear(); aLSpIn.Clear(); // // 1. In Parts BOPTools_ListOfPaveBlock aLPBIn; // pPF->RealSplitsInFace(nF, aLPBIn); // aItPB.Initialize(aLPBIn); for (; aItPB.More(); aItPB.Next()) { const BOPTools_PaveBlock& aPB1=aItPB.Value(); nSpIn=aPB1.Edge(); const TopoDS_Shape& aSpIn=aDS.Shape(nSpIn); aLSpIn.Append(aSpIn); } // // 2. Section Parts for (j=1; j<=aNbFFs; ++j) { BOPTools_SSInterference& aFF=aFFs(j); aFF.Indices(n1, n2); if (!(n1==nF || n2==nF)) { continue; } BOPTools_SequenceOfCurves& aSC=aFF.Curves(); aNbCurves=aSC.Length(); if (!aNbCurves) { continue; } // const BOPTools_Curve& aBC=aSC(1); const BOPTools_ListOfPaveBlock& aLPB=aBC.NewPaveBlocks(); aItPB.Initialize(aLPB); for (; aItPB.More(); aItPB.Next()) { const BOPTools_PaveBlock& aPBSc=aItPB.Value(); nSpSc=aPBSc.Edge(); const TopoDS_Shape& aSpSc=aDS.Shape(nSpSc); if (aMFence.Add(aSpSc)){ aLSpIn.Append(aSpSc); } } } aNbSpIn=aLSpIn.Extent(); if (aNbSpIn) { myInParts.Add(aF, aLSpIn); } }//for (nF=1; nF<=aNbS; ++nF) { }
//======================================================================= // function: FillImagesEdges // purpose: //======================================================================= void GEOMAlgo_Builder::FillImagesEdges() { myErrorStatus=0; // const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS(); NMTTools_PaveFiller* pPF=myPaveFiller; const BOPTools_SplitShapesPool& aSSP=pPF->SplitShapesPool(); const Handle(IntTools_Context)& aCtx=pPF->Context(); // Standard_Boolean bToReverse; Standard_Integer i, aNb, aNbSp, nSp, nSpR, nSpx, aIsCB, aNbLB; TColStd_ListIteratorOfListOfInteger aItLB; TColStd_ListOfInteger aLB; TopoDS_Edge aEE, aESpR; TopTools_MapOfShape aMFence; TopTools_ListOfShape aLSp; TopTools_ListIteratorOfListOfShape aIt1; BOPTools_ListIteratorOfListOfPaveBlock aIt; // aNb=aDS.NumberOfShapesOfTheObject(); for (i=1; i<=aNb; ++i) { const TopoDS_Shape& aE=aDS.Shape(i); if (aE.ShapeType()!=TopAbs_EDGE) { continue; } // if (!aMFence.Add(aE)) { continue; } // const BOPTools_ListOfPaveBlock& aLPB=aSSP(aDS.RefEdge(i)); aNbSp=aLPB.Extent(); if (!aNbSp) { continue; } // aEE=TopoDS::Edge(aE); aLSp.Clear(); // if (aNbSp==1) { const BOPTools_PaveBlock& aPB=aLPB.First(); nSp=aPB.Edge(); const TopoDS_Shape& aSp=aDS.Shape(nSp); // const BOPTools_PaveBlock& aPBR=pPF->RealPaveBlock(aPB, aLB, aIsCB); //modified by NIZNHY-PKV Wed Oct 27 11:19:30 2010f aNbLB=aLB.Extent(); if (aIsCB && aNbLB<2) { aIsCB=0; } //modified by NIZNHY-PKV Wed Oct 27 11:19:34 2010t // nSpR=aPBR.Edge(); const TopoDS_Shape& aSpR=aDS.Shape(nSpR); if (aSpR.IsSame(aSp) && aSpR.IsSame(aE) && !aIsCB) { continue; } // aESpR=TopoDS::Edge(aSpR); bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aESpR, aEE, aCtx); if (bToReverse) { aESpR.Reverse(); } aLSp.Append(aESpR); // aItLB.Initialize(aLB); for (; aItLB.More(); aItLB.Next()) { nSpx=aItLB.Value(); const TopoDS_Shape& aSpx=aDS.Shape(nSpx); mySameDomainShapes.Add(aSpx ,aSpR); } // // }// if (aNbSp==1) { else { aIt.Initialize(aLPB); for (; aIt.More(); aIt.Next()) { const BOPTools_PaveBlock& aPB=aIt.Value(); const BOPTools_PaveBlock& aPBR=pPF->RealPaveBlock(aPB, aLB, aIsCB); nSpR=aPBR.Edge(); const TopoDS_Shape& aSpR=aDS.Shape(nSpR); // aESpR=TopoDS::Edge(aSpR); bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aESpR, aEE, aCtx); if (bToReverse) { aESpR.Reverse(); } aLSp.Append(aESpR); // aItLB.Initialize(aLB); for (; aItLB.More(); aItLB.Next()) { nSpx=aItLB.Value(); const TopoDS_Shape& aSpx=aDS.Shape(nSpx); mySameDomainShapes.Add(aSpx ,aSpR); } } } // myImages.Bind(aE, aLSp); }//for (i=1; i<=aNb; ++i) }
//======================================================================= //function : SortShapes //purpose : //======================================================================= void GEOMUtils::SortShapes (TopTools_ListOfShape& SL, const Standard_Boolean isOldSorting) { #ifdef STD_SORT_ALGO std::vector<TopoDS_Shape> aShapesVec; aShapesVec.reserve(SL.Extent()); TopTools_ListIteratorOfListOfShape it (SL); for (; it.More(); it.Next()) { aShapesVec.push_back(it.Value()); } SL.Clear(); CompareShapes shComp (isOldSorting); std::stable_sort(aShapesVec.begin(), aShapesVec.end(), shComp); //std::sort(aShapesVec.begin(), aShapesVec.end(), shComp); std::vector<TopoDS_Shape>::const_iterator anIter = aShapesVec.begin(); for (; anIter != aShapesVec.end(); ++anIter) { SL.Append(*anIter); } #else // old implementation Standard_Integer MaxShapes = SL.Extent(); TopTools_Array1OfShape aShapes (1,MaxShapes); TColStd_Array1OfInteger OrderInd(1,MaxShapes); TColStd_Array1OfReal MidXYZ (1,MaxShapes); //X,Y,Z; TColStd_Array1OfReal Length (1,MaxShapes); //X,Y,Z; // Computing of CentreOfMass Standard_Integer Index; GProp_GProps GPr; gp_Pnt GPoint; TopTools_ListIteratorOfListOfShape it(SL); for (Index=1; it.More(); Index++) { TopoDS_Shape S = it.Value(); SL.Remove( it ); // == it.Next() aShapes(Index) = S; OrderInd.SetValue (Index, Index); if (S.ShapeType() == TopAbs_VERTEX) { GPoint = BRep_Tool::Pnt( TopoDS::Vertex( S )); Length.SetValue( Index, (Standard_Real) S.Orientation()); } else { // BEGIN: fix for Mantis issue 0020842 if (isOldSorting) { BRepGProp::LinearProperties (S, GPr); } else { if (S.ShapeType() == TopAbs_EDGE || S.ShapeType() == TopAbs_WIRE) { BRepGProp::LinearProperties (S, GPr); } else if (S.ShapeType() == TopAbs_FACE || S.ShapeType() == TopAbs_SHELL) { BRepGProp::SurfaceProperties(S, GPr); } else { BRepGProp::VolumeProperties(S, GPr); } } // END: fix for Mantis issue 0020842 GPoint = GPr.CentreOfMass(); Length.SetValue(Index, GPr.Mass()); } MidXYZ.SetValue(Index, GPoint.X()*999.0 + GPoint.Y()*99.0 + GPoint.Z()*0.9); //cout << Index << " L: " << Length(Index) << "CG: " << MidXYZ(Index) << endl; } // Sorting Standard_Integer aTemp; Standard_Boolean exchange, Sort = Standard_True; Standard_Real tol = Precision::Confusion(); while (Sort) { Sort = Standard_False; for (Index=1; Index < MaxShapes; Index++) { exchange = Standard_False; Standard_Real dMidXYZ = MidXYZ(OrderInd(Index)) - MidXYZ(OrderInd(Index+1)); Standard_Real dLength = Length(OrderInd(Index)) - Length(OrderInd(Index+1)); if ( dMidXYZ >= tol ) { // cout << "MidXYZ: " << MidXYZ(OrderInd(Index))<< " > " <<MidXYZ(OrderInd(Index+1)) // << " d: " << dMidXYZ << endl; exchange = Standard_True; } else if ( Abs(dMidXYZ) < tol && dLength >= tol ) { // cout << "Length: " << Length(OrderInd(Index))<< " > " <<Length(OrderInd(Index+1)) // << " d: " << dLength << endl; exchange = Standard_True; } else if ( Abs(dMidXYZ) < tol && Abs(dLength) < tol && aShapes(OrderInd(Index)).ShapeType() <= TopAbs_FACE) { // PAL17233 // equal values possible on shapes such as two halves of a sphere and // a membrane inside the sphere Bnd_Box box1,box2; BRepBndLib::Add( aShapes( OrderInd(Index) ), box1 ); if ( box1.IsVoid() ) continue; BRepBndLib::Add( aShapes( OrderInd(Index+1) ), box2 ); Standard_Real dSquareExtent = box1.SquareExtent() - box2.SquareExtent(); if ( dSquareExtent >= tol ) { // cout << "SquareExtent: " << box1.SquareExtent()<<" > "<<box2.SquareExtent() << endl; exchange = Standard_True; } else if ( Abs(dSquareExtent) < tol ) { Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax, val1, val2; box1.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); val1 = (aXmin+aXmax)*999 + (aYmin+aYmax)*99 + (aZmin+aZmax)*0.9; box2.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); val2 = (aXmin+aXmax)*999 + (aYmin+aYmax)*99 + (aZmin+aZmax)*0.9; //exchange = val1 > val2; if ((val1 - val2) >= tol) { exchange = Standard_True; } //cout << "box: " << val1<<" > "<<val2 << endl; } } if (exchange) { // cout << "exchange " << Index << " & " << Index+1 << endl; aTemp = OrderInd(Index); OrderInd(Index) = OrderInd(Index+1); OrderInd(Index+1) = aTemp; Sort = Standard_True; } } } for (Index=1; Index <= MaxShapes; Index++) SL.Append( aShapes( OrderInd(Index) )); #endif }
//---------------------------------------------------------------- // Function: TopoDS_Shape level function to update the core Surface // for any movement or Boolean operation of the body. // Author: Jane Hu //---------------------------------------------------------------- CubitStatus OCCSurface::update_OCC_entity(TopoDS_Face& old_surface, TopoDS_Shape& new_surface, BRepBuilderAPI_MakeShape *op, TopoDS_Vertex* removed_vertex, LocOpe_SplitShape* sp) { //set the Wires TopTools_IndexedMapOfShape M, M2; TopoDS_Shape shape, shape2, shape_edge, shape_vertex; TopExp::MapShapes(old_surface, TopAbs_WIRE, M); TopTools_ListOfShape shapes; BRepFilletAPI_MakeFillet2d* test_op = NULL; for (int ii=1; ii<=M.Extent(); ii++) { TopoDS_Wire wire = TopoDS::Wire(M(ii)); TopTools_ListOfShape shapes; if(op) { test_op = dynamic_cast<BRepFilletAPI_MakeFillet2d*>(op); if(!test_op) shapes.Assign(op->Modified(wire)); if(shapes.Extent() == 0) shapes.Assign(op->Generated(wire)); if(!new_surface.IsNull()) TopExp::MapShapes(new_surface,TopAbs_WIRE, M2); } else if(sp) shapes.Assign(sp->DescendantShapes(wire)); if (shapes.Extent() == 1) { shape = shapes.First(); if(M2.Extent() == 1) { shape2 = TopoDS::Wire(M2(1)); if(!shape.IsSame(shape2)) shape = shape2; } else if(M2.Extent() > 1) shape.Nullify(); } else if(shapes.Extent() > 1) shape.Nullify(); else if(op->IsDeleted(wire) || shapes.Extent() == 0) { TopTools_IndexedMapOfShape M_new; TopExp::MapShapes(new_surface, TopAbs_WIRE, M_new); if (M_new.Extent()== 1) shape = M_new(1); else shape.Nullify(); } else { shape = wire; continue; } //set curves BRepTools_WireExplorer Ex; for(Ex.Init(wire); Ex.More();Ex.Next()) { TopoDS_Edge edge = Ex.Current(); if(op && !test_op) { shapes.Assign(op->Modified(edge)); if(shapes.Extent() == 0) shapes.Assign(op->Generated(edge)); } else if(sp) shapes.Assign(sp->DescendantShapes(edge)); if (shapes.Extent() == 1) { //in fillet creating mothod, one edge could generated a face, so check //it here. TopAbs_ShapeEnum type = shapes.First().TShape()->ShapeType(); if(type != TopAbs_EDGE) shape_edge.Nullify(); else shape_edge = shapes.First(); } else if (shapes.Extent() > 1) { //update all attributes first. TopTools_ListIteratorOfListOfShape it; it.Initialize(shapes); for(; it.More(); it.Next()) { shape_edge = it.Value(); OCCQueryEngine::instance()->copy_attributes(edge, shape_edge); } shape_edge.Nullify(); } else if (op->IsDeleted(edge)) shape_edge.Nullify(); else if (test_op) { if(!test_op->IsModified(edge)) shape_edge = edge; else shape_edge = (test_op->Modified(edge)).First(); } else shape_edge = edge; //update vertex TopoDS_Vertex vertex = Ex.CurrentVertex(); shapes.Clear(); if(test_op) assert(removed_vertex != NULL); if(op && ! test_op ) shapes.Assign(op->Modified(vertex)); else if(sp) shapes.Assign(sp->DescendantShapes(vertex)); if (shapes.Extent() == 1) shape_vertex = shapes.First(); else if(shapes.Extent() > 1) { //update all attributes first. TopTools_ListIteratorOfListOfShape it; it.Initialize(shapes); for(; it.More(); it.Next()) { shape_vertex = it.Value(); OCCQueryEngine::instance()->copy_attributes(vertex, shape_vertex); } shape_vertex.Nullify() ; } else if(op->IsDeleted(vertex) || (test_op && vertex.IsSame( *removed_vertex))) shape_vertex.Nullify() ; else shape_vertex = vertex; if(!vertex.IsSame(shape_vertex) ) OCCQueryEngine::instance()->update_OCC_map(vertex, shape_vertex); if (!edge.IsSame(shape_edge)) OCCQueryEngine::instance()->update_OCC_map(edge, shape_edge); } if (!wire.IsSame(shape)) OCCQueryEngine::instance()->update_OCC_map(wire, shape); } double dTOL = OCCQueryEngine::instance()->get_sme_resabs_tolerance(); if (!old_surface.IsSame(new_surface)) { TopAbs_ShapeEnum shapetype = TopAbs_SHAPE; if(!new_surface.IsNull()) shapetype = new_surface.TShape()->ShapeType(); if(shapetype == TopAbs_FACE || new_surface.IsNull()) OCCQueryEngine::instance()->update_OCC_map(old_surface, new_surface); else { TopTools_IndexedMapOfShape M; TopExp::MapShapes(new_surface, TopAbs_FACE, M); TopoDS_Shape new_shape; if(M.Extent() == 1) new_shape = M(1); else if(M.Extent() > 1) { for(int i = 1; i <= M.Extent(); i++) { GProp_GProps myProps; BRepGProp::SurfaceProperties(old_surface, myProps); double orig_mass = myProps.Mass(); gp_Pnt orig_pnt = myProps.CentreOfMass(); BRepGProp::SurfaceProperties(M(i), myProps); double after_mass = myProps.Mass(); gp_Pnt after_pnt = myProps.CentreOfMass(); if(fabs(-after_mass + orig_mass) <= dTOL && orig_pnt.IsEqual(after_pnt, dTOL)) { new_shape = M(i); break; } } } OCCQueryEngine::instance()->update_OCC_map(old_surface, new_shape); } } return CUBIT_SUCCESS; }
//======================================================================= // function: PerformVV // purpose: //======================================================================= void NMTTools_PaveFiller::PerformVV() { myIsDone=Standard_False; // Standard_Integer aNbVVs, aBL, aNbVSD, nVnew, i, j, n1, n2; TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger aIt1; TColStd_ListIteratorOfListOfInteger aItX, aItY; TColStd_ListOfInteger aLIX; TopTools_ListOfShape aLV; TopoDS_Vertex aVnew; // myVSD.Clear(); // const TColStd_DataMapOfIntegerListOfInteger& aMVSD=myDSIt->SDVertices(); aNbVSD=aMVSD.Extent(); if (!aNbVSD) { return; } // BOPTools_CArray1OfVVInterference& aVVs=myIP->VVInterferences(); // // BlockLength correction myDSIt->Initialize(TopAbs_VERTEX, TopAbs_VERTEX); aNbVVs=myDSIt->BlockLength(); aBL=aVVs.BlockLength(); if (aNbVVs > aBL) { aVVs.SetBlockLength(aNbVVs); } // aIt1.Initialize(aMVSD); for (; aIt1.More(); aIt1.Next()) { aLV.Clear(); // n1=aIt1.Key(); const TColStd_ListOfInteger& aLIV=aIt1.Value(); // // new vertex const TopoDS_Shape& aS1=myDS->Shape(n1); aLV.Append(aS1); aItX.Initialize(aLIV); for (; aItX.More(); aItX.Next()) { n2=aItX.Value(); const TopoDS_Shape& aS2=myDS->Shape(n2); aLV.Append(aS2); } // NMTTools_Tools::MakeNewVertex(aLV, aVnew); // BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq; // myDS->InsertShapeAndAncestorsSuccessors(aVnew, anASSeq); nVnew=myDS->NumberOfInsertedShapes(); myDS->SetState (nVnew, BooleanOperations_ON); // // myVSD, aLIX aLIX.Clear(); aLIX.Append(n1); myVSD.Bind(n1, nVnew); // aItX.Initialize(aLIV); for (; aItX.More(); aItX.Next()) { n2=aItX.Value(); aLIX.Append(n2); myVSD.Bind(n2, nVnew); } // // interferences aItX.Initialize(aLIX); for (i=0; aItX.More(); aItX.Next(), ++i) { aItY.Initialize(aLIX); for (j=0; aItY.More(); aItY.Next(), ++j) { if (j>i) { n1=aItX.Value(); n2=aItY.Value(); myIP->Add(n1, n2, Standard_True, NMTDS_TI_VV); // BOPTools_VVInterference aVV(n1, n2); aVV.SetNewShape(nVnew); aVVs.Append(aVV); } } } }//for (; aIt1.More(); aIt1.Next()) { myIsDone=Standard_True; }
//======================================================================= //function : PerformInternalShapes //purpose : //======================================================================= void GEOMAlgo_BuilderFace::PerformInternalShapes() { myErrorStatus=0; // Standard_Integer aNbWI=myLoopsInternal.Extent(); if (!aNbWI) {// nothing to do return; } // //Standard_Real aTol; BRep_Builder aBB; TopTools_ListIteratorOfListOfShape aIt1, aIt2; TopoDS_Iterator aIt; TopTools_MapOfShape aME, aMEP; TopTools_MapIteratorOfMapOfShape aItME; TopTools_IndexedDataMapOfShapeListOfShape aMVE; TopTools_ListOfShape aLSI; // // 1. All internal edges aIt1.Initialize(myLoopsInternal); for (; aIt1.More(); aIt1.Next()) { const TopoDS_Shape& aWire=aIt1.Value(); aIt.Initialize(aWire); for (; aIt.More(); aIt.Next()) { const TopoDS_Shape& aE=aIt.Value(); aME.Add(aE); } } aNbWI=aME.Extent(); // // 2 Process faces aIt2.Initialize(myAreas); for ( ; aIt2.More(); aIt2.Next()) { TopoDS_Face& aF=TopoDS::Face(aIt2.Value()); // aMVE.Clear(); TopExp::MapShapesAndAncestors(aF, TopAbs_VERTEX, TopAbs_EDGE, aMVE); // // 2.1 Separate faces to process aMEP aMEP.Clear(); aItME.Initialize(aME); for (; aItME.More(); aItME.Next()) { const TopoDS_Edge& aE=TopoDS::Edge(aItME.Key()); if (IsInside(aE, aF, myContext)) { aMEP.Add(aE); } } // // 2.2 Make Internal Wires aLSI.Clear(); MakeInternalWires(aMEP, aLSI); // // 2.3 Add them to aF aIt1.Initialize(aLSI); for (; aIt1.More(); aIt1.Next()) { const TopoDS_Shape& aSI=aIt1.Value(); aBB.Add (aF, aSI); } // // 2.4 Remove faces aMFP from aMF aItME.Initialize(aMEP); for (; aItME.More(); aItME.Next()) { const TopoDS_Shape& aE=aItME.Key(); aME.Remove(aE); } // aNbWI=aME.Extent(); if (!aNbWI) { break; } } //for ( ; aIt2.More(); aIt2.Next()) { }