//======================================================================= //function : ShapeToDouble //purpose : used by CompareShapes::operator() //======================================================================= std::pair<double, double> GEOMUtils::ShapeToDouble (const TopoDS_Shape& S, bool isOldSorting) { // Computing of CentreOfMass gp_Pnt GPoint; double Len; if (S.ShapeType() == TopAbs_VERTEX) { GPoint = BRep_Tool::Pnt(TopoDS::Vertex(S)); Len = (double)S.Orientation(); } else { GProp_GProps GPr; // 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(); Len = GPr.Mass(); } double dMidXYZ = GPoint.X() * 999.0 + GPoint.Y() * 99.0 + GPoint.Z() * 0.9; return std::make_pair(dMidXYZ, Len); }
//======================================================================= //function : GetPosition //purpose : //======================================================================= gp_Ax3 GEOMUtils::GetPosition (const TopoDS_Shape& theShape) { gp_Ax3 aResult; if (theShape.IsNull()) return aResult; // Axes aResult.Transform(theShape.Location().Transformation()); if (theShape.ShapeType() == TopAbs_FACE) { Handle(Geom_Surface) aGS = BRep_Tool::Surface(TopoDS::Face(theShape)); if (!aGS.IsNull() && aGS->IsKind(STANDARD_TYPE(Geom_Plane))) { Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast(aGS); gp_Pln aPln = aGPlane->Pln(); aResult = aPln.Position(); // In case of reverse orinetation of the face invert the plane normal // (the face's normal does not mathc the plane's normal in this case) if(theShape.Orientation() == TopAbs_REVERSED) { gp_Dir Vx = aResult.XDirection(); gp_Dir N = aResult.Direction().Mirrored(Vx); gp_Pnt P = aResult.Location(); aResult = gp_Ax3(P, N, Vx); } } } // Origin gp_Pnt aPnt; TopAbs_ShapeEnum aShType = theShape.ShapeType(); if (aShType == TopAbs_VERTEX) { aPnt = BRep_Tool::Pnt(TopoDS::Vertex(theShape)); } else { if (aShType == TopAbs_COMPOUND) { aShType = GetTypeOfSimplePart(theShape); } GProp_GProps aSystem; if (aShType == TopAbs_EDGE || aShType == TopAbs_WIRE) BRepGProp::LinearProperties(theShape, aSystem); else if (aShType == TopAbs_FACE || aShType == TopAbs_SHELL) BRepGProp::SurfaceProperties(theShape, aSystem); else BRepGProp::VolumeProperties(theShape, aSystem); aPnt = aSystem.CentreOfMass(); } aResult.SetLocation(aPnt); return aResult; }
bool Extrusion::fetchAxisLink(const App::PropertyLinkSub& axisLink, Base::Vector3d& basepoint, Base::Vector3d& dir) { if (!axisLink.getValue()) return false; if (!axisLink.getValue()->isDerivedFrom(Part::Feature::getClassTypeId())) throw Base::TypeError("AxisLink has no OCC shape"); Part::Feature* linked = static_cast<Part::Feature*>(axisLink.getValue()); TopoDS_Shape axEdge; if (axisLink.getSubValues().size() > 0 && axisLink.getSubValues()[0].length() > 0){ axEdge = linked->Shape.getShape().getSubShape(axisLink.getSubValues()[0].c_str()); } else { axEdge = linked->Shape.getValue(); } if (axEdge.IsNull()) throw Base::ValueError("DirLink shape is null"); if (axEdge.ShapeType() != TopAbs_EDGE) throw Base::TypeError("DirLink shape is not an edge"); BRepAdaptor_Curve crv(TopoDS::Edge(axEdge)); gp_Pnt startpoint; gp_Pnt endpoint; if (crv.GetType() == GeomAbs_Line){ startpoint = crv.Value(crv.FirstParameter()); endpoint = crv.Value(crv.LastParameter()); if (axEdge.Orientation() == TopAbs_REVERSED) std::swap(startpoint, endpoint); } else { throw Base::TypeError("DirLink edge is not a line."); } basepoint.Set(startpoint.X(), startpoint.Y(), startpoint.Z()); gp_Vec vec = gp_Vec(startpoint, endpoint); dir.Set(vec.X(), vec.Y(), vec.Z()); return true; }
bool SMESH_Algo::IsReversedSubMesh (const TopoDS_Face& theFace, SMESHDS_Mesh* theMeshDS) { if ( theFace.IsNull() || !theMeshDS ) return false; // find out orientation of a meshed face int faceID = theMeshDS->ShapeToIndex( theFace ); TopoDS_Shape aMeshedFace = theMeshDS->IndexToShape( faceID ); bool isReversed = ( theFace.Orientation() != aMeshedFace.Orientation() ); const SMESHDS_SubMesh * aSubMeshDSFace = theMeshDS->MeshElements( faceID ); if ( !aSubMeshDSFace ) return isReversed; // find element with node located on face and get its normal const SMDS_FacePosition* facePos = 0; int vertexID = 0; gp_Pnt nPnt[3]; gp_Vec Ne; bool normalOK = false; SMDS_ElemIteratorPtr iteratorElem = aSubMeshDSFace->GetElements(); while ( iteratorElem->more() ) // loop on elements on theFace { const SMDS_MeshElement* elem = iteratorElem->next(); if ( elem && elem->NbNodes() > 2 ) { SMDS_ElemIteratorPtr nodesIt = elem->nodesIterator(); const SMDS_FacePosition* fPos = 0; int i = 0, vID = 0; while ( nodesIt->more() ) { // loop on nodes const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode *>(nodesIt->next()); if ( i == 3 ) i = 2; nPnt[ i++ ].SetCoord( node->X(), node->Y(), node->Z() ); // check position const SMDS_PositionPtr& pos = node->GetPosition(); if ( !pos ) continue; if ( pos->GetTypeOfPosition() == SMDS_TOP_FACE ) { fPos = dynamic_cast< const SMDS_FacePosition* >( pos.get() ); } else if ( pos->GetTypeOfPosition() == SMDS_TOP_VERTEX ) { vID = pos->GetShapeId(); } } if ( fPos || ( !normalOK && vID )) { // compute normal gp_Vec v01( nPnt[0], nPnt[1] ), v02( nPnt[0], nPnt[2] ); if ( v01.SquareMagnitude() > RealSmall() && v02.SquareMagnitude() > RealSmall() ) { Ne = v01 ^ v02; normalOK = ( Ne.SquareMagnitude() > RealSmall() ); } // we need position on theFace or at least on vertex if ( normalOK ) { vertexID = vID; if ((facePos = fPos)) break; } } } } if ( !normalOK ) return isReversed; // node position on face double u,v; if ( facePos ) { u = facePos->GetUParameter(); v = facePos->GetVParameter(); } else if ( vertexID ) { TopoDS_Shape V = theMeshDS->IndexToShape( vertexID ); if ( V.IsNull() || V.ShapeType() != TopAbs_VERTEX ) return isReversed; gp_Pnt2d uv = BRep_Tool::Parameters( TopoDS::Vertex( V ), theFace ); u = uv.X(); v = uv.Y(); } else { return isReversed; } // face normal at node position TopLoc_Location loc; Handle(Geom_Surface) surf = BRep_Tool::Surface( theFace, loc ); if ( surf.IsNull() || surf->Continuity() < GeomAbs_C1 ) return isReversed; gp_Vec d1u, d1v; surf->D1( u, v, nPnt[0], d1u, d1v ); gp_Vec Nf = (d1u ^ d1v).Transformed( loc ); if ( theFace.Orientation() == TopAbs_REVERSED ) Nf.Reverse(); return Ne * Nf < 0.; }
//======================================================================= //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 }
bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) { MESSAGE("NETGENPlugin_NETGEN_2D_ONLY::Compute()"); SMESHDS_Mesh* meshDS = aMesh.GetMeshDS(); int faceID = meshDS->ShapeToIndex( aShape ); SMESH_MesherHelper helper(aMesh); _quadraticMesh = helper.IsQuadraticSubMesh(aShape); helper.SetElementsOnShape( true ); const bool ignoreMediumNodes = _quadraticMesh; // ------------------------ // get all edges of a face // ------------------------ const TopoDS_Face F = TopoDS::Face( aShape.Oriented( TopAbs_FORWARD )); TError problem; TSideVector wires = StdMeshers_FaceSide::GetFaceWires( F, aMesh, ignoreMediumNodes, problem ); if ( problem && !problem->IsOK() ) return error( problem ); int nbWires = wires.size(); if ( nbWires == 0 ) return error( "Problem in StdMeshers_FaceSide::GetFaceWires()"); if ( wires[0]->NbSegments() < 3 ) // ex: a circle with 2 segments return error(COMPERR_BAD_INPUT_MESH, SMESH_Comment("Too few segments: ")<<wires[0]->NbSegments()); // ------------------------- // Make input netgen mesh // ------------------------- Ng_Init(); netgen::Mesh * ngMesh = new netgen::Mesh (); netgen::OCCGeometry occgeo; NETGENPlugin_Mesher::PrepareOCCgeometry( occgeo, F, aMesh ); occgeo.fmap.Clear(); // face can be reversed, which is wrong in this case (issue 19978) occgeo.fmap.Add( F ); vector< const SMDS_MeshNode* > nodeVec; problem = AddSegmentsToMesh( *ngMesh, occgeo, wires, helper, nodeVec ); if ( problem && !problem->IsOK() ) { delete ngMesh; Ng_Exit(); return error( problem ); } // -------------------- // compute edge length // -------------------- double edgeLength = 0; if (_hypLengthFromEdges || (!_hypLengthFromEdges && !_hypMaxElementArea)) { int nbSegments = 0; for ( int iW = 0; iW < nbWires; ++iW ) { edgeLength += wires[ iW ]->Length(); nbSegments += wires[ iW ]->NbSegments(); } if ( nbSegments ) edgeLength /= nbSegments; } if ( _hypMaxElementArea ) { double maxArea = _hypMaxElementArea->GetMaxArea(); edgeLength = sqrt(2. * maxArea/sqrt(3.0)); } if ( edgeLength < DBL_MIN ) edgeLength = occgeo.GetBoundingBox().Diam(); //cout << " edgeLength = " << edgeLength << endl; netgen::mparam.maxh = edgeLength; netgen::mparam.quad = _hypQuadranglePreference ? 1 : 0; //ngMesh->SetGlobalH ( edgeLength ); // ------------------------- // Generate surface mesh // ------------------------- char *optstr = 0; int startWith = MESHCONST_MESHSURFACE; int endWith = MESHCONST_OPTSURFACE; int err = 1; try { #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 OCC_CATCH_SIGNALS; #endif #ifdef NETGEN_V5 err = netgen::OCCGenerateMesh(occgeo, ngMesh,netgen::mparam, startWith, endWith); #else err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr); #endif } catch (Standard_Failure& ex) { string comment = ex.DynamicType()->Name(); if ( ex.GetMessageString() && strlen( ex.GetMessageString() )) { comment += ": "; comment += ex.GetMessageString(); } error(COMPERR_OCC_EXCEPTION, comment); } catch (NgException exc) { error( SMESH_Comment("NgException: ") << exc.What() ); } catch (...) { error(COMPERR_EXCEPTION,"Exception in netgen::OCCGenerateMesh()"); } // ---------------------------------------------------- // Fill the SMESHDS with the generated nodes and faces // ---------------------------------------------------- int nbNodes = ngMesh->GetNP(); int nbFaces = ngMesh->GetNSE(); int nbInputNodes = nodeVec.size(); nodeVec.resize( nbNodes, 0 ); // add nodes for ( int i = nbInputNodes + 1; i <= nbNodes; ++i ) { const MeshPoint& ngPoint = ngMesh->Point(i); SMDS_MeshNode * node = meshDS->AddNode(ngPoint(0), ngPoint(1), ngPoint(2)); nodeVec[ i-1 ] = node; } // create faces bool reverse = ( aShape.Orientation() == TopAbs_REVERSED ); for ( int i = 1; i <= nbFaces ; ++i ) { const Element2d& elem = ngMesh->SurfaceElement(i); vector<const SMDS_MeshNode*> nodes( elem.GetNP() ); for (int j=1; j <= elem.GetNP(); ++j) { int pind = elem.PNum(j); const SMDS_MeshNode* node = nodeVec.at(pind-1); if ( reverse ) nodes[ nodes.size()-j ] = node; else nodes[ j-1 ] = node; if ( node->GetPosition()->GetTypeOfPosition() == SMDS_TOP_3DSPACE ) { const PointGeomInfo& pgi = elem.GeomInfoPi(j); meshDS->SetNodeOnFace((SMDS_MeshNode*)node, faceID, pgi.u, pgi.v); } } SMDS_MeshFace* face = 0; if ( elem.GetType() == TRIG ) face = helper.AddFace(nodes[0],nodes[1],nodes[2]); else face = helper.AddFace(nodes[0],nodes[1],nodes[2],nodes[3]); } Ng_DeleteMesh((nglib::Ng_Mesh*)ngMesh); Ng_Exit(); NETGENPlugin_Mesher::RemoveTmpFiles(); return !err; }
//======================================================================= //function : BuildDraftSolid //purpose : //======================================================================= void GEOMAlgo_Builder::BuildDraftSolid (const TopoDS_Shape& theSolid, TopoDS_Shape& theDraftSolid, TopTools_ListOfShape& theLIF) { myErrorStatus=0; // NMTTools_PaveFiller* pPF=myPaveFiller; const Handle(IntTools_Context)& aCtx= pPF->Context(); // Standard_Boolean bToReverse; Standard_Integer iFlag; TopAbs_Orientation aOrF, aOrSh, aOrSd; TopoDS_Iterator aIt1, aIt2; TopTools_ListIteratorOfListOfShape aItS; BRep_Builder aBB; TopoDS_Shell aShD; TopoDS_Shape aFSDx, aFx; // aOrSd=theSolid.Orientation(); theDraftSolid.Orientation(aOrSd); // aIt1.Initialize(theSolid); for (; aIt1.More(); aIt1.Next()) { const TopoDS_Shape& aSh=aIt1.Value(); if(aSh.ShapeType()!=TopAbs_SHELL) { continue; // mb internal edges,vertices } // aOrSh=aSh.Orientation(); aBB.MakeShell(aShD); aShD.Orientation(aOrSh); iFlag=0; // aIt2.Initialize(aSh); for (; aIt2.More(); aIt2.Next()) { const TopoDS_Shape& aF=aIt2.Value(); aOrF=aF.Orientation(); // if (myImages.HasImage(aF)) { const TopTools_ListOfShape& aLSp=myImages.Image(aF); aItS.Initialize(aLSp); for (; aItS.More(); aItS.Next()) { aFx=aItS.Value(); // if (mySameDomainShapes.Contains(aFx)) { aFSDx=mySameDomainShapes.FindFromKey(aFx); // if (aOrF==TopAbs_INTERNAL) { aFSDx.Orientation(aOrF); theLIF.Append(aFSDx); } else { bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aFSDx, aF, aCtx); if (bToReverse) { aFSDx.Reverse(); } // iFlag=1; aBB.Add(aShD, aFSDx); } }// if (mySameDomainShapes.Contains(aFx)) { else { aFx.Orientation(aOrF); if (aOrF==TopAbs_INTERNAL) { theLIF.Append(aFx); } else{ iFlag=1; aBB.Add(aShD, aFx); } } } } //if (myImages.HasImage(aF)) { // else { if (aOrF==TopAbs_INTERNAL) { theLIF.Append(aF); } else{ iFlag=1; aBB.Add(aShD, aF); } } } //for (; aIt2.More(); aIt2.Next()) { // if (iFlag) { aBB.Add(theDraftSolid, aShD); } } //for (; aIt1.More(); aIt1.Next()) { }
//======================================================================= // function: MakeBlocks // purpose: //======================================================================= void NMTTools_PaveFiller::MakeBlocks() { myIsDone=Standard_False; // Standard_Boolean bIsExistingPaveBlock, bIsValidIn2D, bIsCoincided; Standard_Boolean bIsMicroEdge, bHasES; Standard_Integer i, aNbFFs, nF1, nF2; Standard_Integer nV1, nV2, j, aNbCurves; Standard_Real aTolR3D, aTol2D, aT1, aT2, aTolPPC=Precision::PConfusion(); TopoDS_Face aF1, aF2; NMTTools_IndexedDataMapOfShapePaveBlock aMEPB; BooleanOperations_IndexedDataMapOfShapeInteger aMapEI; BOPTools_ListIteratorOfListOfPaveBlock anIt; // BOPTools_CArray1OfSSInterference& aFFs=myIP->SSInterferences(); // // // 1. Make Section Edges from intersection curves // between each pair of faces aNbFFs=aFFs.Extent(); if (!aNbFFs) { return; } // FillFaceInfo(); // for (i=1; i<=aNbFFs; ++i) { BOPTools_ListOfPaveBlock aLPB; TColStd_MapOfInteger aMVStick; TopTools_ListOfShape aLSE; TColStd_ListOfInteger aLNE; BOPTools_PaveSet aPSF; NMTTools_MapOfPaveBlock aMPBX; TColStd_MapIteratorOfMapOfInteger aItMI; NMTTools_MapIteratorOfMapOfPaveBlock aItMPB; // BOPTools_SSInterference& aFFi=aFFs(i); // // Faces aFFi.Indices(nF1, nF2); aF1=*((TopoDS_Face*)(&myDS->Shape(nF1))); aF2=*((TopoDS_Face*)(&myDS->Shape(nF2))); // SharedEdges(nF1, nF2, aLNE, aLSE); aFFi.SetSharedEdges(aLNE); // // aMVStick const NMTTools_FaceInfo& aFI1=myFaceInfo.Find(nF1); const NMTTools_FaceInfo& aFI2=myFaceInfo.Find(nF2); // const TColStd_MapOfInteger& aMVOn1=aFI1.VerticesOn(); const TColStd_MapOfInteger& aMVIn1=aFI1.VerticesIn(); const TColStd_MapOfInteger& aMVOn2=aFI2.VerticesOn(); const TColStd_MapOfInteger& aMVIn2=aFI2.VerticesIn(); // for (j=0; j<2; ++j) { const TColStd_MapOfInteger& aMV1=(!j) ? aMVOn1 :aMVIn1; aItMI.Initialize(aMV1); for (; aItMI.More(); aItMI.Next()) { nV1=aItMI.Key(); if (aMVOn2.Contains(nV1) || aMVIn2.Contains(nV1)) { aMVStick.Add(nV1); } } } // // aLPB const NMTTools_MapOfPaveBlock& aMPBIn1=aFI1.PaveBlocksIn(); const NMTTools_MapOfPaveBlock& aMPBOn1=aFI1.PaveBlocksOn(); const NMTTools_MapOfPaveBlock& aMPBIn2=aFI2.PaveBlocksIn(); const NMTTools_MapOfPaveBlock& aMPBOn2=aFI2.PaveBlocksOn(); // aMPBX.Clear(); for (j=0; j<4; ++j) { NMTTools_MapOfPaveBlock *pMPB; // if (!j) { pMPB=((NMTTools_MapOfPaveBlock*)&aMPBIn1); } else if (j==1) { pMPB=((NMTTools_MapOfPaveBlock*)&aMPBOn1); } else if (j==2) { pMPB=((NMTTools_MapOfPaveBlock*)&aMPBIn2); } else if (j==3) { pMPB=((NMTTools_MapOfPaveBlock*)&aMPBOn2); } // const NMTTools_MapOfPaveBlock& aMPB=*pMPB; aItMPB.Initialize(aMPB); for (; aItMPB.More(); aItMPB.Next()) { const BOPTools_PaveBlock& aPB=aItMPB.Key(); if (aMPBX.Add(aPB)) { aLPB.Append(aPB); } // else { if (j>1) { aFFi.AppendBlock(aPB); } } // } } // BOPTools_SequenceOfCurves& aSCvs=aFFi.Curves(); aNbCurves=aSCvs.Length(); if (!aNbCurves) { continue; } // aTolR3D=aFFi.TolR3D(); aTol2D=(aTolR3D < 1.e-3) ? 1.e-3 : aTolR3D; // CorrectTolR3D(aFFi, aMVStick, aTolR3D); // PrepareSetForFace (nF1, nF2, aLPB, aPSF); // // Put Paves On Curves for (j=1; j<=aNbCurves; ++j) { BOPTools_Curve& aBC=aSCvs(j); const IntTools_Curve& aC=aBC.Curve(); // DEBUG f Handle(Geom_Curve) aC3D = aC.Curve(); // DEBUG t PutPaveOnCurve (aPSF, aTolR3D, aBC); } // // Put bounding paves on curves for (j=1; j<=aNbCurves; ++j) { BOPTools_Curve& aBC=aSCvs(j); PutBoundPaveOnCurve (aBC, aFFi); } //modified by NIZNHY-PKV Wed Sep 14 13:12:14 2011f #if OCC_VERSION_LARGE > 0x06050100 // For OCCT6.5.2 and higher // // Put closing pave if needded for (j=1; j<=aNbCurves; ++j) { BOPTools_Curve& aBC=aSCvs(j); PutClosingPaveOnCurve (aBC, aFFi); } #endif // OCC_VERSION_LARGE > 0x06050100 // For OCCT6.5.2 and higher //modified by NIZNHY-PKV Wed Sep 14 13:12:17 2011t // // Pave Blocks on Curves bHasES=Standard_False; for (j=1; j<=aNbCurves; ++j) { BOPTools_Curve& aBC=aSCvs(j); const IntTools_Curve& aIC= aBC.Curve(); BOPTools_PaveSet& aPaveSet=aBC.Set(); // BOPTools_PaveBlockIterator aPBIter(0, aPaveSet); for (; aPBIter.More(); aPBIter.Next()) { BOPTools_PaveBlock& aPBNew=aPBIter.Value(); aPBNew.SetCurve(aIC); aPBNew.SetFace1(nF1); aPBNew.SetFace2(nF2); // nV1=aPBNew.Pave1().Index(); nV2=aPBNew.Pave2().Index(); aT1=aPBNew.Pave1().Param(); aT2=aPBNew.Pave2().Param(); // if((nV1==nV2) && (Abs(aT2 - aT1) < aTolPPC)) { continue;// mkk ft ??? } // // 1 bIsExistingPaveBlock=IsExistingPaveBlock(aPBNew, aLPB, aTolR3D); if (bIsExistingPaveBlock) { continue; } // bIsCoincided=CheckCoincidence(aPBNew, aLPB); if(bIsCoincided) { continue; } // // 2 bIsExistingPaveBlock=IsExistingPaveBlock(aPBNew, aLSE, aTolR3D); if (bIsExistingPaveBlock) { continue; } // // Checking of validity in 2D // bIsValidIn2D=myContext->IsValidBlockForFaces(aT1, aT2, aIC, aF1, aF2, aTol2D); if (!bIsValidIn2D) { continue; } // // // Make Section Edge TopoDS_Edge aES; // const TopoDS_Vertex aV1=TopoDS::Vertex(myDS->Shape(nV1)); const TopoDS_Vertex aV2=TopoDS::Vertex(myDS->Shape(nV2)); // { Standard_Real aT; // myContext->IsVertexOnLine(aV1, aIC, aTolR3D, aT); BOPTools_Tools::UpdateVertex (aIC, aT, aV1); // myContext->IsVertexOnLine(aV2, aIC, aTolR3D, aT); BOPTools_Tools::UpdateVertex (aIC, aT, aV2); } // BOPTools_Tools::MakeSectEdge (aIC, aV1, aT1, aV2, aT2, aES); // NMTTools_Tools::UpdateEdge (aES, aTolR3D); bIsMicroEdge=IsMicroEdge(aES, myContext); if (bIsMicroEdge) { continue; } // { Handle(Geom2d_Curve) aC2D1, aC2D2; // aC2D1=aIC.FirstCurve2d(); aC2D2=aIC.SecondCurve2d(); // NMTTools_Tools::MakePCurve(aES, aF1, aC2D1); NMTTools_Tools::MakePCurve(aES, aF2, aC2D2); } // aMEPB.Add(aES, aPBNew); aMapEI.Add(aES, i); // bHasES=Standard_True; }// for (; aPBIter.More(); aPBIter.Next()) } // end of for (j=1; j<=aNbCurves; ++j) // qqf if (bHasES) { myIP->Add(nF1, nF2, Standard_True, NMTDS_TI_FF); } // qqt }// for (i=1; i<=aNbFFs; ++i) //============================================================= // // II. Post treatment // // Input data: aMEPB, aMapEI // Result : section edges in myDS // Standard_Integer aNbSE; // aNbSE=aMEPB.Extent(); if (!aNbSE) { // there is nothing to do here return; } // BRep_Builder aBB; TopoDS_Compound aCompound; // // 1. Make compound from SE aBB.MakeCompound(aCompound); for (i=1; i<=aNbSE; ++i) { const TopoDS_Shape& aSE=aMEPB.FindKey(i); aBB.Add(aCompound, aSE); } // // // 2. Intersect SE using auxiliary Filler NMTTools_PaveFiller tPF; // tPF.SetCompositeShape(aCompound); // // 2.1.VV tPF.Init(); tPF.PerformVV(); // // 2.2.VE tPF.myPavePool.Resize (tPF.myNbEdges); tPF.PrepareEdges(); tPF.PerformVE(); // // 2.3.VF tPF.PerformVF(); // // 2.4.EE tPF.myCommonBlockPool.Resize (tPF.myNbEdges); tPF.mySplitShapesPool.Resize (tPF.myNbEdges); tPF.myPavePoolNew .Resize (tPF.myNbEdges); tPF.PreparePaveBlocks(TopAbs_VERTEX, TopAbs_EDGE); tPF.PreparePaveBlocks(TopAbs_EDGE, TopAbs_EDGE); // tPF.PerformEE(); // tPF.RefinePavePool (); // tPF.myPavePoolNew.Destroy(); // tPF.MakeSplitEdges(); tPF.UpdateCommonBlocks(); // // 3. Treatment of the result of intersection // Standard_Integer aNbOld, aNbLines, aNbPB, mV1, mV2, nE, mE, iFF; TopAbs_ShapeEnum aType; BOPTools_ListIteratorOfListOfPaveBlock aIt; BOPTColStd_IndexedDataMapOfIntegerInteger aMNewOld; // const NMTDS_ShapesDataStructure& tDS=*(tPF.DS()); const BOPTools_SplitShapesPool& aSSP=tPF.mySplitShapesPool; const NMTTools_CommonBlockPool& aCBP=tPF.myCommonBlockPool; // aNbLines=tDS.NumberOfInsertedShapes(); aNbOld=tDS.NumberOfShapesOfTheObject(); // // 3.1 Links between indices in tDS and DS (kept in aMNewOld) // // 3.1.1.Old vertices [ links ] for (i=1; i<=aNbOld; ++i) { const TopoDS_Shape& aV=tDS.Shape(i); aType=aV.ShapeType(); if (aType!=TopAbs_VERTEX) { continue; } // for (j=1; j<=aNbSE; ++j) { const BOPTools_PaveBlock& aPBSE=aMEPB(j); nV1=aPBSE.Pave1().Index(); const TopoDS_Shape aV1=myDS->Shape(nV1);//mpv if (aV1.IsSame(aV)) { aMNewOld.Add(i, nV1); break; } nV2=aPBSE.Pave2().Index(); const TopoDS_Shape aV2=myDS->Shape(nV2);//mpv if (aV2.IsSame(aV)) { aMNewOld.Add(i, nV2); break; } } } // // 3.1.2. New vertices [ links ] i=tDS.NumberOfSourceShapes()+1; for (; i<=aNbLines; ++i) { const TopoDS_Shape& aV=tDS.Shape(i); aType=aV.ShapeType(); if (aType!=TopAbs_VERTEX) { continue; } // // Insert new vertex in myDS BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq; myDS->InsertShapeAndAncestorsSuccessors(aV, anASSeq); nV1=myDS->NumberOfInsertedShapes(); // link aMNewOld.Add(i, nV1); } // // 3.2. Treatment of section edges (SE) for (i=1; i<=aNbOld; ++i) { const TopoDS_Shape& aE=tDS.Shape(i); aType=aE.ShapeType(); if (aType!=TopAbs_EDGE) { continue; } // // block of section edge that we already have for this SE BOPTools_PaveBlock& aPBSE=aMEPB.ChangeFromKey(aE); // // Corresponding FF-interference iFF=aMapEI.FindFromKey(aE); BOPTools_SSInterference& aFFi=aFFs(iFF); BOPTools_SequenceOfCurves& aSCvs=aFFi.Curves(); // BOPTools_Curve& aBC=aSCvs(1); // const BOPTools_ListOfPaveBlock& aLPB=aSSP(tDS.RefEdge(i)); aNbPB=aLPB.Extent(); // if (!aNbPB) { // no pave blocks -> use aPBSE and whole edge aE BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq; // nV1=aPBSE.Pave1().Index(); const TopoDS_Shape aV1=myDS->Shape(nV1);//mpv nV2=aPBSE.Pave2().Index(); const TopoDS_Shape aV2=myDS->Shape(nV2);//mpv // anASSeq.SetNewSuccessor(nV1); anASSeq.SetNewOrientation(aV1.Orientation()); anASSeq.SetNewSuccessor(nV2); anASSeq.SetNewOrientation(aV2.Orientation()); // myDS->InsertShapeAndAncestorsSuccessors(aE, anASSeq); nE=myDS->NumberOfInsertedShapes(); // aPBSE.SetEdge(nE); aBC.AppendNewBlock(aPBSE); // continue; } // nF1=aPBSE.Face1(); nF2=aPBSE.Face2(); // const NMTTools_ListOfCommonBlock& aLCB=aCBP(tDS.RefEdge(i)); NMTTools_CommonBlockAPI aCBAPI(aLCB); // aIt.Initialize(aLPB); for (; aIt.More(); aIt.Next()) { BOPTools_PaveBlock aPB=aIt.Value(); // const TopoDS_Face aF1=TopoDS::Face(myDS->Shape(nF1)); const TopoDS_Face aF2=TopoDS::Face(myDS->Shape(nF2)); // if (aCBAPI.IsCommonBlock(aPB)) { // it can be Common Block Standard_Real aTolEx; Handle(Geom2d_Curve) aC2D1, aC2D2; TopoDS_Face aF1FWD, aF2FWD; // NMTTools_CommonBlock& aCB=aCBAPI.CommonBlock(aPB); //const BOPTools_ListOfPaveBlock& aLPBx=aCB.PaveBlocks(); // aPB=aCB.PaveBlock1(); mE=aPB.Edge(); // index of edge in tDS const TopoDS_Edge& aEx=TopoDS::Edge(tDS.Shape(mE)); aTolEx=BRep_Tool::Tolerance(aEx); // aF1FWD=aF1; aF1FWD.Orientation(TopAbs_FORWARD); aF2FWD=aF2; aF2FWD.Orientation(TopAbs_FORWARD); // NMTTools_Tools::MakePCurve(aEx, aF1FWD, aC2D1); NMTTools_Tools::MakePCurve(aEx, aF2FWD, aC2D2); NMTTools_Tools::UpdateEdge (aEx, aTolEx); } //if (aCBAPI.IsCommonBlock(aPB)) // // new SE mE=aPB.Edge(); // index of edge in tDS const TopoDS_Shape& aSp=tDS.Shape(mE); // const BOPTools_Pave& aPave1=aPB.Pave1(); aT1=aPave1.Param(); mV1=aPave1.Index(); // index in tDS nV1=aMNewOld.FindFromKey(mV1); // index in myDS const TopoDS_Shape aV1=myDS->Shape(nV1);//mpv // const BOPTools_Pave& aPave2=aPB.Pave2(); aT2=aPave2.Param(); mV2=aPave2.Index(); nV2=aMNewOld.FindFromKey(mV2); const TopoDS_Shape aV2=myDS->Shape(nV2);//mpv // if (!aMNewOld.Contains(mE)) { // add new SE to the myDS BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq; // anASSeq.SetNewSuccessor(nV1); anASSeq.SetNewOrientation(aV1.Orientation()); anASSeq.SetNewSuccessor(nV2); anASSeq.SetNewOrientation(aV2.Orientation()); myDS->InsertShapeAndAncestorsSuccessors(aSp, anASSeq); nE=myDS->NumberOfInsertedShapes(); // aMNewOld.Add(mE, nE); } else { nE=aMNewOld.FindFromKey(mE); } // Form PaveBlock; BOPTools_PaveBlock aPBx; BOPTools_Pave aP1, aP2; // aPBx.SetFace1(nF1); aPBx.SetFace1(nF2); // aP1.SetIndex(nV1); aP1.SetParam(aT1); // aP2.SetIndex(nV2); aP2.SetParam(aT2); // aPBx.SetPave1(aP1); aPBx.SetPave2(aP2); // aPBx.SetEdge(nE); // aBC.AppendNewBlock(aPBx); }// for (; aIt.More(); aIt.Next()) }// for (i=1; i<=aNbOld; ++i) // myIsDone=Standard_True; }