diff --git a/src/BRepTools/BRepTools.cxx b/src/BRepTools/BRepTools.cxx index 5a707a0da1..6a1096fa79 100644 --- a/src/BRepTools/BRepTools.cxx +++ b/src/BRepTools/BRepTools.cxx @@ -19,7 +19,8 @@ #include <BndLib_Add2dCurve.hxx> #include <BRep_Builder.hxx> #include <BRep_CurveRepresentation.hxx> -#include <BRep_ListIteratorOfListOfCurveRepresentation.hxx> +#include <BRep_GCurve.hxx> +#include <BRep_ListOfCurveRepresentation.hxx> #include <BRep_TEdge.hxx> #include <BRep_Tool.hxx> #include <BRepTools.hxx> @@ -548,132 +549,45 @@ void BRepTools::Update(const TopoDS_Shape& S) } } - //======================================================================= //function : UpdateFaceUVPoints -//purpose : reset the UV points of a Face +//purpose : Reset the UV points of edges on the Face //======================================================================= - -void BRepTools::UpdateFaceUVPoints(const TopoDS_Face& F) +void BRepTools::UpdateFaceUVPoints(const TopoDS_Face& theF) { - // Recompute for each edge the two UV points in order to have the same - // UV point on connected edges. + // For each edge of the face <F> reset the UV points to the bounding + // points of the parametric curve of the edge on the face. - // First edge loop, store the vertices in a Map with their 2d points - - BRepTools_MapOfVertexPnt2d theVertices; - TopoDS_Iterator expE,expV; - TopoDS_Iterator EdgeIt,VertIt; - TColStd_SequenceOfReal aFSeq, aLSeq; - TColGeom2d_SequenceOfCurve aCSeq; - TopTools_SequenceOfShape aShSeq; - gp_Pnt2d P; - Standard_Integer i; - // a 3d tolerance for UV !! - Standard_Real tolerance = BRep_Tool::Tolerance(F); - TColgp_SequenceOfPnt2d emptySequence; - - for (expE.Initialize(F); expE.More(); expE.Next()) { - if(expE.Value().ShapeType() != TopAbs_WIRE) - continue; - - EdgeIt.Initialize(expE.Value()); - for( ; EdgeIt.More(); EdgeIt.Next()) - { - const TopoDS_Edge& E = TopoDS::Edge(EdgeIt.Value()); - Standard_Real f,l; - Handle(Geom2d_Curve) C = BRep_Tool::CurveOnSurface(E,F,f,l); - - aFSeq.Append(f); - aLSeq.Append(l); - aCSeq.Append(C); - aShSeq.Append(E); - - if (C.IsNull()) continue; - - for (expV.Initialize(E.Oriented(TopAbs_FORWARD)); - expV.More(); expV.Next()) { - - const TopoDS_Vertex& V = TopoDS::Vertex(expV.Value()); - - TopAbs_Orientation Vori = V.Orientation(); - if ( Vori == TopAbs_INTERNAL ) { - continue; - } - - Standard_Real p = BRep_Tool::Parameter(V,E,F); - C->D0(p,P); - if (!theVertices.IsBound(V)) - theVertices.Bind(V,emptySequence); - TColgp_SequenceOfPnt2d& S = theVertices(V); - for (i = 1; i <= S.Length(); i++) { - if (P.Distance(S(i)) < tolerance) break; - } - if (i > S.Length()) - S.Append(P); - } - } - } - - // second edge loop, update the edges 2d points - TopoDS_Vertex Vf,Vl; - gp_Pnt2d Pf,Pl; - - for(Standard_Integer j = 1; j <= aShSeq.Length(); j++) + // Get surface of the face + TopLoc_Location aLoc; + const Handle(Geom_Surface)& aSurf = BRep_Tool::Surface(theF, aLoc); + // Iterate on edges and reset UV points + TopExp_Explorer anExpE(theF, TopAbs_EDGE); + for (; anExpE.More(); anExpE.Next()) { - const TopoDS_Edge& E = TopoDS::Edge(aShSeq.Value(j)); - const Handle(Geom2d_Curve)& C = aCSeq.Value(j); - if (C.IsNull()) continue; - - TopExp::Vertices(E,Vf,Vl); - if (Vf.IsNull()) { - Pf.SetCoord(RealLast(),RealLast()); - } - else { - if ( Vf.Orientation() == TopAbs_INTERNAL ) { - continue; - } - const TColgp_SequenceOfPnt2d& seqf = theVertices(Vf); - if (seqf.Length() == 1) - Pf = seqf(1); - else { - C->D0(aFSeq.Value(j),Pf); - for (i = 1; i <= seqf.Length(); i++) { - if (Pf.Distance(seqf(i)) <= tolerance) { - Pf = seqf(i); - break; - } - } - } - } - if (Vl.IsNull()) { - Pl.SetCoord(RealLast(),RealLast()); - } - else { - if ( Vl.Orientation() == TopAbs_INTERNAL ) { - continue; - } - const TColgp_SequenceOfPnt2d& seql = theVertices(Vl); - if (seql.Length() == 1) - Pl = seql(1); - else { - C->D0(aLSeq.Value(j),Pl); - for (i = 1; i <= seql.Length(); i++) { - if (Pl.Distance(seql(i)) <= tolerance) { - Pl = seql(i); - break; - } - } - } - } + const TopoDS_Edge& aE = TopoDS::Edge(anExpE.Current()); - // set the correct points - BRep_Tool::SetUVPoints(E,F,Pf,Pl); + const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&aE.TShape()); + if (TE->Locked()) + return; + + const TopLoc_Location aELoc = aLoc.Predivided(aE.Location()); + // Edge representations + BRep_ListOfCurveRepresentation& aLCR = TE->ChangeCurves(); + BRep_ListIteratorOfListOfCurveRepresentation itLCR(aLCR); + for (; itLCR.More(); itLCR.Next()) + { + Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itLCR.Value()); + if (!GC.IsNull() && GC->IsCurveOnSurface(aSurf, aELoc)) + { + // Update UV points + GC->Update(); + break; + } + } } } - - //======================================================================= //function : Compare //purpose : diff --git a/src/BRepTools/BRepTools.hxx b/src/BRepTools/BRepTools.hxx index fb0ff959a2..b5113a97ea 100644 --- a/src/BRepTools/BRepTools.hxx +++ b/src/BRepTools/BRepTools.hxx @@ -73,10 +73,8 @@ class Geom_Surface; //! * Update : Methods to call when a topology has //! been created to compute all missing data. //! -//! * UpdateFaceUVPoints : Method to update the UV -//! points stored with the edges on a face. This -//! method ensure that connected edges have the same -//! UV point on their common extremity. +//! * UpdateFaceUVPoints: Method to update the UV points +//! stored with the edges on a face. //! //! * Compare : Method to compare two vertices. //! @@ -147,10 +145,10 @@ public: //! Update a shape, call the corect update. Standard_EXPORT static void Update (const TopoDS_Shape& S); - //! For all the edges of the face <F> reset the UV - //! points to ensure that connected faces have the - //! same point at there common extremity. - Standard_EXPORT static void UpdateFaceUVPoints (const TopoDS_Face& F); + //! For each edge of the face <F> reset the UV points + //! to the bounding points of the parametric curve of the + //! edge on the face. + Standard_EXPORT static void UpdateFaceUVPoints (const TopoDS_Face& theF); //! Removes all the triangulations of the faces of <S> //! and removes all polygons on triangulations of the diff --git a/tests/bugs/modalg_6/bug21246 b/tests/bugs/modalg_6/bug21246 index 97ee7e4ad4..3b50b6da8b 100644 --- a/tests/bugs/modalg_6/bug21246 +++ b/tests/bugs/modalg_6/bug21246 @@ -1,4 +1,4 @@ -puts "REQUIRED ALL: Faulty shapes in variables faulty_1 to faulty_1" +puts "REQUIRED ALL: Faulty shapes in variables faulty_1 to faulty_2" puts "========" puts "OCC21246" diff --git a/tests/bugs/modalg_7/bug29701_1 b/tests/bugs/modalg_7/bug29701_1 new file mode 100644 index 0000000000..35c5dd168f --- /dev/null +++ b/tests/bugs/modalg_7/bug29701_1 @@ -0,0 +1,34 @@ +puts "========" +puts "OCC29701" +puts "========" +puts "" +################################################# +# BRepTools::Update(Face) unexpectedly updates UV points of pcurve +################################################# + +brestore [locate_data_file bug29701_brepmesh_triangle_bad_collapsed.brep] s + +# mesh the face +repeat 2 { + if {![regexp "NoError" [incmesh s 0.1]]} { + puts "Error: Unable to build triangulation" + } +} + +tcopy s copy + +# mesh the copy face +repeat 2 { + if {![regexp "NoError" [incmesh copy 0.1]]} { + puts "Error: Unable to build triangulation on copy shape" + } +} + +fixshape fixed s + +# mesh the fixed face +repeat 2 { + if {![regexp "NoError" [incmesh fixed 0.1]]} { + puts "Error: Unable to build triangulation on fixed shape" + } +} diff --git a/tests/bugs/modalg_7/bug29701_2 b/tests/bugs/modalg_7/bug29701_2 new file mode 100644 index 0000000000..f179c21cac --- /dev/null +++ b/tests/bugs/modalg_7/bug29701_2 @@ -0,0 +1,34 @@ +puts "========" +puts "OCC29701" +puts "========" +puts "" +################################################# +# BRepTools::Update(Face) unexpectedly updates UV points of pcurve +################################################# + +brestore [locate_data_file bug29701_hullshape.brep] s + +# mesh the face +repeat 2 { + if {![regexp "NoError" [incmesh s 0.1]]} { + puts "Error: Unable to build triangulation" + } +} + +tcopy s copy + +# mesh the copy face +repeat 2 { + if {![regexp "NoError" [incmesh copy 0.1]]} { + puts "Error: Unable to build triangulation on copy shape" + } +} + +fixshape fixed s + +# mesh the fixed face +repeat 2 { + if {![regexp "NoError" [incmesh fixed 0.1]]} { + puts "Error: Unable to build triangulation on fixed shape" + } +} diff --git a/tests/bugs/modalg_7/bug29701_3 b/tests/bugs/modalg_7/bug29701_3 new file mode 100644 index 0000000000..cdcdfa92d0 --- /dev/null +++ b/tests/bugs/modalg_7/bug29701_3 @@ -0,0 +1,34 @@ +puts "========" +puts "OCC29701" +puts "========" +puts "" +################################################# +# BRepTools::Update(Face) unexpectedly updates UV points of pcurve +################################################# + +brestore [locate_data_file bug29701_Plate_B.brep] s + +# mesh the face +repeat 2 { + if {![regexp "NoError" [incmesh s 0.1]]} { + puts "Error: Unable to build triangulation" + } +} + +tcopy s copy + +# mesh the copy face +repeat 2 { + if {![regexp "NoError" [incmesh copy 0.1]]} { + puts "Error: Unable to build triangulation on copy shape" + } +} + +fixshape fixed s + +# mesh the fixed face +repeat 2 { + if {![regexp "NoError" [incmesh fixed 0.1]]} { + puts "Error: Unable to build triangulation on fixed shape" + } +} diff --git a/tests/heal/data/advanced/ZC3 b/tests/heal/data/advanced/ZC3 index feabedf40c..24b5cf71b8 100644 --- a/tests/heal/data/advanced/ZC3 +++ b/tests/heal/data/advanced/ZC3 @@ -1,5 +1,5 @@ if {[string compare $command "SplitAngle"] == 0 } { - puts "TODO OCC23127 ALL: Faulty shapes in variables faulty_1 to faulty_38 " + puts "TODO OCC23127 ALL: Faulty shapes in variables faulty_1 to faulty_ " } restore [locate_data_file CED_PIEUSI.brep] a diff --git a/tests/heal/data/advanced/ZE6 b/tests/heal/data/advanced/ZE6 index c68c5730f2..8c37d2a7ec 100644 --- a/tests/heal/data/advanced/ZE6 +++ b/tests/heal/data/advanced/ZE6 @@ -1,5 +1,5 @@ if {[string compare $command "SplitAngle"] == 0 } { - puts "TODO OCC23127 ALL: Faulty shapes in variables faulty_1 to faulty_6 " + puts "TODO OCC23127 ALL: Faulty shapes in variables faulty_1 to faulty_ " } restore [locate_data_file SOLMIR.brep] a diff --git a/tests/heal/data/advanced/ZE9 b/tests/heal/data/advanced/ZE9 index 627c037280..9d40d6df5d 100644 --- a/tests/heal/data/advanced/ZE9 +++ b/tests/heal/data/advanced/ZE9 @@ -1,5 +1,5 @@ if {[string compare $command "SplitAngle"] == 0 } { - puts "TODO OCC23127 ALL: Faulty shapes in variables faulty_1 to faulty_28 " + puts "TODO OCC23127 ALL: Faulty shapes in variables faulty_1 to faulty_ " } restore [locate_data_file BPLSEITRE.brep] a