1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-07-10 12:25:50 +03:00

0024206: Exception is raised in the STEP loopback tests.

Fixed several cases of potentially uninitialized variables in Shape Healing.
Corrections to avoid warning for unused variable distmini and to avoid regression for case bug22805
This commit is contained in:
gka 2013-10-24 11:48:44 +04:00 committed by bugmaster
parent 8da5fb19a9
commit 62f225930c
2 changed files with 146 additions and 104 deletions

View File

@ -176,27 +176,46 @@ Standard_Real ShapeAnalysis_Curve::Project(const Adaptor3d_Curve& C3D,
const Standard_Boolean AdjustToEnds) const const Standard_Boolean AdjustToEnds) const
{ {
Standard_Real uMin = C3D.FirstParameter(); Standard_Real uMin = C3D.FirstParameter();
Standard_Real uMax = C3D.LastParameter(); Standard_Real uMax = C3D.LastParameter();
Standard_Real distmin;
if (!Precision::IsInfinite(uMin)||!Precision::IsInfinite(uMax)) { if (Precision::IsInfinite(uMin) && Precision::IsInfinite(uMax))
Standard_Real prec = ( AdjustToEnds ? preci : Precision::Confusion() ); //:j8 abv 10 Dec 98: tr10_r0501_db.stp #9423: protection against densing of points near one end return ProjectAct(C3D, P3D, preci, proj, param);
gp_Pnt LowBound = C3D.Value(uMin);
gp_Pnt HigBound = C3D.Value(uMax); Standard_Real distmin_L = Precision::Infinite(), distmin_H = Precision::Infinite();
distmin = LowBound.Distance(P3D); Standard_Real prec = ( AdjustToEnds ? preci : Precision::Confusion() ); //:j8 abv 10 Dec 98: tr10_r0501_db.stp #9423: protection against densing of points near one end
if (distmin <= prec) { gp_Pnt LowBound = C3D.Value(uMin);
param = uMin; gp_Pnt HigBound = C3D.Value(uMax);
proj = LowBound; distmin_L = LowBound.Distance(P3D);
return distmin; distmin_H = HigBound.Distance(P3D);
}
distmin = HigBound.Distance(P3D); if (distmin_L <= prec) {
if (distmin <= prec) { param = uMin;
param = uMax; proj = LowBound;
proj = HigBound; return distmin_L;
return distmin;
}
} }
return ProjectAct(C3D, P3D, preci, proj, param);
if (distmin_H <= prec) {
param = uMax;
proj = HigBound;
return distmin_H;
}
Standard_Real distProj = ProjectAct(C3D, P3D, preci, proj, param);
if( distProj < distmin_L + Precision::Confusion() && distProj < distmin_H + Precision::Confusion())
return distProj;
if( distmin_L < distmin_H)
{
param = uMin;
proj = LowBound;
return distmin_L;
}
param = uMax;
proj = HigBound;
return distmin_H;
} }
//======================================================================= //=======================================================================
@ -212,6 +231,7 @@ Standard_Real ShapeAnalysis_Curve::ProjectAct(const Adaptor3d_Curve& C3D,
{ {
Standard_Boolean OK = Standard_False; Standard_Boolean OK = Standard_False;
param = 0.;
try { try {
OCC_CATCH_SIGNALS OCC_CATCH_SIGNALS
Extrema_ExtPC myExtPC(P3D,C3D); Extrema_ExtPC myExtPC(P3D,C3D);
@ -234,11 +254,11 @@ Standard_Real ShapeAnalysis_Curve::ProjectAct(const Adaptor3d_Curve& C3D,
Standard_Failure::Caught()->Print(cout); cout << endl; Standard_Failure::Caught()->Print(cout); cout << endl;
#endif #endif
} }
//szv#4:S4163:12Mar99 moved //szv#4:S4163:12Mar99 moved
Standard_Real uMin = C3D.FirstParameter(), uMax = C3D.LastParameter(); Standard_Real uMin = C3D.FirstParameter(), uMax = C3D.LastParameter();
Standard_Boolean closed = Standard_False; // si on franchit les bornes ... Standard_Boolean closed = Standard_False; // si on franchit les bornes ...
Standard_Real distmin = RealLast(), valclosed = 0.; Standard_Real distmin = Precision::Infinite(), valclosed = 0.;
Standard_Real aModParam = param; Standard_Real aModParam = param;
Standard_Real aModMin = distmin; Standard_Real aModMin = distmin;
@ -386,7 +406,7 @@ Standard_Real ShapeAnalysis_Curve::NextProject(const Standard_Real paramPrev,
{ {
Standard_Real uMin = (cf < cl ? cf : cl); Standard_Real uMin = (cf < cl ? cf : cl);
Standard_Real uMax = (cf < cl ? cl : cf); Standard_Real uMax = (cf < cl ? cl : cf);
Standard_Real distmin; Standard_Real distmin = Precision::Infinite();
if (C3D->IsKind(STANDARD_TYPE(Geom_BoundedCurve))) { if (C3D->IsKind(STANDARD_TYPE(Geom_BoundedCurve))) {
Standard_Real prec = ( AdjustToEnds ? preci : Precision::Confusion() ); //:j8 abv 10 Dec 98: tr10_r0501_db.stp #9423: protection against densing of points near one end Standard_Real prec = ( AdjustToEnds ? preci : Precision::Confusion() ); //:j8 abv 10 Dec 98: tr10_r0501_db.stp #9423: protection against densing of points near one end
gp_Pnt LowBound = C3D->Value(uMin); gp_Pnt LowBound = C3D->Value(uMin);

View File

@ -81,6 +81,7 @@ void ShapeFix_EdgeProjAux::Init (const TopoDS_Face& F,
{ {
myFace = F; myFace = F;
myEdge = E; myEdge = E;
myFirstParam = myLastParam = 0.;
myFirstDone = myLastDone = Standard_False; myFirstDone = myLastDone = Standard_False;
} }
@ -232,7 +233,8 @@ void ShapeFix_EdgeProjAux::Init2d (const Standard_Real preci)
Handle(Geom_Surface) theSurface = BRep_Tool::Surface(myFace); Handle(Geom_Surface) theSurface = BRep_Tool::Surface(myFace);
Handle(Geom2d_Curve) theCurve2d = BRep_Tool::CurveOnSurface(myEdge, myFace, cf, cl); Handle(Geom2d_Curve) theCurve2d = BRep_Tool::CurveOnSurface(myEdge, myFace, cf, cl);
if ( theCurve2d.IsNull() ) return; //:r5 abv 6 Apr 99: ec_turbine-A.stp, #4313 if ( theCurve2d.IsNull() ) return; //:r5 abv 6 Apr 99: ec_turbine-A.stp, #4313
myFirstParam = cf;
myLastParam = cl;
TopoDS_Vertex V1,V2; TopoDS_Vertex V1,V2;
TopExp::Vertices(myEdge, V1, V2); TopExp::Vertices(myEdge, V1, V2);
gp_Pnt Pt1,Pt2; gp_Pnt Pt1,Pt2;
@ -248,34 +250,34 @@ void ShapeFix_EdgeProjAux::Init2d (const Standard_Real preci)
Pt1 = BRep_Tool::Pnt(V1); Pt1 = BRep_Tool::Pnt(V1);
Pt2 = BRep_Tool::Pnt(V2); Pt2 = BRep_Tool::Pnt(V2);
} }
//:S4136 Standard_Real preci = BRepAPI::Precision(); //:S4136 Standard_Real preci = BRepAPI::Precision();
//pdn to manage degenerated case //pdn to manage degenerated case
if (V1.IsSame(V2)) { if (V1.IsSame(V2)) {
Handle(ShapeAnalysis_Surface) stsu = new ShapeAnalysis_Surface (theSurface); Handle(ShapeAnalysis_Surface) stsu = new ShapeAnalysis_Surface (theSurface);
gp_Pnt2d aPt1,aPt2; gp_Pnt2d aPt1,aPt2;
Standard_Real firstpar,lastpar; Standard_Real firstpar,lastpar;
if (stsu->DegeneratedValues(Pt1,preci,aPt1,aPt2,firstpar,lastpar)){ if (stsu->DegeneratedValues(Pt1,preci,aPt1,aPt2,firstpar,lastpar)){
if(theCurve2d->IsKind(STANDARD_TYPE(Geom2d_Line))) { if(theCurve2d->IsKind(STANDARD_TYPE(Geom2d_Line))) {
if (aPt1.IsEqual(theCurve2d->Value(firstpar),preci) && if (aPt1.IsEqual(theCurve2d->Value(firstpar),preci) &&
aPt2.IsEqual(theCurve2d->Value(lastpar),preci)){ aPt2.IsEqual(theCurve2d->Value(lastpar),preci)){
myFirstParam = firstpar; myFirstParam = firstpar;
myLastParam = lastpar; myLastParam = lastpar;
myFirstDone = myLastDone = Standard_True; myFirstDone = myLastDone = Standard_True;
return; return;
} }
} }
#ifdef DEBUG #ifdef DEBUG
else cout <<"Other type of deg curve"<<endl; else cout <<"Other type of deg curve"<<endl;
#endif #endif
} }
} }
Standard_Boolean parU = Standard_False, parV = Standard_False; Standard_Boolean parU = Standard_False, parV = Standard_False;
GeomAdaptor_Surface SA = GeomAdaptor_Surface(theSurface); GeomAdaptor_Surface SA = GeomAdaptor_Surface(theSurface);
Handle(GeomAdaptor_HSurface) myHSur = new GeomAdaptor_HSurface(SA); Handle(GeomAdaptor_HSurface) myHSur = new GeomAdaptor_HSurface(SA);
cf = theCurve2d->FirstParameter(); cf = theCurve2d->FirstParameter();
cl = theCurve2d->LastParameter(); cl = theCurve2d->LastParameter();
//pdn cutting pcurve by suface bounds //pdn cutting pcurve by suface bounds
@ -284,60 +286,60 @@ void ShapeFix_EdgeProjAux::Init2d (const Standard_Real preci)
Standard_Real uf,ul,vf,vl; Standard_Real uf,ul,vf,vl;
theSurface->Bounds(uf,ul,vf,vl); theSurface->Bounds(uf,ul,vf,vl);
if(!Precision::IsInfinite(uf)&&!Precision::IsInfinite(ul)&& if(!Precision::IsInfinite(uf)&&!Precision::IsInfinite(ul)&&
!Precision::IsInfinite(vf)&&!Precision::IsInfinite(vl)) { !Precision::IsInfinite(vf)&&!Precision::IsInfinite(vl)) {
Standard_Real cfi,cli; Standard_Real cfi,cli;
Handle(Geom2d_Line) lin = Handle(Geom2d_Line)::DownCast(theCurve2d); Handle(Geom2d_Line) lin = Handle(Geom2d_Line)::DownCast(theCurve2d);
gp_Pnt2d pnt = lin->Location(); gp_Pnt2d pnt = lin->Location();
gp_Dir2d dir = lin->Direction(); gp_Dir2d dir = lin->Direction();
if (dir.Y()==0) { if (dir.Y()==0) {
parU = Standard_True; parU = Standard_True;
cfi = (uf-pnt.X())/dir.X(); cfi = (uf-pnt.X())/dir.X();
cli = (ul-pnt.X())/dir.X(); cli = (ul-pnt.X())/dir.X();
} }
else if (dir.X()==0) { else if (dir.X()==0) {
parV = Standard_True; parV = Standard_True;
cfi = (vf-pnt.Y())/dir.Y(); cfi = (vf-pnt.Y())/dir.Y();
cli = (vl-pnt.Y())/dir.Y(); cli = (vl-pnt.Y())/dir.Y();
} }
else {//common case else {//common case
Standard_Real xfi, xli, yfi, yli; Standard_Real xfi, xli, yfi, yli;
xfi = (uf-pnt.X())/dir.X(); xfi = (uf-pnt.X())/dir.X();
xli = (ul-pnt.X())/dir.X(); xli = (ul-pnt.X())/dir.X();
yfi = (vf-pnt.Y())/dir.Y(); yfi = (vf-pnt.Y())/dir.Y();
yli = (vl-pnt.Y())/dir.Y(); yli = (vl-pnt.Y())/dir.Y();
if (dir.X()*dir.Y() > 0) { if (dir.X()*dir.Y() > 0) {
cfi = (Abs(xli-xfi) < Abs(xli-yfi)? xfi : yfi); cfi = (Abs(xli-xfi) < Abs(xli-yfi)? xfi : yfi);
cli = (Abs(xfi-xli) < Abs(xfi-yli)? xli : yli); cli = (Abs(xfi-xli) < Abs(xfi-yli)? xli : yli);
} else { } else {
cfi = (Abs(xli-xfi) < Abs(xli-yli)? xfi : yli); cfi = (Abs(xli-xfi) < Abs(xli-yli)? xfi : yli);
cli = (Abs(yli-xli) < Abs(yli-yfi)? xli : yfi); cli = (Abs(yli-xli) < Abs(yli-yfi)? xli : yfi);
} }
} }
if (cfi < cli) { cf = cfi; cl = cli; } if (cfi < cli) { cf = cfi; cl = cli; }
else { cf = cli; cl = cfi; } else { cf = cli; cl = cfi; }
} }
else if(!Precision::IsInfinite(uf)&&!Precision::IsInfinite(ul)){ else if(!Precision::IsInfinite(uf)&&!Precision::IsInfinite(ul)){
Handle(Geom2d_Line) lin = Handle(Geom2d_Line)::DownCast(theCurve2d); Handle(Geom2d_Line) lin = Handle(Geom2d_Line)::DownCast(theCurve2d);
gp_Dir2d dir = lin->Direction(); gp_Dir2d dir = lin->Direction();
if (dir.X()!=0) { if (dir.X()!=0) {
if (dir.Y()==0) parU = Standard_True; if (dir.Y()==0) parU = Standard_True;
gp_Pnt2d pnt = lin->Location(); //szv#4:S4163:12Mar99 moved gp_Pnt2d pnt = lin->Location(); //szv#4:S4163:12Mar99 moved
Standard_Real cfi = (uf-pnt.X())/dir.X(); Standard_Real cfi = (uf-pnt.X())/dir.X();
Standard_Real cli = (ul-pnt.X())/dir.X(); Standard_Real cli = (ul-pnt.X())/dir.X();
if (cfi < cli) { cf = cfi; cl = cli; } if (cfi < cli) { cf = cfi; cl = cli; }
else { cf = cli; cl = cfi; } else { cf = cli; cl = cfi; }
} }
else { else {
cf=-10000; cf=-10000;
cl= 10000; cl= 10000;
} }
} }
else { else {
cf=-10000; cf=-10000;
cl= 10000; cl= 10000;
//pdn not cutted by bounds //pdn not cutted by bounds
#ifdef DEBUG #ifdef DEBUG
cout<<"Infinite Surface"<<endl; cout<<"Infinite Surface"<<endl;
#endif #endif
} }
} }
@ -350,10 +352,11 @@ void ShapeFix_EdgeProjAux::Init2d (const Standard_Real preci)
#endif #endif
} }
} }
myFirstParam = cf;
myLastParam = cl;
Geom2dAdaptor_Curve CA = Geom2dAdaptor_Curve(theCurve2d,cf,cl); Geom2dAdaptor_Curve CA = Geom2dAdaptor_Curve(theCurve2d,cf,cl);
Handle(Geom2dAdaptor_HCurve) myHCur = new Geom2dAdaptor_HCurve(CA); Handle(Geom2dAdaptor_HCurve) myHCur = new Geom2dAdaptor_HCurve(CA);
Adaptor3d_CurveOnSurface COnS = Adaptor3d_CurveOnSurface(myHCur, myHSur); Adaptor3d_CurveOnSurface COnS = Adaptor3d_CurveOnSurface(myHCur, myHSur);
// ---------------------------------------------- // ----------------------------------------------
@ -361,15 +364,34 @@ void ShapeFix_EdgeProjAux::Init2d (const Standard_Real preci)
// ---------------------------------------------- // ----------------------------------------------
Standard_Real Uinf = COnS.FirstParameter(); Standard_Real Uinf = COnS.FirstParameter();
Standard_Real Usup = COnS.LastParameter(); Standard_Real Usup = COnS.LastParameter();
myFirstDone = myLastDone = Standard_True;
Standard_Real w1,w2; Standard_Real w1 = 0., w2 = 0.;
ShapeAnalysis_Curve sac; ShapeAnalysis_Curve sac;
gp_Pnt pnt; gp_Pnt pnt;
Standard_Real dist = sac.Project(COnS,Pt1,preci,pnt,w1,Standard_False); Standard_Real dist = sac.Project(COnS,Pt1,preci,pnt,w1,Standard_False);
if (dist > preci) return; //if distance is infinite then projection is not performed
if( Precision::IsInfinite(dist))
{
myFirstDone = Standard_False;
myLastDone = Standard_False;
return;
}
if (dist > preci)
return;
dist = sac.Project(COnS,Pt2,preci,pnt,w2,Standard_False); dist = sac.Project(COnS,Pt2,preci,pnt,w2,Standard_False);
if (dist > preci) return; if( Precision::IsInfinite(dist))
{
myLastDone = Standard_False;
return;
}
if (dist > preci)
return;
if(fabs(w1 - w2) < Precision::PConfusion())
{
if(!theSurface->IsUPeriodic() && !theSurface->IsVPeriodic())
return;
}
myFirstParam = w1; myFirstParam = w1;
myLastParam = w2; myLastParam = w2;
myFirstDone = myLastDone = Standard_True; myFirstDone = myLastDone = Standard_True;
@ -387,14 +409,14 @@ void ShapeFix_EdgeProjAux::Init2d (const Standard_Real preci)
if ( COnS.Value(Uinf).Distance ( COnS.Value(Usup) ) < Precision::Confusion() ) { if ( COnS.Value(Uinf).Distance ( COnS.Value(Usup) ) < Precision::Confusion() ) {
// 18.11.2002 SKL OCC630 compare values with tolerance Precision::PConfusion() instead of "==" // 18.11.2002 SKL OCC630 compare values with tolerance Precision::PConfusion() instead of "=="
if ( Abs(myFirstParam-Uinf) < ::Precision::PConfusion() && if ( Abs(myFirstParam-Uinf) < ::Precision::PConfusion() &&
Abs(myLastParam-Uinf) < ::Precision::PConfusion() ) Abs(myLastParam-Uinf) < ::Precision::PConfusion() )
myLastParam = w2 = Usup; myLastParam = w2 = Usup;
// 18.11.2002 SKL OCC630 compare values with tolerance Precision::PConfusion() instead of "==" // 18.11.2002 SKL OCC630 compare values with tolerance Precision::PConfusion() instead of "=="
else if ( Abs(myFirstParam-Usup) < ::Precision::PConfusion() && else if ( Abs(myFirstParam-Usup) < ::Precision::PConfusion() &&
Abs(myLastParam-Usup) < ::Precision::PConfusion() ) Abs(myLastParam-Usup) < ::Precision::PConfusion() )
myFirstParam = w1 = Uinf; myFirstParam = w1 = Uinf;
} }
//pdn adjust parameters in periodic case //pdn adjust parameters in periodic case
if(parU || parV) { if(parU || parV) {
Standard_Real uf,ul,vf,vl; Standard_Real uf,ul,vf,vl;
@ -416,24 +438,24 @@ void ShapeFix_EdgeProjAux::Init2d (const Standard_Real preci)
if(w1>w2) { if(w1>w2) {
if(w2 > wmid) myFirstParam -= period; if(w2 > wmid) myFirstParam -= period;
else if (w1 > wmid) else if (w1 > wmid)
UpdateParam2d(theCurve2d); UpdateParam2d(theCurve2d);
else { else {
myLastParam+=period; myLastParam+=period;
#ifdef DEBUG #ifdef DEBUG
cout <<" Added"<<endl; cout <<" Added"<<endl;
#endif #endif
} }
} }
else { else {
if(w1 > wmid) { if(w1 > wmid) {
myLastParam -=period; myLastParam -=period;
UpdateParam2d(theCurve2d); UpdateParam2d(theCurve2d);
#ifdef DEBUG #ifdef DEBUG
cout <<" Added & Inverted"<<endl; cout <<" Added & Inverted"<<endl;
#endif #endif
} else if (w2 < wmid) { } else if (w2 < wmid) {
myFirstParam += period; myFirstParam += period;
UpdateParam2d(theCurve2d); UpdateParam2d(theCurve2d);
} }
} }
} }
@ -455,7 +477,7 @@ void ShapeFix_EdgeProjAux::Init3d (const Standard_Real preci)
Handle(Geom2d_Curve) theCurve2d = BRep_Tool::CurveOnSurface(myEdge, myFace, cf, cl); Handle(Geom2d_Curve) theCurve2d = BRep_Tool::CurveOnSurface(myEdge, myFace, cf, cl);
if ( theCurve2d.IsNull() ) return; //:r5 abv 6 Apr 99: ec_turbine-A.stp, #4313 if ( theCurve2d.IsNull() ) return; //:r5 abv 6 Apr 99: ec_turbine-A.stp, #4313
TopoDS_Vertex V1,V2; TopoDS_Vertex V1,V2;
V1 = TopExp::FirstVertex(myEdge); V1 = TopExp::FirstVertex(myEdge);
V2 = TopExp::LastVertex(myEdge); V2 = TopExp::LastVertex(myEdge);
gp_Pnt Pt1 = BRep_Tool::Pnt(V1); gp_Pnt Pt1 = BRep_Tool::Pnt(V1);