From: jgv Date: Fri, 19 Oct 2012 14:28:46 +0000 (+0400) Subject: 0023367: New functionality restoring the middle path of pipe-like shape X-Git-Tag: V6_5_4~29 X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=commitdiff_plain;h=7416e83cf6b1b7b4b2b7d048e5c8dca36d412f44 0023367: New functionality restoring the middle path of pipe-like shape --- diff --git a/src/BRepOffsetAPI/BRepOffsetAPI_MiddlePath.cxx b/src/BRepOffsetAPI/BRepOffsetAPI_MiddlePath.cxx index 4df8ef5376..e9bcb40f79 100644 --- a/src/BRepOffsetAPI/BRepOffsetAPI_MiddlePath.cxx +++ b/src/BRepOffsetAPI/BRepOffsetAPI_MiddlePath.cxx @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -361,7 +362,7 @@ void BRepOffsetAPI_MiddlePath::Build() TopTools_MapOfShape CurVertices; Standard_Integer i, j, k; - TopoDS_Edge anEdge, theEdge; + TopoDS_Edge anEdge; TopoDS_Vertex V1, V2, NextVertex; //Initialization of for (i = 1; i <= StartVertices.Length(); i++) @@ -389,29 +390,29 @@ void BRepOffsetAPI_MiddlePath::Build() } //Filling of "myPaths" - //TopTools_MapOfShape StartFacesMap; TopTools_ListOfShape NextVertices; for (;;) { - /* - StartFacesMap.Clear(); for (i = 1; i <= myPaths.Length(); i++) { - const TopoDS_Shape& LastEdge = myPaths(i).Last(); - const TopTools_ListOfShape& LF = EFmap(LastEdge); - for (itl.Initialize(LF); itl.More(); itl.Next()) - StartFacesMap.Add(itl.Value(); - } - */ - //TopTools_SequenceOfShape NewEdges; - for (i = 1; i <= myPaths.Length(); i++) - { - theEdge = TopoDS::Edge(myPaths(i).Last()); - TopoDS_Vertex theVertex = TopExp::LastVertex(theEdge, Standard_True); + const TopoDS_Shape& theShape = myPaths(i).Last(); + TopoDS_Edge theEdge; + TopoDS_Vertex theVertex; + if (theShape.ShapeType() == TopAbs_EDGE) + { + theEdge = TopoDS::Edge(theShape); + theVertex = TopExp::LastVertex(theEdge, Standard_True); + } + else //last segment of path was punctual + { + theEdge = TopoDS::Edge(myPaths(i)(myPaths(i).Length()-1)); + theVertex = TopoDS::Vertex(theShape); + } + if (EndVertices.Contains(theVertex)) continue; const TopTools_ListOfShape& LE = VEmap.FindFromKey(theVertex); - Standard_Boolean NextEdgeFound = Standard_False; + TopTools_MapOfShape NextEdgeCandidates; for (itl.Initialize(LE); itl.More(); itl.Next()) { anEdge = TopoDS::Edge(itl.Value()); @@ -426,15 +427,20 @@ void BRepOffsetAPI_MiddlePath::Build() NextVertex = V1; } if (!CurVertices.Contains(NextVertex)) - { - NextEdgeFound = Standard_True; - break; - } + NextEdgeCandidates.Add(anEdge); } - if (NextEdgeFound) + if (!NextEdgeCandidates.IsEmpty()) { - myPaths(i).Append(anEdge); - NextVertices.Append(NextVertex); + if (NextEdgeCandidates.Extent() > 1) + myPaths(i).Append(theVertex); //punctual segment of path + else + { + TopTools_MapIteratorOfMapOfShape mapit(NextEdgeCandidates); + anEdge = TopoDS::Edge(mapit.Key()); + myPaths(i).Append(anEdge); + NextVertex = TopExp::LastVertex(anEdge, Standard_True); + NextVertices.Append(NextVertex); + } } } if (NextVertices.IsEmpty()) @@ -444,8 +450,32 @@ void BRepOffsetAPI_MiddlePath::Build() NextVertices.Clear(); } + //Temporary + /* + TopoDS_Compound aCompound, aCmp1; + BRep_Builder BB; + BB.MakeCompound(aCompound); + BB.MakeCompound(aCmp1); + for (i = 1; i <= myPaths.Length(); i++) + { + TopoDS_Compound aCmp; + BB.MakeCompound(aCmp); + for (j = 1; j <= myPaths(i).Length(); j++) + BB.Add(aCmp, myPaths(i)(j)); + BB.Add(aCmp1, aCmp); + } + BB.Add(aCompound, aCmp1); + + myShape = aCompound; + + Done(); + return; + */ + //////////// + //Building of set of sections Standard_Integer NbE = EdgeSeq.Length(); + Standard_Integer NbPaths = myPaths.Length(); Standard_Integer NbVer = myPaths.Length(); if (myClosedSection) NbVer++; @@ -461,6 +491,21 @@ void BRepOffsetAPI_MiddlePath::Build() { if (!EdgeSeq(j-1).IsNull()) continue; + + //for the end of initial shape + if (myPaths(j-1).Length() < i) + { + TopoDS_Edge aE1 = TopoDS::Edge(myPaths(j-1)(i-1)); + TopoDS_Shape LastVer = TopExp::LastVertex(aE1, Standard_True); + myPaths(j-1).Append(LastVer); + } + if (myPaths((j<=NbPaths)? j : 1).Length() < i) + { + TopoDS_Edge aE2 = TopoDS::Edge(myPaths((j<=NbPaths)? j : 1)(i-1)); + TopoDS_Shape LastVer = TopExp::LastVertex(aE2, Standard_True); + myPaths((j<=NbPaths)? j : 1).Append(LastVer); + } + ////////////////////////////// if (ToInsertVertex) { @@ -470,11 +515,11 @@ void BRepOffsetAPI_MiddlePath::Build() TopoDS_Shape fver = TopExp::FirstVertex(aE1, Standard_True); myPaths(j-1).InsertBefore(i, fver); } - if (myPaths((j<=NbE)? j : 1)(i).ShapeType() == TopAbs_EDGE) + if (myPaths((j<=NbPaths)? j : 1)(i).ShapeType() == TopAbs_EDGE) { - TopoDS_Edge aE2 = TopoDS::Edge(myPaths((j<=NbE)? j : 1)(i)); + TopoDS_Edge aE2 = TopoDS::Edge(myPaths((j<=NbPaths)? j : 1)(i)); TopoDS_Shape fver = TopExp::FirstVertex(aE2, Standard_True); - myPaths((j<=NbE)? j : 1).InsertBefore(i, fver); + myPaths((j<=NbPaths)? j : 1).InsertBefore(i, fver); } ToInsertVertex = Standard_False; } @@ -482,15 +527,15 @@ void BRepOffsetAPI_MiddlePath::Build() TopoDS_Edge E1, E2; if (myPaths(j-1)(i).ShapeType() == TopAbs_EDGE) E1 = TopoDS::Edge(myPaths(j-1)(i)); - if (myPaths((j<=NbE)? j : 1)(i).ShapeType() == TopAbs_EDGE) - E2 = TopoDS::Edge(myPaths((j<=NbE)? j : 1)(i)); + if (myPaths((j<=NbPaths)? j : 1)(i).ShapeType() == TopAbs_EDGE) + E2 = TopoDS::Edge(myPaths((j<=NbPaths)? j : 1)(i)); TopoDS_Edge E12 = TopoDS::Edge(SectionsEdges(i)(j-1)); //TopoDS_Vertex PrevVertex = TopoDS::Vertex(VerSeq(j-1)); //TopoDS_Vertex CurVertex = TopoDS::Vertex(VerSeq(j)); TopoDS_Vertex PrevVertex = (E1.IsNull())? TopoDS::Vertex(myPaths(j-1)(i)) : TopExp::LastVertex(E1, Standard_True); - TopoDS_Vertex CurVertex = (E2.IsNull())? TopoDS::Vertex(myPaths((j<=NbE)? j : 1)(i)) + TopoDS_Vertex CurVertex = (E2.IsNull())? TopoDS::Vertex(myPaths((j<=NbPaths)? j : 1)(i)) : TopExp::LastVertex(E2, Standard_True); TopoDS_Edge ProperEdge; @@ -512,7 +557,7 @@ void BRepOffsetAPI_MiddlePath::Build() } if ((myPaths(j-1)(i)).ShapeType() == TopAbs_VERTEX && - (myPaths((j<=NbE)? j : 1)(i)).ShapeType() == TopAbs_VERTEX) + (myPaths((j<=NbPaths)? j : 1)(i)).ShapeType() == TopAbs_VERTEX) { EdgeSeq(j-1) = ProperEdge; continue; @@ -524,11 +569,12 @@ void BRepOffsetAPI_MiddlePath::Build() : TopExp::FirstVertex(E2, Standard_True); if (ProperEdge.IsNull()) //no connection between these two vertices { + //Find the face on which E1, E2 and E12 lie //ToInsertVertex = Standard_False; const TopoDS_Shape& EE1 = (E1.IsNull())? myPaths(j-1)(i-1) : E1; const TopoDS_Shape& EE2 = (E2.IsNull())? - myPaths((j<=NbE)? j : 1)(i-1) : E2; + myPaths((j<=NbPaths)? j : 1)(i-1) : E2; const TopTools_ListOfShape& LF = EFmap.FindFromKey(EE1); TopoDS_Face theFace; for (itl.Initialize(LF); itl.More(); itl.Next()) @@ -562,7 +608,7 @@ void BRepOffsetAPI_MiddlePath::Build() if (E1.IsNull()) E1 = TopoDS::Edge(myPaths(j-1)(i-1)); if (E2.IsNull()) - E2 = TopoDS::Edge(myPaths((j<=NbE)? j : 1)(i-1)); + E2 = TopoDS::Edge(myPaths((j<=NbPaths)? j : 1)(i-1)); Standard_Real fpar1, lpar1, fpar2, lpar2; Standard_Real FirstPar1, LastPar1, FirstPar2, LastPar2; Handle(Geom2d_Curve) PCurve1 = BRep_Tool::CurveOnSurface(E1, theFace, fpar1, lpar1); @@ -671,7 +717,7 @@ void BRepOffsetAPI_MiddlePath::Build() TopoDS_Shape VertexAsEdge = TopExp::FirstVertex(aLastEdge, Standard_True); myPaths(k).InsertBefore(i, VertexAsEdge); } - j = 1; + j = 1; //start from beginning } else if (ChooseEdge == 2) { @@ -687,7 +733,7 @@ void BRepOffsetAPI_MiddlePath::Build() if (ToInsertVertex) { myPaths(j-1).InsertBefore(i, PrevPrevVer); - myPaths((j<=NbE)? j : 1).InsertBefore(i, PrevCurVer); + myPaths((j<=NbPaths)? j : 1).InsertBefore(i, PrevCurVer); EdgeSeq(j-1) = E12; } else @@ -781,6 +827,7 @@ void BRepOffsetAPI_MiddlePath::Build() gp_Ax1 theAxis; gp_Dir theDir1, theDir2; Standard_Real theAngle; + gp_Vec theTangent; Standard_Boolean SimilarArcs = Standard_True; for (j = 1; j <= myPaths.Length(); j++) { @@ -799,6 +846,11 @@ void BRepOffsetAPI_MiddlePath::Build() theDir1 = gp_Vec(aCirc.Location(), Pnt1); theDir2 = gp_Vec(aCirc.Location(), Pnt2); theAngle = lpar - fpar; + Standard_Real theParam = (anEdge.Orientation() == TopAbs_FORWARD)? + fpar : lpar; + aCurve->D1(theParam, Pnt1, theTangent); + if (anEdge.Orientation() == TopAbs_REVERSED) + theTangent.Reverse(); } else { @@ -842,6 +894,14 @@ void BRepOffsetAPI_MiddlePath::Build() theAxis.Reverse(); gp_Ax2 theAx2(theCenterOfCirc, theAxis.Direction(), Vec1); Handle(Geom_Circle) theCircle = GC_MakeCircle(theAx2, Vec1.Magnitude()); + gp_Vec aTangent; + theCircle->D1( 0., Pnt1, aTangent ); + if (aTangent * theTangent < 0.) + { + theAxis.Reverse(); + theAx2 = gp_Ax2(theCenterOfCirc, theAxis.Direction(), Vec1); + theCircle = GC_MakeCircle(theAx2, Vec1.Magnitude()); + } MidEdges(i) = BRepLib_MakeEdge(theCircle, 0., theAngle); } } diff --git a/src/GeomLib/GeomLib_IsPlanarSurface.cxx b/src/GeomLib/GeomLib_IsPlanarSurface.cxx index 9cec271d6a..b2e879c3e6 100755 --- a/src/GeomLib/GeomLib_IsPlanarSurface.cxx +++ b/src/GeomLib/GeomLib_IsPlanarSurface.cxx @@ -240,6 +240,13 @@ GeomLib_IsPlanarSurface::GeomLib_IsPlanarSurface(const Handle(Geom_Surface)& S, Standard_Real Umin, Umax, Vmin, Vmax; S->Bounds(Umin, Umax, Vmin, Vmax); S->D1((Umin+Umax)/2, (Vmin+Vmax)/2, P, DU, DV); + if (DU.Magnitude() <= gp::Resolution() || + DV.Magnitude() <= gp::Resolution()) + { + Standard_Real NewU = (Umin+Umax)/2 + (Umax-Umin)*0.1; + Standard_Real NewV = (Vmin+Vmax)/2 + (Vmax-Vmin)*0.1; + S->D1( NewU, NewV, P, DU, DV ); + } Dn = DU^DV; if (Dn.Magnitude() > 1.e-7) { Standard_Real angle = Dir.Angle(Dn); @@ -274,6 +281,13 @@ GeomLib_IsPlanarSurface::GeomLib_IsPlanarSurface(const Handle(Geom_Surface)& S, S->Bounds(Umin, Umax, Vmin, Vmax); S->D1((Umin+Umax)/2, (Vmin+Vmax)/2, P, Du, Dv); + if (Du.Magnitude() <= gp::Resolution() || + Dv.Magnitude() <= gp::Resolution()) + { + Standard_Real NewU = (Umin+Umax)/2 + (Umax-Umin)*0.1; + Standard_Real NewV = (Vmin+Vmax)/2 + (Vmax-Vmin)*0.1; + S->D1( NewU, NewV, P, Du, Dv ); + } Dn = Du^Dv; norm = Dn.Magnitude(); if (norm > 1.e-15) { diff --git a/tests/bugs/modalg/bug23367_10 b/tests/bugs/modalg/bug23367_10 new file mode 100755 index 0000000000..b9821e2265 --- /dev/null +++ b/tests/bugs/modalg/bug23367_10 @@ -0,0 +1,27 @@ +puts "============" +puts "CR23367" +puts "============" +puts "" +########################################################################################################## +# New functionality restoring the middle path of pipe-like shape +########################################################################################################## + +polyline pp 0 0 0 10 0 0 20 10 0 20 20 0 +polyline sp 0 0 0 0 0 100 0 50 200 0 100 100 +mksweep sp +addsweep pp +buildsweep a -R +explode a e +wire w1 a_2 a_5 a_8 +wire w2 a_24 a_22 a_20 +donly a w1 w2 +fit +middlepath result a w1 w2 + +set length 1. + +set 2dviewer 1 + + + + diff --git a/tests/bugs/modalg/bug23367_11 b/tests/bugs/modalg/bug23367_11 new file mode 100755 index 0000000000..036edc9289 --- /dev/null +++ b/tests/bugs/modalg/bug23367_11 @@ -0,0 +1,23 @@ +puts "============" +puts "CR23367" +puts "============" +puts "" +########################################################################################################## +# New functionality restoring the middle path of pipe-like shape +########################################################################################################## + +restore [locate_data_file bug23367_pipe1.brep] a +explode a e +wire w1 a_2 +wire w2 a_6 +donly a w1 w2 +fit +middlepath result a w2 w1 + +set length 1386.13 + +set 2dviewer 1 + + + + diff --git a/tests/bugs/modalg/bug23367_12 b/tests/bugs/modalg/bug23367_12 new file mode 100755 index 0000000000..a59f0ff806 --- /dev/null +++ b/tests/bugs/modalg/bug23367_12 @@ -0,0 +1,23 @@ +puts "============" +puts "CR23367" +puts "============" +puts "" +########################################################################################################## +# New functionality restoring the middle path of pipe-like shape +########################################################################################################## + +restore [locate_data_file bug23367_aa.brep] a +explode a e +wire w1 a_57 a_73 a_54 a_71 +wire w2 a_133 a_148 a_130 a_146 +donly a w1 w2 +fit +middlepath result a w2 w1 + +set length 3.46311 + +set 2dviewer 1 + + + + diff --git a/tests/bugs/modalg/bug23367_13 b/tests/bugs/modalg/bug23367_13 new file mode 100755 index 0000000000..62858680b1 --- /dev/null +++ b/tests/bugs/modalg/bug23367_13 @@ -0,0 +1,27 @@ +puts "============" +puts "CR23367" +puts "============" +puts "" +########################################################################################################## +# New functionality restoring the middle path of pipe-like shape +########################################################################################################## + +polyline pp 0 0 0 10 0 0 20 10 0 20 20 0 +polyline sp 0 0 0 0 0 100 -50 50 200 -100 100 100 +mksweep sp +addsweep pp +buildsweep a -R +explode a e +wire w1 a_2 a_5 a_8 +wire w2 a_24 a_27 a_30 +donly a w1 w2 +fit +middlepath result a w1 w2 + +set length 1. + +set 2dviewer 1 + + + + diff --git a/tests/bugs/modalg/bug23367_14 b/tests/bugs/modalg/bug23367_14 new file mode 100755 index 0000000000..e15e4b57e7 --- /dev/null +++ b/tests/bugs/modalg/bug23367_14 @@ -0,0 +1,26 @@ +puts "============" +puts "CR23367" +puts "============" +puts "" +########################################################################################################## +# New functionality restoring the middle path of pipe-like shape +########################################################################################################## + +polyline pp 0 0 0 10 -10 0 20 0 0 10 10 0 0 0 0 +polyline sp 0 0 0 0 0 50 -100 0 0 -50 0 -50 0 0 0 +mksweep sp +addsweep pp +buildsweep a -R +explode a e +wire ww a_11 a_8 a_5 a_2 +donly a ww +fit +middlepath result a ww ww + +set length 1. + +set 2dviewer 1 + + + + diff --git a/tests/bugs/modalg/bug23367_15 b/tests/bugs/modalg/bug23367_15 new file mode 100755 index 0000000000..4ddfb8521e --- /dev/null +++ b/tests/bugs/modalg/bug23367_15 @@ -0,0 +1,27 @@ +puts "============" +puts "CR23367" +puts "============" +puts "" +########################################################################################################## +# New functionality restoring the middle path of pipe-like shape +########################################################################################################## + +polyline pp 0 0 0 10 -10 0 20 0 0 10 10 0 0 0 0 +polyline sp 0 0 0 0 0 50 -100 0 0 -50 0 -50 +mksweep sp +addsweep pp +buildsweep a -R +explode a e +wire w1 a_11 a_8 a_5 a_2 +wire w2 a_34 a_36 a_28 a_31 +donly a w1 w2 +fit +middlepath result a w1 w2 + +set length 1. + +set 2dviewer 1 + + + + diff --git a/tests/bugs/modalg/bug23367_7 b/tests/bugs/modalg/bug23367_7 new file mode 100755 index 0000000000..b6df910357 --- /dev/null +++ b/tests/bugs/modalg/bug23367_7 @@ -0,0 +1,22 @@ +puts "============" +puts "CR23367" +puts "============" +puts "" +########################################################################################################## +# New functionality restoring the middle path of pipe-like shape +########################################################################################################## + +restore [locate_data_file bug23367_aa.brep] a +explode a e +wire w1 a_57 a_73 a_54 a_71 +wire w2 a_133 a_148 a_130 a_146 +donly a w1 w2 +fit +middlepath result a w1 w2 + +set length 3.46311 + +set 2dviewer 1 + + + diff --git a/tests/bugs/modalg/bug23367_8 b/tests/bugs/modalg/bug23367_8 new file mode 100755 index 0000000000..c2432001f7 --- /dev/null +++ b/tests/bugs/modalg/bug23367_8 @@ -0,0 +1,22 @@ +puts "============" +puts "CR23367" +puts "============" +puts "" +########################################################################################################## +# New functionality restoring the middle path of pipe-like shape +########################################################################################################## + +restore [locate_data_file bug23367_bb.brep] b +explode b e +wire w1 b_1 b_29 b_60 b_27 +wire w2 b_11 b_23 b_56 b_33 +donly b w1 w2 +fit +middlepath result b w1 w2 + +set length 1.94244 + +set 2dviewer 1 + + + diff --git a/tests/bugs/modalg/bug23367_9 b/tests/bugs/modalg/bug23367_9 new file mode 100755 index 0000000000..c6c13211d7 --- /dev/null +++ b/tests/bugs/modalg/bug23367_9 @@ -0,0 +1,25 @@ +puts "============" +puts "CR23367" +puts "============" +puts "" +########################################################################################################## +# New functionality restoring the middle path of pipe-like shape +########################################################################################################## + +ptorus a 50 10 0 180 +explode a f +shape b Sh +add a_1 b +explode b e +wire ww b_2 +donly b ww +fit +middlepath result b ww ww + +set length 1. + +set 2dviewer 1 + + + +