1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-07 18:30:55 +03:00

0026241: Sewing algorithm computes tolerance of joint vertex too rough

Upgrade method of computing vertex tolerance.
Update function, which used the old method.
Test case for issue CR26241
Delete obsolete variables.
Small correction of test cases for issue CR26241
This commit is contained in:
ika 2015-06-18 14:03:53 +03:00 committed by bugmaster
parent e2df45413e
commit 93937391be
24 changed files with 147 additions and 105 deletions

View File

@ -492,9 +492,83 @@ static Standard_Boolean findNMVertices(const TopoDS_Edge& theEdge,
return Standard_True; return Standard_True;
} }
static inline Standard_Real ComputeToleranceVertex(const Standard_Real dist, const Standard_Real Tol1, const Standard_Real Tol2) static void ComputeToleranceVertex(TopoDS_Vertex theV1, TopoDS_Vertex theV2,
TopoDS_Vertex& theNewV)
{ {
return (dist * 0.5 + Tol1 + Tol2); Standard_Integer m, n;
Standard_Real aR[2], dR, aD, aEps;
TopoDS_Vertex aV[2];
gp_Pnt aP[2];
BRep_Builder aBB;
//
aEps = RealEpsilon();
aV[0] = theV1;
aV[1] = theV2;
for (m = 0; m < 2; ++m) {
aP[m] = BRep_Tool::Pnt(aV[m]);
aR[m] = BRep_Tool::Tolerance(aV[m]);
}
//
m=0; // max R
n=1; // min R
if (aR[0] < aR[1]) {
m=1;
n=0;
}
//
dR = aR[m] - aR[n]; // dR >= 0.
gp_Vec aVD(aP[m], aP[n]);
aD = aVD.Magnitude();
//
if (aD <= dR || aD < aEps) {
aBB.MakeVertex (theNewV, aP[m], aR[m]);
}
else {
Standard_Real aRr;
gp_XYZ aXYZr;
gp_Pnt aPr;
//
aRr = 0.5 * (aR[m] + aR[n] + aD);
aXYZr = 0.5 * (aP[m].XYZ() + aP[n].XYZ() - aVD.XYZ() * (dR/aD));
aPr.SetXYZ(aXYZr);
//
aBB.MakeVertex (theNewV, aPr, aRr);
}
return;
}
static void ComputeToleranceVertex(TopoDS_Vertex theV1, TopoDS_Vertex theV2,
TopoDS_Vertex theV3, TopoDS_Vertex& theNewV)
{
Standard_Real aDi, aDmax;
gp_Pnt aCenter;
gp_Pnt aP[3];
Standard_Real aR[3];
TopoDS_Vertex aV[3];
gp_XYZ aXYZ(0.,0.,0.);
aV[0] = theV1;
aV[1] = theV2;
aV[2] = theV3;
for (Standard_Integer i = 0; i < 3; ++i) {
aP[i] = BRep_Tool::Pnt(aV[i]);
aR[i] = BRep_Tool::Tolerance(aV[i]);
aXYZ = aXYZ + aP[i].XYZ();
}
//
aXYZ.Divide(3.0);
aCenter.SetXYZ(aXYZ);
//
aDmax=-1.;
for ( Standard_Integer i = 0; i < 3; ++i) {
aDi = aCenter.Distance(aP[i]);
aDi += aR[i];
if (aDi > aDmax)
aDmax = aDi;
}
BRep_Builder aBB;
aBB.MakeVertex (theNewV, aCenter, aDmax);
return;
} }
TopoDS_Edge BRepBuilderAPI_Sewing::SameParameterEdge(const TopoDS_Edge& edgeFirst, TopoDS_Edge BRepBuilderAPI_Sewing::SameParameterEdge(const TopoDS_Edge& edgeFirst,
@ -605,111 +679,54 @@ TopoDS_Edge BRepBuilderAPI_Sewing::SameParameterEdge(const TopoDS_Edge& edgeFirs
//V21 = TopoDS::Vertex(myReShape->Apply(V21)); //V21 = TopoDS::Vertex(myReShape->Apply(V21));
//V22 = TopoDS::Vertex(myReShape->Apply(V22)); //V22 = TopoDS::Vertex(myReShape->Apply(V22));
gp_Pnt p11 = BRep_Tool::Pnt(V11);
gp_Pnt p12 = BRep_Tool::Pnt(V12);
gp_Pnt p21 = BRep_Tool::Pnt(V21);
gp_Pnt p22 = BRep_Tool::Pnt(V22);
//Standard_Boolean isRev = Standard_False; //Standard_Boolean isRev = Standard_False;
gp_Pnt pfirst;
Standard_Real Tol1 = 0.;
if (isClosed1 || isClosed2) { if (isClosed1 || isClosed2) {
// at least one of the edges is closed // at least one of the edges is closed
if (isClosed1 && isClosed2) { if (isClosed1 && isClosed2) {
// both edges are closed // both edges are closed
pfirst.SetXYZ(0.5*(p11.XYZ() + p21.XYZ())); ComputeToleranceVertex(V11, V21, V1New);
gp_Vec v1 = p21.XYZ() - p11.XYZ();
Standard_Real d1 = v1.Magnitude();
Tol1 = ComputeToleranceVertex(d1,BRep_Tool::Tolerance(V11),BRep_Tool::Tolerance(V21));
//Tol1 = Max(pfirst.Distance(p11),pfirst.Distance(p21));
} }
else if (isClosed1) { else if (isClosed1) {
// only first edge is closed // only first edge is closed
gp_XYZ pt =0.5*(p21.XYZ()+ p22.XYZ()); ComputeToleranceVertex(V22, V21, V11, V1New);
pfirst.SetXYZ(0.5*(p11.XYZ() + pt));
gp_Vec v1 = p22.XYZ() - p21.XYZ();
Standard_Real d1 = v1.Magnitude();
Tol1= ComputeToleranceVertex(d1,BRep_Tool::Tolerance(V22),BRep_Tool::Tolerance(V21));
gp_Vec v2 = p11.XYZ() - pt;
Standard_Real d2 = v2.Magnitude();
Tol1= ComputeToleranceVertex(d2,Tol1,BRep_Tool::Tolerance(V11));
//Tol1 = Max(pfirst.Distance(p21),pfirst.Distance(p22));
//Tol1 = Max(pfirst.Distance(p11),Tol1);
} }
else { else {
// only second edge is closed // only second edge is closed
gp_XYZ pt = 0.5*(p11.XYZ()+ p12.XYZ()); ComputeToleranceVertex(V11, V12, V21, V1New);
pfirst.SetXYZ(0.5*(p21.XYZ() + pt));
gp_Vec v1 = p11.XYZ() - p12.XYZ();
Standard_Real d1 = v1.Magnitude();
Tol1 = ComputeToleranceVertex(d1,BRep_Tool::Tolerance(V11),BRep_Tool::Tolerance(V12));
gp_Vec v2 = p21.XYZ() - pt;
Standard_Real d2 = v2.Magnitude();
Tol1 = ComputeToleranceVertex(d2,Tol1,BRep_Tool::Tolerance(V21));
//Tol1 = Max(pfirst.Distance(p11),pfirst.Distance(p12));
//Tol1 = Max(pfirst.Distance(p21),Tol1);
} }
aBuilder.MakeVertex(V1New,pfirst,Tol1);
V2New = V1New; V2New = V1New;
} }
else { else {
// both edges are open // both edges are open
gp_Pnt plast;
Standard_Real Tol2 = 0.;
Standard_Boolean isOldFirst = ( secForward ? V11.IsSame(V21) : V11.IsSame(V22) ); Standard_Boolean isOldFirst = ( secForward ? V11.IsSame(V21) : V11.IsSame(V22) );
Standard_Boolean isOldLast = ( secForward ? V12.IsSame(V22) : V12.IsSame(V21)) ; Standard_Boolean isOldLast = ( secForward ? V12.IsSame(V22) : V12.IsSame(V21)) ;
if (secForward) { if (secForward) {
//case if vertices already sewed //case if vertices already sewed
if(!isOldFirst) if(!isOldFirst)
{ {
pfirst.SetXYZ(0.5*(p11.XYZ() + p21.XYZ())); ComputeToleranceVertex(V11, V21, V1New);
gp_Vec v1 = p21.XYZ() - p11.XYZ();
Standard_Real d1 = v1.Magnitude();
Tol1 = ComputeToleranceVertex(d1,BRep_Tool::Tolerance(V11),BRep_Tool::Tolerance(V21));
} }
if(!isOldLast) if(!isOldLast)
{ {
plast.SetXYZ(0.5*(p12.XYZ() + p22.XYZ())); ComputeToleranceVertex(V12, V22, V2New);
gp_Vec v2 = p22.XYZ() - p12.XYZ();
Standard_Real d2 = v2.Magnitude();
Tol2 = ComputeToleranceVertex(d2,BRep_Tool::Tolerance(V12),BRep_Tool::Tolerance(V22));
} }
} }
else { else {
if(!isOldFirst) if(!isOldFirst)
{ {
pfirst.SetXYZ(0.5*(p11.XYZ() + p22.XYZ())); ComputeToleranceVertex(V11, V22, V1New);
gp_Vec v1 = p22.XYZ() - p11.XYZ();
Standard_Real d1 = v1.Magnitude();
Tol1 = ComputeToleranceVertex(d1,BRep_Tool::Tolerance(V11),BRep_Tool::Tolerance(V22));
} }
if(!isOldLast) if(!isOldLast)
{ {
plast.SetXYZ(0.5*(p12.XYZ() + p21.XYZ())); ComputeToleranceVertex(V12, V21, V2New);
gp_Vec v2 = p21.XYZ() - p12.XYZ();
Standard_Real d2 = v2.Magnitude();
Tol2 = ComputeToleranceVertex(d2,BRep_Tool::Tolerance(V12),BRep_Tool::Tolerance(V21));
} }
} }
if(!isOldFirst) if(isOldFirst)
aBuilder.MakeVertex(V1New,pfirst,Tol1);
else
V1New = V11; V1New = V11;
if(isOldLast)
if(!isOldLast)
aBuilder.MakeVertex(V2New,plast,Tol2);
else
V2New = V12; V2New = V12;
} }
// Add the vertices in the good sense // Add the vertices in the good sense
TopoDS_Shape anEdge = edge.Oriented(TopAbs_FORWARD); TopoDS_Shape anEdge = edge.Oriented(TopAbs_FORWARD);
TopoDS_Shape aLocalEdge = V1New.Oriented(TopAbs_FORWARD); //(listNode.First()).Oriented(TopAbs_FORWARD); TopoDS_Shape aLocalEdge = V1New.Oriented(TopAbs_FORWARD); //(listNode.First()).Oriented(TopAbs_FORWARD);

View File

@ -14,18 +14,21 @@ sewing result +t 0.01 a b +mint 0.01 -a
set square 1.88469e+07 set square 1.88469e+07
set nb_v_good 478 checkmaxtol result 0.00087010032709666047
set nb_e_good 748 checkfreebounds result 12
set nb_w_good 273
set nb_f_good 259
set nb_sh_good 2
set nb_sol_good 0
set nb_compsol_good 0
set nb_compound_good 1
set nb_shape_good 1761
checkmaxtol result 0.002196807453775285 set nbshapes_expected "
checknbshapes result -shell 2 Number of shapes in shape
checkfreebounds result 10 VERTEX : 479
EDGE : 748
WIRE : 273
FACE : 259
SHELL : 2
SOLID : 0
COMPSOLID : 0
COMPOUND : 1
SHAPE : 1762
"
checknbshapes result -ref ${nbshapes_expected} -t -m "sewing result"
set 3dviewer 0 set 3dviewer 1

View File

@ -24,7 +24,7 @@ set nb_compsol_good 0
set nb_compound_good 1 set nb_compound_good 1
set nb_shape_good 1759 set nb_shape_good 1759
checkmaxtol result 0.002196807453775285 checkmaxtol result 0.00087010032709666047
checknbshapes result -shell 2 checknbshapes result -shell 2
checkfreebounds result 6 checkfreebounds result 6

View File

@ -25,7 +25,7 @@ set nb_compsol_good 0
set nb_compound_good 1 set nb_compound_good 1
set nb_shape_good 1756 set nb_shape_good 1756
checkmaxtol result 0.002196807453775285 checkmaxtol result 0.00087010032709666047
checknbshapes result -shell 2 checknbshapes result -shell 2
checkfreebounds result 0 checkfreebounds result 0

View File

@ -27,7 +27,7 @@ set nb_compsol_good 0
set nb_compound_good 1 set nb_compound_good 1
set nb_shape_good 1759 set nb_shape_good 1759
checkmaxtol result 0.002196807453775285 checkmaxtol result 0.00087010032709666047
checknbshapes result -shell 2 checknbshapes result -shell 2
checkfreebounds result 0 checkfreebounds result 0

View File

@ -27,8 +27,8 @@ set nb_compsol_good 0
set nb_compound_good 1 set nb_compound_good 1
set nb_shape_good 1761 set nb_shape_good 1761
checkmaxtol result 0.002196807453775285 checkmaxtol result 0.00087010032709666047
checknbshapes result -shell 2 checknbshapes result -shell 2
checkfreebounds result 4 checkfreebounds result 6
set 3dviewer 0 set 3dviewer 0

View File

@ -27,7 +27,7 @@ set nb_compsol_good 0
set nb_compound_good 1 set nb_compound_good 1
set nb_shape_good 1759 set nb_shape_good 1759
checkmaxtol result 0.002196807453775285 checkmaxtol result 0.00087010032709666047
checknbshapes result -shell 2 checknbshapes result -shell 2
checkfreebounds result 0 checkfreebounds result 0

View File

@ -25,7 +25,7 @@ set nb_compsol_good 0
set nb_compound_good 1 set nb_compound_good 1
set nb_shape_good 1762 set nb_shape_good 1762
checkmaxtol result 0.002196807453775285 checkmaxtol result 0.00087010032709666047
checknbshapes result -shell 2 checknbshapes result -shell 2
checkfreebounds result 9 checkfreebounds result 9

View File

@ -25,7 +25,7 @@ set nb_compsol_good 0
set nb_compound_good 1 set nb_compound_good 1
set nb_shape_good 1756 set nb_shape_good 1756
checkmaxtol result 0.002196807453775285 checkmaxtol result 0.00087010032709666047
checknbshapes result -shell 2 checknbshapes result -shell 2
checkfreebounds result 0 checkfreebounds result 0

View File

@ -25,7 +25,7 @@ set nb_compsol_good 0
set nb_compound_good 1 set nb_compound_good 1
set nb_shape_good 1756 set nb_shape_good 1756
checkmaxtol result 0.002196807453775285 checkmaxtol result 0.00087010032709666047
checknbshapes result -shell 2 checknbshapes result -shell 2
checkfreebounds result 0 checkfreebounds result 0

View File

@ -26,7 +26,7 @@ set nb_compsol_good 0
set nb_compound_good 1 set nb_compound_good 1
set nb_shape_good 1761 set nb_shape_good 1761
checkmaxtol result 0.002196807453775285 checkmaxtol result 0.00087010032709666047
checknbshapes result -shell 2 checknbshapes result -shell 2
checkfreebounds result 6 checkfreebounds result 6

View File

@ -24,7 +24,7 @@ set nb_compsol_good 0
set nb_compound_good 1 set nb_compound_good 1
set nb_shape_good 1759 set nb_shape_good 1759
checkmaxtol result 0.002196807453775285 checkmaxtol result 0.00087010032709666047
checknbshapes result -shell 2 checknbshapes result -shell 2
checkfreebounds result 6 checkfreebounds result 6

View File

@ -14,7 +14,7 @@ restore [locate_data_file bug24390_face2.brep] f2
sewing result f1 f2 sewing result f1 f2
checkshape result checkshape result
checkmaxtol result 0.028334611098393123 {f1 f2} -min_tol 0 -multi_tol 5. checkmaxtol result 0.016556973295771653 {f1 f2} -min_tol 0 -multi_tol 5.
checknbshapes result -shell 1 checknbshapes result -shell 1
checkfreebounds result 6 checkfreebounds result 6

View File

@ -15,7 +15,7 @@ whatis r
regexp {Tolerance +MAX=([-0-9.+eE]+)} [tolerance r] full MaxTolerance regexp {Tolerance +MAX=([-0-9.+eE]+)} [tolerance r] full MaxTolerance
puts "MaxTolerance=$MaxTolerance" puts "MaxTolerance=$MaxTolerance"
set expected_MaxTolerance 0.00082956492865075794 set expected_MaxTolerance 0.00068453844086764995
set tol_abs_MaxTolerance 0.00001 set tol_abs_MaxTolerance 0.00001
set tol_rel_MaxTolerance 0.00001 set tol_rel_MaxTolerance 0.00001
checkreal "MaxTolerance" ${MaxTolerance} ${expected_MaxTolerance} ${tol_abs_MaxTolerance} ${tol_rel_MaxTolerance} checkreal "MaxTolerance" ${MaxTolerance} ${expected_MaxTolerance} ${tol_abs_MaxTolerance} ${tol_rel_MaxTolerance}

22
tests/bugs/modalg_6/bug26241 Executable file
View File

@ -0,0 +1,22 @@
puts "========"
puts "OCC26241"
puts "========"
puts ""
###########################################################
# Sewing algorithm computes tolerance of joint vertex too rough
###########################################################
plane p 0 0 0 0 0 1 1 0 0
mkface f1 p 0 10 0 10
mkface f2 p 0 10 11 21
settolerance f1 2
settolerance f2 3
sewing res 3 f1 f2
regexp {Tolerance +MAX=([-0-9.+eE]+)} [tolerance res] full MaxTolerance
puts "MaxTolerance=$MaxTolerance"
set expected_MaxTolerance 3.0
set tol_abs_MaxTolerance 0.1
set tol_rel_MaxTolerance 0.1
checkreal "MaxTolerance" ${MaxTolerance} ${expected_MaxTolerance} ${tol_abs_MaxTolerance} ${tol_rel_MaxTolerance}

View File

@ -18,7 +18,7 @@ if [catch {igesbrep $filepath a *} catch_result] {
# #
sewing result1 100. a sewing result1 100. a
checkmaxtol result1 0.21325393968565914 checkmaxtol result1 0.20874930847108514
checknbshapes result1 -shell 1 checknbshapes result1 -shell 1
checkfreebounds result1 86 checkfreebounds result1 86
@ -71,7 +71,7 @@ if [catch {igesbrep $filepath a *} catch_result] {
tpcompound a tpcompound a
sewing result2 100. a sewing result2 100. a
checkmaxtol result2 0.21325393968565914 checkmaxtol result2 0.20874930847108514
checknbshapes result2 -shell 1 checknbshapes result2 -shell 1
checkfreebounds result2 86 checkfreebounds result2 86

View File

@ -34,7 +34,7 @@ if { [llength $closed_wires] != 1} {
puts "Error : Amount of free closed wires is not equal 1" puts "Error : Amount of free closed wires is not equal 1"
} }
checkmaxtol result 0.21325393955468794 checkmaxtol result 0.20874930847108514
checknbshapes result -shell 1 checknbshapes result -shell 1
checkfreebounds result 86 checkfreebounds result 86

2
tests/sewing/tol_1/S5 Normal file → Executable file
View File

@ -2,7 +2,7 @@ restore [locate_data_file CIN001_a20.rle] a
sewing result $tol a sewing result $tol a
checkmaxtol result 0.0049520649253341166 checkmaxtol result 0.0035009498713573254
checknbshapes result -shell 1 checknbshapes result -shell 1
checkfreebounds result 74 checkfreebounds result 74
checkfaults result a 0 checkfaults result a 0

4
tests/sewing/tol_100/I5 Normal file → Executable file
View File

@ -4,7 +4,7 @@ restore [locate_data_file CIN901_intcqhmi.rle] a
sewing result $tol a sewing result $tol a
checkmaxtol result 27.029859224903987 checkmaxtol result 15.355207687279844
checknbshapes result -shell 1 checknbshapes result -shell 1
checkfreebounds result 0 checkfreebounds result 3
checkfaults result a 6 checkfaults result a 6

2
tests/sewing/tol_100/I6 Normal file → Executable file
View File

@ -4,7 +4,7 @@ restore [locate_data_file CIN901_intcqhmj.rle] a
sewing result $tol a sewing result $tol a
checkmaxtol result 153.66065674630602 checkmaxtol result 71.039012505679182
checknbshapes result -shell 1 checknbshapes result -shell 1
checkfreebounds result 34 checkfreebounds result 34
checkfaults result a 3 checkfaults result a 3

2
tests/sewing/tol_100/I9 Normal file → Executable file
View File

@ -4,7 +4,7 @@ restore [locate_data_file CIN902_intcqhmm.rle] a
sewing result $tol a sewing result $tol a
checkmaxtol result 30.472070989451943 checkmaxtol result 15.98267511059735
checknbshapes result -shell 1 checknbshapes result -shell 1
checkfreebounds result 28 checkfreebounds result 28
checkfaults result a 11 checkfaults result a 11

2
tests/sewing/tol_100/J3 Normal file → Executable file
View File

@ -4,7 +4,7 @@ restore [locate_data_file CIN902_intcqhmp.rle] a
sewing result $tol a sewing result $tol a
checkmaxtol result 268.87290128183184 checkmaxtol result 122.47700432877426
checknbshapes result -shell 1 checknbshapes result -shell 1
checkfreebounds result 19 checkfreebounds result 19
checkfaults result a 7 checkfaults result a 7

View File

@ -2,7 +2,7 @@ restore [locate_data_file ma-test3.rle] a
sewing result $tol a sewing result $tol a
checkmaxtol result 6.2643182979358158 checkmaxtol result 5.8186555567983991
checknbshapes result -shell 1 checknbshapes result -shell 1
checkfreebounds result 0 checkfreebounds result 0
checkfaults result a 0 checkfaults result a 0

2
tests/sewing/tol_100/U1 Normal file → Executable file
View File

@ -2,7 +2,7 @@ restore [locate_data_file ma-test5.rle] a
sewing result $tol a sewing result $tol a
checkmaxtol result 2.1507390207569199 checkmaxtol result 1.14347452525616
checknbshapes result -shell 1 checknbshapes result -shell 1
checkfreebounds result 0 checkfreebounds result 0
checkfaults result a 0 checkfaults result a 0