1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-16 10:08:36 +03:00

0029405: Modeling Algorithms - Check normal define status in HLRBRep_Data

Fixed exception when trying to calculate line and edge normal in methods HLRBRep_Data::OrientOutLine and HLRBRep_Data::OrientOthEdge, added a check for the existence of the normal before subsequent calculations. A correct check for zero derivative, correction of floating point error and division by zero determinant directly in HLRBRep_EdgeFaceTool::CurvatureValue was set.
This commit is contained in:
vkuzin 2021-08-13 14:43:22 +03:00 committed by smoskvin
parent f1c209dc77
commit 96b92906de
3 changed files with 69 additions and 56 deletions

View File

@ -1543,6 +1543,7 @@ Standard_Boolean HLRBRep_Data::OrientOutLine (const Standard_Integer I, HLRBRep_
V = gp_Dir(0,0,-1); V = gp_Dir(0,0,-1);
} }
V.Transform(TI); V.Transform(TI);
if (mySLProps.IsNormalDefined()) {
Standard_Real curv = HLRBRep_EdgeFaceTool::CurvatureValue Standard_Real curv = HLRBRep_EdgeFaceTool::CurvatureValue
(iFaceGeom,pu,pv,V); (iFaceGeom,pu,pv,V);
gp_Vec Nm = mySLProps.Normal(); gp_Vec Nm = mySLProps.Normal();
@ -1568,7 +1569,7 @@ Standard_Boolean HLRBRep_Data::OrientOutLine (const Standard_Integer I, HLRBRep_
} }
if (myProj.Perspective()) if (myProj.Perspective())
r = Nm.Z() * myProj.Focus() - r = Nm.Z() * myProj.Focus() -
( Nm.X() * Pt.X() + Nm.Y() * Pt.Y() + Nm.Z() * Pt.Z() ); (Nm.X() * Pt.X() + Nm.Y() * Pt.Y() + Nm.Z() * Pt.Z());
else else
r = Nm.Z(); r = Nm.Z();
myFEOri = (r > 0) ? TopAbs_FORWARD : TopAbs_REVERSED; myFEOri = (r > 0) ? TopAbs_FORWARD : TopAbs_REVERSED;
@ -1579,7 +1580,8 @@ Standard_Boolean HLRBRep_Data::OrientOutLine (const Standard_Integer I, HLRBRep_
inverted = Standard_True; inverted = Standard_True;
} }
} }
eb1->Orientation(ie1,myFEOri); eb1->Orientation(ie1, myFEOri);
}
} }
else { else {
#ifdef OCCT_DEBUG #ifdef OCCT_DEBUG
@ -1627,19 +1629,21 @@ void HLRBRep_Data::OrientOthEdge (const Standard_Integer I,
if (HLRBRep_EdgeFaceTool::UVPoint(p,myFEGeom,iFaceGeom,pu,pv)) { if (HLRBRep_EdgeFaceTool::UVPoint(p,myFEGeom,iFaceGeom,pu,pv)) {
gp_Pnt Pt = EC.Value3D(p); gp_Pnt Pt = EC.Value3D(p);
mySLProps.SetParameters(pu,pv); mySLProps.SetParameters(pu,pv);
if (mySLProps.IsNormalDefined()) {
gp_Vec Nm = mySLProps.Normal(); gp_Vec Nm = mySLProps.Normal();
Pt.Transform(T); Pt.Transform(T);
Nm.Transform(T); Nm.Transform(T);
if (myProj.Perspective()) { if (myProj.Perspective()) {
r = Nm.Z() * myProj.Focus() - r = Nm.Z() * myProj.Focus() -
( Nm.X() * Pt.X() + Nm.Y() * Pt.Y() + Nm.Z() * Pt.Z() ); (Nm.X() * Pt.X() + Nm.Y() * Pt.Y() + Nm.Z() * Pt.Z());
} }
else { else {
r = Nm.Z(); r = Nm.Z();
} }
if (r < 0) { if (r < 0) {
myFEOri = TopAbs::Reverse(myFEOri); myFEOri = TopAbs::Reverse(myFEOri);
eb1->Orientation(ie1,myFEOri); eb1->Orientation(ie1, myFEOri);
}
} }
} }
#ifdef OCCT_DEBUG #ifdef OCCT_DEBUG

View File

@ -45,17 +45,17 @@ Standard_Real HLRBRep_EdgeFaceTool::CurvatureValue
Standard_Real nmu2 = D1U*D1U; Standard_Real nmu2 = D1U*D1U;
Standard_Real nmv2 = D1V*D1V; Standard_Real nmv2 = D1V*D1V;
Standard_Real det = nmu2 * nmv2 - d1ud1v * d1ud1v; Standard_Real det = nmu2 * nmv2 - d1ud1v * d1ud1v;
Standard_Real alfa = ( d1ut * nmv2 - d1vt * d1ud1v ) / det; if (det > gp::Resolution()) {
Standard_Real beta = ( d1vt * nmu2 - d1ut * d1ud1v ) / det; Standard_Real alfa = (d1ut * nmv2 - d1vt * d1ud1v) / det;
Standard_Real beta = (d1vt * nmu2 - d1ut * d1ud1v) / det;
Standard_Real alfa2 = alfa * alfa;
Standard_Real beta2 = beta * beta;
Standard_Real alfabeta = alfa * beta;
gp_Vec Nm = D1U ^ D1V; gp_Vec Nm = D1U ^ D1V;
if (Nm.Magnitude() > gp::Resolution()) {
Nm.Normalize(); Nm.Normalize();
Standard_Real alfa2 = alfa*alfa; Standard_Real N = (Nm * D2U) * alfa2 + 2 * (Nm * D2UV) * alfabeta + (Nm * D2V) * beta2;
Standard_Real beta2 = beta*beta; Standard_Real D = nmu2 * alfa2 + 2 * d1ud1v * alfabeta + nmv2 * beta2;
Standard_Real alfabeta = alfa*beta; return N / D;
Standard_Real N = (Nm*D2U)*alfa2 + 2*(Nm*D2UV)*alfabeta + (Nm*D2V)*beta2;
Standard_Real D = nmu2 *alfa2 + 2*d1ud1v *alfabeta + nmv2 *beta2;
return N/D;
} }
return 0.; return 0.;
} }

View File

@ -0,0 +1,9 @@
puts "============================================"
puts "OCC29405: Modeling Algorithms - Check normal define status in HLRBRep_Data"
puts "============================================"
puts ""
pload ALL
ptorus t 17.37 17.37 [dval 2.35*180/pi]
vdisplay t
vcomputehlr t t2 -algotype algo 0 50 0 0 -50 0 0 0 1