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

0032293: Coding Rules - merge GCPnts_UniformDeflection.pxx into GCPnts_UniformDeflection.cxx

This commit is contained in:
kgv 2021-04-10 11:13:14 +03:00
parent a2af24d1a9
commit 3d42fbc189
7 changed files with 507 additions and 446 deletions

View File

@ -11,11 +11,11 @@ GCPnts_QuasiUniformDeflection.pxx
GCPnts_QuasiUniformDeflection.hxx GCPnts_QuasiUniformDeflection.hxx
GCPnts_TangentialDeflection.cxx GCPnts_TangentialDeflection.cxx
GCPnts_TangentialDeflection.hxx GCPnts_TangentialDeflection.hxx
GCPnts_TCurveTypes.hxx
GCPnts_UniformAbscissa.cxx GCPnts_UniformAbscissa.cxx
GCPnts_UniformAbscissa.pxx GCPnts_UniformAbscissa.pxx
GCPnts_UniformAbscissa.hxx GCPnts_UniformAbscissa.hxx
GCPnts_UniformDeflection.cxx GCPnts_UniformDeflection.cxx
GCPnts_UniformDeflection.pxx
GCPnts_UniformDeflection.hxx GCPnts_UniformDeflection.hxx
GCPnts_DistFunction.hxx GCPnts_DistFunction.hxx
GCPnts_DistFunction.cxx GCPnts_DistFunction.cxx

View File

@ -23,7 +23,7 @@ class gp_Pnt;
//! Class to define function, which calculates square distance between point on curve //! Class to define function, which calculates square distance between point on curve
//! C(u), U1 <= u <= U2 and line passing through points C(U1) and C(U2) //! C(u), U1 <= u <= U2 and line passing through points C(U1) and C(U2)
//! This function is used in any minimisation algorithm to define maximal deviation between curve and line, //! This function is used in any minimization algorithm to define maximal deviation between curve and line,
//! which required one variable function without derivative (for ex. math_BrentMinimum) //! which required one variable function without derivative (for ex. math_BrentMinimum)
class GCPnts_DistFunction : public math_Function class GCPnts_DistFunction : public math_Function
{ {

View File

@ -0,0 +1,49 @@
// Copyright (c) 2021 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _GCPnts_TCurveTypes_HeaderFile
#define _GCPnts_TCurveTypes_HeaderFile
#include <Adaptor2d_Curve2d.hxx>
#include <Adaptor3d_Curve.hxx>
#include <Geom_BezierCurve.hxx>
#include <Geom_BSplineCurve.hxx>
#include <Geom2d_BezierCurve.hxx>
#include <Geom2d_BSplineCurve.hxx>
#include <GCPnts_DistFunction.hxx>
#include <GCPnts_DistFunction2d.hxx>
//! Auxiliary tool to resolve 2D/3D curve classes.
template<class TheCurve> struct GCPnts_TCurveTypes {};
//! Auxiliary tool to resolve 3D curve classes.
template<> struct GCPnts_TCurveTypes<Adaptor3d_Curve>
{
typedef gp_Pnt Point;
typedef Geom_BezierCurve BezierCurve;
typedef Geom_BSplineCurve BSplineCurve;
typedef GCPnts_DistFunction DistFunction;
typedef GCPnts_DistFunctionMV DistFunctionMV;
};
//! Auxiliary tool to resolve 2D curve classes.
template<> struct GCPnts_TCurveTypes<Adaptor2d_Curve2d>
{
typedef gp_Pnt2d Point;
typedef Geom2d_BezierCurve BezierCurve;
typedef Geom2d_BSplineCurve BSplineCurve;
typedef GCPnts_DistFunction2d DistFunction;
typedef GCPnts_DistFunction2dMV DistFunctionMV;
};
#endif // _GCPnts_TCurveTypes_HeaderFile

View File

@ -16,8 +16,8 @@
#include <GCPnts_TangentialDeflection.hxx> #include <GCPnts_TangentialDeflection.hxx>
#include <Adaptor2d_Curve2d.hxx> #include <GCPnts_TCurveTypes.hxx>
#include <Adaptor3d_Curve.hxx>
#include <gp_Pnt.hxx> #include <gp_Pnt.hxx>
#include <gp_Pnt2d.hxx> #include <gp_Pnt2d.hxx>
#include <gp_Vec.hxx> #include <gp_Vec.hxx>
@ -25,12 +25,6 @@
#include <gp_XYZ.hxx> #include <gp_XYZ.hxx>
#include <gp_Circ.hxx> #include <gp_Circ.hxx>
#include <gp_Circ2d.hxx> #include <gp_Circ2d.hxx>
#include <GCPnts_DistFunction2d.hxx>
#include <GCPnts_DistFunction.hxx>
#include <Geom_BezierCurve.hxx>
#include <Geom_BSplineCurve.hxx>
#include <Geom2d_BezierCurve.hxx>
#include <Geom2d_BSplineCurve.hxx>
#include <math_BrentMinimum.hxx> #include <math_BrentMinimum.hxx>
#include <math_PSO.hxx> #include <math_PSO.hxx>
#include <Precision.hxx> #include <Precision.hxx>
@ -42,27 +36,6 @@ namespace
{ {
static const Standard_Real Us3 = 0.3333333333333333333333333333; static const Standard_Real Us3 = 0.3333333333333333333333333333;
//! Auxiliary tool to resolve 2D/3D curve classes.
template<class TheCurve> struct CurveTypes {};
//! Auxiliary tool to resolve 3D curve classes.
template<> struct CurveTypes<Adaptor3d_Curve>
{
typedef Geom_BezierCurve BezierCurve;
typedef Geom_BSplineCurve BSplineCurve;
typedef GCPnts_DistFunction DistFunction;
typedef GCPnts_DistFunctionMV DistFunctionMV;
};
//! Auxiliary tool to resolve 2D curve classes.
template<> struct CurveTypes<Adaptor2d_Curve2d>
{
typedef Geom2d_BezierCurve BezierCurve;
typedef Geom2d_BSplineCurve BSplineCurve;
typedef GCPnts_DistFunction2d DistFunction;
typedef GCPnts_DistFunction2dMV DistFunctionMV;
};
inline static void D0 (const Adaptor3d_Curve& C, const Standard_Real U, gp_Pnt& P) inline static void D0 (const Adaptor3d_Curve& C, const Standard_Real U, gp_Pnt& P)
{ {
C.D0 (U, P); C.D0 (U, P);
@ -435,14 +408,14 @@ void GCPnts_TangentialDeflection::initialize (const TheCurve& theC,
} }
case GeomAbs_BSplineCurve: case GeomAbs_BSplineCurve:
{ {
Handle(typename CurveTypes<TheCurve>::BSplineCurve) aBS = theC.BSpline(); Handle(typename GCPnts_TCurveTypes<TheCurve>::BSplineCurve) aBS = theC.BSpline();
if (aBS->NbPoles() == 2) PerformLinear (theC); if (aBS->NbPoles() == 2) PerformLinear (theC);
else PerformCurve (theC); else PerformCurve (theC);
break; break;
} }
case GeomAbs_BezierCurve: case GeomAbs_BezierCurve:
{ {
Handle(typename CurveTypes<TheCurve>::BezierCurve) aBZ = theC.Bezier(); Handle(typename GCPnts_TCurveTypes<TheCurve>::BezierCurve) aBZ = theC.Bezier();
if (aBZ->NbPoles() == 2) PerformLinear (theC); if (aBZ->NbPoles() == 2) PerformLinear (theC);
else PerformCurve (theC); else PerformCurve (theC);
break; break;
@ -577,13 +550,13 @@ void GCPnts_TangentialDeflection::PerformCurve (const TheCurve& theC)
{ {
case GeomAbs_BSplineCurve: case GeomAbs_BSplineCurve:
{ {
Handle(typename CurveTypes<TheCurve>::BSplineCurve) BS = theC.BSpline(); Handle(typename GCPnts_TCurveTypes<TheCurve>::BSplineCurve) BS = theC.BSpline();
NbPoints = Max(BS->Degree() + 1, NbPoints); NbPoints = Max(BS->Degree() + 1, NbPoints);
break; break;
} }
case GeomAbs_BezierCurve: case GeomAbs_BezierCurve:
{ {
Handle(typename CurveTypes<TheCurve>::BezierCurve) BZ = theC.Bezier(); Handle(typename GCPnts_TCurveTypes<TheCurve>::BezierCurve) BZ = theC.Bezier();
NbPoints = Max(BZ->Degree() + 1, NbPoints); NbPoints = Max(BZ->Degree() + 1, NbPoints);
break; break;
} }
@ -963,7 +936,7 @@ void GCPnts_TangentialDeflection::EstimDefl (const TheCurve& theC,
{ {
const Standard_Real Du = (myLastU - myFirstu); const Standard_Real Du = (myLastU - myFirstu);
// //
typename CurveTypes<TheCurve>::DistFunction aFunc (theC, theU1, theU2); typename GCPnts_TCurveTypes<TheCurve>::DistFunction aFunc (theC, theU1, theU2);
// //
const Standard_Integer aNbIter = 100; const Standard_Integer aNbIter = 100;
const Standard_Real aRelTol = Max (1.e-3, 2. * myUTol / (Abs(theU1) + Abs(theU2))); const Standard_Real aRelTol = Max (1.e-3, 2. * myUTol / (Abs(theU1) + Abs(theU2)));
@ -986,7 +959,7 @@ void GCPnts_TangentialDeflection::EstimDefl (const TheCurve& theC,
// //
Standard_Real aValue = 0.0; Standard_Real aValue = 0.0;
math_Vector aT (1, 1); math_Vector aT (1, 1);
typename CurveTypes<TheCurve>::DistFunctionMV aFuncMV(aFunc); typename GCPnts_TCurveTypes<TheCurve>::DistFunctionMV aFuncMV(aFunc);
math_PSO aFinder (&aFuncMV, aLowBorder, aUppBorder, aSteps, aNbParticles); math_PSO aFinder (&aFuncMV, aLowBorder, aUppBorder, aSteps, aNbParticles);
aFinder.Perform (aSteps, aValue, aT); aFinder.Perform (aSteps, aValue, aT);

View File

@ -12,10 +12,11 @@
// Alternatively, this file may be used under the terms of Open CASCADE // Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement. // commercial license or contractual agreement.
#include <Adaptor2d_Curve2d.hxx>
#include <Adaptor3d_Curve.hxx>
#include <GCPnts_UniformDeflection.hxx> #include <GCPnts_UniformDeflection.hxx>
#include <CPnts_UniformDeflection.hxx>
#include <GCPnts_DeflectionType.hxx>
#include <GCPnts_TCurveTypes.hxx>
#include <gp_Pnt.hxx> #include <gp_Pnt.hxx>
#include <gp_Pnt2d.hxx> #include <gp_Pnt2d.hxx>
#include <Standard_ConstructionError.hxx> #include <Standard_ConstructionError.hxx>
@ -25,68 +26,357 @@
#include <StdFail_NotDone.hxx> #include <StdFail_NotDone.hxx>
// mask the return of a Adaptor2d_Curve2d as a gp_Pnt // mask the return of a Adaptor2d_Curve2d as a gp_Pnt
static gp_Pnt Value(const Adaptor3d_Curve & C, static gp_Pnt Value (const Adaptor3d_Curve& theC,
const Standard_Real Parameter) const Standard_Real theParameter)
{ {
return C.Value(Parameter) ; return theC.Value (theParameter);
} }
static gp_Pnt Value(const Adaptor2d_Curve2d & C,
const Standard_Real Parameter)
{
gp_Pnt aPoint ;
gp_Pnt2d a2dPoint =
C.Value(Parameter) ;
aPoint.SetX ( a2dPoint.X()) ;
aPoint.SetY ( a2dPoint.Y()) ;
aPoint.SetZ ( 0.0e0) ;
return aPoint ;
}
//=======================================================================
//function : Value
//purpose :
//=======================================================================
gp_Pnt GCPnts_UniformDeflection::Value static gp_Pnt Value (const Adaptor2d_Curve2d& theC,
(const Standard_Integer Index) const const Standard_Real theParameter)
{ {
StdFail_NotDone_Raise_if(!myDone, const gp_Pnt2d a2dPoint = theC.Value (theParameter);
"GCPnts_UniformAbscissa::Parameter()"); return gp_Pnt (a2dPoint.X(), a2dPoint.Y(), 0.0);
return myPoints.Value(Index) ;
} }
//======================================================================= //=======================================================================
//function : GCPnts_UniformDeflection //function : GCPnts_UniformDeflection
//purpose : //purpose :
//======================================================================= //=======================================================================
GCPnts_UniformDeflection::GCPnts_UniformDeflection()
GCPnts_UniformDeflection::GCPnts_UniformDeflection () : myDone (Standard_False),
: myDone(Standard_False), myDeflection (0.0)
myDeflection(0.0)
{ {
} //
}
#include <Geom_BezierCurve.hxx> //=======================================================================
#include <Geom_BSplineCurve.hxx> //function : GCPnts_UniformDeflection
//purpose :
//=======================================================================
GCPnts_UniformDeflection::GCPnts_UniformDeflection (const Adaptor3d_Curve& theC,
const Standard_Real theDeflection,
const Standard_Real theU1,
const Standard_Real theU2,
const Standard_Boolean theWithControl)
: myDone (Standard_False),
myDeflection (theDeflection)
{
Initialize (theC, theDeflection, theU1, theU2, theWithControl);
}
#define TheCurve Adaptor3d_Curve //=======================================================================
#define Handle_TheBezierCurve Handle(Geom_BezierCurve) //function : GCPnts_UniformDeflection
#define Handle_TheBSplineCurve Handle(Geom_BSplineCurve) //purpose :
#include "GCPnts_UniformDeflection.pxx" //=======================================================================
#undef TheCurve GCPnts_UniformDeflection::GCPnts_UniformDeflection (const Adaptor3d_Curve& theC,
#undef Handle_TheBezierCurve const Standard_Real theDeflection,
#undef Handle_TheBSplineCurve const Standard_Boolean theWithControl)
: myDone (Standard_False),
myDeflection (theDeflection)
{
Initialize (theC, theDeflection, theWithControl);
}
#include <Geom2d_BezierCurve.hxx> //=======================================================================
#include <Geom2d_BSplineCurve.hxx> //function : GCPnts_UniformDeflection
#define TheCurve Adaptor2d_Curve2d //purpose :
#define Handle_TheBezierCurve Handle(Geom2d_BezierCurve) //=======================================================================
#define Handle_TheBSplineCurve Handle(Geom2d_BSplineCurve) GCPnts_UniformDeflection::GCPnts_UniformDeflection (const Adaptor2d_Curve2d& theC,
#include "GCPnts_UniformDeflection.pxx" const Standard_Real theDeflection,
#undef TheCurve const Standard_Real theU1,
#undef Handle_TheBezierCurve const Standard_Real theU2,
#undef Handle_TheBSplineCurve const Standard_Boolean theWithControl)
: myDone (Standard_False),
myDeflection (theDeflection)
{
Initialize (theC, theDeflection, theU1, theU2, theWithControl);
}
//=======================================================================
//function : GCPnts_UniformDeflection
//purpose :
//=======================================================================
GCPnts_UniformDeflection::GCPnts_UniformDeflection (const Adaptor2d_Curve2d& theC,
const Standard_Real theDeflection,
const Standard_Boolean theWithControl)
: myDone (Standard_False),
myDeflection (theDeflection)
{
Initialize (theC, theDeflection, theWithControl);
}
//=======================================================================
//function : Initialize
//purpose :
//=======================================================================
void GCPnts_UniformDeflection::Initialize (const Adaptor3d_Curve& theC,
const Standard_Real theDeflection,
const Standard_Boolean theWithControl)
{
Initialize (theC, theDeflection, theC.FirstParameter(), theC.LastParameter(), theWithControl);
}
//=======================================================================
//function : Initialize
//purpose :
//=======================================================================
void GCPnts_UniformDeflection::Initialize (const Adaptor2d_Curve2d& theC,
const Standard_Real theDeflection,
const Standard_Boolean theWithControl)
{
Initialize (theC, theDeflection, theC.FirstParameter(), theC.LastParameter(), theWithControl);
}
//=======================================================================
//function : Initialize
//purpose :
//=======================================================================
void GCPnts_UniformDeflection::Initialize (const Adaptor3d_Curve& theC,
const Standard_Real theDeflection,
const Standard_Real theU1,
const Standard_Real theU2,
const Standard_Boolean theWithControl)
{
initialize (theC, theDeflection, theU1, theU2, theWithControl);
}
//=======================================================================
//function : Initialize
//purpose :
//=======================================================================
void GCPnts_UniformDeflection::Initialize (const Adaptor2d_Curve2d& theC,
const Standard_Real theDeflection,
const Standard_Real theU1,
const Standard_Real theU2,
const Standard_Boolean theWithControl)
{
initialize (theC, theDeflection, theU1, theU2, theWithControl);
}
//=======================================================================
//function : Value
//purpose :
//=======================================================================
gp_Pnt GCPnts_UniformDeflection::Value (const Standard_Integer theIndex) const
{
StdFail_NotDone_Raise_if(!myDone, "GCPnts_UniformAbscissa::Parameter()");
return myPoints.Value (theIndex);
}
//! Control of the last points.
template<class TheCurve>
static void Controle (const TheCurve& theC,
TColStd_SequenceOfReal& theParameters,
TColgp_SequenceOfPnt& thePoints,
const Standard_Real theU2)
{
const Standard_Integer aNbPnts = thePoints.Length();
if (aNbPnts > 2)
{
const Standard_Real aUa = theParameters (aNbPnts - 2);
const Standard_Real aUb = theParameters (aNbPnts - 1);
if (theU2 - aUb < 0.33 * (theU2 - aUa))
{
const Standard_Real aUc = (theU2 + aUa) * 0.5;
theParameters (aNbPnts - 1) = aUc;
thePoints (aNbPnts - 1) = Value (theC, aUc);
}
}
}
//=======================================================================
//function : PerformLinear
//purpose :
//=======================================================================
template<class TheCurve>
static Standard_Boolean PerformLinear (const TheCurve& theC,
TColStd_SequenceOfReal& theParameters,
TColgp_SequenceOfPnt& thePoints,
const Standard_Real theU1,
const Standard_Real theU2)
{
theParameters.Append (theU1);
gp_Pnt aPoint = Value (theC, theU1);
thePoints.Append (aPoint);
theParameters.Append (theU2);
aPoint = Value (theC, theU2);
thePoints.Append (aPoint);
return Standard_True;
}
//=======================================================================
//function : PerformCircular
//purpose :
//=======================================================================
template<class TheCurve>
static Standard_Boolean PerformCircular (const TheCurve& theC,
TColStd_SequenceOfReal& theParameters,
TColgp_SequenceOfPnt& thePoints,
const Standard_Real theDeflection,
const Standard_Real theU1,
const Standard_Real theU2)
{
gp_Pnt aPoint;
Standard_Real anAngle = Max (1.0 - (theDeflection / theC.Circle().Radius()), 0.0);
anAngle = 2.0e0 * ACos (anAngle);
Standard_Integer aNbPoints = (Standard_Integer )((theU2 - theU1) / anAngle);
aNbPoints += 2;
anAngle = (theU2 - theU1) / (Standard_Real) (aNbPoints - 1);
Standard_Real aU = theU1;
for (Standard_Integer i = 1; i <= aNbPoints; ++i)
{
theParameters.Append (aU);
aPoint = Value (theC, aU);
thePoints.Append (aPoint);
aU += anAngle;
}
return Standard_True;
}
//=======================================================================
//function : GetDefType
//purpose :
//=======================================================================
template<class TheCurve>
static GCPnts_DeflectionType GetDefType (const TheCurve& theC)
{
if (theC.NbIntervals (GeomAbs_C2) > 1)
{
return GCPnts_DefComposite;
}
switch (theC.GetType())
{
case GeomAbs_Line: return GCPnts_Linear;
case GeomAbs_Circle: return GCPnts_Circular;
case GeomAbs_BSplineCurve:
{
Handle(typename GCPnts_TCurveTypes<TheCurve>::BSplineCurve) aBSpline = theC.BSpline();
return (aBSpline->NbPoles() == 2) ? GCPnts_Linear : GCPnts_Curved;
}
case GeomAbs_BezierCurve:
{
Handle(typename GCPnts_TCurveTypes<TheCurve>::BezierCurve) aBezier = theC.Bezier();
return (aBezier->NbPoles() == 2) ? GCPnts_Linear : GCPnts_Curved;
}
default:
{
return GCPnts_Curved;
}
}
}
//=======================================================================
//function : PerformCurve
//purpose :
//=======================================================================
template<class TheCurve>
static Standard_Boolean PerformCurve (TColStd_SequenceOfReal& theParameters,
TColgp_SequenceOfPnt& thePoints,
const TheCurve& theC,
const Standard_Real theDeflection,
const Standard_Real theU1,
const Standard_Real theU2,
const Standard_Real theEPSILON,
const Standard_Boolean theWithControl)
{
CPnts_UniformDeflection anIterator (theC, theDeflection, theU1, theU2, theEPSILON, theWithControl);
for (; anIterator.More(); anIterator.Next())
{
theParameters.Append (anIterator.Value());
thePoints.Append (anIterator.Point());
}
return anIterator.IsAllDone();
}
//=======================================================================
//function : PerformComposite
//purpose :
//=======================================================================
template<class TheCurve>
static Standard_Boolean PerformComposite (TColStd_SequenceOfReal& theParameters,
TColgp_SequenceOfPnt& thePoints,
const TheCurve& theC,
const Standard_Real theDeflection,
const Standard_Real theU1,
const Standard_Real theU2,
const Standard_Real theEPSILON,
const Standard_Boolean theWithControl)
{
const Standard_Integer aNbIntervals = theC.NbIntervals (GeomAbs_C2);
Standard_Integer aPIndex = 0;
TColStd_Array1OfReal aTI (1, aNbIntervals + 1);
theC.Intervals (aTI, GeomAbs_C2);
BSplCLib::Hunt (aTI, theU1, aPIndex);
// iterate by continuous segments
Standard_Real aUa = theU1;
for (Standard_Integer anIndex = aPIndex;;)
{
Standard_Real aUb = anIndex + 1 <= aTI.Upper()
? Min (theU2, aTI (anIndex + 1))
: theU2;
if (!PerformCurve (theParameters, thePoints, theC, theDeflection,
aUa, aUb, theEPSILON, theWithControl))
{
return Standard_False;
}
++anIndex;
if (anIndex > aNbIntervals || theU2 < aTI (anIndex))
{
return Standard_True;
}
// remove last point to avoid duplication
theParameters.Remove (theParameters.Length());
thePoints.Remove (thePoints.Length());
aUa = aUb;
}
}
//=======================================================================
//function : initialize
//purpose :
//=======================================================================
template<class TheCurve>
void GCPnts_UniformDeflection::initialize (const TheCurve& theC,
const Standard_Real theDeflection,
const Standard_Real theU1,
const Standard_Real theU2,
const Standard_Boolean theWithControl)
{
const Standard_Real anEPSILON = theC.Resolution (Precision::Confusion());
myDeflection = theDeflection;
myDone = Standard_False;
myParams.Clear();
myPoints.Clear();
const Standard_Real aU1 = Min (theU1, theU2);
const Standard_Real aU2 = Max (theU1, theU2);
const GCPnts_DeflectionType aType = GetDefType (theC);
switch (aType)
{
case GCPnts_Linear:
myDone = PerformLinear (theC, myParams, myPoints, aU1, aU2);
break;
case GCPnts_Circular:
myDone = PerformCircular (theC, myParams, myPoints, theDeflection, aU1, aU2);
break;
case GCPnts_Curved:
myDone = PerformCurve (myParams, myPoints, theC, theDeflection,
aU1, aU2, anEPSILON, theWithControl);
break;
case GCPnts_DefComposite:
myDone = PerformComposite (myParams, myPoints, theC, theDeflection,
aU1, aU2, anEPSILON, theWithControl);
break;
}
// control of the last points
Controle (theC, myParams, myPoints, aU2);
}

View File

@ -21,112 +21,125 @@
#include <TColStd_SequenceOfReal.hxx> #include <TColStd_SequenceOfReal.hxx>
#include <TColgp_SequenceOfPnt.hxx> #include <TColgp_SequenceOfPnt.hxx>
class Standard_DomainError;
class Standard_ConstructionError;
class Standard_OutOfRange;
class StdFail_NotDone;
class Adaptor3d_Curve; class Adaptor3d_Curve;
class Adaptor2d_Curve2d; class Adaptor2d_Curve2d;
class gp_Pnt; class gp_Pnt;
//! Provides an algorithm to compute a distribution of //! Provides an algorithm to compute a distribution of
//! points on a 'C2' continuous curve. The algorithm //! points on a 'C2' continuous curve.
//! respects a criterion of maximum deflection between //! The algorithm respects a criterion of maximum deflection between
//! the curve and the polygon that results from the computed points. //! the curve and the polygon that results from the computed points.
//! Note: This algorithm is relatively time consuming. A //! Note: This algorithm is relatively time consuming.
//! GCPnts_QuasiUniformDeflection algorithm is //! A GCPnts_QuasiUniformDeflection algorithm is quicker;
//! quicker; it can also work with non-'C2' continuous //! it can also work with non-'C2' continuous curves,
//! curves, but it generates more points in the distribution. //! but it generates more points in the distribution.
class GCPnts_UniformDeflection class GCPnts_UniformDeflection
{ {
public: public:
DEFINE_STANDARD_ALLOC DEFINE_STANDARD_ALLOC
//! Constructs an empty algorithm.
//! Constructs an empty algorithm. To define the problem //! To define the problem to be solved, use the function Initialize.
//! to be solved, use the function Initialize.
Standard_EXPORT GCPnts_UniformDeflection(); Standard_EXPORT GCPnts_UniformDeflection();
//! Computes a uniform Deflection distribution of points on the curve.
//! @param theC [in] input 3D curve
//! @param theDeflection [in] target deflection
//! @param theWithControl [in] when TRUE, the algorithm controls the estimate deflection
Standard_EXPORT GCPnts_UniformDeflection (const Adaptor3d_Curve& theC,
const Standard_Real theDeflection,
const Standard_Boolean theWithControl = Standard_True);
//! Computes a uniform Deflection distribution of points on the curve.
//! @param theC [in] input 2D curve
//! @param theDeflection [in] target deflection
//! @param theWithControl [in] when TRUE, the algorithm controls the estimate deflection
Standard_EXPORT GCPnts_UniformDeflection (const Adaptor2d_Curve2d& theC,
const Standard_Real theDeflection,
const Standard_Boolean theWithControl = Standard_True);
//! Computes a Uniform Deflection distribution of points on a part of the curve.
//! @param theC [in] input 3D curve
//! @param theDeflection [in] target deflection
//! @param theU1 [in] first parameter on curve
//! @param theU2 [in] last parameter on curve
//! @param theWithControl [in] when TRUE, the algorithm controls the estimate deflection
Standard_EXPORT GCPnts_UniformDeflection (const Adaptor3d_Curve& theC,
const Standard_Real theDeflection,
const Standard_Real theU1, const Standard_Real theU2,
const Standard_Boolean theWithControl = Standard_True);
//! Computes a uniform Deflection distribution of points on //! Computes a Uniform Deflection distribution of points on a part of the curve.
//! the Curve <C>. //! @param theC [in] input 2D curve
//! if <WithControl> is True,the algorithm controls the estimate //! @param theDeflection [in] target deflection
//! deflection //! @param theU1 [in] first parameter on curve
Standard_EXPORT GCPnts_UniformDeflection(const Adaptor3d_Curve& C, const Standard_Real Deflection, const Standard_Boolean WithControl = Standard_True); //! @param theU2 [in] last parameter on curve
//! @param theWithControl [in] when TRUE, the algorithm controls the estimate deflection
Standard_EXPORT GCPnts_UniformDeflection (const Adaptor2d_Curve2d& theC,
const Standard_Real theDeflection,
const Standard_Real theU1, const Standard_Real theU2,
const Standard_Boolean theWithControl = Standard_True);
//! Initialize the algorithms with 3D curve and deflection.
Standard_EXPORT void Initialize (const Adaptor3d_Curve& theC,
const Standard_Real theDeflection,
const Standard_Boolean theWithControl = Standard_True);
//! Initialize the algorithms with 2D curve and deflection.
Standard_EXPORT void Initialize (const Adaptor2d_Curve2d& theC,
const Standard_Real theDeflection,
const Standard_Boolean theWithControl = Standard_True);
//! Initialize the algorithms with 3D curve, deflection, parameter range.
Standard_EXPORT void Initialize (const Adaptor3d_Curve& theC,
const Standard_Real theDeflection,
const Standard_Real theU1, const Standard_Real theU2,
const Standard_Boolean theWithControl = Standard_True);
//! Computes a uniform Deflection distribution of points on //! Initialize the algorithms with curve, deflection, parameter range.
//! the Curve <C>.
//! if <WithControl> is True,the algorithm controls the estimate
//! deflection
Standard_EXPORT GCPnts_UniformDeflection(const Adaptor2d_Curve2d& C, const Standard_Real Deflection, const Standard_Boolean WithControl = Standard_True);
//! Computes a Uniform Deflection distribution of points
//! on a part of the Curve <C>.
//! if <WithControl> is True,the algorithm controls the estimate
//! deflection
Standard_EXPORT GCPnts_UniformDeflection(const Adaptor3d_Curve& C, const Standard_Real Deflection, const Standard_Real U1, const Standard_Real U2, const Standard_Boolean WithControl = Standard_True);
//! Computes a Uniform Deflection distribution of points
//! on a part of the Curve <C>.
//! if <WithControl> is True,the algorithm controls the estimate
//! deflection
Standard_EXPORT GCPnts_UniformDeflection(const Adaptor2d_Curve2d& C, const Standard_Real Deflection, const Standard_Real U1, const Standard_Real U2, const Standard_Boolean WithControl = Standard_True);
//! Initialize the algorithms with <C>, <Deflection>
Standard_EXPORT void Initialize (const Adaptor3d_Curve& C, const Standard_Real Deflection, const Standard_Boolean WithControl = Standard_True);
//! Initialize the algorithms with <C>, <Deflection>
Standard_EXPORT void Initialize (const Adaptor2d_Curve2d& C, const Standard_Real Deflection, const Standard_Boolean WithControl = Standard_True);
//! Initialize the algorithms with <C>, <Deflection>,
//! <U1>,<U2>
Standard_EXPORT void Initialize (const Adaptor3d_Curve& C, const Standard_Real Deflection, const Standard_Real U1, const Standard_Real U2, const Standard_Boolean WithControl = Standard_True);
//! Initialize the algorithms with <C>, <Deflection>,
//! <U1>,<U2>
//! This and the above methods initialize (or reinitialize) this algorithm and //! This and the above methods initialize (or reinitialize) this algorithm and
//! compute a distribution of points: //! compute a distribution of points:
//! - on the curve C, or //! - on the curve theC, or
//! - on the part of curve C limited by the two //! - on the part of curve theC limited by the two parameter values theU1 and theU2,
//! parameter values U1 and U2, //! where the maximum distance between theC and the
//! where the maximum distance between C and the
//! polygon that results from the points of the //! polygon that results from the points of the
//! distribution is not greater than Deflection. //! distribution is not greater than theDeflection.
//! The first point of the distribution is either the origin //! The first point of the distribution is either the origin
//! of curve C or the point of parameter U1. The last //! of curve theC or the point of parameter theU1.
//! point of the distribution is either the end point of //! The last point of the distribution is either the end point of
//! curve C or the point of parameter U2. Intermediate //! curve theC or the point of parameter theU2.
//! points of the distribution are built using //! Intermediate points of the distribution are built using
//! interpolations of segments of the curve limited at //! interpolations of segments of the curve limited at the 2nd degree.
//! the 2nd degree. The construction ensures, in a first //! The construction ensures, in a first step,
//! step, that the chordal deviation for this //! that the chordal deviation for this
//! interpolation of the curve is less than or equal to //! interpolation of the curve is less than or equal to theDeflection.
//! Deflection. However, it does not ensure that the //! However, it does not ensure that the chordal deviation
//! chordal deviation for the curve itself is less than or //! for the curve itself is less than or equal to theDeflection.
//! equal to Deflection. To do this a check is //! To do this a check is necessary,
//! necessary, which may generate (second step) //! which may generate (second step) additional intermediate points.
//! additional intermediate points. This check is time //! This check is time consuming, and can be avoided by setting theWithControl to false.
//! consuming, and can be avoided by setting //! Note that by default theWithControl is true and check is performed.
//! WithControl to false. Note that by default //! Use the function IsDone to verify that the computation was successful,
//! WithControl is true and check is performed. //! the function NbPoints() to obtain the number of points of the computed distribution,
//! Use the function IsDone to verify that the //! and the function Parameter to read the parameter of each point.
//! computation was successful, the function NbPoints //!
//! to obtain the number of points of the computed
//! distribution, and the function Parameter to read
//! the parameter of each point.
//! Warning //! Warning
//! - C is necessary, 'C2' continuous. This property is //! - theC is necessary, 'C2' continuous.
//! not checked at construction time. //! This property is not checked at construction time.
//! - The roles of U1 and U2 are inverted if U1 > U2. //! - The roles of theU1 and theU2 are inverted if theU1 > theU2.
//!
//! Warning //! Warning
//! C is an adapted curve, i.e. an object which is an interface between: //! theC is an adapted curve, i.e. an object which is an interface between:
//! - the services provided by either a 2D curve from //! - the services provided by either a 2D curve from
//! the package Geom2d (in the case of an //! the package Geom2d (in the case of an Adaptor2d_Curve2d curve)
//! Adaptor2d_Curve2d curve) or a 3D curve from //! or a 3D curve from the package Geom (in the case of an Adaptor3d_Curve curve),
//! the package Geom (in the case of an Adaptor3d_Curve curve),
//! - and those required on the curve by the computation algorithm. //! - and those required on the curve by the computation algorithm.
Standard_EXPORT void Initialize (const Adaptor2d_Curve2d& C, const Standard_Real Deflection, const Standard_Real U1, const Standard_Real U2, const Standard_Boolean WithControl = Standard_True); Standard_EXPORT void Initialize (const Adaptor2d_Curve2d& theC,
const Standard_Real theDeflection,
const Standard_Real theU1, const Standard_Real theU2,
const Standard_Boolean theWithControl = Standard_True);
//! Returns true if the computation was successful. //! Returns true if the computation was successful.
//! IsDone is a protection against: //! IsDone is a protection against:
//! - non-convergence of the algorithm //! - non-convergence of the algorithm
@ -189,6 +202,16 @@ public:
return myDeflection; return myDeflection;
} }
private:
//! Initialize the algorithm.
template<class TheCurve>
void initialize (const TheCurve& theC,
const Standard_Real theDeflection,
const Standard_Real theU1,
const Standard_Real theU2,
const Standard_Boolean theWithControl);
private: private:
Standard_Boolean myDone; Standard_Boolean myDone;
Standard_Real myDeflection; Standard_Real myDeflection;

View File

@ -1,274 +0,0 @@
// Copyright (c) 1995-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <StdFail_NotDone.hxx>
#include <Standard_DomainError.hxx>
#include <Standard_OutOfRange.hxx>
#include <Standard_ConstructionError.hxx>
#include <Standard_NotImplemented.hxx>
#include <GCPnts_DeflectionType.hxx>
#include <CPnts_UniformDeflection.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <TColStd_SequenceOfReal.hxx>
#include <BSplCLib.hxx>
#include <gp_Circ.hxx>
#include <gp_Circ2d.hxx>
#include <Precision.hxx>
//=======================================================================
//function : Controle
//purpose :
//=======================================================================
static void Controle (const TheCurve& C,
TColStd_SequenceOfReal& Parameters,
TColgp_SequenceOfPnt& Points,
const Standard_Real U2)
{
Standard_Integer nbp = Points.Length();
if (nbp > 2)
{
Standard_Real Ua = Parameters (nbp - 2);
Standard_Real Ub = Parameters (nbp - 1);
if (U2 - Ub < 0.33 * (U2 - Ua))
{
Standard_Real Uc = (U2 + Ua) * 0.5;
Parameters (nbp - 1) = Uc;
Points (nbp - 1) = Value (C, Uc);
}
}
}
//=======================================================================
//function : PerformLinear
//purpose :
//=======================================================================
static Standard_Boolean PerformLinear (const TheCurve& C,
TColStd_SequenceOfReal& Parameters,
TColgp_SequenceOfPnt& Points,
const Standard_Real U1,
const Standard_Real U2)
{
gp_Pnt aPoint;
Parameters.Append (U1);
aPoint = Value (C, U1);
Points.Append (aPoint);
Parameters.Append (U2);
aPoint = Value (C, U2);
Points.Append (aPoint);
return Standard_True;
}
//=======================================================================
//function : PerformCircular
//purpose :
//=======================================================================
static Standard_Boolean PerformCircular (const TheCurve& C,
TColStd_SequenceOfReal& Parameters,
TColgp_SequenceOfPnt& Points,
const Standard_Real Deflection,
const Standard_Real U1,
const Standard_Real U2)
{
gp_Pnt aPoint;
Standard_Real Angle = Max (1.0e0 - (Deflection / C.Circle().Radius()), 0.0e0);
Angle = 2.0e0 * ACos (Angle);
Standard_Integer NbPoints = (Standard_Integer )((U2 - U1) / Angle);
NbPoints += 2;
Angle = (U2 - U1) / (Standard_Real) (NbPoints - 1);
Standard_Real U = U1;
for (Standard_Integer i = 1; i <= NbPoints; ++i)
{
Parameters.Append (U);
aPoint = Value (C, U);
Points.Append (aPoint);
U += Angle;
}
return Standard_True;
}
static GCPnts_DeflectionType GetDefType (const TheCurve& C)
{
if (C.NbIntervals (GeomAbs_C2) > 1)
return GCPnts_DefComposite;
switch (C.GetType())
{
case GeomAbs_Line: return GCPnts_Linear;
case GeomAbs_Circle: return GCPnts_Circular;
case GeomAbs_BSplineCurve:
{
Handle_TheBSplineCurve aBSpline = C.BSpline();
return (aBSpline->NbPoles() == 2) ? GCPnts_Linear : GCPnts_Curved;
}
case GeomAbs_BezierCurve:
{
Handle_TheBezierCurve aBezier = C.Bezier();
return (aBezier->NbPoles() == 2) ? GCPnts_Linear : GCPnts_Curved;
}
default: return GCPnts_Curved;
}
}
//=======================================================================
//function : PerformCurve
//purpose :
//=======================================================================
static Standard_Boolean PerformCurve (TColStd_SequenceOfReal& Parameters,
TColgp_SequenceOfPnt& Points,
const TheCurve& C,
const Standard_Real Deflection,
const Standard_Real U1,
const Standard_Real U2,
const Standard_Real EPSILON,
const Standard_Boolean WithControl)
{
CPnts_UniformDeflection Iterator (C, Deflection, U1, U2, EPSILON, WithControl);
for(; Iterator.More(); Iterator.Next())
{
Parameters.Append (Iterator.Value());
Points.Append (Iterator.Point());
}
return Iterator.IsAllDone();
}
//=======================================================================
//function : PerformComposite
//purpose :
//=======================================================================
static Standard_Boolean PerformComposite (TColStd_SequenceOfReal& Parameters,
TColgp_SequenceOfPnt& Points,
const TheCurve& C,
const Standard_Real Deflection,
const Standard_Real U1,
const Standard_Real U2,
const Standard_Real EPSILON,
const Standard_Boolean WithControl)
{
Standard_Integer NbIntervals = C.NbIntervals (GeomAbs_C2);
Standard_Integer PIndex;
TColStd_Array1OfReal TI (1, NbIntervals + 1);
C.Intervals (TI, GeomAbs_C2);
BSplCLib::Hunt (TI, U1, PIndex);
// iterate by continuous segments
Standard_Real Ua = U1;
for (Standard_Integer Index = PIndex;;)
{
Standard_Real Ub = Index + 1 <= TI.Upper()
? Min (U2, TI (Index + 1))
: U2;
if (!PerformCurve (Parameters, Points, C, Deflection,
Ua, Ub, EPSILON, WithControl))
{
return Standard_False;
}
++Index;
if (Index > NbIntervals || U2 < TI (Index))
return Standard_True;
// remove last point to avoid duplication
Parameters.Remove (Parameters.Length());
Points.Remove (Points.Length());
Ua = Ub;
}
}
//=======================================================================
//function : GCPnts_UniformDeflection
//purpose :
//=======================================================================
GCPnts_UniformDeflection::GCPnts_UniformDeflection (const TheCurve& C,
const Standard_Real Deflection,
const Standard_Real U1,
const Standard_Real U2,
const Standard_Boolean WithControl)
{
Initialize (C, Deflection, U1, U2, WithControl);
}
//=======================================================================
//function : GCPnts_UniformDeflection
//purpose :
//=======================================================================
GCPnts_UniformDeflection::GCPnts_UniformDeflection (const TheCurve& C,
const Standard_Real Deflection,
const Standard_Boolean WithControl)
{
Initialize(C, Deflection, WithControl);
}
//=======================================================================
//function : Initialize
//purpose :
//=======================================================================
void GCPnts_UniformDeflection::Initialize (const TheCurve& C,
const Standard_Real Deflection,
const Standard_Boolean WithControl)
{
Initialize (C, Deflection, C.FirstParameter(), C.LastParameter(), WithControl);
}
//=======================================================================
//function : Initialize
//purpose :
//=======================================================================
void GCPnts_UniformDeflection::Initialize (const TheCurve& C,
const Standard_Real Deflection,
const Standard_Real theU1,
const Standard_Real theU2,
const Standard_Boolean WithControl)
{
Standard_Real EPSILON = C.Resolution (Precision::Confusion());
myDeflection = Deflection;
myDone = Standard_False;
myParams.Clear();
myPoints.Clear();
Standard_Real U1 = Min (theU1, theU2);
Standard_Real U2 = Max (theU1, theU2);
GCPnts_DeflectionType Type = GetDefType (C);
switch (Type)
{
case GCPnts_Linear:
myDone = PerformLinear (C, myParams, myPoints, U1, U2);
break;
case GCPnts_Circular:
myDone = PerformCircular (C, myParams, myPoints, Deflection, U1, U2);
break;
case GCPnts_Curved:
myDone = PerformCurve (myParams, myPoints, C, Deflection,
U1, U2, EPSILON, WithControl);
break;
case GCPnts_DefComposite:
myDone = PerformComposite (myParams, myPoints, C, Deflection,
U1, U2, EPSILON, WithControl);
break;
}
// controle des derniers points:
Controle (C, myParams, myPoints, U2);
}