From: jgv Date: Mon, 24 Aug 2020 22:36:20 +0000 (+0300) Subject: Usage of ShapeUpgrade_UnifySameDomain instead of BlockFix_UnionFaces and BlockFix_Uni... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4be43fc33eb24d7ae5a55a817f57a37662c4df2e;p=modules%2Fgeom.git Usage of ShapeUpgrade_UnifySameDomain instead of BlockFix_UnionFaces and BlockFix_UnionEdges. --- diff --git a/src/BlockFix/BlockFix.hxx b/src/BlockFix/BlockFix.hxx index e19649ae4..6d95246b5 100644 --- a/src/BlockFix/BlockFix.hxx +++ b/src/BlockFix/BlockFix.hxx @@ -27,8 +27,6 @@ class TopoDS_Shape; class BlockFix_SphereSpaceModifier; -class BlockFix_UnionFaces; -class BlockFix_UnionEdges; class BlockFix_BlockFixAPI; class BlockFix_PeriodicSurfaceModifier; class BlockFix_CheckTool; @@ -46,8 +44,6 @@ public: private: friend class BlockFix_SphereSpaceModifier; -friend class BlockFix_UnionFaces; -friend class BlockFix_UnionEdges; friend class BlockFix_BlockFixAPI; friend class BlockFix_PeriodicSurfaceModifier; friend class BlockFix_CheckTool; diff --git a/src/BlockFix/BlockFix_BlockFixAPI.cxx b/src/BlockFix/BlockFix_BlockFixAPI.cxx index 1701aaef5..8b4a86122 100644 --- a/src/BlockFix/BlockFix_BlockFixAPI.cxx +++ b/src/BlockFix/BlockFix_BlockFixAPI.cxx @@ -27,10 +27,9 @@ #include #include -#include -#include #include +#include #include @@ -67,10 +66,21 @@ void BlockFix_BlockFixAPI::Perform() myShape = BlockFix::RefillProblemFaces(myShape); // faces unification - BlockFix_UnionFaces aFaceUnifier; - aFaceUnifier.GetTolerance() = myTolerance; - aFaceUnifier.GetOptimumNbFaces() = myOptimumNbFaces; - TopoDS_Shape aResult = aFaceUnifier.Perform(myShape); + ShapeUpgrade_UnifySameDomain Unifier; + TopoDS_Shape aResult = myShape; + if (myOptimumNbFaces != -1) + { + //only faces + Standard_Boolean isUnifyEdges = Standard_False; + Standard_Boolean isUnifyFaces = Standard_True; + Standard_Boolean isConcatBSplines = Standard_True; + Unifier.Initialize(myShape, isUnifyEdges, isUnifyFaces, isConcatBSplines); + //Unifier.SetLinearTolerance(myTolerance); + Unifier.SetLinearTolerance(Precision::Confusion()); + Unifier.SetAngularTolerance(Precision::Confusion()); + Unifier.Build(); + aResult = Unifier.Shape(); + } // avoid problem with degenerated edges appearance // due to shape quality regress @@ -79,8 +89,13 @@ void BlockFix_BlockFixAPI::Perform() aResult = RemLoc.GetResult(); // edges unification - BlockFix_UnionEdges anEdgeUnifier; - myShape = anEdgeUnifier.Perform(aResult,myTolerance); + Standard_Boolean isUnifyEdges = Standard_True; + Standard_Boolean isUnifyFaces = Standard_False; //only edges + Standard_Boolean isConcatBSplines = Standard_True; + Unifier.Initialize(aResult, isUnifyEdges, isUnifyFaces, isConcatBSplines); + Unifier.SetLinearTolerance(myTolerance); + Unifier.Build(); + myShape = Unifier.Shape(); TopoDS_Shape aRes = BlockFix::FixRanges(myShape,myTolerance); myShape = aRes; diff --git a/src/BlockFix/BlockFix_UnionEdges.cxx b/src/BlockFix/BlockFix_UnionEdges.cxx deleted file mode 100644 index 2d36d308f..000000000 --- a/src/BlockFix/BlockFix_UnionEdges.cxx +++ /dev/null @@ -1,862 +0,0 @@ -// Copyright (C) 2007-2021 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 library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -// File: BlockFix_UnionEdges.cxx -// Created: 07.12.04 15:27:30 -// Author: Sergey KUUL - -#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 -#include -#include -#include -#include -#include -#include -#include -#include - -#include "utilities.h" - -//======================================================================= -//function : IsToMerge -//purpose : This method return Standard_True if two edges have common -// vertex. This vertex is returned by output parameter. The -// difference with the method TopExp::CommonVertex is only in -// the case if there are two common vertices. In this case -// this method returns the last vertex of theEdge1, not the first -// one that TopExp::CommonVertex does. -//======================================================================= -static Standard_Boolean GetCommonVertex(const TopoDS_Edge &theEdge1, - const TopoDS_Edge &theEdge2, - TopoDS_Vertex &theCommon) -{ - Standard_Boolean isFound = Standard_True; - ShapeAnalysis_Edge aSae; - TopoDS_Vertex aVF1 = aSae.FirstVertex(theEdge1); - TopoDS_Vertex aVL1 = aSae.LastVertex(theEdge1); - TopoDS_Vertex aVF2 = aSae.FirstVertex(theEdge2); - TopoDS_Vertex aVL2 = aSae.LastVertex(theEdge2); - - if (aVL1.IsSame(aVF2) || aVL1.IsSame(aVL2)) { - theCommon = aVL1; - } else if (aVF1.IsSame(aVL2) || aVF1.IsSame(aVF2)) { - theCommon = aVF1; - } else { - theCommon.Nullify(); - isFound = Standard_False; - } - - return isFound; -} - -//======================================================================= -//function : IsToMerge -//purpose : This method return Standard_True if two consequent edges can -// be merged. The edges can be merged if: -// 1. They belong to same faces. -// 2. They either both seam or both not seam on each face. -// 3. There are no another edges (e.g. seam) on each common face -// that are connected to the common vertex of two edges. -// 4. They are based on coincident lines, or: -// 5. They are based on coincident circles, or: -// 6. They are based on either Bezier of BSplines. -//======================================================================= -static Standard_Boolean IsToMerge - (const TopoDS_Edge &theEdge1, - const TopoDS_Edge &theEdge2, - const TopTools_IndexedDataMapOfShapeListOfShape &theMapEdgeFaces, - const Standard_Real theTolerance) -{ - Standard_Boolean aResult = Standard_False; - Standard_Boolean isDegen1 = BRep_Tool::Degenerated(theEdge1); - Standard_Boolean isDegen2 = BRep_Tool::Degenerated(theEdge2); - - if (isDegen1 && isDegen2) { - // Both of edges are degenerated. - aResult = Standard_True; - } else if (!isDegen1 && !isDegen2) { - // Both of edges are not degenerated. - // Check if they belong to the same faces. - Standard_Boolean isSame = Standard_False; - Standard_Boolean has1 = theMapEdgeFaces.Contains(theEdge1); - Standard_Boolean has2 = theMapEdgeFaces.Contains(theEdge2); - - if (has1 && has2) { - const TopTools_ListOfShape &aLst1 = theMapEdgeFaces.FindFromKey(theEdge1); - const TopTools_ListOfShape &aLst2 = theMapEdgeFaces.FindFromKey(theEdge2); - - if (aLst1.Extent() == aLst2.Extent()) { - TopTools_ListIteratorOfListOfShape anIter1(aLst1); - - isSame = Standard_True; - - for (; anIter1.More() && isSame; anIter1.Next()) { - TopoDS_Face aFace1 = TopoDS::Face(anIter1.Value()); - TopTools_ListIteratorOfListOfShape anIter2(aLst2); - - for (; anIter2.More(); anIter2.Next()) { - if (aFace1.IsSame(anIter2.Value())) { - // Same face is detected. Break the loop. - // Check if edges either both seam or both not seam on this face. - Standard_Boolean isSeam1 = BRep_Tool::IsClosed(theEdge1, aFace1); - Standard_Boolean isSeam2 = BRep_Tool::IsClosed(theEdge2, aFace1); - - isSame = (isSeam1 && isSeam2) || (isSeam1 == isSeam2); - - if (isSame) { - // Check if there are no other edges (e.g. seam) on this face - // that are connected to the common vertex. - TopoDS_Vertex aVCommon; - - if (GetCommonVertex(theEdge1, theEdge2, aVCommon)) { - TopTools_IndexedDataMapOfShapeListOfShape aMapVE; - - TopExp::MapShapesAndAncestors - (aFace1, TopAbs_VERTEX, TopAbs_EDGE, aMapVE); - - if (aMapVE.Contains(aVCommon)) { - TopTools_ListIteratorOfListOfShape - anItE(aMapVE.FindFromKey(aVCommon)); - - for (; anItE.More(); anItE.Next()) { - const TopoDS_Shape &anEdge = anItE.Value(); - - if (!theEdge1.IsSame(anEdge) && - !theEdge2.IsSame(anEdge)) { - // There is another edge that shares the common vertex. - // Nothing to merge. - isSame = Standard_False; - break; - } - } - } else { - // Common vertex doesn't belong to the face. - // Nothing to merge. NEVERREACHED. - isSame = Standard_False; - } - } else { - // No common vertex. Nothing to merge. NEVERREACHED. - isSame = Standard_False; - } - } - - break; - } - } - - if (isSame && !anIter2.More()) { - // No same face is detected. Break the loop. - isSame = Standard_False; - break; - } - } - } - } else { - isSame = (has1 == has2); // True if the both of has are negative. - } - - if (isSame) { - // Check edges geometry. - Standard_Real aFP1; - Standard_Real aFP2; - Standard_Real aLP1; - Standard_Real aLP2; - Handle(Geom_Curve) aC3d1 = BRep_Tool::Curve(theEdge1, aFP1, aLP1); - Handle(Geom_Curve) aC3d2 = BRep_Tool::Curve(theEdge2, aFP2, aLP2); - - if (aC3d1.IsNull() == Standard_False && - aC3d2.IsNull() == Standard_False) { - // Get the basis curves. - while(aC3d1->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) { - Handle(Geom_TrimmedCurve) aTc = - Handle(Geom_TrimmedCurve)::DownCast(aC3d1); - aC3d1 = aTc->BasisCurve(); - } - - while(aC3d2->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) { - Handle(Geom_TrimmedCurve) aTc = - Handle(Geom_TrimmedCurve)::DownCast(aC3d2); - aC3d2 = aTc->BasisCurve(); - } - - if(aC3d1->IsKind(STANDARD_TYPE(Geom_Line)) && - aC3d2->IsKind(STANDARD_TYPE(Geom_Line))) { - // Two curves are lines. - Handle(Geom_Line) aL1 = Handle(Geom_Line)::DownCast(aC3d1); - Handle(Geom_Line) aL2 = Handle(Geom_Line)::DownCast(aC3d2); - gp_Dir aDir1 = aL1->Position().Direction(); - gp_Dir aDir2 = aL2->Position().Direction(); - - if(aDir1.IsParallel(aDir2, theTolerance)) { - // Two coincident lines. - aResult = Standard_True; - } - } else if(aC3d1->IsKind(STANDARD_TYPE(Geom_Circle)) && - aC3d2->IsKind(STANDARD_TYPE(Geom_Circle))) { - // Two curves are circles. - Handle(Geom_Circle) aC1 = Handle(Geom_Circle)::DownCast(aC3d1); - Handle(Geom_Circle) aC2 = Handle(Geom_Circle)::DownCast(aC3d2); - gp_Pnt aP01 = aC1->Location(); - gp_Pnt aP02 = aC2->Location(); - - if (aP01.Distance(aP02) <= Precision::Confusion()) { - // Two coincident circles. - aResult = Standard_True; - } - } else if (aC3d1->IsKind(STANDARD_TYPE(Geom_BSplineCurve)) || - aC3d1->IsKind(STANDARD_TYPE(Geom_BezierCurve))) { - if (aC3d2->IsKind(STANDARD_TYPE(Geom_BSplineCurve)) || - aC3d2->IsKind(STANDARD_TYPE(Geom_BezierCurve))) { - // Both of the curves are either bezier or BSplines. - aResult = Standard_True; - } - } - } - } - } - - return aResult; -} - -//======================================================================= -//function : BlockFix_UnionEdges() -//purpose : Constructor -//======================================================================= -BlockFix_UnionEdges::BlockFix_UnionEdges ( ) -{ -} - -//======================================================================= -//function : GlueEdgesWithPCurves -//purpose : Glues the pcurves of the sequence of edges -// and glues their 3d curves -//======================================================================= -static TopoDS_Edge GlueEdgesWithPCurves(const TopTools_SequenceOfShape& aChain, - const TopoDS_Vertex& FirstVertex, - const TopoDS_Vertex& LastVertex) -{ - Standard_Integer i, j; - - TopoDS_Edge FirstEdge = TopoDS::Edge(aChain(1)); - //TColGeom2d_SequenceOfCurve PCurveSeq; - TColGeom_SequenceOfSurface SurfSeq; - //TopTools_SequenceOfShape LocSeq; - - BRep_ListIteratorOfListOfCurveRepresentation itr( (Handle(BRep_TEdge)::DownCast(FirstEdge.TShape()))->Curves() ); - for (; itr.More(); itr.Next()) - { - Handle(BRep_CurveRepresentation) CurveRep = itr.Value(); - if (CurveRep->IsCurveOnSurface()) - { - //PCurveSeq.Append(CurveRep->PCurve()); - SurfSeq.Append(CurveRep->Surface()); - /* - TopoDS_Shape aLocShape; - aLocShape.Location(CurveRep->Location()); - LocSeq.Append(aLocShape); - */ - } - } - - Standard_Real fpar, lpar; - BRep_Tool::Range(FirstEdge, fpar, lpar); - TopoDS_Edge PrevEdge = FirstEdge; - TopoDS_Vertex CV; - Standard_Real MaxTol = 0.; - - TopoDS_Edge ResEdge; - BRep_Builder BB; - - Standard_Integer nb_curve = aChain.Length(); //number of curves - TColGeom_Array1OfBSplineCurve tab_c3d(0,nb_curve-1); //array of the curves - TColStd_Array1OfReal tabtolvertex(0,nb_curve-1); //(0,nb_curve-2); //array of the tolerances - - TopoDS_Vertex PrevVertex = FirstVertex; - for (i = 1; i <= nb_curve; i++) - { - TopoDS_Edge anEdge = TopoDS::Edge(aChain(i)); - TopoDS_Vertex VF, VL; - TopExp::Vertices(anEdge, VF, VL); - Standard_Boolean ToReverse = (!VF.IsSame(PrevVertex)); - - Standard_Real Tol1 = BRep_Tool::Tolerance(VF); - Standard_Real Tol2 = BRep_Tool::Tolerance(VL); - if (Tol1 > MaxTol) - MaxTol = Tol1; - if (Tol2 > MaxTol) - MaxTol = Tol2; - - if (i > 1) - { - GetCommonVertex(PrevEdge, anEdge, CV); - Standard_Real Tol = BRep_Tool::Tolerance(CV); - tabtolvertex(i-2) = Tol; - } - - Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, fpar, lpar); - Handle(Geom_TrimmedCurve) aTrCurve = new Geom_TrimmedCurve(aCurve, fpar, lpar); - tab_c3d(i-1) = GeomConvert::CurveToBSplineCurve(aTrCurve); - GeomConvert::C0BSplineToC1BSplineCurve(tab_c3d(i-1), Precision::Confusion()); - if (ToReverse) - tab_c3d(i-1)->Reverse(); - PrevVertex = (ToReverse)? VF : VL; - PrevEdge = anEdge; - } - Handle(TColGeom_HArray1OfBSplineCurve) concatcurve; //array of the concatenated curves - Handle(TColStd_HArray1OfInteger) ArrayOfIndices; //array of the remining Vertex - Standard_Boolean ClosedFlag = Standard_False; - GeomConvert::ConcatC1(tab_c3d, - tabtolvertex, - ArrayOfIndices, - concatcurve, - ClosedFlag, - Precision::Confusion()); //C1 concatenation - - if (concatcurve->Length() > 1) - { - GeomConvert_CompCurveToBSplineCurve Concat(concatcurve->Value(concatcurve->Lower())); - - for (i = concatcurve->Lower()+1; i <= concatcurve->Upper(); i++) - Concat.Add( concatcurve->Value(i), MaxTol, Standard_True ); - - concatcurve->SetValue(concatcurve->Lower(), Concat.BSplineCurve()); - } - Handle(Geom_BSplineCurve) ResCurve = concatcurve->Value(concatcurve->Lower()); - - TColGeom2d_SequenceOfBoundedCurve ResPCurves; - TopLoc_Location aLoc; - for (j = 1; j <= SurfSeq.Length(); j++) - { - TColGeom2d_Array1OfBSplineCurve tab_c2d(0,nb_curve-1); //array of the pcurves - - PrevVertex = FirstVertex; - PrevEdge = FirstEdge; - //TopLoc_Location theLoc = LocSeq(j).Location(); - for (i = 1; i <= nb_curve; i++) - { - TopoDS_Edge anEdge = TopoDS::Edge(aChain(i)); - TopoDS_Vertex VF, VL; - TopExp::Vertices(anEdge, VF, VL); - Standard_Boolean ToReverse = (!VF.IsSame(PrevVertex)); - - /* - Handle(Geom2d_Curve) aPCurve = - BRep_Tool::CurveOnSurface(anEdge, SurfSeq(j), anEdge.Location()*theLoc, fpar, lpar); - */ - Handle(Geom2d_Curve) aPCurve = - BRep_Tool::CurveOnSurface(anEdge, SurfSeq(j), aLoc, fpar, lpar); - Handle(Geom2d_TrimmedCurve) aTrPCurve = new Geom2d_TrimmedCurve(aPCurve, fpar, lpar); - tab_c2d(i-1) = Geom2dConvert::CurveToBSplineCurve(aTrPCurve); - Geom2dConvert::C0BSplineToC1BSplineCurve(tab_c2d(i-1), Precision::Confusion()); - if (ToReverse) - tab_c2d(i-1)->Reverse(); - PrevVertex = (ToReverse)? VF : VL; - PrevEdge = anEdge; - } - Handle(TColGeom2d_HArray1OfBSplineCurve) concatc2d; //array of the concatenated curves - Handle(TColStd_HArray1OfInteger) ArrayOfInd2d; //array of the remining Vertex - Standard_Boolean ClosedFlag = Standard_False; - Geom2dConvert::ConcatC1(tab_c2d, - tabtolvertex, - ArrayOfInd2d, - concatc2d, - ClosedFlag, - Precision::Confusion()); //C1 concatenation - - if (concatc2d->Length() > 1) - { - Geom2dConvert_CompCurveToBSplineCurve Concat2d(concatc2d->Value(concatc2d->Lower())); - - for (i = concatc2d->Lower()+1; i <= concatc2d->Upper(); i++) - Concat2d.Add( concatc2d->Value(i), MaxTol, Standard_True ); - - concatc2d->SetValue(concatc2d->Lower(), Concat2d.BSplineCurve()); - } - Handle(Geom2d_BSplineCurve) aResPCurve = concatc2d->Value(concatc2d->Lower()); - ResPCurves.Append(aResPCurve); - } - - ResEdge = BRepLib_MakeEdge(ResCurve, - FirstVertex, LastVertex, - ResCurve->FirstParameter(), ResCurve->LastParameter()); - BB.SameRange(ResEdge, Standard_False); - BB.SameParameter(ResEdge, Standard_False); - for (j = 1; j <= ResPCurves.Length(); j++) - { - BB.UpdateEdge(ResEdge, ResPCurves(j), SurfSeq(j), aLoc, MaxTol); - BB.Range(ResEdge, SurfSeq(j), aLoc, ResPCurves(j)->FirstParameter(), ResPCurves(j)->LastParameter()); - } - - BRepLib::SameParameter(ResEdge, MaxTol, Standard_True); - - return ResEdge; -} - -//======================================================================= -//function : MergeEdges -//purpose : auxiliary -//======================================================================= -static Standard_Boolean MergeEdges(const TopTools_SequenceOfShape& SeqEdges, - const Standard_Real Tol, - TopoDS_Edge& anEdge) -{ - // make chain for union - BRep_Builder B; - ShapeAnalysis_Edge sae; - TopoDS_Edge FirstE = TopoDS::Edge(SeqEdges.Value(1)); - TopoDS_Edge LastE = FirstE; - TopoDS_Vertex VF = sae.FirstVertex(FirstE); - TopoDS_Vertex VL = sae.LastVertex(LastE); - TopTools_SequenceOfShape aChain; - aChain.Append(FirstE); - TColStd_MapOfInteger IndUsedEdges; - IndUsedEdges.Add(1); - Standard_Integer j; - for(j=2; j<=SeqEdges.Length(); j++) { - for(Standard_Integer k=2; k<=SeqEdges.Length(); k++) { - if(IndUsedEdges.Contains(k)) continue; - TopoDS_Edge edge = TopoDS::Edge(SeqEdges.Value(k)); - TopoDS_Vertex VF2 = sae.FirstVertex(edge); - TopoDS_Vertex VL2 = sae.LastVertex(edge); - if(sae.FirstVertex(edge).IsSame(VL)) { - aChain.Append(edge); - LastE = edge; - VL = sae.LastVertex(LastE); - IndUsedEdges.Add(k); - } - else if(sae.LastVertex(edge).IsSame(VF)) { - aChain.Prepend(edge); - FirstE = edge; - VF = sae.FirstVertex(FirstE); - IndUsedEdges.Add(k); - } - } - } - if(aChain.Length()IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) { - Handle(Geom_TrimmedCurve) tc = - Handle(Geom_TrimmedCurve)::DownCast(c3d1); - c3d1 = tc->BasisCurve(); - } - TopoDS_Edge edge2 = TopoDS::Edge(aChain.Value(j+1)); - Handle(Geom_Curve) c3d2 = BRep_Tool::Curve(edge2,Loc,fp2,lp2); - if(c3d2.IsNull()) break; - while(c3d2->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) { - Handle(Geom_TrimmedCurve) tc = - Handle(Geom_TrimmedCurve)::DownCast(c3d2); - c3d2 = tc->BasisCurve(); - } - if( c3d1->IsKind(STANDARD_TYPE(Geom_Line)) && c3d2->IsKind(STANDARD_TYPE(Geom_Line)) ) { - // union lines - Handle(Geom_Line) L1 = Handle(Geom_Line)::DownCast(c3d1); - Handle(Geom_Line) L2 = Handle(Geom_Line)::DownCast(c3d2); - gp_Dir Dir1 = L1->Position().Direction(); - gp_Dir Dir2 = L2->Position().Direction(); - //if(!Dir1.IsEqual(Dir2,Precision::Angular())) { - //if(!Dir1.IsParallel(Dir2,Precision::Angular())) { - if(!Dir1.IsParallel(Dir2,Tol)) { - continue; - } - // can union lines => create new edge - TopoDS_Vertex V1 = sae.FirstVertex(edge1); - gp_Pnt PV1 = BRep_Tool::Pnt(V1); - TopoDS_Vertex V2 = sae.LastVertex(edge2); - gp_Pnt PV2 = BRep_Tool::Pnt(V2); - gp_Vec Vec(PV1,PV2); - Handle(Geom_Line) L = new Geom_Line(gp_Ax1(PV1,Vec)); - Standard_Real dist = PV1.Distance(PV2); - Handle(Geom_TrimmedCurve) tc = new Geom_TrimmedCurve(L,0.0,dist); - TopoDS_Edge E; - B.MakeEdge (E,tc,Precision::Confusion()); - B.Add (E,V1); B.Add (E,V2); - B.UpdateVertex(V1, 0., E, 0.); - B.UpdateVertex(V2, dist, E, 0.); - aChain.Remove(j); - aChain.SetValue(j,E); - j--; - } - if( c3d1->IsKind(STANDARD_TYPE(Geom_Circle)) && c3d2->IsKind(STANDARD_TYPE(Geom_Circle)) ) { - // union circles - Handle(Geom_Circle) C1 = Handle(Geom_Circle)::DownCast(c3d1); - Handle(Geom_Circle) C2 = Handle(Geom_Circle)::DownCast(c3d2); - gp_Pnt P01 = C1->Location(); - gp_Pnt P02 = C2->Location(); - if (P01.Distance(P02) > Precision::Confusion()) continue; - // can union circles => create new edge - TopoDS_Vertex V1 = sae.FirstVertex(edge1); - gp_Pnt PV1 = BRep_Tool::Pnt(V1); - TopoDS_Vertex V2 = sae.LastVertex(edge2); - gp_Pnt PV2 = BRep_Tool::Pnt(V2); - TopoDS_Vertex VM = sae.LastVertex(edge1); - gp_Pnt PVM = BRep_Tool::Pnt(VM); - GC_MakeCircle MC (PV1,PVM,PV2); - Handle(Geom_Circle) C; - TopoDS_Edge E; - - if (MC.IsDone()) { - C = MC.Value(); - } - - if (C.IsNull()) { - // jfa for Mantis issue 0020228 - if (PV1.Distance(PV2) > Precision::Confusion()) continue; - // closed chain. Make a closed circular edge starting from V1. - gp_Ax1 anAxis = C1->Axis(); - - if (edge1.Orientation() == TopAbs_REVERSED) { - anAxis.Reverse(); - } - - const gp_Pnt &aP0 = anAxis.Location(); - gp_Dir aDX(PV1.XYZ().Subtracted(aP0.XYZ())); - gp_Ax2 aNewAxis(aP0, anAxis.Direction(), aDX); - - C = new Geom_Circle(aNewAxis, C1->Radius()); - - B.MakeEdge (E,C,Precision::Confusion()); - B.Add(E,V1); - B.Add(E,V2); - B.UpdateVertex(V1, 0., E, 0.); - B.UpdateVertex(V2, 2.*M_PI, E, 0.); - } - else { - gp_Pnt P0 = C->Location(); - gp_Dir D1(gp_Vec(P0,PV1)); - gp_Dir D2(gp_Vec(P0,PV2)); - Standard_Real fpar = C->XAxis().Direction().Angle(D1); - if(fabs(fpar)>Precision::Confusion()) { - // check orientation - gp_Dir ND = C->XAxis().Direction().Crossed(D1); - if(ND.IsOpposite(C->Axis().Direction(),Precision::Confusion())) { - fpar = -fpar; - } - } - Standard_Real lpar = C->XAxis().Direction().Angle(D2); - if(fabs(lpar)>Precision::Confusion()) { - // check orientation - gp_Dir ND = C->XAxis().Direction().Crossed(D2); - if(ND.IsOpposite(C->Axis().Direction(),Precision::Confusion())) { - lpar = -lpar; - } - } - if (lpar < fpar) lpar += 2*M_PI; - Handle(Geom_TrimmedCurve) tc = new Geom_TrimmedCurve(C,fpar,lpar); - B.MakeEdge (E,tc,Precision::Confusion()); - B.Add(E,V1); - B.Add(E,V2); - B.UpdateVertex(V1, fpar, E, 0.); - B.UpdateVertex(V2, lpar, E, 0.); - } - aChain.Remove(j); - aChain.SetValue(j,E); - j--; - } - } - if (j < aChain.Length()) { - MESSAGE ("null curve3d in edge..."); - return Standard_False; - } - if (aChain.Length() > 1) { - // second step: union edges with various curves - // skl for bug 0020052 from Mantis: perform such unions - // only if curves are bspline or bezier - bool NeedUnion = true; - for(j=1; j<=aChain.Length(); j++) { - TopoDS_Edge edge = TopoDS::Edge(aChain.Value(j)); - Handle(Geom_Curve) c3d = BRep_Tool::Curve(edge,Loc,fp1,lp1); - if(c3d.IsNull()) continue; - while(c3d->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) { - Handle(Geom_TrimmedCurve) tc = - Handle(Geom_TrimmedCurve)::DownCast(c3d); - c3d = tc->BasisCurve(); - } - if( ( c3d->IsKind(STANDARD_TYPE(Geom_BSplineCurve)) || - c3d->IsKind(STANDARD_TYPE(Geom_BezierCurve)) ) ) continue; - NeedUnion = false; - break; - } - if(NeedUnion) { - MESSAGE ("can not make analytical union => make approximation"); - TopoDS_Edge E = GlueEdgesWithPCurves(aChain, VF, VL); - aChain.SetValue(1,E); - } - else { - MESSAGE ("can not make approximation for such types of curves"); - return Standard_False; - } - } - - anEdge = TopoDS::Edge(aChain.Value(1)); - return Standard_True; -} - -//======================================================================= -//function : Perform -//purpose : -//======================================================================= -TopoDS_Shape BlockFix_UnionEdges::Perform(const TopoDS_Shape& theShape, - const Standard_Real theTol) -{ - // Fill Map of edges as keys and list of faces as items. - TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces; - Standard_Boolean isModified = Standard_False; - - TopExp::MapShapesAndAncestors - (theShape, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces); - - // processing each face - Handle(ShapeBuild_ReShape) aContext = new ShapeBuild_ReShape; - TopTools_MapOfShape aProcessed; - TopTools_MapOfShape aModifiedFaces; - TopExp_Explorer anExpF(theShape, TopAbs_FACE); - - for (; anExpF.More(); anExpF.Next()) { - // Processing of each wire of the face - TopoDS_Face aFace = TopoDS::Face(anExpF.Current()); - - if (!aProcessed.Add(aFace)) { - continue; - } - - TopExp_Explorer anExpW(aFace, TopAbs_WIRE); - - for (; anExpW.More(); anExpW.Next()) { - // Get the ordered list of edges in the wire. - TopoDS_Wire aWire = TopoDS::Wire(anExpW.Current()); - BRepTools_WireExplorer aWExp(aWire, aFace); - TopTools_ListOfShape aChainEdges; - Standard_Integer aNbEdges = 0; - - for (; aWExp.More(); aWExp.Next(), aNbEdges++) { - aChainEdges.Append(aWExp.Current()); - } - - if (aNbEdges < 2) { - // Nothing to merge. - continue; - } - - // Fill the list of flags that neighbour edges can be merged. - TColStd_ListOfInteger aChainCanMerged; - TopoDS_Edge anEdge1 = TopoDS::Edge(aChainEdges.Last()); - TopoDS_Edge anEdge2; - Standard_Boolean isToMerge; - TopTools_ListIteratorOfListOfShape anIter(aChainEdges); - Standard_Boolean isFirstMerge = Standard_False; - Standard_Boolean isFirst = Standard_True; - Standard_Boolean isReorder = Standard_False; - - // The first element is the flag between last and first edges. - for (; anIter.More(); anIter.Next()) { - anEdge2 = TopoDS::Edge(anIter.Value()); - - if (aProcessed.Contains(anEdge1) || aProcessed.Contains(anEdge2)) { - // No need to merge already processed edges. - isToMerge = Standard_False; - } else { - isToMerge = IsToMerge(anEdge1, anEdge2, aMapEdgeFaces, theTol); - } - - aChainCanMerged.Append(isToMerge); - anEdge1 = anEdge2; - - if (isFirst) { - isFirstMerge = isToMerge; - isFirst = Standard_False; - } else if (isFirstMerge && !isToMerge) { - isReorder = Standard_True; - } - } - - // Fill the map of processed shape by the edges. - for (anIter.Initialize(aChainEdges); anIter.More(); anIter.Next()) { - aProcessed.Add(anIter.Value()); - } - - // Reorder edges in the chain. - if (isReorder) { - // Find the first edge that can't be merged. - while (aChainCanMerged.First()) { - TopoDS_Shape aTmpShape = aChainEdges.First(); - - isToMerge = aChainCanMerged.First(); - aChainCanMerged.RemoveFirst(); - aChainCanMerged.Append(isToMerge); - aChainEdges.RemoveFirst(); - aChainEdges.Append(aTmpShape); - } - } - - // Merge parts of chain to be merged. - TColStd_ListIteratorOfListOfInteger aFlagIter(aChainCanMerged); - anIter.Initialize(aChainEdges); - - while (anIter.More()) { - TopTools_SequenceOfShape aSeqEdges; - - aSeqEdges.Append(anIter.Value()); - aFlagIter.Next(); - anIter.Next(); - - for (; anIter.More(); anIter.Next(), aFlagIter.Next()) { - if (aFlagIter.Value()) { - // Continue the chain. - aSeqEdges.Append(anIter.Value()); - } else { - // Stop the chain. - break; - } - } - - const Standard_Integer aNbEdges = aSeqEdges.Length(); - - if (aNbEdges > 1) { - // There are several edges to be merged. - TopoDS_Edge aMergedEdge; - - if (MergeEdges(aSeqEdges, theTol, aMergedEdge)) { - isModified = Standard_True; - // now we have only one edge - aMergedEdge. - // we have to replace old ListEdges with this new edge - const TopoDS_Shape &anEdge = aSeqEdges.Value(1); - - aContext->Replace(anEdge, aMergedEdge); - - for (Standard_Integer j = 2; j <= aNbEdges; j++) { - aContext->Remove(aSeqEdges(j)); - } - - // Fix affected faces. - if (aMapEdgeFaces.Contains(anEdge)) { - const TopTools_ListOfShape &aList = - aMapEdgeFaces.FindFromKey(anEdge); - TopTools_ListIteratorOfListOfShape anIter(aList); - - for (; anIter.More(); anIter.Next()) { - aModifiedFaces.Add(anIter.Value()); - } - } - } - } - } - } - } - - if (isModified) { - // Fix modified faces. - TopTools_MapIteratorOfMapOfShape aModifIt(aModifiedFaces); - - for (; aModifIt.More(); aModifIt.Next()) { - TopoDS_Face aModifiedFace = - TopoDS::Face(aContext->Apply(aModifIt.Key())); - Handle(ShapeFix_Face) aSff = new ShapeFix_Face(aModifiedFace); - - aSff->SetContext(aContext); - aSff->SetPrecision(theTol); - aSff->SetMinTolerance(theTol); - aSff->SetMaxTolerance(Max(1., theTol*1000.)); - aSff->Perform(); - aContext->Replace(aModifiedFace, aSff->Face()); - } - - // Check if the result shape contains shells. - // If yes, fix the faces orientation in the shell. - TopoDS_Shape aModifShape = aContext->Apply(theShape); - TopExp_Explorer anExpSh(aModifShape, TopAbs_SHELL); - - for (; anExpSh.More(); anExpSh.Next()) { - TopoDS_Shell aShell = TopoDS::Shell(anExpSh.Current()); - Handle(ShapeFix_Shell) aSfsh = new ShapeFix_Shell; - - aSfsh->FixFaceOrientation(aShell); - aContext->Replace(aShell, aSfsh->Shell()); - } - } - - const TopoDS_Shape aResult = aContext->Apply(theShape); - - return aResult; -} diff --git a/src/BlockFix/BlockFix_UnionEdges.hxx b/src/BlockFix/BlockFix_UnionEdges.hxx deleted file mode 100644 index 43acf5da8..000000000 --- a/src/BlockFix/BlockFix_UnionEdges.hxx +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (C) 2007-2021 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 library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#ifndef _BlockFix_UnionEdges_HeaderFile -#define _BlockFix_UnionEdges_HeaderFile - -#include - -#include - -#include -#include - -class TopoDS_Shape; - -class BlockFix_UnionEdges { - -public: - Standard_EXPORT BlockFix_UnionEdges(); - - Standard_EXPORT TopoDS_Shape Perform (const TopoDS_Shape& Shape,const Standard_Real Tol); - -private: - Standard_Real myTolerance; - Handle(ShapeBuild_ReShape) myContext; - -}; - -#endif diff --git a/src/BlockFix/BlockFix_UnionFaces.cxx b/src/BlockFix/BlockFix_UnionFaces.cxx deleted file mode 100644 index caa78198c..000000000 --- a/src/BlockFix/BlockFix_UnionFaces.cxx +++ /dev/null @@ -1,990 +0,0 @@ -// Copyright (C) 2007-2021 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 library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -// File: BlockFix_UnionFaces.cxx -// Created: Tue Dec 7 17:15:42 2004 -// Author: Pavel DURANDIN - -#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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -#include -#include - -#include -#include // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC - -//======================================================================= -//function : BlockFix_UnionFaces -//purpose : -//======================================================================= -BlockFix_UnionFaces::BlockFix_UnionFaces() - : myTolerance(Precision::Confusion()), - myOptimumNbFaces(6) -{ -} - -//======================================================================= -//function : GetTolerance -//purpose : -//======================================================================= -Standard_Real& BlockFix_UnionFaces::GetTolerance() -{ - return myTolerance; -} - -//======================================================================= -//function : GetOptimumNbFaces -//purpose : -//======================================================================= -Standard_Integer& BlockFix_UnionFaces::GetOptimumNbFaces() -{ - return myOptimumNbFaces; -} - -//======================================================================= -//function : AddOrdinaryEdges -//purpose : auxiliary -// adds edges from the shape to the sequence -// seams and equal edges are dropped -// Returns true if one of original edges dropped -//======================================================================= -static Standard_Boolean AddOrdinaryEdges(TopTools_SequenceOfShape& edges, - const TopoDS_Shape aShape, - Standard_Integer& anIndex) -{ - //map of edges - TopTools_MapOfShape aNewEdges; - TopExp_Explorer exp(aShape,TopAbs_EDGE); - //add edges without seams - for(; exp.More(); exp.Next()) { - TopoDS_Shape edge = exp.Current(); - if(aNewEdges.Contains(edge)) - aNewEdges.Remove(edge); - else - aNewEdges.Add(edge); - } - - Standard_Boolean isDropped = Standard_False; - //merge edges and drop seams - for(Standard_Integer i = 1; i <= edges.Length(); i++) { - TopoDS_Shape current = edges(i); - if(aNewEdges.Contains(current)) { - - aNewEdges.Remove(current); - edges.Remove(i); - i--; - - if(!isDropped) { - isDropped = Standard_True; - anIndex = i; - } - } - } - - //add edges to the sequence - for(exp.ReInit(); exp.More(); exp.Next()) { - const TopoDS_Shape &anEdge = exp.Current(); - - if (aNewEdges.Contains(anEdge)) { - edges.Append(anEdge); - } - } - - return isDropped; -} - -//======================================================================= -//function : ClearRts -//purpose : auxiliary -//======================================================================= -static Handle(Geom_Surface) ClearRts(const Handle(Geom_Surface)& aSurface) -{ - if(aSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) { - Handle(Geom_RectangularTrimmedSurface) rts = - Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface); - return rts->BasisSurface(); - } - return aSurface; -} - -//======================================================================= -//function : IsFacesOfSameSolids -//purpose : auxiliary -//======================================================================= -static Standard_Boolean IsFacesOfSameSolids - (const TopoDS_Face &theFace1, - const TopoDS_Face &theFace2, - const TopTools_IndexedDataMapOfShapeListOfShape &theMapFaceSolids) -{ - Standard_Boolean isSame = Standard_False; - - if (theMapFaceSolids.Contains(theFace1) && - theMapFaceSolids.Contains(theFace2)) { - const TopTools_ListOfShape& aList1 = theMapFaceSolids.FindFromKey(theFace1); - const TopTools_ListOfShape& aList2 = theMapFaceSolids.FindFromKey(theFace2); - - if (aList1.Extent() == aList2.Extent()) { - TopTools_ListIteratorOfListOfShape anIter1(aList1); - - isSame = Standard_True; - - for (; anIter1.More(); anIter1.Next()) { - const TopoDS_Shape &aSolid1 = anIter1.Value(); - TopTools_ListIteratorOfListOfShape anIter2(aList2); - - for (; anIter2.More(); anIter2.Next()) { - if (aSolid1.IsSame(anIter2.Value())) { - // Same solid is detected. Break the loop - break; - } - } - - if (!anIter2.More()) { - // No same solid is detected. Break the loop. - isSame = Standard_False; - break; - } - } - } - } - - return isSame; -} - -//======================================================================= -//function : DefineMaxTolerance -//purpose : calculates maximum possible tolerance on edges of shape -//======================================================================= -static Standard_Real DefineMaxTolerance(const TopoDS_Shape& theShape) -{ - Standard_Real aTol = Precision::Confusion(); - - Standard_Real MinSize = RealLast(); - TopExp_Explorer Explo(theShape, TopAbs_EDGE); - for (; Explo.More(); Explo.Next()) - { - const TopoDS_Edge& anEdge = TopoDS::Edge(Explo.Current()); - Bnd_Box aBox; - BRepBndLib::Add(anEdge, aBox); - Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax; - aBox.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax); - Standard_Real MaxSize = Max(Xmax - Xmin, Max(Ymax - Ymin, Zmax - Zmin)); - if (MaxSize < MinSize) - MinSize = MaxSize; - } - - if (!Precision::IsInfinite(MinSize)) - aTol = 0.1 * MinSize; - - return aTol; -} - -//======================================================================= -//function : IsTangentFaces -//purpose : decides: is edge on closed surface tangent or not -//======================================================================= -static Standard_Boolean IsTangentFaces(const TopoDS_Edge& theEdge, - const TopoDS_Face& theFace) -{ - Standard_Real TolC0 = Max(0.001, 1.5*BRep_Tool::Tolerance(theEdge)); - - Standard_Real aFirst; - Standard_Real aLast; - -// Obtaining of pcurves of edge on two faces. - const Handle(Geom2d_Curve) aC2d1 = BRep_Tool::CurveOnSurface - (theEdge, theFace, aFirst, aLast); - TopoDS_Edge ReversedEdge = theEdge; - ReversedEdge.Reverse(); - const Handle(Geom2d_Curve) aC2d2 = BRep_Tool::CurveOnSurface - (ReversedEdge, theFace, aFirst, aLast); - if (aC2d1.IsNull() || aC2d2.IsNull()) - return Standard_False; - -// Obtaining of two surfaces from adjacent faces. - Handle(Geom_Surface) aSurf = BRep_Tool::Surface(theFace); - - if (aSurf.IsNull()) - return Standard_False; - -// Computation of the number of samples on the edge. - BRepAdaptor_Surface aBAS(theFace); - Handle(BRepAdaptor_HSurface) aBAHS = new BRepAdaptor_HSurface(aBAS); - Handle(BRepTopAdaptor_TopolTool) aTool = new BRepTopAdaptor_TopolTool(aBAHS); - Standard_Integer aNbSamples = aTool->NbSamples(); - const Standard_Integer aNbSamplesMax = 23; - aNbSamples = Min(aNbSamplesMax, aNbSamples); - const Standard_Real aTolAngle = M_PI/18; - - -// Computation of the continuity. - Standard_Real aPar; - Standard_Real aDelta = (aLast - aFirst)/(aNbSamples - 1); - Standard_Integer i, nbNotDone = 0; - - for (i = 1, aPar = aFirst; i <= aNbSamples; i++, aPar += aDelta) { - if (i == aNbSamples) aPar = aLast; - - LocalAnalysis_SurfaceContinuity aCont(aC2d1, aC2d2, aPar, - aSurf, aSurf, GeomAbs_G1, - 0.001, TolC0, aTolAngle, 0.1, 0.1); - if (!aCont.IsDone()) - { - nbNotDone++; - continue; - } - - if (!aCont.IsG1()) - return Standard_False; - } - - if (nbNotDone == aNbSamples) - return Standard_False; - - return Standard_True; -} - -//======================================================================= -//function : HasSeamEdge -//purpose : Detects if a face contains a seam edge -//======================================================================= -static Standard_Boolean HasSeamEdge(const TopoDS_Face& theFace) -{ - TopExp_Explorer Explo(theFace, TopAbs_EDGE); - for (; Explo.More(); Explo.Next()) - { - const TopoDS_Edge& anEdge = TopoDS::Edge(Explo.Current()); - if (BRepTools::IsReallyClosed(anEdge, theFace)) - return Standard_True; - } - - return Standard_False; -} - - -//======================================================================= -//function : IsEdgeValidToMerge -//purpose : Edge is valid if it is not seam or if it is a seam and the face -// has another seam edge. -//======================================================================= -static Standard_Boolean IsEdgeValidToMerge(const TopoDS_Edge& theEdge, - const TopoDS_Face& theFace, - const Handle(Geom_Surface)& theSurface, - Standard_Boolean& theIsEdgeOnSeam, - Standard_Boolean& theToMakeUPeriodic, - Standard_Boolean& theToMakeVPeriodic) -{ - Standard_Boolean isValid = Standard_True; - - theIsEdgeOnSeam |= BRep_Tool::IsClosed(theEdge, theFace); - - if (BRepTools::IsReallyClosed(theEdge, theFace)) { - // Mantis issue 0023451, now code corresponds to the comment to this method - isValid = Standard_False; - - // This is a seam edge. Check if there are another seam edges on the face. - TopExp_Explorer anExp(theFace, TopAbs_EDGE); - - for (; anExp.More(); anExp.Next()) { - const TopoDS_Shape &aShEdge = anExp.Current(); - - // Skip same edge. - if (theEdge.IsSame(aShEdge)) { - continue; - } - - // Check if this edge is a seam. - TopoDS_Edge anEdge = TopoDS::Edge(aShEdge); - - if (BRep_Tool::IsClosed(anEdge, theFace)) { - // Mantis issue 0023451, now code corresponds to the comment to this method - //isValid = Standard_False; - isValid = Standard_True; - break; - } - } - } - else if (theIsEdgeOnSeam) - { - Standard_Real fpar, lpar; - Handle(Geom2d_Curve) aPCurve = BRep_Tool::CurveOnSurface(theEdge, theFace, fpar, lpar); - gp_Pnt2d P2d1 = aPCurve->Value(fpar); - gp_Pnt2d P2d2 = aPCurve->Value(lpar); - if (!theSurface->IsUPeriodic() && - theSurface->IsUClosed() && - Abs(P2d1.X() - P2d2.X()) < Abs(P2d1.Y() - P2d2.Y())) - { - if (IsTangentFaces(theEdge, theFace)) - theToMakeUPeriodic = Standard_True; - else - isValid = Standard_False; - } - if (!theSurface->IsVPeriodic() && - theSurface->IsVClosed() && - Abs(P2d1.Y() - P2d2.Y()) < Abs(P2d1.X() - P2d2.X())) - { - if (IsTangentFaces(theEdge, theFace)) - theToMakeVPeriodic = Standard_True; - else - isValid = Standard_False; - } - } - - return isValid; -} - -//======================================================================= -//function : Perform -//purpose : -//======================================================================= -TopoDS_Shape BlockFix_UnionFaces::Perform(const TopoDS_Shape& Shape) -{ - // Fill Map of faces as keys and list of solids or shells as items. - TopTools_IndexedDataMapOfShapeListOfShape aMapFaceSoOrSh; - - TopAbs_ShapeEnum aType = Shape.ShapeType(); - - if (aType != TopAbs_SHELL) { - aType = TopAbs_SOLID; - } - - TopExp::MapShapesAndAncestors - (Shape, TopAbs_FACE, aType, aMapFaceSoOrSh); - - // processing each solid - Handle(ShapeBuild_ReShape) aContext = new ShapeBuild_ReShape; - TopTools_MapOfShape aProcessed; - TopExp_Explorer exps; - for (exps.Init(Shape, aType); exps.More(); exps.Next()) { - TopoDS_Shape aSoOrSh = exps.Current(); - - // creating map of edge faces - TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces; - TopExp::MapShapesAndAncestors(aSoOrSh, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces); - - Standard_Integer NbModif = 0; - Standard_Boolean hasFailed = Standard_False; - Standard_Real tol = Min(Max(Precision::Confusion(), myTolerance/10.), 0.1); - - // count faces - int nbf = 0; - TopExp_Explorer exp; - TopTools_MapOfShape mapF; - for (exp.Init(aSoOrSh, TopAbs_FACE); exp.More(); exp.Next()) { - if (mapF.Add(exp.Current())) - nbf++; - } - - bool doUnion = ((myOptimumNbFaces == 0) || - ((myOptimumNbFaces > 0) && (nbf > myOptimumNbFaces))); - - // processing each face - mapF.Clear(); - for (exp.Init(aSoOrSh, TopAbs_FACE); exp.More() && doUnion; exp.Next()) { - TopoDS_Face aFace = TopoDS::Face(exp.Current().Oriented(TopAbs_FORWARD)); - - if (aProcessed.Contains(aFace)) { - continue; - } - - Standard_Integer dummy; - TopTools_SequenceOfShape edges; - AddOrdinaryEdges(edges,aFace,dummy); - - TopTools_SequenceOfShape faces; - faces.Append(aFace); - - //surface and location to construct result - TopLoc_Location aBaseLocation; - Handle(Geom_Surface) aBaseSurface = BRep_Tool::Surface(aFace,aBaseLocation); - aBaseSurface = ClearRts(aBaseSurface); - aBaseSurface = Handle(Geom_Surface)::DownCast(aBaseSurface->Copy()); - Standard_Boolean ToMakeUPeriodic = Standard_False, ToMakeVPeriodic = Standard_False; - - // find adjacent faces to union - Standard_Integer i; - for (i = 1; i <= edges.Length(); i++) { - TopoDS_Edge edge = TopoDS::Edge(edges(i)); - Standard_Boolean IsEdgeOnSeam = Standard_False; - if (BRep_Tool::Degenerated(edge) || - !IsEdgeValidToMerge(edge, aFace, aBaseSurface, - IsEdgeOnSeam, ToMakeUPeriodic, ToMakeVPeriodic)) - continue; - - const TopTools_ListOfShape& aList = aMapEdgeFaces.FindFromKey(edge); - TopTools_ListIteratorOfListOfShape anIter(aList); - for (; anIter.More(); anIter.Next()) { - TopoDS_Face anCheckedFace = TopoDS::Face(anIter.Value().Oriented(TopAbs_FORWARD)); - if (anCheckedFace.IsSame(aFace)) - continue; - - if (aProcessed.Contains(anCheckedFace)) - continue; - - if (!IsEdgeValidToMerge(edge, anCheckedFace, aBaseSurface, - IsEdgeOnSeam, ToMakeUPeriodic, ToMakeVPeriodic)) { - // Skip seam edge. - continue; - } - - // Check if faces belong to same solids. - if (!IsFacesOfSameSolids(aFace, anCheckedFace, aMapFaceSoOrSh)) { - continue; - } - - if (IsSameDomain(aFace,anCheckedFace)) { - - if (aList.Extent() != 2) { - // non mainfold case is not processed - continue; - } - - //Prevent creating a face with parametric range more than period - if (IsEdgeOnSeam && - (HasSeamEdge(aFace) || HasSeamEdge(anCheckedFace))) - continue; - - // replacing pcurves - TopoDS_Face aMockUpFace; - BRep_Builder B; - B.MakeFace(aMockUpFace,aBaseSurface,aBaseLocation,0.); - MovePCurves(aMockUpFace,anCheckedFace); - - if (AddOrdinaryEdges(edges,aMockUpFace,dummy)) { - // sequence edges is modified - i = dummy; - } - - faces.Append(anCheckedFace); - aProcessed.Add(anCheckedFace); - break; - } - } - } - - // all faces collected in the sequence. Perform union of faces - if (faces.Length() > 1) { - NbModif++; - TopoDS_Face aResult; - BRep_Builder B; - if (ToMakeUPeriodic || ToMakeVPeriodic) - { - Handle(Geom_BSplineSurface) aBSplineSurface = Handle(Geom_BSplineSurface)::DownCast(aBaseSurface); - if (aBSplineSurface.IsNull()) - { - Standard_Real aTol = 1.e-4; - GeomAbs_Shape aUCont = GeomAbs_C1, aVCont = GeomAbs_C1; - Standard_Integer degU = 14, degV = 14; - Standard_Integer nmax = 16; - Standard_Integer aPrec = 1; - GeomConvert_ApproxSurface Approximator(aBaseSurface,aTol,aUCont,aVCont,degU,degV,nmax,aPrec); - aBSplineSurface = Approximator.Surface(); - } - - if (ToMakeUPeriodic) - aBSplineSurface->SetUPeriodic(); - if (ToMakeVPeriodic) - aBSplineSurface->SetVPeriodic(); - - aBaseSurface = aBSplineSurface; - } - B.MakeFace(aResult,aBaseSurface,aBaseLocation,0); - Standard_Integer nbWires = 0; - - // connecting wires - while (edges.Length()>0) { - - Standard_Boolean isEdge3d = Standard_False; - nbWires++; - TopTools_MapOfShape aVertices; - TopoDS_Wire aWire; - B.MakeWire(aWire); - - TopoDS_Edge anEdge = TopoDS::Edge(edges(1)); - edges.Remove(1); - - isEdge3d |= !BRep_Tool::Degenerated(anEdge); - B.Add(aWire,anEdge); - TopoDS_Vertex V1,V2; - TopExp::Vertices(anEdge,V1,V2); - aVertices.Add(V1); - aVertices.Add(V2); - - Standard_Boolean isNewFound = Standard_False; - do { - isNewFound = Standard_False; - for(Standard_Integer j = 1; j <= edges.Length(); j++) { - anEdge = TopoDS::Edge(edges(j)); - TopExp::Vertices(anEdge,V1,V2); - if(aVertices.Contains(V1) || aVertices.Contains(V2)) { - isEdge3d |= !BRep_Tool::Degenerated(anEdge); - aVertices.Add(V1); - aVertices.Add(V2); - B.Add(aWire,anEdge); - edges.Remove(j); - j--; - isNewFound = Standard_True; - } - } - } while (isNewFound); - - // sorting any type of edges - aWire = TopoDS::Wire(aContext->Apply(aWire)); - - Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire(aWire,aResult,Precision::Confusion()); - sfw->FixReorder(); - Standard_Boolean isDegRemoved = Standard_False; - if(!sfw->StatusReorder ( ShapeExtend_FAIL )) { - // clear degenerated edges if at least one with 3d curve exist - if(isEdge3d) { - Handle(ShapeExtend_WireData) sewd = sfw->WireData(); - for(Standard_Integer j = 1; j<=sewd->NbEdges();j++) { - TopoDS_Edge E = sewd->Edge(j); - if(BRep_Tool::Degenerated(E)) { - sewd->Remove(j); - isDegRemoved = Standard_True; - j--; - } - } - } - sfw->FixShifted(); - if(isDegRemoved) - sfw->FixDegenerated(); - } - TopoDS_Wire aWireFixed = sfw->Wire(); - aContext->Replace(aWire,aWireFixed); - // add resulting wire - if (isEdge3d) { - B.Add(aResult,aWireFixed); - } - else { - // sorting edges - Handle(ShapeExtend_WireData) sbwd = sfw->WireData(); - Standard_Integer nbEdges = sbwd->NbEdges(); - // sort degenerated edges and create one edge instead of several ones - ShapeAnalysis_WireOrder sawo(Standard_False, 0); - ShapeAnalysis_Edge sae; - Standard_Integer aLastEdge = nbEdges; - for (Standard_Integer j = 1; j <= nbEdges; j++) { - Standard_Real f,l; - //smh protection on NULL pcurve - Handle(Geom2d_Curve) c2d; - if (!sae.PCurve(sbwd->Edge(j),aResult,c2d,f,l)) { - aLastEdge--; - continue; - } - sawo.Add(c2d->Value(f).XY(),c2d->Value(l).XY()); - } - if (aLastEdge > 0) { - sawo.Perform(); - - // constructing one degenerative edge - gp_XY aStart, anEnd, tmp; - Standard_Integer nbFirst = sawo.Ordered(1); - TopoDS_Edge anOrigE = TopoDS::Edge(sbwd->Edge(nbFirst).Oriented(TopAbs_FORWARD)); - ShapeBuild_Edge sbe; - TopoDS_Vertex aDummyV; - TopoDS_Edge E = sbe.CopyReplaceVertices(anOrigE,aDummyV,aDummyV); - sawo.XY(nbFirst,aStart,tmp); - sawo.XY(sawo.Ordered(aLastEdge),tmp,anEnd); - - gp_XY aVec = anEnd-aStart; - Handle(Geom2d_Line) aLine = new Geom2d_Line(aStart,gp_Dir2d(anEnd-aStart)); - - B.UpdateEdge(E,aLine,aResult,0.); - B.Range(E,aResult,0.,aVec.Modulus()); - Handle(Geom_Curve) C3d; - B.UpdateEdge(E,C3d,0.); - B.Degenerated(E,Standard_True); - TopoDS_Wire aW; - B.MakeWire(aW); - B.Add(aW,E); - B.Add(aResult,aW); - } - } - } - - // perform substitution of face - aContext->Replace(aContext->Apply(aFace),aResult); - - ShapeFix_Face sff (aResult); - //Initializing by tolerances - sff.SetPrecision(myTolerance); - sff.SetMinTolerance(tol); - Standard_Real MaxTol = DefineMaxTolerance(aResult); - sff.SetMaxTolerance(MaxTol); - //Setting modes - sff.FixOrientationMode() = 0; - //sff.FixWireMode() = 0; - sff.SetContext(aContext); - // Applying the fixes - sff.Perform(); - if(sff.Status(ShapeExtend_FAIL)) - hasFailed = Standard_True; - - // breaking down to several faces - TopoDS_Shape theResult = aContext->Apply(aResult); - for (TopExp_Explorer aFaceExp (theResult,TopAbs_FACE); aFaceExp.More(); aFaceExp.Next()) { - TopoDS_Face aCurrent = TopoDS::Face(aFaceExp.Current().Oriented(TopAbs_FORWARD)); - Handle(TColGeom_HArray2OfSurface) grid = new TColGeom_HArray2OfSurface ( 1, 1, 1, 1 ); - grid->SetValue ( 1, 1, aBaseSurface ); - Handle(ShapeExtend_CompositeSurface) G = new ShapeExtend_CompositeSurface ( grid ); - ShapeFix_ComposeShell CompShell; - CompShell.Init ( G, aBaseLocation, aCurrent, ::Precision::Confusion() );//myPrecision - CompShell.SetContext( aContext ); - - TopTools_SequenceOfShape parts; - ShapeFix_SequenceOfWireSegment wires; - for(TopExp_Explorer W_Exp(aCurrent,TopAbs_WIRE);W_Exp.More();W_Exp.Next()) { - Handle(ShapeExtend_WireData) sbwd = - new ShapeExtend_WireData ( TopoDS::Wire(W_Exp.Current() )); - ShapeFix_WireSegment seg ( sbwd, TopAbs_REVERSED ); - wires.Append(seg); - } - - CompShell.DispatchWires ( parts,wires ); - for (Standard_Integer j=1; j <= parts.Length(); j++ ) { - ShapeFix_Face aFixOrient(TopoDS::Face(parts(j))); - aFixOrient.SetContext(aContext); - aFixOrient.FixOrientation(); - } - - TopoDS_Shape CompRes; - if ( faces.Length() !=1 ) { - TopoDS_Shell S; - B.MakeShell ( S ); - for ( i=1; i <= parts.Length(); i++ ) - B.Add ( S, parts(i) ); - CompRes = S; - } - else CompRes = parts(1); - - aContext->Replace(aCurrent,CompRes); - } - - // remove the remaining faces - for(i = 2; i <= faces.Length(); i++) - aContext->Remove(faces(i)); - } - } // end processing each face - - //TopoDS_Shape aResult = Shape; - if (NbModif > 0 && !hasFailed) { - TopoDS_Shape aResult = aContext->Apply(aSoOrSh); - - ShapeFix_Edge sfe; - for (exp.Init(aResult,TopAbs_EDGE); exp.More(); exp.Next()) { - TopoDS_Edge E = TopoDS::Edge(exp.Current()); - sfe.FixVertexTolerance (E); - // ptv add fix same parameter - sfe.FixSameParameter(E, myTolerance); - } - } - - for (exp.Init(aSoOrSh, TopAbs_FACE); exp.More(); exp.Next()) { - TopoDS_Face aFace = TopoDS::Face(exp.Current().Oriented(TopAbs_FORWARD)); - Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire; - sfw->SetContext(aContext); - sfw->SetPrecision(myTolerance); - sfw->SetMinTolerance(myTolerance); - sfw->SetMaxTolerance(Max(1.,myTolerance*1000.)); - sfw->SetFace(aFace); - for (TopoDS_Iterator iter (aFace,Standard_False); iter.More(); iter.Next()) { - TopoDS_Shape aFaceCont = iter.Value(); - if (!aFaceCont.IsNull() && aFaceCont.ShapeType() == TopAbs_WIRE) { - TopoDS_Wire wire = TopoDS::Wire(iter.Value()); - sfw->Load(wire); - sfw->FixReorder(); - sfw->FixShifted(); - } - } - } - } // end processing each solid - - const TopoDS_Shape aResShape = aContext->Apply(Shape); - - return aResShape; -} - -//======================================================================= -//function : IsSameDomain -//purpose : -//======================================================================= -bool getCylinder (Handle(Geom_Surface)& theInSurface, gp_Cylinder& theOutCylinder) -{ - bool isCylinder = false; - - if (theInSurface->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) { - Handle(Geom_CylindricalSurface) aGC = Handle(Geom_CylindricalSurface)::DownCast(theInSurface); - - theOutCylinder = aGC->Cylinder(); - isCylinder = true; - } - else if (theInSurface->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution))) { - Handle(Geom_SurfaceOfRevolution) aRS = - Handle(Geom_SurfaceOfRevolution)::DownCast(theInSurface); - Handle(Geom_Curve) aBasis = aRS->BasisCurve(); - if (aBasis->IsKind(STANDARD_TYPE(Geom_Line))) { - Handle(Geom_Line) aBasisLine = Handle(Geom_Line)::DownCast(aBasis); - gp_Dir aDir = aRS->Direction(); - gp_Dir aBasisDir = aBasisLine->Position().Direction(); - if (aBasisDir.IsParallel(aDir, Precision::Confusion())) { - // basis line is parallel to the revolution axis: it is a cylinder - gp_Pnt aLoc = aRS->Location(); - Standard_Real aR = aBasisLine->Lin().Distance(aLoc); - gp_Ax3 aCylAx (aLoc, aDir); - - theOutCylinder = gp_Cylinder(aCylAx, aR); - isCylinder = true; - } - } - } - else if (theInSurface->IsKind(STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion))) { - Handle(Geom_SurfaceOfLinearExtrusion) aLES = - Handle(Geom_SurfaceOfLinearExtrusion)::DownCast(theInSurface); - Handle(Geom_Curve) aBasis = aLES->BasisCurve(); - if (aBasis->IsKind(STANDARD_TYPE(Geom_Circle))) { - Handle(Geom_Circle) aBasisCircle = Handle(Geom_Circle)::DownCast(aBasis); - gp_Dir aDir = aLES->Direction(); - gp_Dir aBasisDir = aBasisCircle->Position().Direction(); - if (aBasisDir.IsParallel(aDir, Precision::Confusion())) { - // basis circle is normal to the extrusion axis: it is a cylinder - gp_Pnt aLoc = aBasisCircle->Location(); - Standard_Real aR = aBasisCircle->Radius(); - gp_Ax3 aCylAx (aLoc, aDir); - - theOutCylinder = gp_Cylinder(aCylAx, aR); - isCylinder = true; - } - } - } - else { - } - - return isCylinder; -} - -Standard_Boolean BlockFix_UnionFaces::IsSameDomain(const TopoDS_Face& aFace, - const TopoDS_Face& aCheckedFace) const -{ - //checking the same handles - TopLoc_Location L1, L2; - Handle(Geom_Surface) S1, S2; - - S1 = BRep_Tool::Surface(aFace,L1); - S2 = BRep_Tool::Surface(aCheckedFace,L2); - - if (S1 == S2 && L1 == L2) - return true; - - // planar and cylindrical cases (IMP 20052) - Standard_Real aPrec = Precision::Confusion(); - - S1 = BRep_Tool::Surface(aFace); - S2 = BRep_Tool::Surface(aCheckedFace); - - S1 = ClearRts(S1); - S2 = ClearRts(S2); - - //Handle(Geom_OffsetSurface) aGOFS1, aGOFS2; - //aGOFS1 = Handle(Geom_OffsetSurface)::DownCast(S1); - //aGOFS2 = Handle(Geom_OffsetSurface)::DownCast(S2); - //if (!aGOFS1.IsNull()) S1 = aGOFS1->BasisSurface(); - //if (!aGOFS2.IsNull()) S2 = aGOFS2->BasisSurface(); - - // case of two elementary surfaces: use OCCT tool - // elementary surfaces: ConicalSurface, CylindricalSurface, - // Plane, SphericalSurface and ToroidalSurface - if (S1->IsKind(STANDARD_TYPE(Geom_ElementarySurface)) && - S2->IsKind(STANDARD_TYPE(Geom_ElementarySurface))) - { - Handle(GeomAdaptor_HSurface) aGA1 = new GeomAdaptor_HSurface(S1); - Handle(GeomAdaptor_HSurface) aGA2 = new GeomAdaptor_HSurface(S2); - - Handle(BRepTopAdaptor_TopolTool) aTT1 = new BRepTopAdaptor_TopolTool(); - Handle(BRepTopAdaptor_TopolTool) aTT2 = new BRepTopAdaptor_TopolTool(); - - try { - OCC_CATCH_SIGNALS; - - IntPatch_ImpImpIntersection anIIInt (aGA1, aTT1, aGA2, aTT2, aPrec, aPrec); - - if (!anIIInt.IsDone() || anIIInt.IsEmpty()) - return false; - - return anIIInt.TangentFaces(); - } - catch (Standard_Failure&) { - return false; - } - } - - // case of two planar surfaces: - // all kinds of surfaces checked, including b-spline and bezier - GeomLib_IsPlanarSurface aPlanarityChecker1 (S1, aPrec); - if (aPlanarityChecker1.IsPlanar()) { - GeomLib_IsPlanarSurface aPlanarityChecker2 (S2, aPrec); - if (aPlanarityChecker2.IsPlanar()) { - gp_Pln aPln1 = aPlanarityChecker1.Plan(); - gp_Pln aPln2 = aPlanarityChecker2.Plan(); - - if (aPln1.Position().Direction().IsParallel(aPln2.Position().Direction(), aPrec) && - aPln1.Distance(aPln2) < aPrec) { - return true; - } - } - } - - // case of two cylindrical surfaces, at least one of which is a swept surface - // swept surfaces: SurfaceOfLinearExtrusion, SurfaceOfRevolution - if ((S1->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)) || - S1->IsKind(STANDARD_TYPE(Geom_SweptSurface))) && - (S2->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)) || - S2->IsKind(STANDARD_TYPE(Geom_SweptSurface)))) - { - gp_Cylinder aCyl1, aCyl2; - if (getCylinder(S1, aCyl1) && getCylinder(S2, aCyl2)) { - if (fabs(aCyl1.Radius() - aCyl2.Radius()) < aPrec) { - gp_Dir aDir1 = aCyl1.Position().Direction(); - gp_Dir aDir2 = aCyl2.Position().Direction(); - if (aDir1.IsParallel(aDir2, aPrec)) { - gp_Pnt aLoc1 = aCyl1.Location(); - gp_Pnt aLoc2 = aCyl2.Location(); - gp_Vec aVec12 (aLoc1, aLoc2); - if (aVec12.SquareMagnitude() < aPrec*aPrec || - aVec12.IsParallel(aDir1, aPrec)) { - return true; - } - } - } - } - } - - return false; -} - -//======================================================================= -//function : MovePCurves -//purpose : -//======================================================================= -void BlockFix_UnionFaces::MovePCurves(TopoDS_Face& aTarget, - const TopoDS_Face& aSource) const -{ - BRep_Builder B; - for(TopExp_Explorer wexp(aSource,TopAbs_WIRE);wexp.More();wexp.Next()) { - Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire(TopoDS::Wire(wexp.Current()), - aTarget, Precision::Confusion()); - sfw->FixReorder(); - Standard_Boolean isReoredFailed = sfw->StatusReorder ( ShapeExtend_FAIL ); - sfw->FixEdgeCurves(); - if(isReoredFailed) - continue; - - sfw->FixShifted(); - sfw->FixDegenerated(); - - // remove degenerated edges from not degenerated points - ShapeAnalysis_Edge sae; - Handle(ShapeExtend_WireData) sewd = sfw->WireData(); - for(Standard_Integer i = 1; i<=sewd->NbEdges();i++) { - TopoDS_Edge E = sewd->Edge(i); - if(BRep_Tool::Degenerated(E)&&!sae.HasPCurve(E,aTarget)) { - sewd->Remove(i); - i--; - } - } - - TopoDS_Wire ResWire = sfw->Wire(); - B.Add(aTarget,ResWire); - } -} diff --git a/src/BlockFix/BlockFix_UnionFaces.hxx b/src/BlockFix/BlockFix_UnionFaces.hxx deleted file mode 100644 index 2eb217f5c..000000000 --- a/src/BlockFix/BlockFix_UnionFaces.hxx +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (C) 2007-2021 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 library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#ifndef _BlockFix_UnionFaces_HeaderFile -#define _BlockFix_UnionFaces_HeaderFile - -#include -#include -#include -#include - -class TopoDS_Shape; -class TopoDS_Face; - -class BlockFix_UnionFaces -{ -public: - Standard_EXPORT BlockFix_UnionFaces(); - - Standard_EXPORT Standard_Real& GetTolerance(); - - /* \brief To get/set the OptimumNbFaces parameter - * - * If a being processed solid has less than OptimumNbFaces - * faces, no union will be performed. - * By default this parameter is set to 6 (to correctly - * process blocks - hexahedral solids) - * Special values: 0 - do all possible unions, regardless the faces quantity, - * negative - do not perform any unions, regardless the faces quantity. - * - */ - Standard_EXPORT Standard_Integer& GetOptimumNbFaces(); - - Standard_EXPORT TopoDS_Shape Perform(const TopoDS_Shape& Shape); - - Standard_EXPORT virtual Standard_Boolean IsSameDomain(const TopoDS_Face& aFace, - const TopoDS_Face& aChekedFace) const; - - Standard_EXPORT virtual void MovePCurves(TopoDS_Face& aTarget, - const TopoDS_Face& aSource) const; - -private: - Standard_Real myTolerance; - Standard_Integer myOptimumNbFaces; -}; - -#endif diff --git a/src/BlockFix/CMakeLists.txt b/src/BlockFix/CMakeLists.txt index e2567d6b0..c15d0c711 100644 --- a/src/BlockFix/CMakeLists.txt +++ b/src/BlockFix/CMakeLists.txt @@ -47,8 +47,6 @@ SET(BlockFix_HEADERS BlockFix_CheckTool.hxx BlockFix_PeriodicSurfaceModifier.hxx BlockFix_SphereSpaceModifier.hxx - BlockFix_UnionEdges.hxx - BlockFix_UnionFaces.hxx ) # --- sources --- @@ -59,8 +57,6 @@ SET(BlockFix_SOURCES BlockFix.cxx BlockFix_PeriodicSurfaceModifier.cxx BlockFix_SphereSpaceModifier.cxx - BlockFix_UnionEdges.cxx - BlockFix_UnionFaces.cxx ) # --- rules --- diff --git a/src/GEOMImpl/GEOMImpl_BlockDriver.cxx b/src/GEOMImpl/GEOMImpl_BlockDriver.cxx index 22d2b0b52..e06cd476a 100644 --- a/src/GEOMImpl/GEOMImpl_BlockDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_BlockDriver.cxx @@ -39,7 +39,6 @@ #include //#include #include -#include #include "utilities.h" @@ -62,6 +61,7 @@ #include #include #include +#include #include #include @@ -734,7 +734,9 @@ Standard_Integer GEOMImpl_BlockDriver::Execute(Handle(TFunction_Logbook)& log) c // Glue faces of the multi-block aShape = GEOMImpl_GlueDriver::GlueFaces(aMulti, aTol, Standard_False); - } else if (aType == BLOCK_UNION_FACES) { + } + else if (aType == BLOCK_UNION_FACES) + { GEOMImpl_IBlockTrsf aCI (aFunction); Handle(GEOM_Function) aRefShape = aCI.GetOriginal(); TopoDS_Shape aBlockOrComp = aRefShape->GetValue(); @@ -742,11 +744,17 @@ Standard_Integer GEOMImpl_BlockDriver::Execute(Handle(TFunction_Logbook)& log) c Standard_NullObject::Raise("Null Shape given"); } - BlockFix_UnionFaces aFaceUnifier; - - aFaceUnifier.GetOptimumNbFaces() = 0; // To force union faces. - aShape = aFaceUnifier.Perform(aBlockOrComp); - } else { // unknown function type + Standard_Boolean isUnifyEdges = Standard_False; + Standard_Boolean isUnifyFaces = Standard_True; + Standard_Boolean isConcatBSplines = Standard_True; + ShapeUpgrade_UnifySameDomain aUnifier (aBlockOrComp, + isUnifyEdges, isUnifyFaces, isConcatBSplines); + aUnifier.SetLinearTolerance(Precision::Confusion()); + aUnifier.SetAngularTolerance(Precision::Confusion()); + aUnifier.Build(); + aShape = aUnifier.Shape(); + } + else { // unknown function type return 0; } }