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

0024955: Misuse of DownCast

Code where DownCast was applied to Handle of the type being not a base class of the target one is revised and (hopefully) corrected.
Code corrected following review remarks
GeomConvert::CurveToBSplineCurve() is called even for b-spline curves to ensure that result is non-periodic
Check for conic is corrected
This commit is contained in:
abv
2014-06-05 14:14:14 +04:00
committed by apn
parent 3a01a933af
commit 5e5b6f81c1
7 changed files with 182 additions and 204 deletions

View File

@@ -848,6 +848,76 @@ void BRepOffsetAPI_ThruSections::CreateSmoothed()
}
}
//=======================================================================
//function : EdgeToBSpline
//purpose : auxiliary -- get curve from edge and convert it to bspline
// parameterized from 0 to 1
//=======================================================================
// NOTE: this code duplicates the same function in BRepFill_NSections.cxx
static Handle(Geom_BSplineCurve) EdgeToBSpline (const TopoDS_Edge& theEdge)
{
Handle(Geom_BSplineCurve) aBSCurve;
if (BRep_Tool::Degenerated(theEdge)) {
// degenerated edge : construction of a point curve
TColStd_Array1OfReal aKnots (1,2);
aKnots(1) = 0.;
aKnots(2) = 1.;
TColStd_Array1OfInteger aMults (1,2);
aMults(1) = 2;
aMults(2) = 2;
TColgp_Array1OfPnt aPoles(1,2);
TopoDS_Vertex vf, vl;
TopExp::Vertices(theEdge,vl,vf);
aPoles(1) = BRep_Tool::Pnt(vf);
aPoles(2) = BRep_Tool::Pnt(vl);
aBSCurve = new Geom_BSplineCurve (aPoles, aKnots, aMults, 1);
}
else
{
// get the curve of the edge
TopLoc_Location aLoc;
Standard_Real aFirst, aLast;
Handle(Geom_Curve) aCurve = BRep_Tool::Curve (theEdge, aLoc, aFirst, aLast);
// convert its part used by edge to bspline; note that if edge curve is bspline,
// conversion made via trimmed curve is still needed -- it will copy it, segment
// as appropriate, and remove periodicity if it is periodic (deadly for approximator)
Handle(Geom_TrimmedCurve) aTrimCurve = new Geom_TrimmedCurve (aCurve, aFirst, aLast);
// special treatment of conic curve
if (aTrimCurve->BasisCurve()->IsKind(STANDARD_TYPE(Geom_Conic)))
{
GeomConvert_ApproxCurve anAppr (aTrimCurve, Precision::Confusion(), GeomAbs_C1, 16, 14);
if (anAppr.HasResult())
aBSCurve = anAppr.Curve();
}
// general case
if (aBSCurve.IsNull())
aBSCurve = GeomConvert::CurveToBSplineCurve (aTrimCurve);
// apply transformation if needed
if (! aLoc.IsIdentity())
aBSCurve->Transform (aLoc.Transformation());
// reparameterize to [0,1]
TColStd_Array1OfReal aKnots (1, aBSCurve->NbKnots());
aBSCurve->Knots (aKnots);
BSplCLib::Reparametrize (0., 1., aKnots);
aBSCurve->SetKnots (aKnots);
}
// reverse curve if edge is reversed
if (theEdge.Orientation() == TopAbs_REVERSED)
aBSCurve->Reverse();
return aBSCurve;
}
//=======================================================================
//function : TotalSurf
//purpose :
@@ -863,8 +933,6 @@ Handle(Geom_BSplineSurface) BRepOffsetAPI_ThruSections::
{
Standard_Integer i,j,jdeb=1,jfin=NbSects;
TopoDS_Edge edge;
TopLoc_Location loc;
Standard_Real first, last;
TopoDS_Vertex vf,vl;
GeomFill_SectionGenerator section;
@@ -883,12 +951,11 @@ Handle(Geom_BSplineSurface) BRepOffsetAPI_ThruSections::
TColStd_Array1OfReal Bounds(1,2);
Bounds(1) = 0.;
Bounds(2) = 1.;
Standard_Integer Deg = 1;
TColStd_Array1OfInteger Mult(1,2);
Mult(1) = Deg+1;
Mult(2) = Deg+1;
Mult(1) = 2;
Mult(2) = 2;
Handle(Geom_BSplineCurve) BSPoint
= new Geom_BSplineCurve(Extremities,Bounds,Mult,Deg);
= new Geom_BSplineCurve(Extremities,Bounds,Mult,1);
section.AddCurve(BSPoint);
}
@@ -905,97 +972,19 @@ Handle(Geom_BSplineSurface) BRepOffsetAPI_ThruSections::
else {
// read the first edge to initialise CompBS;
edge = TopoDS::Edge(shapes((j-1)*NbEdges+1));
if (BRep_Tool::Degenerated(edge)) {
// degenerated edge : construction of a punctual curve
TopExp::Vertices(edge,vl,vf);
TColgp_Array1OfPnt Extremities(1,2);
Extremities(1) = BRep_Tool::Pnt(vf);
Extremities(2) = BRep_Tool::Pnt(vl);
Handle(Geom_Curve) curv = new Geom_BezierCurve(Extremities);
curvTrim = new Geom_TrimmedCurve(curv,
curv->FirstParameter(),
curv->LastParameter());
}
else {
// recover the curve on the edge
Handle(Geom_Curve) curv = BRep_Tool::Curve(edge, loc, first, last);
curvTrim = new Geom_TrimmedCurve(curv, first, last);
curvTrim->Transform(loc.Transformation());
}
if (edge.Orientation() == TopAbs_REVERSED) {
curvTrim->Reverse();
}
TopoDS_Edge aPrevEdge = TopoDS::Edge (shapes((j-1)*NbEdges+1));
Handle(Geom_BSplineCurve) curvBS = EdgeToBSpline (aPrevEdge);
// transformation into BSpline reparameterized on [i-1,i]
curvBS = Handle(Geom_BSplineCurve)::DownCast(curvTrim);
if (curvBS.IsNull()) {
Handle(Geom_Curve) theCurve = curvTrim->BasisCurve();
if (theCurve->IsKind(STANDARD_TYPE(Geom_Conic)))
{
GeomConvert_ApproxCurve appr(curvTrim, Precision::Confusion(), GeomAbs_C1, 16, 14);
if (appr.HasResult())
curvBS = appr.Curve();
}
if (curvBS.IsNull())
curvBS = GeomConvert::CurveToBSplineCurve(curvTrim);
}
TColStd_Array1OfReal BSK(1,curvBS->NbKnots());
curvBS->Knots(BSK);
BSplCLib::Reparametrize(0.,1.,BSK);
curvBS->SetKnots(BSK);
// initialization
GeomConvert_CompCurveToBSplineCurve CompBS(curvBS);
for (i=2; i<=NbEdges; i++) {
// read the edge
edge = TopoDS::Edge(shapes((j-1)*NbEdges+i));
if (BRep_Tool::Degenerated(edge)) {
// degenerated edge : construction of a punctual curve
TopExp::Vertices(edge,vl,vf);
TColgp_Array1OfPnt Extremities(1,2);
Extremities(1) = BRep_Tool::Pnt(vf);
Extremities(2) = BRep_Tool::Pnt(vl);
Handle(Geom_Curve) curv = new Geom_BezierCurve(Extremities);
curvTrim = new Geom_TrimmedCurve(curv,
curv->FirstParameter(),
curv->LastParameter());
}
else {
// return the curve on the edge
Handle(Geom_Curve) curv = BRep_Tool::Curve(edge, loc, first, last);
curvTrim = new Geom_TrimmedCurve(curv, first, last);
curvTrim->Transform(loc.Transformation());
}
if (edge.Orientation() == TopAbs_REVERSED) {
curvTrim->Reverse();
}
// transformation into BSpline reparameterized on [i-1,i]
curvBS = Handle(Geom_BSplineCurve)::DownCast(curvTrim);
if (curvBS.IsNull()) {
Handle(Geom_Curve) theCurve = curvTrim->BasisCurve();
if (theCurve->IsKind(STANDARD_TYPE(Geom_Conic)))
{
GeomConvert_ApproxCurve appr(curvTrim, Precision::Confusion(), GeomAbs_C1, 16, 14);
if (appr.HasResult())
curvBS = appr.Curve();
}
if (curvBS.IsNull())
curvBS = GeomConvert::CurveToBSplineCurve(curvTrim);
}
TColStd_Array1OfReal BSK(1,curvBS->NbKnots());
curvBS->Knots(BSK);
BSplCLib::Reparametrize(i-1,i,BSK);
curvBS->SetKnots(BSK);
TopoDS_Edge aNextEdge = TopoDS::Edge (shapes((j-1)*NbEdges+i));
curvBS = EdgeToBSpline (aNextEdge);
// concatenation
CompBS.Add(curvBS,
Precision::Confusion(),
Standard_True,
Standard_False,
1);
CompBS.Add(curvBS, Precision::Confusion(), Standard_True, Standard_False, 1);
}
// return the final section
@@ -1019,12 +1008,11 @@ Handle(Geom_BSplineSurface) BRepOffsetAPI_ThruSections::
TColStd_Array1OfReal Bounds(1,2);
Bounds(1) = 0.;
Bounds(2) = 1.;
Standard_Integer Deg = 1;
TColStd_Array1OfInteger Mult(1,2);
Mult(1) = Deg+1;
Mult(2) = Deg+1;
Mult(1) = 2;
Mult(2) = 2;
Handle(Geom_BSplineCurve) BSPoint
= new Geom_BSplineCurve(Extremities,Bounds,Mult,Deg);
= new Geom_BSplineCurve(Extremities,Bounds,Mult,1);
section.AddCurve(BSPoint);
}