From 8662adfe46b44b7214dc1c91fa93a0d109152ed8 Mon Sep 17 00:00:00 2001 From: Pasukhin Dmitry Date: Sat, 6 Dec 2025 17:08:32 +0000 Subject: [PATCH] Modeling - Refactor Extrema package (#869) - Replacing preprocessor-based generic programming with C++ templates - Converting inline implementation files (`.lxx`) to inline definitions within header files - Removing legacy instantiation files (`_0.cxx`) - Updating type aliases to use modern `using` declarations instead of macro-based instantiation --- .../TKGeomAlgo/Geom2dInt/FILES.cmake | 3 - .../TKGeomAlgo/Geom2dInt/Geom2dInt_GInter.hxx | 3 +- ...FOfTheLocateExtPCOfTheProjPCurOfGInter.hxx | 99 +- ...fTheLocateExtPCOfTheProjPCurOfGInter_0.cxx | 42 - ...t_TheCurveLocatorOfTheProjPCurOfGInter.hxx | 55 +- ...TheCurveLocatorOfTheProjPCurOfGInter_0.cxx | 38 - ...nt_TheLocateExtPCOfTheProjPCurOfGInter.hxx | 94 +- ..._TheLocateExtPCOfTheProjPCurOfGInter_0.cxx | 48 - .../Geom2dInt_TheProjPCurOfGInter.hxx | 4 +- .../TKHLR/HLRBRep/FILES.cmake | 3 - .../TKHLR/HLRBRep/HLRBRep_CInter.hxx | 3 +- ...FOfTheLocateExtPCOfTheProjPCurOfCInter.hxx | 98 +- ...fTheLocateExtPCOfTheProjPCurOfCInter_0.cxx | 41 - ...p_TheCurveLocatorOfTheProjPCurOfCInter.hxx | 54 +- ...TheCurveLocatorOfTheProjPCurOfCInter_0.cxx | 37 - ...ep_TheLocateExtPCOfTheProjPCurOfCInter.hxx | 89 +- ..._TheLocateExtPCOfTheProjPCurOfCInter_0.cxx | 47 - .../HLRBRep/HLRBRep_TheProjPCurOfCInter.hxx | 4 +- .../Extrema/Extrema_CCLocFOfLocECC.hxx | 154 +-- .../Extrema/Extrema_CCLocFOfLocECC2d.hxx | 154 +-- .../Extrema/Extrema_CCLocFOfLocECC2d_0.cxx | 46 - .../Extrema/Extrema_CCLocFOfLocECC_0.cxx | 46 - .../Extrema/Extrema_Curve2dTool.hxx | 168 ++-- .../Extrema/Extrema_Curve2dTool.lxx | 231 ----- .../Extrema/Extrema_CurveLocator.gxx | 108 -- .../TKGeomBase/Extrema/Extrema_CurveTool.hxx | 143 +-- .../TKGeomBase/Extrema/Extrema_CurveTool.lxx | 218 ---- .../TKGeomBase/Extrema/Extrema_ECC.hxx | 102 +- .../TKGeomBase/Extrema/Extrema_ECC2d.hxx | 100 +- .../TKGeomBase/Extrema/Extrema_ECC2d_0.cxx | 46 - .../TKGeomBase/Extrema/Extrema_ECC_0.cxx | 46 - .../Extrema/Extrema_ELPCOfLocateExtPC.hxx | 137 +-- .../Extrema/Extrema_ELPCOfLocateExtPC2d.hxx | 137 +-- .../Extrema/Extrema_ELPCOfLocateExtPC2d_0.cxx | 53 - .../Extrema/Extrema_ELPCOfLocateExtPC_0.cxx | 53 - .../Extrema_EPCOfELPCOfLocateExtPC.hxx | 122 +-- .../Extrema_EPCOfELPCOfLocateExtPC2d.hxx | 123 +-- .../Extrema_EPCOfELPCOfLocateExtPC2d_0.cxx | 48 - .../Extrema_EPCOfELPCOfLocateExtPC_0.cxx | 48 - .../TKGeomBase/Extrema/Extrema_EPCOfExtPC.hxx | 122 +-- .../Extrema/Extrema_EPCOfExtPC2d.hxx | 122 +-- .../Extrema/Extrema_EPCOfExtPC2d_0.cxx | 48 - .../Extrema/Extrema_EPCOfExtPC_0.cxx | 48 - .../TKGeomBase/Extrema/Extrema_ExtCC2d.hxx | 3 +- .../TKGeomBase/Extrema/Extrema_ExtPC.hxx | 136 +-- .../TKGeomBase/Extrema/Extrema_ExtPC2d.hxx | 136 +-- .../TKGeomBase/Extrema/Extrema_ExtPC2d_0.cxx | 53 - .../TKGeomBase/Extrema/Extrema_ExtPC_0.cxx | 53 - .../TKGeomBase/Extrema/Extrema_FuncExtCC.gxx | 726 -------------- .../TKGeomBase/Extrema/Extrema_FuncExtCC.lxx | 61 -- .../TKGeomBase/Extrema/Extrema_FuncExtPC.gxx | 438 --------- .../Extrema/Extrema_GCurveLocator.hxx | 131 +++ .../TKGeomBase/Extrema/Extrema_GExtPC.gxx | 634 ------------ .../TKGeomBase/Extrema/Extrema_GFuncExtCC.hxx | 927 ++++++++++++++++++ .../TKGeomBase/Extrema/Extrema_GFuncExtPC.hxx | 482 +++++++++ .../TKGeomBase/Extrema/Extrema_GGExtPC.hxx | 658 +++++++++++++ .../TKGeomBase/Extrema/Extrema_GGenExtCC.hxx | 906 +++++++++++++++++ .../TKGeomBase/Extrema/Extrema_GGenExtPC.hxx | 236 +++++ .../Extrema/Extrema_GLocateExtPC.gxx | 367 ------- .../Extrema/Extrema_GLocateExtPC.hxx | 399 ++++++++ .../TKGeomBase/Extrema/Extrema_GenExtCC.gxx | 701 ------------- .../TKGeomBase/Extrema/Extrema_GenExtPC.gxx | 213 ---- .../Extrema/Extrema_GenLocateExtCC.gxx | 139 --- .../Extrema/Extrema_GenLocateExtCC.hxx | 145 +++ .../Extrema/Extrema_GenLocateExtPC.gxx | 149 --- .../Extrema/Extrema_GenLocateExtPC.hxx | 169 ++++ .../TKGeomBase/Extrema/Extrema_LocECC.hxx | 56 +- .../TKGeomBase/Extrema/Extrema_LocECC2d.hxx | 56 +- .../TKGeomBase/Extrema/Extrema_LocECC2d_0.cxx | 51 - .../TKGeomBase/Extrema/Extrema_LocECC_0.cxx | 51 - .../Extrema/Extrema_LocEPCOfLocateExtPC.hxx | 92 +- .../Extrema/Extrema_LocEPCOfLocateExtPC2d.hxx | 94 +- .../Extrema_LocEPCOfLocateExtPC2d_0.cxx | 48 - .../Extrema/Extrema_LocEPCOfLocateExtPC_0.cxx | 48 - .../Extrema/Extrema_LocateExtPC.hxx | 106 +- .../Extrema/Extrema_LocateExtPC2d.hxx | 108 +- .../Extrema/Extrema_LocateExtPC2d_0.cxx | 60 -- .../Extrema/Extrema_LocateExtPC_0.cxx | 60 -- .../Extrema_PCFOfEPCOfELPCOfLocateExtPC.hxx | 96 +- .../Extrema_PCFOfEPCOfELPCOfLocateExtPC2d.hxx | 98 +- ...xtrema_PCFOfEPCOfELPCOfLocateExtPC2d_0.cxx | 42 - .../Extrema_PCFOfEPCOfELPCOfLocateExtPC_0.cxx | 42 - .../Extrema/Extrema_PCFOfEPCOfExtPC.hxx | 96 +- .../Extrema/Extrema_PCFOfEPCOfExtPC2d.hxx | 96 +- .../Extrema/Extrema_PCFOfEPCOfExtPC2d_0.cxx | 42 - .../Extrema/Extrema_PCFOfEPCOfExtPC_0.cxx | 42 - .../Extrema_PCLocFOfLocEPCOfLocateExtPC.hxx | 96 +- .../Extrema_PCLocFOfLocEPCOfLocateExtPC2d.hxx | 98 +- ...xtrema_PCLocFOfLocEPCOfLocateExtPC2d_0.cxx | 42 - .../Extrema_PCLocFOfLocEPCOfLocateExtPC_0.cxx | 42 - .../TKGeomBase/Extrema/Extrema_POnCurv.hxx | 48 +- .../TKGeomBase/Extrema/Extrema_POnCurv2d.hxx | 47 +- .../Extrema/Extrema_POnCurv2d_0.cxx | 36 - .../TKGeomBase/Extrema/Extrema_POnCurv_0.cxx | 36 - .../TKGeomBase/Extrema/Extrema_POnSurf.hxx | 43 +- .../TKGeomBase/Extrema/Extrema_POnSurf.lxx | 51 - .../Extrema/Extrema_POnSurfParams.hxx | 51 +- .../Extrema/Extrema_POnSurfParams.lxx | 65 -- .../TKGeomBase/Extrema/FILES.cmake | 49 +- 99 files changed, 4726 insertions(+), 8609 deletions(-) delete mode 100644 src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/Geom2dInt_PCLocFOfTheLocateExtPCOfTheProjPCurOfGInter_0.cxx delete mode 100644 src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/Geom2dInt_TheCurveLocatorOfTheProjPCurOfGInter_0.cxx delete mode 100644 src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/Geom2dInt_TheLocateExtPCOfTheProjPCurOfGInter_0.cxx delete mode 100644 src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_PCLocFOfTheLocateExtPCOfTheProjPCurOfCInter_0.cxx delete mode 100644 src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_TheCurveLocatorOfTheProjPCurOfCInter_0.cxx delete mode 100644 src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_TheLocateExtPCOfTheProjPCurOfCInter_0.cxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_CCLocFOfLocECC2d_0.cxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_CCLocFOfLocECC_0.cxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_Curve2dTool.lxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_CurveLocator.gxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_CurveTool.lxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_ECC2d_0.cxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_ECC_0.cxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_ELPCOfLocateExtPC2d_0.cxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_ELPCOfLocateExtPC_0.cxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_EPCOfELPCOfLocateExtPC2d_0.cxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_EPCOfELPCOfLocateExtPC_0.cxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_EPCOfExtPC2d_0.cxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_EPCOfExtPC_0.cxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_ExtPC2d_0.cxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_ExtPC_0.cxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_FuncExtCC.gxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_FuncExtCC.lxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_FuncExtPC.gxx create mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_GCurveLocator.hxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_GExtPC.gxx create mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_GFuncExtCC.hxx create mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_GFuncExtPC.hxx create mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_GGExtPC.hxx create mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_GGenExtCC.hxx create mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_GGenExtPC.hxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_GLocateExtPC.gxx create mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_GLocateExtPC.hxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_GenExtCC.gxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_GenExtPC.gxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_GenLocateExtCC.gxx create mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_GenLocateExtCC.hxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_GenLocateExtPC.gxx create mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_GenLocateExtPC.hxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_LocECC2d_0.cxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_LocECC_0.cxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_LocEPCOfLocateExtPC2d_0.cxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_LocEPCOfLocateExtPC_0.cxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_LocateExtPC2d_0.cxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_LocateExtPC_0.cxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_PCFOfEPCOfELPCOfLocateExtPC2d_0.cxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_PCFOfEPCOfELPCOfLocateExtPC_0.cxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_PCFOfEPCOfExtPC2d_0.cxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_PCFOfEPCOfExtPC_0.cxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_PCLocFOfLocEPCOfLocateExtPC2d_0.cxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_PCLocFOfLocEPCOfLocateExtPC_0.cxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_POnCurv2d_0.cxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_POnCurv_0.cxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_POnSurf.lxx delete mode 100644 src/ModelingData/TKGeomBase/Extrema/Extrema_POnSurfParams.lxx diff --git a/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/FILES.cmake b/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/FILES.cmake index 4452ffb279..631bc22548 100644 --- a/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/FILES.cmake +++ b/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/FILES.cmake @@ -14,9 +14,7 @@ set(OCCT_Geom2dInt_FILES Geom2dInt_MyImpParToolOfTheIntersectorOfTheIntConicCurveOfGInter.hxx Geom2dInt_MyImpParToolOfTheIntersectorOfTheIntConicCurveOfGInter_0.cxx Geom2dInt_PCLocFOfTheLocateExtPCOfTheProjPCurOfGInter.hxx - Geom2dInt_PCLocFOfTheLocateExtPCOfTheProjPCurOfGInter_0.cxx Geom2dInt_TheCurveLocatorOfTheProjPCurOfGInter.hxx - Geom2dInt_TheCurveLocatorOfTheProjPCurOfGInter_0.cxx Geom2dInt_TheDistBetweenPCurvesOfTheIntPCurvePCurveOfGInter.hxx Geom2dInt_TheDistBetweenPCurvesOfTheIntPCurvePCurveOfGInter_0.cxx Geom2dInt_TheIntConicCurveOfGInter.hxx @@ -26,7 +24,6 @@ set(OCCT_Geom2dInt_FILES Geom2dInt_TheIntPCurvePCurveOfGInter.hxx Geom2dInt_TheIntPCurvePCurveOfGInter_0.cxx Geom2dInt_TheLocateExtPCOfTheProjPCurOfGInter.hxx - Geom2dInt_TheLocateExtPCOfTheProjPCurOfGInter_0.cxx Geom2dInt_ThePolygon2dOfTheIntPCurvePCurveOfGInter.hxx Geom2dInt_ThePolygon2dOfTheIntPCurvePCurveOfGInter_0.cxx Geom2dInt_TheProjPCurOfGInter.hxx diff --git a/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/Geom2dInt_GInter.hxx b/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/Geom2dInt_GInter.hxx index 1503f62305..7d03b36ef5 100644 --- a/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/Geom2dInt_GInter.hxx +++ b/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/Geom2dInt_GInter.hxx @@ -17,6 +17,7 @@ #ifndef _Geom2dInt_GInter_HeaderFile #define _Geom2dInt_GInter_HeaderFile +#include #include #include @@ -30,8 +31,6 @@ class Standard_ConstructionError; class Adaptor2d_Curve2d; class Geom2dInt_Geom2dCurveTool; class Geom2dInt_TheProjPCurOfGInter; -class Geom2dInt_TheCurveLocatorOfTheProjPCurOfGInter; -class Geom2dInt_TheLocateExtPCOfTheProjPCurOfGInter; class Geom2dInt_TheIntConicCurveOfGInter; class Geom2dInt_TheIntersectorOfTheIntConicCurveOfGInter; class Geom2dInt_IntConicCurveOfGInter; diff --git a/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/Geom2dInt_PCLocFOfTheLocateExtPCOfTheProjPCurOfGInter.hxx b/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/Geom2dInt_PCLocFOfTheLocateExtPCOfTheProjPCurOfGInter.hxx index 4e42fdc19e..042f45f400 100644 --- a/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/Geom2dInt_PCLocFOfTheLocateExtPCOfTheProjPCurOfGInter.hxx +++ b/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/Geom2dInt_PCLocFOfTheLocateExtPCOfTheProjPCurOfGInter.hxx @@ -17,92 +17,21 @@ #ifndef _Geom2dInt_PCLocFOfTheLocateExtPCOfTheProjPCurOfGInter_HeaderFile #define _Geom2dInt_PCLocFOfTheLocateExtPCOfTheProjPCurOfGInter_HeaderFile -#include -#include -#include - -#include -#include -#include +#include +#include +#include #include -#include -#include -class Standard_OutOfRange; -class Standard_TypeMismatch; -class Adaptor2d_Curve2d; -class Geom2dInt_Geom2dCurveTool; -class Extrema_POnCurv2d; -class gp_Pnt2d; -class gp_Vec2d; +#include +#include +#include -class Geom2dInt_PCLocFOfTheLocateExtPCOfTheProjPCurOfGInter : public math_FunctionWithDerivative -{ -public: - DEFINE_STANDARD_ALLOC - - Standard_EXPORT Geom2dInt_PCLocFOfTheLocateExtPCOfTheProjPCurOfGInter(); - - Standard_EXPORT Geom2dInt_PCLocFOfTheLocateExtPCOfTheProjPCurOfGInter(const gp_Pnt2d& P, - const Adaptor2d_Curve2d& C); - - //! sets the field mycurve of the function. - Standard_EXPORT void Initialize(const Adaptor2d_Curve2d& C); - - //! sets the field P of the function. - Standard_EXPORT void SetPoint(const gp_Pnt2d& P); - - //! Calculation of F(U). - Standard_EXPORT Standard_Boolean Value(const Standard_Real U, Standard_Real& F) Standard_OVERRIDE; - - //! Calculation of F'(U). - Standard_EXPORT Standard_Boolean Derivative(const Standard_Real U, - Standard_Real& DF) Standard_OVERRIDE; - - //! Calculation of F(U) and F'(U). - Standard_EXPORT Standard_Boolean Values(const Standard_Real U, - Standard_Real& F, - Standard_Real& DF) Standard_OVERRIDE; - - //! Save the found extremum. - Standard_EXPORT virtual Standard_Integer GetStateNumber() Standard_OVERRIDE; - - //! Return the number of found extrema. - Standard_EXPORT Standard_Integer NbExt() const; - - //! Returns the Nth distance. - Standard_EXPORT Standard_Real SquareDistance(const Standard_Integer N) const; - - //! Shows if the Nth distance is a minimum. - Standard_EXPORT Standard_Boolean IsMin(const Standard_Integer N) const; - - //! Returns the Nth extremum. - Standard_EXPORT const Extrema_POnCurv2d& Point(const Standard_Integer N) const; - - //! Determines boundaries of subinterval for find of root. - Standard_EXPORT void SubIntervalInitialize(const Standard_Real theUfirst, - const Standard_Real theUlast); - - //! Computes a Tol value. If 1st derivative of curve - //! |D1|; #endif // _Geom2dInt_PCLocFOfTheLocateExtPCOfTheProjPCurOfGInter_HeaderFile diff --git a/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/Geom2dInt_PCLocFOfTheLocateExtPCOfTheProjPCurOfGInter_0.cxx b/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/Geom2dInt_PCLocFOfTheLocateExtPCOfTheProjPCurOfGInter_0.cxx deleted file mode 100644 index ff9da7c731..0000000000 --- a/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/Geom2dInt_PCLocFOfTheLocateExtPCOfTheProjPCurOfGInter_0.cxx +++ /dev/null @@ -1,42 +0,0 @@ -// Created on: 1992-06-04 -// Created by: Jacques GOUSSARD -// Copyright (c) 1992-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 - -#include -#include -#include -#include -#include -#include -#include -#include - -#define Curve Adaptor2d_Curve2d -#define Curve_hxx -#define Tool Geom2dInt_Geom2dCurveTool -#define Tool_hxx -#define POnC Extrema_POnCurv2d -#define POnC_hxx -#define Pnt gp_Pnt2d -#define Pnt_hxx -#define Vec gp_Vec2d -#define Vec_hxx -#define Extrema_SeqPC Extrema_SequenceOfPOnCurv2d -#define Extrema_SeqPC_hxx -#define Extrema_FuncExtPC Geom2dInt_PCLocFOfTheLocateExtPCOfTheProjPCurOfGInter -#define Extrema_FuncExtPC_hxx -#include diff --git a/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/Geom2dInt_TheCurveLocatorOfTheProjPCurOfGInter.hxx b/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/Geom2dInt_TheCurveLocatorOfTheProjPCurOfGInter.hxx index 9414566641..3eaf240231 100644 --- a/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/Geom2dInt_TheCurveLocatorOfTheProjPCurOfGInter.hxx +++ b/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/Geom2dInt_TheCurveLocatorOfTheProjPCurOfGInter.hxx @@ -17,53 +17,14 @@ #ifndef _Geom2dInt_TheCurveLocatorOfTheProjPCurOfGInter_HeaderFile #define _Geom2dInt_TheCurveLocatorOfTheProjPCurOfGInter_HeaderFile -#include -#include -#include +#include +#include +#include +#include +#include -#include -class Adaptor2d_Curve2d; -class Geom2dInt_Geom2dCurveTool; -class Extrema_POnCurv2d; -class gp_Pnt2d; - -class Geom2dInt_TheCurveLocatorOfTheProjPCurOfGInter -{ -public: - DEFINE_STANDARD_ALLOC - - //! Among a set of points {C(ui),i=1,NbU}, locate the point - //! P=C(uj) such that: - //! distance(P,C) = Min{distance(P,C(ui))} - Standard_EXPORT static void Locate(const gp_Pnt2d& P, - const Adaptor2d_Curve2d& C, - const Standard_Integer NbU, - Extrema_POnCurv2d& Papp); - - //! Among a set of points {C(ui),i=1,NbU}, locate the point - //! P=C(uj) such that: - //! distance(P,C) = Min{distance(P,C(ui))} - //! The research is done between umin and usup. - Standard_EXPORT static void Locate(const gp_Pnt2d& P, - const Adaptor2d_Curve2d& C, - const Standard_Integer NbU, - const Standard_Real Umin, - const Standard_Real Usup, - Extrema_POnCurv2d& Papp); - - //! Among two sets of points {C1(ui),i=1,NbU} and - //! {C2(vj),j=1,NbV}, locate the two points P1=C1(uk) and - //! P2=C2(vl) such that: - //! distance(P1,P2) = Min {distance(C1(ui),C2(vj))}. - Standard_EXPORT static void Locate(const Adaptor2d_Curve2d& C1, - const Adaptor2d_Curve2d& C2, - const Standard_Integer NbU, - const Standard_Integer NbV, - Extrema_POnCurv2d& Papp1, - Extrema_POnCurv2d& Papp2); - -protected: -private: -}; +//! Type alias for 2D curve locator using Geom2dInt_Geom2dCurveTool. +using Geom2dInt_TheCurveLocatorOfTheProjPCurOfGInter = + Extrema_GCurveLocator; #endif // _Geom2dInt_TheCurveLocatorOfTheProjPCurOfGInter_HeaderFile diff --git a/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/Geom2dInt_TheCurveLocatorOfTheProjPCurOfGInter_0.cxx b/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/Geom2dInt_TheCurveLocatorOfTheProjPCurOfGInter_0.cxx deleted file mode 100644 index 564d137f2f..0000000000 --- a/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/Geom2dInt_TheCurveLocatorOfTheProjPCurOfGInter_0.cxx +++ /dev/null @@ -1,38 +0,0 @@ -// Created on: 1992-06-04 -// Created by: Jacques GOUSSARD -// Copyright (c) 1992-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 - -#include -#include -#include -#include - -#define Curve1 Adaptor2d_Curve2d -#define Curve1_hxx -#define Tool1 Geom2dInt_Geom2dCurveTool -#define Tool1_hxx -#define Curve2 Adaptor2d_Curve2d -#define Curve2_hxx -#define Tool2 Geom2dInt_Geom2dCurveTool -#define Tool2_hxx -#define POnC Extrema_POnCurv2d -#define POnC_hxx -#define Pnt gp_Pnt2d -#define Pnt_hxx -#define Extrema_CurveLocator Geom2dInt_TheCurveLocatorOfTheProjPCurOfGInter -#define Extrema_CurveLocator_hxx -#include diff --git a/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/Geom2dInt_TheLocateExtPCOfTheProjPCurOfGInter.hxx b/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/Geom2dInt_TheLocateExtPCOfTheProjPCurOfGInter.hxx index e37baa178c..7113e5e330 100644 --- a/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/Geom2dInt_TheLocateExtPCOfTheProjPCurOfGInter.hxx +++ b/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/Geom2dInt_TheLocateExtPCOfTheProjPCurOfGInter.hxx @@ -17,89 +17,19 @@ #ifndef _Geom2dInt_TheLocateExtPCOfTheProjPCurOfGInter_HeaderFile #define _Geom2dInt_TheLocateExtPCOfTheProjPCurOfGInter_HeaderFile -#include -#include -#include - -#include +#include +#include +#include +#include #include -class Standard_DomainError; -class Standard_TypeMismatch; -class StdFail_NotDone; -class Adaptor2d_Curve2d; -class Geom2dInt_Geom2dCurveTool; -class Extrema_POnCurv2d; -class gp_Pnt2d; -class gp_Vec2d; +#include -class Geom2dInt_TheLocateExtPCOfTheProjPCurOfGInter -{ -public: - DEFINE_STANDARD_ALLOC - - Standard_EXPORT Geom2dInt_TheLocateExtPCOfTheProjPCurOfGInter(); - - //! Calculates the distance with a close point. - //! The close point is defined by the parameter value - //! U0. - //! The function F(u)=distance(P,C(u)) has an extremum - //! when g(u)=dF/du=0. The algorithm searches a zero - //! near the close point. - //! TolU is used to decide to stop the iterations. - //! At the nth iteration, the criteria is: - //! abs(Un - Un-1) < TolU. - Standard_EXPORT Geom2dInt_TheLocateExtPCOfTheProjPCurOfGInter(const gp_Pnt2d& P, - const Adaptor2d_Curve2d& C, - const Standard_Real U0, - const Standard_Real TolU); - - //! Calculates the distance with a close point. - //! The close point is defined by the parameter value - //! U0. - //! The function F(u)=distance(P,C(u)) has an extremum - //! when g(u)=dF/du=0. The algorithm searches a zero - //! near the close point. - //! Zeros are searched between Umin et Usup. - //! TolU is used to decide to stop the iterations. - //! At the nth iteration, the criteria is: - //! abs(Un - Un-1) < TolU. - Standard_EXPORT Geom2dInt_TheLocateExtPCOfTheProjPCurOfGInter(const gp_Pnt2d& P, - const Adaptor2d_Curve2d& C, - const Standard_Real U0, - const Standard_Real Umin, - const Standard_Real Usup, - const Standard_Real TolU); - - //! sets the fields of the algorithm. - Standard_EXPORT void Initialize(const Adaptor2d_Curve2d& C, - const Standard_Real Umin, - const Standard_Real Usup, - const Standard_Real TolU); - - //! the algorithm is done with the point P. - //! An exception is raised if the fields have not - //! been initialized. - Standard_EXPORT void Perform(const gp_Pnt2d& P, const Standard_Real U0); - - //! Returns True if the distance is found. - Standard_EXPORT Standard_Boolean IsDone() const; - - //! Returns the value of the extremum square distance. - Standard_EXPORT Standard_Real SquareDistance() const; - - //! Returns True if the extremum distance is a minimum. - Standard_EXPORT Standard_Boolean IsMin() const; - - //! Returns the point of the extremum distance. - Standard_EXPORT const Extrema_POnCurv2d& Point() const; - -protected: -private: - Standard_Boolean myDone; - Standard_Real mytolU; - Standard_Real myumin; - Standard_Real myusup; - Geom2dInt_PCLocFOfTheLocateExtPCOfTheProjPCurOfGInter myF; -}; +//! Type alias for Geom2dInt local extremum search. +using Geom2dInt_TheLocateExtPCOfTheProjPCurOfGInter = + Extrema_GenLocateExtPC; #endif // _Geom2dInt_TheLocateExtPCOfTheProjPCurOfGInter_HeaderFile diff --git a/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/Geom2dInt_TheLocateExtPCOfTheProjPCurOfGInter_0.cxx b/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/Geom2dInt_TheLocateExtPCOfTheProjPCurOfGInter_0.cxx deleted file mode 100644 index 1e23dd7d10..0000000000 --- a/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/Geom2dInt_TheLocateExtPCOfTheProjPCurOfGInter_0.cxx +++ /dev/null @@ -1,48 +0,0 @@ -// Created on: 1992-06-04 -// Created by: Jacques GOUSSARD -// Copyright (c) 1992-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 - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define Curve Adaptor2d_Curve2d -#define Curve_hxx -#define Tool Geom2dInt_Geom2dCurveTool -#define Tool_hxx -#define POnC Extrema_POnCurv2d -#define POnC_hxx -#define Pnt gp_Pnt2d -#define Pnt_hxx -#define Vec gp_Vec2d -#define Vec_hxx -#define Extrema_PCLocF Geom2dInt_PCLocFOfTheLocateExtPCOfTheProjPCurOfGInter -#define Extrema_PCLocF_hxx -#define Extrema_SeqPCOfPCLocF Extrema_SequenceOfPOnCurv2d -#define Extrema_SeqPCOfPCLocF_hxx -#define Extrema_SeqPCOfPCLocF Extrema_SequenceOfPOnCurv2d -#define Extrema_SeqPCOfPCLocF_hxx -#define Extrema_GenLocateExtPC Geom2dInt_TheLocateExtPCOfTheProjPCurOfGInter -#define Extrema_GenLocateExtPC_hxx -#include diff --git a/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/Geom2dInt_TheProjPCurOfGInter.hxx b/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/Geom2dInt_TheProjPCurOfGInter.hxx index d4842eebd1..458e2a391b 100644 --- a/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/Geom2dInt_TheProjPCurOfGInter.hxx +++ b/src/ModelingAlgorithms/TKGeomAlgo/Geom2dInt/Geom2dInt_TheProjPCurOfGInter.hxx @@ -17,14 +17,12 @@ #ifndef _Geom2dInt_TheProjPCurOfGInter_HeaderFile #define _Geom2dInt_TheProjPCurOfGInter_HeaderFile +#include #include #include class Adaptor2d_Curve2d; class Geom2dInt_Geom2dCurveTool; -class Geom2dInt_TheCurveLocatorOfTheProjPCurOfGInter; -class Geom2dInt_TheLocateExtPCOfTheProjPCurOfGInter; -class Geom2dInt_PCLocFOfTheLocateExtPCOfTheProjPCurOfGInter; class gp_Pnt2d; class Geom2dInt_TheProjPCurOfGInter diff --git a/src/ModelingAlgorithms/TKHLR/HLRBRep/FILES.cmake b/src/ModelingAlgorithms/TKHLR/HLRBRep/FILES.cmake index 43ef0e637b..345d4ff155 100644 --- a/src/ModelingAlgorithms/TKHLR/HLRBRep/FILES.cmake +++ b/src/ModelingAlgorithms/TKHLR/HLRBRep/FILES.cmake @@ -75,7 +75,6 @@ set(OCCT_HLRBRep_FILES HLRBRep_MyImpParToolOfTheIntersectorOfTheIntConicCurveOfCInter.hxx HLRBRep_MyImpParToolOfTheIntersectorOfTheIntConicCurveOfCInter_0.cxx HLRBRep_PCLocFOfTheLocateExtPCOfTheProjPCurOfCInter.hxx - HLRBRep_PCLocFOfTheLocateExtPCOfTheProjPCurOfCInter_0.cxx HLRBRep_PolyAlgo.cxx HLRBRep_PolyAlgo.hxx HLRBRep_PolyHLRToShape.cxx @@ -100,7 +99,6 @@ set(OCCT_HLRBRep_FILES HLRBRep_TheCSFunctionOfInterCSurf.hxx HLRBRep_TheCSFunctionOfInterCSurf_0.cxx HLRBRep_TheCurveLocatorOfTheProjPCurOfCInter.hxx - HLRBRep_TheCurveLocatorOfTheProjPCurOfCInter_0.cxx HLRBRep_TheDistBetweenPCurvesOfTheIntPCurvePCurveOfCInter.hxx HLRBRep_TheDistBetweenPCurvesOfTheIntPCurvePCurveOfCInter_0.cxx HLRBRep_TheExactInterCSurf.hxx @@ -114,7 +112,6 @@ set(OCCT_HLRBRep_FILES HLRBRep_TheIntPCurvePCurveOfCInter.hxx HLRBRep_TheIntPCurvePCurveOfCInter_0.cxx HLRBRep_TheLocateExtPCOfTheProjPCurOfCInter.hxx - HLRBRep_TheLocateExtPCOfTheProjPCurOfCInter_0.cxx HLRBRep_ThePolygon2dOfTheIntPCurvePCurveOfCInter.hxx HLRBRep_ThePolygon2dOfTheIntPCurvePCurveOfCInter_0.cxx HLRBRep_ThePolygonOfInterCSurf.hxx diff --git a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_CInter.hxx b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_CInter.hxx index 82f31c4554..12a3ca8a6a 100644 --- a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_CInter.hxx +++ b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_CInter.hxx @@ -17,6 +17,7 @@ #ifndef _HLRBRep_CInter_HeaderFile #define _HLRBRep_CInter_HeaderFile +#include #include #include @@ -29,8 +30,6 @@ class Standard_ConstructionError; class HLRBRep_CurveTool; class HLRBRep_TheProjPCurOfCInter; -class HLRBRep_TheCurveLocatorOfTheProjPCurOfCInter; -class HLRBRep_TheLocateExtPCOfTheProjPCurOfCInter; class HLRBRep_TheIntConicCurveOfCInter; class HLRBRep_TheIntersectorOfTheIntConicCurveOfCInter; class HLRBRep_IntConicCurveOfCInter; diff --git a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_PCLocFOfTheLocateExtPCOfTheProjPCurOfCInter.hxx b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_PCLocFOfTheLocateExtPCOfTheProjPCurOfCInter.hxx index dc94f45247..18a38c5140 100644 --- a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_PCLocFOfTheLocateExtPCOfTheProjPCurOfCInter.hxx +++ b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_PCLocFOfTheLocateExtPCOfTheProjPCurOfCInter.hxx @@ -17,91 +17,21 @@ #ifndef _HLRBRep_PCLocFOfTheLocateExtPCOfTheProjPCurOfCInter_HeaderFile #define _HLRBRep_PCLocFOfTheLocateExtPCOfTheProjPCurOfCInter_HeaderFile -#include -#include -#include - -#include -#include -#include +#include +#include #include -#include -#include -class Standard_OutOfRange; -class Standard_TypeMismatch; -class HLRBRep_CurveTool; -class Extrema_POnCurv2d; -class gp_Pnt2d; -class gp_Vec2d; +#include +#include +#include +#include -class HLRBRep_PCLocFOfTheLocateExtPCOfTheProjPCurOfCInter : public math_FunctionWithDerivative -{ -public: - DEFINE_STANDARD_ALLOC - - Standard_EXPORT HLRBRep_PCLocFOfTheLocateExtPCOfTheProjPCurOfCInter(); - - Standard_EXPORT HLRBRep_PCLocFOfTheLocateExtPCOfTheProjPCurOfCInter(const gp_Pnt2d& P, - const Standard_Address& C); - - //! sets the field mycurve of the function. - Standard_EXPORT void Initialize(const Standard_Address& C); - - //! sets the field P of the function. - Standard_EXPORT void SetPoint(const gp_Pnt2d& P); - - //! Calculation of F(U). - Standard_EXPORT Standard_Boolean Value(const Standard_Real U, Standard_Real& F) Standard_OVERRIDE; - - //! Calculation of F'(U). - Standard_EXPORT Standard_Boolean Derivative(const Standard_Real U, - Standard_Real& DF) Standard_OVERRIDE; - - //! Calculation of F(U) and F'(U). - Standard_EXPORT Standard_Boolean Values(const Standard_Real U, - Standard_Real& F, - Standard_Real& DF) Standard_OVERRIDE; - - //! Save the found extremum. - Standard_EXPORT virtual Standard_Integer GetStateNumber() Standard_OVERRIDE; - - //! Return the number of found extrema. - Standard_EXPORT Standard_Integer NbExt() const; - - //! Returns the Nth distance. - Standard_EXPORT Standard_Real SquareDistance(const Standard_Integer N) const; - - //! Shows if the Nth distance is a minimum. - Standard_EXPORT Standard_Boolean IsMin(const Standard_Integer N) const; - - //! Returns the Nth extremum. - Standard_EXPORT const Extrema_POnCurv2d& Point(const Standard_Integer N) const; - - //! Determines boundaries of subinterval for find of root. - Standard_EXPORT void SubIntervalInitialize(const Standard_Real theUfirst, - const Standard_Real theUlast); - - //! Computes a Tol value. If 1st derivative of curve - //! |D1|; #endif // _HLRBRep_PCLocFOfTheLocateExtPCOfTheProjPCurOfCInter_HeaderFile diff --git a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_PCLocFOfTheLocateExtPCOfTheProjPCurOfCInter_0.cxx b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_PCLocFOfTheLocateExtPCOfTheProjPCurOfCInter_0.cxx deleted file mode 100644 index 4529a7a8ab..0000000000 --- a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_PCLocFOfTheLocateExtPCOfTheProjPCurOfCInter_0.cxx +++ /dev/null @@ -1,41 +0,0 @@ -// Created on: 1992-10-14 -// Created by: Christophe MARION -// Copyright (c) 1992-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 - -#include -#include -#include -#include -#include -#include -#include - -#define Curve Standard_Address -#define Curve_hxx -#define Tool HLRBRep_CurveTool -#define Tool_hxx -#define POnC Extrema_POnCurv2d -#define POnC_hxx -#define Pnt gp_Pnt2d -#define Pnt_hxx -#define Vec gp_Vec2d -#define Vec_hxx -#define Extrema_SeqPC Extrema_SequenceOfPOnCurv2d -#define Extrema_SeqPC_hxx -#define Extrema_FuncExtPC HLRBRep_PCLocFOfTheLocateExtPCOfTheProjPCurOfCInter -#define Extrema_FuncExtPC_hxx -#include diff --git a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_TheCurveLocatorOfTheProjPCurOfCInter.hxx b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_TheCurveLocatorOfTheProjPCurOfCInter.hxx index 2b8b157f8f..b8aa9e8dca 100644 --- a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_TheCurveLocatorOfTheProjPCurOfCInter.hxx +++ b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_TheCurveLocatorOfTheProjPCurOfCInter.hxx @@ -17,52 +17,14 @@ #ifndef _HLRBRep_TheCurveLocatorOfTheProjPCurOfCInter_HeaderFile #define _HLRBRep_TheCurveLocatorOfTheProjPCurOfCInter_HeaderFile -#include -#include -#include +#include +#include +#include +#include +#include -#include -class HLRBRep_CurveTool; -class Extrema_POnCurv2d; -class gp_Pnt2d; - -class HLRBRep_TheCurveLocatorOfTheProjPCurOfCInter -{ -public: - DEFINE_STANDARD_ALLOC - - //! Among a set of points {C(ui),i=1,NbU}, locate the point - //! P=C(uj) such that: - //! distance(P,C) = Min{distance(P,C(ui))} - Standard_EXPORT static void Locate(const gp_Pnt2d& P, - const Standard_Address& C, - const Standard_Integer NbU, - Extrema_POnCurv2d& Papp); - - //! Among a set of points {C(ui),i=1,NbU}, locate the point - //! P=C(uj) such that: - //! distance(P,C) = Min{distance(P,C(ui))} - //! The research is done between umin and usup. - Standard_EXPORT static void Locate(const gp_Pnt2d& P, - const Standard_Address& C, - const Standard_Integer NbU, - const Standard_Real Umin, - const Standard_Real Usup, - Extrema_POnCurv2d& Papp); - - //! Among two sets of points {C1(ui),i=1,NbU} and - //! {C2(vj),j=1,NbV}, locate the two points P1=C1(uk) and - //! P2=C2(vl) such that: - //! distance(P1,P2) = Min {distance(C1(ui),C2(vj))}. - Standard_EXPORT static void Locate(const Standard_Address& C1, - const Standard_Address& C2, - const Standard_Integer NbU, - const Standard_Integer NbV, - Extrema_POnCurv2d& Papp1, - Extrema_POnCurv2d& Papp2); - -protected: -private: -}; +//! Type alias for curve locator using HLRBRep_CurveTool. +using HLRBRep_TheCurveLocatorOfTheProjPCurOfCInter = + Extrema_GCurveLocator; #endif // _HLRBRep_TheCurveLocatorOfTheProjPCurOfCInter_HeaderFile diff --git a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_TheCurveLocatorOfTheProjPCurOfCInter_0.cxx b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_TheCurveLocatorOfTheProjPCurOfCInter_0.cxx deleted file mode 100644 index c7f86ff354..0000000000 --- a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_TheCurveLocatorOfTheProjPCurOfCInter_0.cxx +++ /dev/null @@ -1,37 +0,0 @@ -// Created on: 1992-10-14 -// Created by: Christophe MARION -// Copyright (c) 1992-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 - -#include -#include -#include - -#define Curve1 Standard_Address -#define Curve1_hxx -#define Tool1 HLRBRep_CurveTool -#define Tool1_hxx -#define Curve2 Standard_Address -#define Curve2_hxx -#define Tool2 HLRBRep_CurveTool -#define Tool2_hxx -#define POnC Extrema_POnCurv2d -#define POnC_hxx -#define Pnt gp_Pnt2d -#define Pnt_hxx -#define Extrema_CurveLocator HLRBRep_TheCurveLocatorOfTheProjPCurOfCInter -#define Extrema_CurveLocator_hxx -#include diff --git a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_TheLocateExtPCOfTheProjPCurOfCInter.hxx b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_TheLocateExtPCOfTheProjPCurOfCInter.hxx index 39884cbcbd..30e2311c4a 100644 --- a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_TheLocateExtPCOfTheProjPCurOfCInter.hxx +++ b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_TheLocateExtPCOfTheProjPCurOfCInter.hxx @@ -17,84 +17,19 @@ #ifndef _HLRBRep_TheLocateExtPCOfTheProjPCurOfCInter_HeaderFile #define _HLRBRep_TheLocateExtPCOfTheProjPCurOfCInter_HeaderFile -#include -#include -#include - -#include +#include +#include +#include +#include #include -class Standard_DomainError; -class Standard_TypeMismatch; -class StdFail_NotDone; -class HLRBRep_CurveTool; -class Extrema_POnCurv2d; -class gp_Pnt2d; -class gp_Vec2d; -class HLRBRep_PCLocFOfTheLocateExtPCOfTheProjPCurOfCInter; +#include -class HLRBRep_TheLocateExtPCOfTheProjPCurOfCInter -{ -public: - DEFINE_STANDARD_ALLOC - - Standard_EXPORT HLRBRep_TheLocateExtPCOfTheProjPCurOfCInter(); - - //! Calculates the distance with a close point. - //! The close point is defined by the parameter value U0. - //! The function F(u)=distance(P,C(u)) has an extremum when g(u)=dF/du=0. - //! The algorithm searches a zero near the close point. - //! TolU is used to decide to stop the iterations. - //! At the nth iteration, the criteria is: - //! abs(Un - Un-1) < TolU. - Standard_EXPORT HLRBRep_TheLocateExtPCOfTheProjPCurOfCInter(const gp_Pnt2d& P, - const Standard_Address& C, - const Standard_Real U0, - const Standard_Real TolU); - - //! Calculates the distance with a close point. - //! The close point is defined by the parameter value U0. - //! The function F(u)=distance(P,C(u)) has an extremum when g(u)=dF/du=0. - //! The algorithm searches a zero near the close point. - //! Zeros are searched between Umin and Usup. - //! TolU is used to decide to stop the iterations. - //! At the nth iteration, the criteria is: - //! abs(Un - Un-1) < TolU. - Standard_EXPORT HLRBRep_TheLocateExtPCOfTheProjPCurOfCInter(const gp_Pnt2d& P, - const Standard_Address& C, - const Standard_Real U0, - const Standard_Real Umin, - const Standard_Real Usup, - const Standard_Real TolU); - - //! sets the fields of the algorithm. - Standard_EXPORT void Initialize(const Standard_Address& C, - const Standard_Real Umin, - const Standard_Real Usup, - const Standard_Real TolU); - - //! the algorithm is done with the point P. - //! An exception is raised if the fields have not - //! been initialized. - Standard_EXPORT void Perform(const gp_Pnt2d& P, const Standard_Real U0); - - //! Returns True if the distance is found. - Standard_EXPORT Standard_Boolean IsDone() const; - - //! Returns the value of the extremum square distance. - Standard_EXPORT Standard_Real SquareDistance() const; - - //! Returns True if the extremum distance is a minimum. - Standard_EXPORT Standard_Boolean IsMin() const; - - //! Returns the point of the extremum distance. - Standard_EXPORT const Extrema_POnCurv2d& Point() const; - -private: - Standard_Boolean myDone; - Standard_Real mytolU; - Standard_Real myumin; - Standard_Real myusup; - HLRBRep_PCLocFOfTheLocateExtPCOfTheProjPCurOfCInter myF; -}; +//! Type alias for HLRBRep local extremum search. +using HLRBRep_TheLocateExtPCOfTheProjPCurOfCInter = + Extrema_GenLocateExtPC; #endif // _HLRBRep_TheLocateExtPCOfTheProjPCurOfCInter_HeaderFile diff --git a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_TheLocateExtPCOfTheProjPCurOfCInter_0.cxx b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_TheLocateExtPCOfTheProjPCurOfCInter_0.cxx deleted file mode 100644 index 5150c6bff8..0000000000 --- a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_TheLocateExtPCOfTheProjPCurOfCInter_0.cxx +++ /dev/null @@ -1,47 +0,0 @@ -// Created on: 1992-10-14 -// Created by: Christophe MARION -// Copyright (c) 1992-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 - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define Curve Standard_Address -#define Curve_hxx -#define Tool HLRBRep_CurveTool -#define Tool_hxx -#define POnC Extrema_POnCurv2d -#define POnC_hxx -#define Pnt gp_Pnt2d -#define Pnt_hxx -#define Vec gp_Vec2d -#define Vec_hxx -#define Extrema_PCLocF HLRBRep_PCLocFOfTheLocateExtPCOfTheProjPCurOfCInter -#define Extrema_PCLocF_hxx -#define Extrema_SeqPCOfPCLocF Extrema_SequenceOfPOnCurv2d -#define Extrema_SeqPCOfPCLocF_hxx -#define Extrema_SeqPCOfPCLocF Extrema_SequenceOfPOnCurv2d -#define Extrema_SeqPCOfPCLocF_hxx -#define Extrema_GenLocateExtPC HLRBRep_TheLocateExtPCOfTheProjPCurOfCInter -#define Extrema_GenLocateExtPC_hxx -#include diff --git a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_TheProjPCurOfCInter.hxx b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_TheProjPCurOfCInter.hxx index 5c8a592b4a..a84875548c 100644 --- a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_TheProjPCurOfCInter.hxx +++ b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_TheProjPCurOfCInter.hxx @@ -17,15 +17,13 @@ #ifndef _HLRBRep_TheProjPCurOfCInter_HeaderFile #define _HLRBRep_TheProjPCurOfCInter_HeaderFile +#include #include #include #include #include class HLRBRep_CurveTool; -class HLRBRep_TheCurveLocatorOfTheProjPCurOfCInter; -class HLRBRep_TheLocateExtPCOfTheProjPCurOfCInter; -class HLRBRep_PCLocFOfTheLocateExtPCOfTheProjPCurOfCInter; class gp_Pnt2d; class HLRBRep_TheProjPCurOfCInter diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_CCLocFOfLocECC.hxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_CCLocFOfLocECC.hxx index de2c9a3993..6d3d7a31fe 100644 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_CCLocFOfLocECC.hxx +++ b/src/ModelingData/TKGeomBase/Extrema/Extrema_CCLocFOfLocECC.hxx @@ -17,148 +17,22 @@ #ifndef _Extrema_CCLocFOfLocECC_HeaderFile #define _Extrema_CCLocFOfLocECC_HeaderFile -#include -#include -#include - +#include +#include +#include +#include +#include #include #include -#include -#include -#include -#include -#include -class Standard_OutOfRange; -class Adaptor3d_Curve; -class Extrema_CurveTool; -class Extrema_POnCurv; -class gp_Pnt; -class gp_Vec; -class math_Matrix; -class Extrema_CCLocFOfLocECC : public math_FunctionSetWithDerivatives -{ -public: - DEFINE_STANDARD_ALLOC - - Standard_EXPORT Extrema_CCLocFOfLocECC(const Standard_Real thetol = 1.0e-10); - - Standard_EXPORT Extrema_CCLocFOfLocECC(const Adaptor3d_Curve& C1, - const Adaptor3d_Curve& C2, - const Standard_Real thetol = 1.0e-10); - - Standard_EXPORT void SetCurve(const Standard_Integer theRank, const Adaptor3d_Curve& C1); - - void SetTolerance(const Standard_Real theTol); - - virtual Standard_Integer NbVariables() const Standard_OVERRIDE; - - virtual Standard_Integer NbEquations() const Standard_OVERRIDE; - - //! Calculate Fi(U,V). - Standard_EXPORT virtual Standard_Boolean Value(const math_Vector& UV, - math_Vector& F) Standard_OVERRIDE; - - //! Calculate Fi'(U,V). - Standard_EXPORT Standard_Boolean Derivatives(const math_Vector& UV, - math_Matrix& DF) Standard_OVERRIDE; - - //! Calculate Fi(U,V) and Fi'(U,V). - Standard_EXPORT Standard_Boolean Values(const math_Vector& UV, - math_Vector& F, - math_Matrix& DF) Standard_OVERRIDE; - - //! Save the found extremum. - Standard_EXPORT virtual Standard_Integer GetStateNumber() Standard_OVERRIDE; - - //! Return the number of found extrema. - Standard_Integer NbExt() const; - - //! Return the value of the Nth distance. - Standard_Real SquareDistance(const Standard_Integer N) const; - - //! Return the points of the Nth extreme distance. - Standard_EXPORT void Points(const Standard_Integer N, - Extrema_POnCurv& P1, - Extrema_POnCurv& P2) const; - - //! Returns a pointer to the curve specified in the constructor - //! or in SetCurve() method. - Standard_Address CurvePtr(const Standard_Integer theRank) const; - - //! Returns a tolerance specified in the constructor - //! or in SetTolerance() method. - Standard_Real Tolerance() const; - - //! Determines of boundaries of subinterval for find of root. - Standard_EXPORT void SubIntervalInitialize(const math_Vector& theUfirst, - const math_Vector& theUlast); - - //! Computes a Tol value. If 1st derivative of curve - //! |D1| -#define Tool1 Extrema_CurveTool -#define Tool1_hxx -#define Curve2 Adaptor3d_Curve -#define Curve2_hxx -#define Tool2 Extrema_CurveTool -#define Tool2_hxx -#define POnC Extrema_POnCurv -#define POnC_hxx -#define Pnt gp_Pnt -#define Pnt_hxx -#define Vec gp_Vec -#define Vec_hxx -#define Extrema_SeqPOnC Extrema_SequenceOfPOnCurv -#define Extrema_SeqPOnC_hxx -#define Extrema_FuncExtCC Extrema_CCLocFOfLocECC -#define Extrema_FuncExtCC_hxx - -#include - -#undef Curve1 -#undef Curve1_hxx -#undef Tool1 -#undef Tool1_hxx -#undef Curve2 -#undef Curve2_hxx -#undef Tool2 -#undef Tool2_hxx -#undef POnC -#undef POnC_hxx -#undef Pnt -#undef Pnt_hxx -#undef Vec -#undef Vec_hxx -#undef Extrema_SeqPOnC -#undef Extrema_SeqPOnC_hxx -#undef Extrema_FuncExtCC -#undef Extrema_FuncExtCC_hxx +//! Type alias for 3D curve-curve extremum function. +using Extrema_CCLocFOfLocECC = Extrema_GFuncExtCC; #endif // _Extrema_CCLocFOfLocECC_HeaderFile diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_CCLocFOfLocECC2d.hxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_CCLocFOfLocECC2d.hxx index afa2c179c2..5189495403 100644 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_CCLocFOfLocECC2d.hxx +++ b/src/ModelingData/TKGeomBase/Extrema/Extrema_CCLocFOfLocECC2d.hxx @@ -17,148 +17,22 @@ #ifndef _Extrema_CCLocFOfLocECC2d_HeaderFile #define _Extrema_CCLocFOfLocECC2d_HeaderFile -#include -#include -#include - +#include +#include +#include +#include +#include #include #include -#include -#include -#include -#include -#include -class Standard_OutOfRange; -class Adaptor2d_Curve2d; -class Extrema_Curve2dTool; -class Extrema_POnCurv2d; -class gp_Pnt2d; -class gp_Vec2d; -class math_Matrix; -class Extrema_CCLocFOfLocECC2d : public math_FunctionSetWithDerivatives -{ -public: - DEFINE_STANDARD_ALLOC - - Standard_EXPORT Extrema_CCLocFOfLocECC2d(const Standard_Real thetol = 1.0e-10); - - Standard_EXPORT Extrema_CCLocFOfLocECC2d(const Adaptor2d_Curve2d& C1, - const Adaptor2d_Curve2d& C2, - const Standard_Real thetol = 1.0e-10); - - Standard_EXPORT void SetCurve(const Standard_Integer theRank, const Adaptor2d_Curve2d& C1); - - void SetTolerance(const Standard_Real theTol); - - virtual Standard_Integer NbVariables() const Standard_OVERRIDE; - - virtual Standard_Integer NbEquations() const Standard_OVERRIDE; - - //! Calculate Fi(U,V). - Standard_EXPORT virtual Standard_Boolean Value(const math_Vector& UV, - math_Vector& F) Standard_OVERRIDE; - - //! Calculate Fi'(U,V). - Standard_EXPORT Standard_Boolean Derivatives(const math_Vector& UV, - math_Matrix& DF) Standard_OVERRIDE; - - //! Calculate Fi(U,V) and Fi'(U,V). - Standard_EXPORT Standard_Boolean Values(const math_Vector& UV, - math_Vector& F, - math_Matrix& DF) Standard_OVERRIDE; - - //! Save the found extremum. - Standard_EXPORT virtual Standard_Integer GetStateNumber() Standard_OVERRIDE; - - //! Return the number of found extrema. - Standard_Integer NbExt() const; - - //! Return the value of the Nth distance. - Standard_Real SquareDistance(const Standard_Integer N) const; - - //! Return the points of the Nth extreme distance. - Standard_EXPORT void Points(const Standard_Integer N, - Extrema_POnCurv2d& P1, - Extrema_POnCurv2d& P2) const; - - //! Returns a pointer to the curve specified in the constructor - //! or in SetCurve() method. - Standard_Address CurvePtr(const Standard_Integer theRank) const; - - //! Returns a tolerance specified in the constructor - //! or in SetTolerance() method. - Standard_Real Tolerance() const; - - //! Determines of boundaries of subinterval for find of root. - Standard_EXPORT void SubIntervalInitialize(const math_Vector& theUfirst, - const math_Vector& theUlast); - - //! Computes a Tol value. If 1st derivative of curve - //! |D1| -#define Tool1 Extrema_Curve2dTool -#define Tool1_hxx -#define Curve2 Adaptor2d_Curve2d -#define Curve2_hxx -#define Tool2 Extrema_Curve2dTool -#define Tool2_hxx -#define POnC Extrema_POnCurv2d -#define POnC_hxx -#define Pnt gp_Pnt2d -#define Pnt_hxx -#define Vec gp_Vec2d -#define Vec_hxx -#define Extrema_SeqPOnC Extrema_SequenceOfPOnCurv2d -#define Extrema_SeqPOnC_hxx -#define Extrema_FuncExtCC Extrema_CCLocFOfLocECC2d -#define Extrema_FuncExtCC_hxx - -#include - -#undef Curve1 -#undef Curve1_hxx -#undef Tool1 -#undef Tool1_hxx -#undef Curve2 -#undef Curve2_hxx -#undef Tool2 -#undef Tool2_hxx -#undef POnC -#undef POnC_hxx -#undef Pnt -#undef Pnt_hxx -#undef Vec -#undef Vec_hxx -#undef Extrema_SeqPOnC -#undef Extrema_SeqPOnC_hxx -#undef Extrema_FuncExtCC -#undef Extrema_FuncExtCC_hxx +//! Type alias for 2D curve-curve extremum function. +using Extrema_CCLocFOfLocECC2d = Extrema_GFuncExtCC; #endif // _Extrema_CCLocFOfLocECC2d_HeaderFile diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_CCLocFOfLocECC2d_0.cxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_CCLocFOfLocECC2d_0.cxx deleted file mode 100644 index 7865485f5c..0000000000 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_CCLocFOfLocECC2d_0.cxx +++ /dev/null @@ -1,46 +0,0 @@ -// Created on: 1991-02-26 -// Created by: Isabelle GRIGNON -// Copyright (c) 1991-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 - -#include -#include -#include -#include -#include -#include -#include -#include - -#define Curve1 Adaptor2d_Curve2d -#define Curve1_hxx -#define Tool1 Extrema_Curve2dTool -#define Tool1_hxx -#define Curve2 Adaptor2d_Curve2d -#define Curve2_hxx -#define Tool2 Extrema_Curve2dTool -#define Tool2_hxx -#define POnC Extrema_POnCurv2d -#define POnC_hxx -#define Pnt gp_Pnt2d -#define Pnt_hxx -#define Vec gp_Vec2d -#define Vec_hxx -#define Extrema_SeqPOnC Extrema_SequenceOfPOnCurv2d -#define Extrema_SeqPOnC_hxx -#define Extrema_FuncExtCC Extrema_CCLocFOfLocECC2d -#define Extrema_FuncExtCC_hxx -#include diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_CCLocFOfLocECC_0.cxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_CCLocFOfLocECC_0.cxx deleted file mode 100644 index d191ecbcbe..0000000000 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_CCLocFOfLocECC_0.cxx +++ /dev/null @@ -1,46 +0,0 @@ -// Created on: 1991-02-26 -// Created by: Isabelle GRIGNON -// Copyright (c) 1991-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 - -#include -#include -#include -#include -#include -#include -#include -#include - -#define Curve1 Adaptor3d_Curve -#define Curve1_hxx -#define Tool1 Extrema_CurveTool -#define Tool1_hxx -#define Curve2 Adaptor3d_Curve -#define Curve2_hxx -#define Tool2 Extrema_CurveTool -#define Tool2_hxx -#define POnC Extrema_POnCurv -#define POnC_hxx -#define Pnt gp_Pnt -#define Pnt_hxx -#define Vec gp_Vec -#define Vec_hxx -#define Extrema_SeqPOnC Extrema_SequenceOfPOnCurv -#define Extrema_SeqPOnC_hxx -#define Extrema_FuncExtCC Extrema_CCLocFOfLocECC -#define Extrema_FuncExtCC_hxx -#include diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_Curve2dTool.hxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_Curve2dTool.hxx index 5da9f4bafb..31ccf710f9 100644 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_Curve2dTool.hxx +++ b/src/ModelingData/TKGeomBase/Extrema/Extrema_Curve2dTool.hxx @@ -17,126 +17,140 @@ #ifndef _Extrema_Curve2dTool_HeaderFile #define _Extrema_Curve2dTool_HeaderFile -#include -#include -#include - -#include -#include -#include -#include -#include -#include +#include +#include +#include #include -#include +#include #include #include #include +#include #include -class Adaptor2d_Curve2d; -class gp_Pnt2d; -class gp_Vec2d; -class Geom2d_BezierCurve; -class Geom2d_BSplineCurve; +#include +#include +#include +#include +#include +#include +#include class Extrema_Curve2dTool { public: DEFINE_STANDARD_ALLOC - static Standard_Real FirstParameter(const Adaptor2d_Curve2d& C); + static double FirstParameter(const Adaptor2d_Curve2d& theC) { return theC.FirstParameter(); } - static Standard_Real LastParameter(const Adaptor2d_Curve2d& C); + static double LastParameter(const Adaptor2d_Curve2d& theC) { return theC.LastParameter(); } - static GeomAbs_Shape Continuity(const Adaptor2d_Curve2d& C); + static GeomAbs_Shape Continuity(const Adaptor2d_Curve2d& theC) { return theC.Continuity(); } - //! If necessary, breaks the curve in intervals of - //! continuity . And returns the number of - //! intervals. - static Standard_Integer NbIntervals(const Adaptor2d_Curve2d& C, const GeomAbs_Shape S); + //! If necessary, breaks the curve in intervals of continuity . + //! And returns the number of intervals. + static int NbIntervals(const Adaptor2d_Curve2d& theC, const GeomAbs_Shape theS) + { + return theC.NbIntervals(theS); + } - //! Stores in the parameters bounding the intervals - //! of continuity . - static void Intervals(const Adaptor2d_Curve2d& C, TColStd_Array1OfReal& T, const GeomAbs_Shape S); + //! Stores in the parameters bounding the intervals of continuity . + static void Intervals(const Adaptor2d_Curve2d& theC, + TColStd_Array1OfReal& theT, + const GeomAbs_Shape theS) + { + theC.Intervals(theT, theS); + } //! Returns the parameters bounding the intervals of subdivision of curve //! according to Curvature deflection. Value of deflection is defined in method. - //! Standard_EXPORT static Handle(TColStd_HArray1OfReal) DeflCurvIntervals( - const Adaptor2d_Curve2d& C); + const Adaptor2d_Curve2d& theC); - static Standard_Boolean IsClosed(const Adaptor2d_Curve2d& C); + static bool IsClosed(const Adaptor2d_Curve2d& theC) { return theC.IsClosed(); } - static Standard_Boolean IsPeriodic(const Adaptor2d_Curve2d& C); + static bool IsPeriodic(const Adaptor2d_Curve2d& theC) { return theC.IsPeriodic(); } - static Standard_Real Period(const Adaptor2d_Curve2d& C); + static double Period(const Adaptor2d_Curve2d& theC) { return theC.Period(); } //! Computes the point of parameter U on the curve. - static gp_Pnt2d Value(const Adaptor2d_Curve2d& C, const Standard_Real U); + static gp_Pnt2d Value(const Adaptor2d_Curve2d& theC, const double theU) + { + return theC.Value(theU); + } //! Computes the point of parameter U on the curve. - static void D0(const Adaptor2d_Curve2d& C, const Standard_Real U, gp_Pnt2d& P); + static void D0(const Adaptor2d_Curve2d& theC, const double theU, gp_Pnt2d& theP) + { + theC.D0(theU, theP); + } - //! Computes the point of parameter U on the curve with its - //! first derivative. - static void D1(const Adaptor2d_Curve2d& C, const Standard_Real U, gp_Pnt2d& P, gp_Vec2d& V); + //! Computes the point of parameter U on the curve with its first derivative. + static void D1(const Adaptor2d_Curve2d& theC, const double theU, gp_Pnt2d& theP, gp_Vec2d& theV) + { + theC.D1(theU, theP, theV); + } - //! Returns the point P of parameter U, the first and second - //! derivatives V1 and V2. - static void D2(const Adaptor2d_Curve2d& C, - const Standard_Real U, - gp_Pnt2d& P, - gp_Vec2d& V1, - gp_Vec2d& V2); + //! Returns the point P of parameter U, the first and second derivatives V1 and V2. + static void D2(const Adaptor2d_Curve2d& theC, + const double theU, + gp_Pnt2d& theP, + gp_Vec2d& theV1, + gp_Vec2d& theV2) + { + theC.D2(theU, theP, theV1, theV2); + } - //! Returns the point P of parameter U, the first, the second - //! and the third derivative. - static void D3(const Adaptor2d_Curve2d& C, - const Standard_Real U, - gp_Pnt2d& P, - gp_Vec2d& V1, - gp_Vec2d& V2, - gp_Vec2d& V3); + //! Returns the point P of parameter U, the first, the second and the third derivative. + static void D3(const Adaptor2d_Curve2d& theC, + const double theU, + gp_Pnt2d& theP, + gp_Vec2d& theV1, + gp_Vec2d& theV2, + gp_Vec2d& theV3) + { + theC.D3(theU, theP, theV1, theV2, theV3); + } - //! The returned vector gives the value of the derivative for the - //! order of derivation N. - static gp_Vec2d DN(const Adaptor2d_Curve2d& C, const Standard_Real U, const Standard_Integer N); + //! The returned vector gives the value of the derivative for the order of derivation N. + static gp_Vec2d DN(const Adaptor2d_Curve2d& theC, const double theU, const int theN) + { + return theC.DN(theU, theN); + } - //! Returns the parametric resolution corresponding - //! to the real space resolution . - static Standard_Real Resolution(const Adaptor2d_Curve2d& C, const Standard_Real R3d); + //! Returns the parametric resolution corresponding to the real space resolution . + static double Resolution(const Adaptor2d_Curve2d& theC, const double theR3d) + { + return theC.Resolution(theR3d); + } - //! Returns the type of the curve in the current - //! interval : Line, Circle, Ellipse, Hyperbola, - //! Parabola, BezierCurve, BSplineCurve, OtherCurve. - static GeomAbs_CurveType GetType(const Adaptor2d_Curve2d& C); + //! Returns the type of the curve in the current interval: + //! Line, Circle, Ellipse, Hyperbola, Parabola, BezierCurve, BSplineCurve, OtherCurve. + static GeomAbs_CurveType GetType(const Adaptor2d_Curve2d& theC) { return theC.GetType(); } - static gp_Lin2d Line(const Adaptor2d_Curve2d& C); + static gp_Lin2d Line(const Adaptor2d_Curve2d& theC) { return theC.Line(); } - static gp_Circ2d Circle(const Adaptor2d_Curve2d& C); + static gp_Circ2d Circle(const Adaptor2d_Curve2d& theC) { return theC.Circle(); } - static gp_Elips2d Ellipse(const Adaptor2d_Curve2d& C); + static gp_Elips2d Ellipse(const Adaptor2d_Curve2d& theC) { return theC.Ellipse(); } - static gp_Hypr2d Hyperbola(const Adaptor2d_Curve2d& C); + static gp_Hypr2d Hyperbola(const Adaptor2d_Curve2d& theC) { return theC.Hyperbola(); } - static gp_Parab2d Parabola(const Adaptor2d_Curve2d& C); + static gp_Parab2d Parabola(const Adaptor2d_Curve2d& theC) { return theC.Parabola(); } - static Standard_Integer Degree(const Adaptor2d_Curve2d& C); + static int Degree(const Adaptor2d_Curve2d& theC) { return theC.Degree(); } - static Standard_Boolean IsRational(const Adaptor2d_Curve2d& C); + static bool IsRational(const Adaptor2d_Curve2d& theC) { return theC.IsRational(); } - static Standard_Integer NbPoles(const Adaptor2d_Curve2d& C); + static int NbPoles(const Adaptor2d_Curve2d& theC) { return theC.NbPoles(); } - static Standard_Integer NbKnots(const Adaptor2d_Curve2d& C); + static int NbKnots(const Adaptor2d_Curve2d& theC) { return theC.NbKnots(); } - static Handle(Geom2d_BezierCurve) Bezier(const Adaptor2d_Curve2d& C); + static Handle(Geom2d_BezierCurve) Bezier(const Adaptor2d_Curve2d& theC) { return theC.Bezier(); } - static Handle(Geom2d_BSplineCurve) BSpline(const Adaptor2d_Curve2d& C); - -protected: -private: + static Handle(Geom2d_BSplineCurve) BSpline(const Adaptor2d_Curve2d& theC) + { + return theC.BSpline(); + } }; -#include - #endif // _Extrema_Curve2dTool_HeaderFile diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_Curve2dTool.lxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_Curve2dTool.lxx deleted file mode 100644 index 2229b9c067..0000000000 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_Curve2dTool.lxx +++ /dev/null @@ -1,231 +0,0 @@ -// Created on: 1995-07-18 -// Created by: Modelistation -// 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 -#include -#include -#include -#include -#include -#include -#include - -//================================================================================================= - -inline Standard_Real Extrema_Curve2dTool::FirstParameter(const Adaptor2d_Curve2d& C) -{ - return C.FirstParameter(); -} - -//================================================================================================= - -inline Standard_Real Extrema_Curve2dTool::LastParameter(const Adaptor2d_Curve2d& C) -{ - return C.LastParameter(); -} - -//================================================================================================= - -inline GeomAbs_Shape Extrema_Curve2dTool::Continuity(const Adaptor2d_Curve2d& C) -{ - return C.Continuity(); -} - -//================================================================================================= - -inline Standard_Integer Extrema_Curve2dTool::NbIntervals(const Adaptor2d_Curve2d& C, - const GeomAbs_Shape S) -{ - return C.NbIntervals(S); -} - -//================================================================================================= - -inline void Extrema_Curve2dTool::Intervals(const Adaptor2d_Curve2d& C, - TColStd_Array1OfReal& T, - const GeomAbs_Shape S) -{ - C.Intervals(T, S); -} - -//================================================================================================= - -inline Standard_Boolean Extrema_Curve2dTool::IsClosed(const Adaptor2d_Curve2d& C) -{ - return C.IsClosed(); -} - -//================================================================================================= - -inline Standard_Boolean Extrema_Curve2dTool::IsPeriodic(const Adaptor2d_Curve2d& C) -{ - return C.IsPeriodic(); -} - -//================================================================================================= - -inline Standard_Real Extrema_Curve2dTool::Period(const Adaptor2d_Curve2d& C) -{ - return C.Period(); -} - -//================================================================================================= - -inline gp_Pnt2d Extrema_Curve2dTool::Value(const Adaptor2d_Curve2d& C, const Standard_Real U) -{ - return C.Value(U); -} - -//================================================================================================= - -inline void Extrema_Curve2dTool::D0(const Adaptor2d_Curve2d& C, const Standard_Real U, gp_Pnt2d& P) -{ - C.D0(U, P); -} - -//================================================================================================= - -inline void Extrema_Curve2dTool::D1(const Adaptor2d_Curve2d& C, - const Standard_Real U, - gp_Pnt2d& P, - gp_Vec2d& V) -{ - C.D1(U, P, V); -} - -//================================================================================================= - -inline void Extrema_Curve2dTool::D2(const Adaptor2d_Curve2d& C, - const Standard_Real U, - gp_Pnt2d& P, - gp_Vec2d& V1, - gp_Vec2d& V2) -{ - C.D2(U, P, V1, V2); -} - -//================================================================================================= - -inline void Extrema_Curve2dTool::D3(const Adaptor2d_Curve2d& C, - const Standard_Real U, - gp_Pnt2d& P, - gp_Vec2d& V1, - gp_Vec2d& V2, - gp_Vec2d& V3) -{ - C.D3(U, P, V1, V2, V3); -} - -//================================================================================================= - -inline gp_Vec2d Extrema_Curve2dTool::DN(const Adaptor2d_Curve2d& C, - const Standard_Real U, - const Standard_Integer N) -{ - return C.DN(U, N); -} - -//================================================================================================= - -inline Standard_Real Extrema_Curve2dTool::Resolution(const Adaptor2d_Curve2d& C, - const Standard_Real R3d) -{ - return C.Resolution(R3d); -} - -//================================================================================================= - -inline GeomAbs_CurveType Extrema_Curve2dTool::GetType(const Adaptor2d_Curve2d& C) -{ - return C.GetType(); -} - -//================================================================================================= - -inline gp_Lin2d Extrema_Curve2dTool::Line(const Adaptor2d_Curve2d& C) -{ - return C.Line(); -} - -//================================================================================================= - -inline gp_Circ2d Extrema_Curve2dTool::Circle(const Adaptor2d_Curve2d& C) -{ - return C.Circle(); -} - -//================================================================================================= - -inline gp_Elips2d Extrema_Curve2dTool::Ellipse(const Adaptor2d_Curve2d& C) -{ - return C.Ellipse(); -} - -//================================================================================================= - -inline gp_Hypr2d Extrema_Curve2dTool::Hyperbola(const Adaptor2d_Curve2d& C) -{ - return C.Hyperbola(); -} - -//================================================================================================= - -inline gp_Parab2d Extrema_Curve2dTool::Parabola(const Adaptor2d_Curve2d& C) -{ - return C.Parabola(); -} - -//================================================================================================= - -inline Standard_Integer Extrema_Curve2dTool::NbPoles(const Adaptor2d_Curve2d& C) -{ - return C.NbPoles(); -} - -//================================================================================================= - -inline Standard_Integer Extrema_Curve2dTool::Degree(const Adaptor2d_Curve2d& C) -{ - return C.Degree(); -} - -//================================================================================================= - -inline Standard_Boolean Extrema_Curve2dTool::IsRational(const Adaptor2d_Curve2d& C) -{ - return C.Degree() != 0; -} - -//================================================================================================= - -inline Standard_Integer Extrema_Curve2dTool::NbKnots(const Adaptor2d_Curve2d& C) -{ - return C.NbKnots(); -} - -//================================================================================================= - -inline Handle(Geom2d_BezierCurve) Extrema_Curve2dTool::Bezier(const Adaptor2d_Curve2d& C) -{ - return C.Bezier(); -} - -//================================================================================================= - -inline Handle(Geom2d_BSplineCurve) Extrema_Curve2dTool::BSpline(const Adaptor2d_Curve2d& C) -{ - return C.BSpline(); -} diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_CurveLocator.gxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_CurveLocator.gxx deleted file mode 100644 index c3b54be8fe..0000000000 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_CurveLocator.gxx +++ /dev/null @@ -1,108 +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 - -void Extrema_CurveLocator::Locate(const Pnt& P, - const Curve1& C, - const Standard_Integer NbU, - POnC& Papp) -{ - - /*----------------------------------------------------------------------------- - Fonction: - Recherche, parmi un echantillon de 'NbU' points de la courbe C, du - point le plus proche du point P. - L'echantillonnage est fait a parametre constant sur l'intervalle de - definition de la courbe. - -----------------------------------------------------------------------------*/ - - if (NbU < 2) - { - throw Standard_OutOfRange(); - } - - Standard_Real U = Tool1::FirstParameter(C); - Standard_Real PasU = (Tool1::LastParameter(C) - U) / (NbU - 1); - Standard_Real Dist2Min = RealLast(), UMin = 0; - Pnt PntMin; - Standard_Real Dist2; - Pnt Pt; - for (Standard_Integer NoSample = 1; NoSample < NbU; NoSample++, U += PasU) - { - Pt = Tool1::Value(C, U); - Dist2 = Pt.SquareDistance(P); - if (Dist2 < Dist2Min) - { - Dist2Min = Dist2; - UMin = U; - PntMin = Pt; - } - } - Papp.SetValues(UMin, PntMin); -} - -void Extrema_CurveLocator::Locate(const Pnt& P, - const Curve1& C, - const Standard_Integer NbU, - const Standard_Real Umin, - const Standard_Real Usup, - POnC& Papp) -{ - - /*----------------------------------------------------------------------------- - Fonction: - Recherche, parmi un echantillon de 'NbU' points de la courbe C, du - point le plus proche du point P. - L'echantillonnage est fait a parametre constant sur l'intervalle de - definition de la courbe. - -----------------------------------------------------------------------------*/ - - if (NbU < 2) - { - throw Standard_OutOfRange(); - } - Standard_Real U1, U2, U11, U12; - Standard_Real Uinf = Tool1::FirstParameter(C); - Standard_Real Ulast = Tool1::LastParameter(C); - - U1 = std::min(Uinf, Ulast); - U2 = std::max(Uinf, Ulast); - U11 = std::min(Umin, Usup); - U12 = std::max(Umin, Usup); - - if (U11 < U1 - RealEpsilon()) - U11 = U1; - if (U12 > U2 + RealEpsilon()) - U12 = U2; - - Standard_Real U = U11; - Standard_Real PasU = (U12 - U) / (NbU - 1); - Standard_Real Dist2Min = RealLast(), UMin = 0; - Pnt PntMin; - Standard_Real Dist2; - Pnt Pt; - for (Standard_Integer NoSample = 1; NoSample < NbU; NoSample++, U += PasU) - { - Pt = Tool1::Value(C, U); - Dist2 = Pt.SquareDistance(P); - if (Dist2 < Dist2Min) - { - Dist2Min = Dist2; - UMin = U; - PntMin = Pt; - } - } - Papp.SetValues(UMin, PntMin); -} diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_CurveTool.hxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_CurveTool.hxx index ab1d8ace12..3ee48fa029 100644 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_CurveTool.hxx +++ b/src/ModelingData/TKGeomBase/Extrema/Extrema_CurveTool.hxx @@ -17,110 +17,123 @@ #ifndef _Extrema_CurveTool_HeaderFile #define _Extrema_CurveTool_HeaderFile -#include -#include -#include - -#include -#include -#include -#include +#include +#include +#include #include -#include -#include -#include +#include #include #include #include +#include #include -class Adaptor3d_Curve; -class gp_Pnt; -class gp_Vec; -class Geom_BezierCurve; -class Geom_BSplineCurve; +#include +#include +#include +#include +#include +#include +#include class Extrema_CurveTool { public: DEFINE_STANDARD_ALLOC - static Standard_Real FirstParameter(const Adaptor3d_Curve& C); + static double FirstParameter(const Adaptor3d_Curve& theC) { return theC.FirstParameter(); } - static Standard_Real LastParameter(const Adaptor3d_Curve& C); + static double LastParameter(const Adaptor3d_Curve& theC) { return theC.LastParameter(); } - static GeomAbs_Shape Continuity(const Adaptor3d_Curve& C); + static GeomAbs_Shape Continuity(const Adaptor3d_Curve& theC) { return theC.Continuity(); } - //! Returns the number of intervals for continuity - //! . May be one if Continuity(me) >= - static Standard_Integer NbIntervals(Adaptor3d_Curve& C, const GeomAbs_Shape S); + //! Returns the number of intervals for continuity . + //! May be one if Continuity(me) >= + static int NbIntervals(Adaptor3d_Curve& theC, const GeomAbs_Shape theS) + { + return theC.NbIntervals(theS); + } - //! Stores in the parameters bounding the intervals - //! of continuity . - //! - //! The array must provide enough room to accommodate - //! for the parameters. i.e. T.Length() > NbIntervals() - static void Intervals(Adaptor3d_Curve& C, TColStd_Array1OfReal& T, const GeomAbs_Shape S); + //! Stores in the parameters bounding the intervals of continuity . + //! The array must provide enough room to accommodate for the parameters. + //! i.e. T.Length() > NbIntervals() + static void Intervals(Adaptor3d_Curve& theC, TColStd_Array1OfReal& theT, const GeomAbs_Shape theS) + { + theC.Intervals(theT, theS); + } //! Returns the parameters bounding the intervals of subdivision of curve //! according to Curvature deflection. Value of deflection is defined in method. - //! - Standard_EXPORT static Handle(TColStd_HArray1OfReal) DeflCurvIntervals(const Adaptor3d_Curve& C); + Standard_EXPORT static Handle(TColStd_HArray1OfReal) DeflCurvIntervals( + const Adaptor3d_Curve& theC); - Standard_EXPORT static Standard_Boolean IsPeriodic(const Adaptor3d_Curve& C); + Standard_EXPORT static bool IsPeriodic(const Adaptor3d_Curve& theC); - static Standard_Real Period(const Adaptor3d_Curve& C); + static double Period(const Adaptor3d_Curve& theC) { return theC.Period(); } - static Standard_Real Resolution(const Adaptor3d_Curve& C, const Standard_Real R3d); + static double Resolution(const Adaptor3d_Curve& theC, const double theR3d) + { + return theC.Resolution(theR3d); + } - static GeomAbs_CurveType GetType(const Adaptor3d_Curve& C); + static GeomAbs_CurveType GetType(const Adaptor3d_Curve& theC) { return theC.GetType(); } - static gp_Pnt Value(const Adaptor3d_Curve& C, const Standard_Real U); + static gp_Pnt Value(const Adaptor3d_Curve& theC, const double theU) { return theC.Value(theU); } - static void D0(const Adaptor3d_Curve& C, const Standard_Real U, gp_Pnt& P); + static void D0(const Adaptor3d_Curve& theC, const double theU, gp_Pnt& theP) + { + theC.D0(theU, theP); + } - static void D1(const Adaptor3d_Curve& C, const Standard_Real U, gp_Pnt& P, gp_Vec& V); + static void D1(const Adaptor3d_Curve& theC, const double theU, gp_Pnt& theP, gp_Vec& theV) + { + theC.D1(theU, theP, theV); + } - static void D2(const Adaptor3d_Curve& C, - const Standard_Real U, - gp_Pnt& P, - gp_Vec& V1, - gp_Vec& V2); + static void D2(const Adaptor3d_Curve& theC, + const double theU, + gp_Pnt& theP, + gp_Vec& theV1, + gp_Vec& theV2) + { + theC.D2(theU, theP, theV1, theV2); + } - static void D3(const Adaptor3d_Curve& C, - const Standard_Real U, - gp_Pnt& P, - gp_Vec& V1, - gp_Vec& V2, - gp_Vec& V3); + static void D3(const Adaptor3d_Curve& theC, + const double theU, + gp_Pnt& theP, + gp_Vec& theV1, + gp_Vec& theV2, + gp_Vec& theV3) + { + theC.D3(theU, theP, theV1, theV2, theV3); + } - static gp_Vec DN(const Adaptor3d_Curve& C, const Standard_Real U, const Standard_Integer N); + static gp_Vec DN(const Adaptor3d_Curve& theC, const double theU, const int theN) + { + return theC.DN(theU, theN); + } - static gp_Lin Line(const Adaptor3d_Curve& C); + static gp_Lin Line(const Adaptor3d_Curve& theC) { return theC.Line(); } - static gp_Circ Circle(const Adaptor3d_Curve& C); + static gp_Circ Circle(const Adaptor3d_Curve& theC) { return theC.Circle(); } - static gp_Elips Ellipse(const Adaptor3d_Curve& C); + static gp_Elips Ellipse(const Adaptor3d_Curve& theC) { return theC.Ellipse(); } - static gp_Hypr Hyperbola(const Adaptor3d_Curve& C); + static gp_Hypr Hyperbola(const Adaptor3d_Curve& theC) { return theC.Hyperbola(); } - static gp_Parab Parabola(const Adaptor3d_Curve& C); + static gp_Parab Parabola(const Adaptor3d_Curve& theC) { return theC.Parabola(); } - static Standard_Integer Degree(const Adaptor3d_Curve& C); + static int Degree(const Adaptor3d_Curve& theC) { return theC.Degree(); } - static Standard_Boolean IsRational(const Adaptor3d_Curve& C); + static bool IsRational(const Adaptor3d_Curve& theC) { return theC.IsRational(); } - static Standard_Integer NbPoles(const Adaptor3d_Curve& C); + static int NbPoles(const Adaptor3d_Curve& theC) { return theC.NbPoles(); } - static Standard_Integer NbKnots(const Adaptor3d_Curve& C); + static int NbKnots(const Adaptor3d_Curve& theC) { return theC.NbKnots(); } - static Handle(Geom_BezierCurve) Bezier(const Adaptor3d_Curve& C); + static Handle(Geom_BezierCurve) Bezier(const Adaptor3d_Curve& theC) { return theC.Bezier(); } - static Handle(Geom_BSplineCurve) BSpline(const Adaptor3d_Curve& C); - -protected: -private: + static Handle(Geom_BSplineCurve) BSpline(const Adaptor3d_Curve& theC) { return theC.BSpline(); } }; -#include - #endif // _Extrema_CurveTool_HeaderFile diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_CurveTool.lxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_CurveTool.lxx deleted file mode 100644 index 8165ad7636..0000000000 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_CurveTool.lxx +++ /dev/null @@ -1,218 +0,0 @@ -// Created on: 1995-07-18 -// Created by: Modelistation -// 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//================================================================================================= - -inline Standard_Real Extrema_CurveTool::FirstParameter(const Adaptor3d_Curve& C) -{ - return C.FirstParameter(); -} - -//================================================================================================= - -inline Standard_Real Extrema_CurveTool::LastParameter(const Adaptor3d_Curve& C) -{ - return C.LastParameter(); -} - -//================================================================================================= - -inline gp_Pnt Extrema_CurveTool::Value(const Adaptor3d_Curve& C, const Standard_Real U) -{ - return C.Value(U); -} - -//================================================================================================= - -inline void Extrema_CurveTool::D0(const Adaptor3d_Curve& C, const Standard_Real U, gp_Pnt& P) -{ - C.D0(U, P); -} - -//================================================================================================= - -inline void Extrema_CurveTool::D1(const Adaptor3d_Curve& C, - const Standard_Real U, - gp_Pnt& P, - gp_Vec& V) -{ - C.D1(U, P, V); -} - -//================================================================================================= - -inline void Extrema_CurveTool::D2(const Adaptor3d_Curve& C, - const Standard_Real U, - gp_Pnt& P, - gp_Vec& V1, - gp_Vec& V2) -{ - C.D2(U, P, V1, V2); -} - -//================================================================================================= - -inline void Extrema_CurveTool::D3(const Adaptor3d_Curve& C, - const Standard_Real U, - gp_Pnt& P, - gp_Vec& V1, - gp_Vec& V2, - gp_Vec& V3) -{ - C.D3(U, P, V1, V2, V3); -} - -//================================================================================================= - -inline gp_Vec Extrema_CurveTool::DN(const Adaptor3d_Curve& C, - const Standard_Real U, - const Standard_Integer N) -{ - return C.DN(U, N); -} - -//================================================================================================= - -inline GeomAbs_Shape Extrema_CurveTool::Continuity(const Adaptor3d_Curve& C) -{ - return C.Continuity(); -} - -//================================================================================================= - -inline Standard_Integer Extrema_CurveTool::NbIntervals(Adaptor3d_Curve& C, const GeomAbs_Shape S) -{ - return C.NbIntervals(S); -} - -//================================================================================================= - -inline void Extrema_CurveTool::Intervals(Adaptor3d_Curve& C, - TColStd_Array1OfReal& T, - const GeomAbs_Shape S) -{ - C.Intervals(T, S); -} - -//================================================================================================= - -inline Standard_Real Extrema_CurveTool::Period(const Adaptor3d_Curve& C) -{ - return C.Period(); -} - -//================================================================================================= - -inline GeomAbs_CurveType Extrema_CurveTool::GetType(const Adaptor3d_Curve& C) -{ - return C.GetType(); -} - -//================================================================================================= - -inline gp_Lin Extrema_CurveTool::Line(const Adaptor3d_Curve& C) -{ - return C.Line(); -} - -//================================================================================================= - -inline gp_Circ Extrema_CurveTool::Circle(const Adaptor3d_Curve& C) -{ - return C.Circle(); -} - -//================================================================================================= - -inline gp_Elips Extrema_CurveTool::Ellipse(const Adaptor3d_Curve& C) -{ - return C.Ellipse(); -} - -//================================================================================================= - -inline gp_Hypr Extrema_CurveTool::Hyperbola(const Adaptor3d_Curve& C) -{ - return C.Hyperbola(); -} - -//================================================================================================= - -inline gp_Parab Extrema_CurveTool::Parabola(const Adaptor3d_Curve& C) -{ - return C.Parabola(); -} - -//================================================================================================= - -inline Standard_Integer Extrema_CurveTool::NbPoles(const Adaptor3d_Curve& C) -{ - return C.NbPoles(); -} - -//================================================================================================= - -inline Standard_Integer Extrema_CurveTool::Degree(const Adaptor3d_Curve& C) -{ - return C.Degree(); -} - -//================================================================================================= - -inline Standard_Boolean Extrema_CurveTool::IsRational(const Adaptor3d_Curve& C) -{ - return C.IsRational(); -} - -//================================================================================================= - -inline Standard_Integer Extrema_CurveTool::NbKnots(const Adaptor3d_Curve& C) -{ - return C.NbKnots(); -} - -//================================================================================================= - -inline Handle(Geom_BezierCurve) Extrema_CurveTool::Bezier(const Adaptor3d_Curve& C) -{ - return C.Bezier(); -} - -//================================================================================================= - -inline Handle(Geom_BSplineCurve) Extrema_CurveTool::BSpline(const Adaptor3d_Curve& C) -{ - return C.BSpline(); -} - -//================================================================================================= - -inline Standard_Real Extrema_CurveTool::Resolution(const Adaptor3d_Curve& C, - const Standard_Real R3d) -{ - return C.Resolution(R3d); -} diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_ECC.hxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_ECC.hxx index d4a31136f7..a4475f3ded 100644 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_ECC.hxx +++ b/src/ModelingData/TKGeomBase/Extrema/Extrema_ECC.hxx @@ -17,94 +17,20 @@ #ifndef _Extrema_ECC_HeaderFile #define _Extrema_ECC_HeaderFile -#include -#include -#include +#include +#include +#include +#include +#include +#include -#include -#include -#include - -class Adaptor3d_Curve; -class Extrema_CurveTool; -class Extrema_POnCurv; -class gp_Pnt; -class gp_Vec; - -class Extrema_ECC -{ -public: - DEFINE_STANDARD_ALLOC - - //! Calculates all the distances as above - //! between Uinf and Usup for C1 and between Vinf and Vsup - //! for C2. - Standard_EXPORT Extrema_ECC(); - - //! It calculates all the distances. - //! The function F(u,v)=distance(C1(u),C2(v)) has an - //! extremum when gradient(f)=0. The algorithm uses - //! Evtushenko's global optimization solver. - Standard_EXPORT Extrema_ECC(const Adaptor3d_Curve& C1, const Adaptor3d_Curve& C2); - - //! Calculates all the distances as above - //! between Uinf and Usup for C1 and between Vinf and Vsup - //! for C2. - Standard_EXPORT Extrema_ECC(const Adaptor3d_Curve& C1, - const Adaptor3d_Curve& C2, - const Standard_Real Uinf, - const Standard_Real Usup, - const Standard_Real Vinf, - const Standard_Real Vsup); - - //! Set params in case of empty constructor is usage. - Standard_EXPORT void SetParams(const Adaptor3d_Curve& C1, - const Adaptor3d_Curve& C2, - const Standard_Real Uinf, - const Standard_Real Usup, - const Standard_Real Vinf, - const Standard_Real Vsup); - - Standard_EXPORT void SetTolerance(const Standard_Real Tol); - - //! Set flag for single extrema computation. Works on parametric solver only. - Standard_EXPORT void SetSingleSolutionFlag(const Standard_Boolean theSingleSolutionFlag); - - //! Get flag for single extrema computation. Works on parametric solver only. - Standard_EXPORT Standard_Boolean GetSingleSolutionFlag() const; - - //! Performs calculations. - Standard_EXPORT void Perform(); - - //! Returns True if the distances are found. - Standard_EXPORT Standard_Boolean IsDone() const; - - //! Returns state of myParallel flag. - Standard_EXPORT Standard_Boolean IsParallel() const; - - //! Returns the number of extremum distances. - Standard_EXPORT Standard_Integer NbExt() const; - - //! Returns the value of the Nth square extremum distance. - Standard_EXPORT Standard_Real SquareDistance(const Standard_Integer N = 1) const; - - //! Returns the points of the Nth extremum distance. - //! P1 is on the first curve, P2 on the second one. - Standard_EXPORT void Points(const Standard_Integer N, - Extrema_POnCurv& P1, - Extrema_POnCurv& P2) const; - -protected: -private: - Standard_Boolean myIsFindSingleSolution; // Default value is false. - Standard_Boolean myParallel; - Standard_Real myCurveMinTol; - math_Vector myLowBorder; - math_Vector myUppBorder; - TColStd_SequenceOfReal myPoints1; - TColStd_SequenceOfReal myPoints2; - Standard_Address myC[2]; - Standard_Boolean myDone; -}; +//! Type alias for 3D curve-curve extremum computation. +using Extrema_ECC = Extrema_GGenExtCC; #endif // _Extrema_ECC_HeaderFile diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_ECC2d.hxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_ECC2d.hxx index 836a4afdf2..8c09e72c87 100644 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_ECC2d.hxx +++ b/src/ModelingData/TKGeomBase/Extrema/Extrema_ECC2d.hxx @@ -17,92 +17,20 @@ #ifndef _Extrema_ECC2d_HeaderFile #define _Extrema_ECC2d_HeaderFile -#include -#include +#include +#include +#include +#include +#include +#include -#include -#include - -class Adaptor2d_Curve2d; -class Extrema_Curve2dTool; -class Extrema_POnCurv2d; -class gp_Pnt2d; -class gp_Vec2d; - -class Extrema_ECC2d -{ -public: - DEFINE_STANDARD_ALLOC - - //! Calculates all the distances as above - //! between Uinf and Usup for C1 and between Vinf and Vsup - //! for C2. - Standard_EXPORT Extrema_ECC2d(); - - //! It calculates all the distances. - //! The function F(u,v)=distance(C1(u),C2(v)) has an - //! extremum when gradient(f)=0. The algorithm uses - //! Evtushenko's global optimization solver. - Standard_EXPORT Extrema_ECC2d(const Adaptor2d_Curve2d& C1, const Adaptor2d_Curve2d& C2); - - //! Calculates all the distances as above - //! between Uinf and Usup for C1 and between Vinf and Vsup - //! for C2. - Standard_EXPORT Extrema_ECC2d(const Adaptor2d_Curve2d& C1, - const Adaptor2d_Curve2d& C2, - const Standard_Real Uinf, - const Standard_Real Usup, - const Standard_Real Vinf, - const Standard_Real Vsup); - - //! Set params in case of empty constructor is usage. - Standard_EXPORT void SetParams(const Adaptor2d_Curve2d& C1, - const Adaptor2d_Curve2d& C2, - const Standard_Real Uinf, - const Standard_Real Usup, - const Standard_Real Vinf, - const Standard_Real Vsup); - - Standard_EXPORT void SetTolerance(const Standard_Real Tol); - - //! Set flag for single extrema computation. Works on parametric solver only. - Standard_EXPORT void SetSingleSolutionFlag(const Standard_Boolean theSingleSolutionFlag); - - //! Get flag for single extrema computation. Works on parametric solver only. - Standard_EXPORT Standard_Boolean GetSingleSolutionFlag() const; - - //! Performs calculations. - Standard_EXPORT void Perform(); - - //! Returns True if the distances are found. - Standard_EXPORT Standard_Boolean IsDone() const; - - //! Returns state of myParallel flag. - Standard_EXPORT Standard_Boolean IsParallel() const; - - //! Returns the number of extremum distances. - Standard_EXPORT Standard_Integer NbExt() const; - - //! Returns the value of the Nth square extremum distance. - Standard_EXPORT Standard_Real SquareDistance(const Standard_Integer N = 1) const; - - //! Returns the points of the Nth extremum distance. - //! P1 is on the first curve, P2 on the second one. - Standard_EXPORT void Points(const Standard_Integer N, - Extrema_POnCurv2d& P1, - Extrema_POnCurv2d& P2) const; - -protected: -private: - Standard_Boolean myIsFindSingleSolution; // Default value is false. - Standard_Boolean myParallel; - Standard_Real myCurveMinTol; - math_Vector myLowBorder; - math_Vector myUppBorder; - TColStd_SequenceOfReal myPoints1; - TColStd_SequenceOfReal myPoints2; - Standard_Address myC[2]; - Standard_Boolean myDone; -}; +//! Type alias for 2D curve-curve extremum computation. +using Extrema_ECC2d = Extrema_GGenExtCC; #endif // _Extrema_ECC2d_HeaderFile diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_ECC2d_0.cxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_ECC2d_0.cxx deleted file mode 100644 index cbb683b0ea..0000000000 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_ECC2d_0.cxx +++ /dev/null @@ -1,46 +0,0 @@ -// Created on: 1991-02-26 -// Created by: Isabelle GRIGNON -// Copyright (c) 1991-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 - -#include -#include -#include -#include -#include -#include - -#define Curve1 Adaptor2d_Curve2d -#define Curve1_hxx -#define Tool1 Extrema_Curve2dTool -#define Tool1_hxx -#define Curve2 Adaptor2d_Curve2d -#define Curve2_hxx -#define Tool2 Extrema_Curve2dTool -#define Tool2_hxx -#define Handle_ArrayOfPnt Handle(TColgp_HArray1OfPnt2d) -#define ArrayOfPnt TColgp_HArray1OfPnt2d -#define ArrayOfPnt_hxx -#define POnC Extrema_POnCurv2d -#define POnC_hxx -#define Pnt gp_Pnt2d -#define Pnt_hxx -#define Vec gp_Vec2d -#define Vec_hxx -#define Extrema_GExtPC Extrema_ExtPC2d -#define Extrema_GenExtCC Extrema_ECC2d -#define Extrema_GenExtCC_hxx -#include diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_ECC_0.cxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_ECC_0.cxx deleted file mode 100644 index dc7e21b56d..0000000000 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_ECC_0.cxx +++ /dev/null @@ -1,46 +0,0 @@ -// Created on: 1991-02-26 -// Created by: Isabelle GRIGNON -// Copyright (c) 1991-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 - -#include -#include -#include -#include -#include -#include - -#define Curve1 Adaptor3d_Curve -#define Curve1_hxx -#define Tool1 Extrema_CurveTool -#define Tool1_hxx -#define Curve2 Adaptor3d_Curve -#define Curve2_hxx -#define Tool2 Extrema_CurveTool -#define Tool2_hxx -#define Handle_ArrayOfPnt Handle(TColgp_HArray1OfPnt) -#define ArrayOfPnt TColgp_HArray1OfPnt -#define ArrayOfPnt_hxx -#define POnC Extrema_POnCurv -#define POnC_hxx -#define Pnt gp_Pnt -#define Pnt_hxx -#define Vec gp_Vec -#define Vec_hxx -#define Extrema_GExtPC Extrema_ExtPC -#define Extrema_GenExtCC Extrema_ECC -#define Extrema_GenExtCC_hxx -#include diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_ELPCOfLocateExtPC.hxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_ELPCOfLocateExtPC.hxx index 2359487c60..11ab3792a2 100644 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_ELPCOfLocateExtPC.hxx +++ b/src/ModelingData/TKGeomBase/Extrema/Extrema_ELPCOfLocateExtPC.hxx @@ -17,127 +17,24 @@ #ifndef _Extrema_ELPCOfLocateExtPC_HeaderFile #define _Extrema_ELPCOfLocateExtPC_HeaderFile -#include -#include - -#include -#include -#include +#include +#include #include -#include -#include -#include -#include -class StdFail_NotDone; -class Standard_OutOfRange; -class Standard_TypeMismatch; -class Adaptor3d_Curve; -class Extrema_CurveTool; -class Extrema_ExtPElC; -class gp_Pnt; -class gp_Vec; -class Extrema_POnCurv; -class Extrema_EPCOfELPCOfLocateExtPC; -class Extrema_PCFOfEPCOfELPCOfLocateExtPC; +#include +#include +#include +#include +#include +#include -class Extrema_ELPCOfLocateExtPC -{ -public: - DEFINE_STANDARD_ALLOC - - Standard_EXPORT Extrema_ELPCOfLocateExtPC(); - - //! It calculates all the distances. - //! The function F(u)=distance(P,C(u)) has an extremum - //! when g(u)=dF/du=0. The algorithm searches all the - //! zeros inside the definition range of the curve. - //! Zeros are searched between uinf and usup. - //! Tol is used to decide to stop the - //! iterations according to the following condition: - //! if n is the number of iterations, - //! the algorithm stops when abs(F(Un)-F(Un-1)) < Tol. - Standard_EXPORT Extrema_ELPCOfLocateExtPC(const gp_Pnt& P, - const Adaptor3d_Curve& C, - const Standard_Real Uinf, - const Standard_Real Usup, - const Standard_Real TolF = 1.0e-10); - - //! It calculates all the distances. - //! The function F(u)=distance(P,C(u)) has an extremum - //! when g(u)=dF/du=0. The algorithm searches all the - //! zeros inside the definition range of the curve. - //! Tol is used to decide to stop the - //! iterations according to the following condition: - //! if n is the number of iterations, - //! the algorithm stops when abs(F(Un)-F(Un-1)) < Tol. - Standard_EXPORT Extrema_ELPCOfLocateExtPC(const gp_Pnt& P, - const Adaptor3d_Curve& C, - const Standard_Real TolF = 1.0e-10); - - //! initializes the fields of the algorithm. - Standard_EXPORT void Initialize(const Adaptor3d_Curve& C, - const Standard_Real Uinf, - const Standard_Real Usup, - const Standard_Real TolF = 1.0e-10); - - //! An exception is raised if the fields have not been - //! initialized. - Standard_EXPORT void Perform(const gp_Pnt& P); - - //! True if the distances are found. - Standard_EXPORT Standard_Boolean IsDone() const; - - //! Returns the value of the th extremum square distance. - Standard_EXPORT Standard_Real SquareDistance(const Standard_Integer N) const; - - //! Returns the number of extremum distances. - Standard_EXPORT Standard_Integer NbExt() const; - - //! Returns True if the th extremum distance is a - //! minimum. - Standard_EXPORT Standard_Boolean IsMin(const Standard_Integer N) const; - - //! Returns the point of the th extremum distance. - Standard_EXPORT const Extrema_POnCurv& Point(const Standard_Integer N) const; - - //! if the curve is a trimmed curve, - //! dist1 is a square distance between

and the point - //! of parameter FirstParameter and - //! dist2 is a square distance between

and the point - //! of parameter LastParameter . - Standard_EXPORT void TrimmedSquareDistances(Standard_Real& dist1, - Standard_Real& dist2, - gp_Pnt& P1, - gp_Pnt& P2) const; - -protected: - Standard_EXPORT void IntervalPerform(const gp_Pnt& P); - - Standard_EXPORT void AddSol(const Standard_Real theU, - const gp_Pnt& theP, - const Standard_Real theSqDist, - const Standard_Boolean isMin); - -private: - Standard_Address myC; - gp_Pnt Pf; - gp_Pnt Pl; - Extrema_ExtPElC myExtPElC; - Extrema_SequenceOfPOnCurv mypoint; - Standard_Boolean mydone; - Standard_Real mydist1; - Standard_Real mydist2; - Extrema_EPCOfELPCOfLocateExtPC myExtPC; - Standard_Real mytolu; - Standard_Real mytolf; - Standard_Integer mysample; - Standard_Real myintuinf; - Standard_Real myintusup; - Standard_Real myuinf; - Standard_Real myusup; - GeomAbs_CurveType type; - TColStd_SequenceOfBoolean myismin; - TColStd_SequenceOfReal mySqDist; -}; +//! Type alias for 3D point-to-curve extremum computation for LocateExtPC. +using Extrema_ELPCOfLocateExtPC = Extrema_GGExtPC; #endif // _Extrema_ELPCOfLocateExtPC_HeaderFile diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_ELPCOfLocateExtPC2d.hxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_ELPCOfLocateExtPC2d.hxx index d943d8b230..d80b0f4c34 100644 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_ELPCOfLocateExtPC2d.hxx +++ b/src/ModelingData/TKGeomBase/Extrema/Extrema_ELPCOfLocateExtPC2d.hxx @@ -17,127 +17,24 @@ #ifndef _Extrema_ELPCOfLocateExtPC2d_HeaderFile #define _Extrema_ELPCOfLocateExtPC2d_HeaderFile -#include -#include -#include - -#include -#include -#include +#include +#include #include -#include -#include -#include -class StdFail_NotDone; -class Standard_OutOfRange; -class Standard_TypeMismatch; -class Adaptor2d_Curve2d; -class Extrema_Curve2dTool; -class Extrema_ExtPElC2d; -class gp_Pnt2d; -class gp_Vec2d; -class Extrema_POnCurv2d; -class Extrema_EPCOfELPCOfLocateExtPC2d; -class Extrema_PCFOfEPCOfELPCOfLocateExtPC2d; +#include +#include +#include +#include +#include +#include -class Extrema_ELPCOfLocateExtPC2d -{ -public: - DEFINE_STANDARD_ALLOC - - Standard_EXPORT Extrema_ELPCOfLocateExtPC2d(); - - //! It calculates all the distances. - //! The function F(u)=distance(P,C(u)) has an extremum - //! when g(u)=dF/du=0. The algorithm searches all the - //! zeros inside the definition range of the curve. - //! Zeros are searched between uinf and usup. - //! Tol is used to decide to stop the - //! iterations according to the following condition: - //! if n is the number of iterations, - //! the algorithm stops when abs(F(Un)-F(Un-1)) < Tol. - Standard_EXPORT Extrema_ELPCOfLocateExtPC2d(const gp_Pnt2d& P, - const Adaptor2d_Curve2d& C, - const Standard_Real Uinf, - const Standard_Real Usup, - const Standard_Real TolF = 1.0e-10); - - //! It calculates all the distances. - //! The function F(u)=distance(P,C(u)) has an extremum - //! when g(u)=dF/du=0. The algorithm searches all the - //! zeros inside the definition range of the curve. - //! Tol is used to decide to stop the - //! iterations according to the following condition: - //! if n is the number of iterations, - //! the algorithm stops when abs(F(Un)-F(Un-1)) < Tol. - Standard_EXPORT Extrema_ELPCOfLocateExtPC2d(const gp_Pnt2d& P, - const Adaptor2d_Curve2d& C, - const Standard_Real TolF = 1.0e-10); - - //! initializes the fields of the algorithm. - Standard_EXPORT void Initialize(const Adaptor2d_Curve2d& C, - const Standard_Real Uinf, - const Standard_Real Usup, - const Standard_Real TolF = 1.0e-10); - - //! An exception is raised if the fields have not been - //! initialized. - Standard_EXPORT void Perform(const gp_Pnt2d& P); - - //! True if the distances are found. - Standard_EXPORT Standard_Boolean IsDone() const; - - //! Returns the value of the th extremum square distance. - Standard_EXPORT Standard_Real SquareDistance(const Standard_Integer N) const; - - //! Returns the number of extremum distances. - Standard_EXPORT Standard_Integer NbExt() const; - - //! Returns True if the th extremum distance is a - //! minimum. - Standard_EXPORT Standard_Boolean IsMin(const Standard_Integer N) const; - - //! Returns the point of the th extremum distance. - Standard_EXPORT const Extrema_POnCurv2d& Point(const Standard_Integer N) const; - - //! if the curve is a trimmed curve, - //! dist1 is a square distance between

and the point - //! of parameter FirstParameter and - //! dist2 is a square distance between

and the point - //! of parameter LastParameter . - Standard_EXPORT void TrimmedSquareDistances(Standard_Real& dist1, - Standard_Real& dist2, - gp_Pnt2d& P1, - gp_Pnt2d& P2) const; - -protected: - Standard_EXPORT void IntervalPerform(const gp_Pnt2d& P); - - Standard_EXPORT void AddSol(const Standard_Real theU, - const gp_Pnt2d& theP, - const Standard_Real theSqDist, - const Standard_Boolean isMin); - -private: - Standard_Address myC; - gp_Pnt2d Pf; - gp_Pnt2d Pl; - Extrema_ExtPElC2d myExtPElC; - Extrema_SequenceOfPOnCurv2d mypoint; - Standard_Boolean mydone; - Standard_Real mydist1; - Standard_Real mydist2; - Extrema_EPCOfELPCOfLocateExtPC2d myExtPC; - Standard_Real mytolu; - Standard_Real mytolf; - Standard_Integer mysample; - Standard_Real myintuinf; - Standard_Real myintusup; - Standard_Real myuinf; - Standard_Real myusup; - GeomAbs_CurveType type; - TColStd_SequenceOfBoolean myismin; - TColStd_SequenceOfReal mySqDist; -}; +//! Type alias for 2D point-to-curve extremum computation for LocateExtPC. +using Extrema_ELPCOfLocateExtPC2d = Extrema_GGExtPC; #endif // _Extrema_ELPCOfLocateExtPC2d_HeaderFile diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_ELPCOfLocateExtPC2d_0.cxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_ELPCOfLocateExtPC2d_0.cxx deleted file mode 100644 index 3e55f3d937..0000000000 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_ELPCOfLocateExtPC2d_0.cxx +++ /dev/null @@ -1,53 +0,0 @@ -// Created on: 1991-02-26 -// Created by: Isabelle GRIGNON -// Copyright (c) 1991-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 - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define TheCurve Adaptor2d_Curve2d -#define TheCurve_hxx -#define TheCurveTool Extrema_Curve2dTool -#define TheCurveTool_hxx -#define TheExtPElC Extrema_ExtPElC2d -#define TheExtPElC_hxx -#define ThePoint gp_Pnt2d -#define ThePoint_hxx -#define TheVector gp_Vec2d -#define TheVector_hxx -#define ThePOnC Extrema_POnCurv2d -#define ThePOnC_hxx -#define TheSequenceOfPOnC Extrema_SequenceOfPOnCurv2d -#define TheSequenceOfPOnC_hxx -#define Extrema_EPC Extrema_EPCOfELPCOfLocateExtPC2d -#define Extrema_EPC_hxx -#define Extrema_PCFOfEPC Extrema_PCFOfEPCOfELPCOfLocateExtPC2d -#define Extrema_PCFOfEPC_hxx -#define Extrema_PCFOfEPC Extrema_PCFOfEPCOfELPCOfLocateExtPC2d -#define Extrema_PCFOfEPC_hxx -#define Extrema_GExtPC Extrema_ELPCOfLocateExtPC2d -#define Extrema_GExtPC_hxx -#include diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_ELPCOfLocateExtPC_0.cxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_ELPCOfLocateExtPC_0.cxx deleted file mode 100644 index 50fab6c9c4..0000000000 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_ELPCOfLocateExtPC_0.cxx +++ /dev/null @@ -1,53 +0,0 @@ -// Created on: 1991-02-26 -// Created by: Isabelle GRIGNON -// Copyright (c) 1991-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 - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define TheCurve Adaptor3d_Curve -#define TheCurve_hxx -#define TheCurveTool Extrema_CurveTool -#define TheCurveTool_hxx -#define TheExtPElC Extrema_ExtPElC -#define TheExtPElC_hxx -#define ThePoint gp_Pnt -#define ThePoint_hxx -#define TheVector gp_Vec -#define TheVector_hxx -#define ThePOnC Extrema_POnCurv -#define ThePOnC_hxx -#define TheSequenceOfPOnC Extrema_SequenceOfPOnCurv -#define TheSequenceOfPOnC_hxx -#define Extrema_EPC Extrema_EPCOfELPCOfLocateExtPC -#define Extrema_EPC_hxx -#define Extrema_PCFOfEPC Extrema_PCFOfEPCOfELPCOfLocateExtPC -#define Extrema_PCFOfEPC_hxx -#define Extrema_PCFOfEPC Extrema_PCFOfEPCOfELPCOfLocateExtPC -#define Extrema_PCFOfEPC_hxx -#define Extrema_GExtPC Extrema_ELPCOfLocateExtPC -#define Extrema_GExtPC_hxx -#include diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_EPCOfELPCOfLocateExtPC.hxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_EPCOfELPCOfLocateExtPC.hxx index c4b3d4351a..2e36356d65 100644 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_EPCOfELPCOfLocateExtPC.hxx +++ b/src/ModelingData/TKGeomBase/Extrema/Extrema_EPCOfELPCOfLocateExtPC.hxx @@ -17,118 +17,18 @@ #ifndef _Extrema_EPCOfELPCOfLocateExtPC_HeaderFile #define _Extrema_EPCOfELPCOfLocateExtPC_HeaderFile -#include -#include - -#include +#include +#include +#include #include -class StdFail_NotDone; -class Standard_OutOfRange; -class Standard_TypeMismatch; -class Adaptor3d_Curve; -class Extrema_CurveTool; -class Extrema_POnCurv; -class gp_Pnt; -class gp_Vec; -class Extrema_PCFOfEPCOfELPCOfLocateExtPC; +#include +#include -class Extrema_EPCOfELPCOfLocateExtPC -{ -public: - DEFINE_STANDARD_ALLOC - - Standard_EXPORT Extrema_EPCOfELPCOfLocateExtPC(); - - //! It calculates all the distances. - //! The function F(u)=distance(P,C(u)) has an extremum - //! when g(u)=dF/du=0. The algorithm searches all the - //! zeros inside the definition range of the curve. - //! NbU is used to locate the close points to - //! find the zeros. - //! Tol and TolU are used to decide to stop the - //! iterations according to the following condition: - //! if n is the number of iterations, - //! abs(Un-Un-1) < TolU and abs(F(Un)-F(Un-1)) < Tol. - Standard_EXPORT Extrema_EPCOfELPCOfLocateExtPC(const gp_Pnt& P, - const Adaptor3d_Curve& C, - const Standard_Integer NbU, - const Standard_Real TolU, - const Standard_Real TolF); - - //! It calculates all the distances. - //! The function F(u)=distance(P,C(u)) has an extremum - //! when g(u)=dF/du=0. The algorithm searches all the - //! zeros inside the definition range of the curve. - //! NbU is used to locate the close points to - //! find the zeros. - //! Zeros are searched between umin and usup. - //! Tol and TolU are used to decide to stop the - //! iterations according to the following condition: - //! if n is the number of iterations, - //! abs(Un-Un-1) < TolU and abs(F(Un)-F(Un-1)) < Tol. - Standard_EXPORT Extrema_EPCOfELPCOfLocateExtPC(const gp_Pnt& P, - const Adaptor3d_Curve& C, - const Standard_Integer NbU, - const Standard_Real Umin, - const Standard_Real Usup, - const Standard_Real TolU, - const Standard_Real TolF); - - //! sets the fields of the algorithm. - Standard_EXPORT void Initialize(const Adaptor3d_Curve& C, - const Standard_Integer NbU, - const Standard_Real TolU, - const Standard_Real TolF); - - //! sets the fields of the algorithm. - Standard_EXPORT void Initialize(const Adaptor3d_Curve& C, - const Standard_Integer NbU, - const Standard_Real Umin, - const Standard_Real Usup, - const Standard_Real TolU, - const Standard_Real TolF); - - //! sets the fields of the algorithm. - Standard_EXPORT void Initialize(const Adaptor3d_Curve& C); - - //! sets the fields of the algorithm. - Standard_EXPORT void Initialize(const Standard_Integer NbU, - const Standard_Real Umin, - const Standard_Real Usup, - const Standard_Real TolU, - const Standard_Real TolF); - - //! the algorithm is done with the point P. - //! An exception is raised if the fields have not - //! been initialized. - Standard_EXPORT void Perform(const gp_Pnt& P); - - //! True if the distances are found. - Standard_EXPORT Standard_Boolean IsDone() const; - - //! Returns the number of extremum distances. - Standard_EXPORT Standard_Integer NbExt() const; - - //! Returns the value of the Nth extremum square distance. - Standard_EXPORT Standard_Real SquareDistance(const Standard_Integer N) const; - - //! Returns True if the Nth extremum distance is a - //! minimum. - Standard_EXPORT Standard_Boolean IsMin(const Standard_Integer N) const; - - //! Returns the point of the Nth extremum distance. - Standard_EXPORT const Extrema_POnCurv& Point(const Standard_Integer N) const; - -protected: -private: - Standard_Boolean myDone; - Standard_Boolean myInit; - Standard_Integer mynbsample; - Standard_Real myumin; - Standard_Real myusup; - Standard_Real mytolu; - Standard_Real mytolF; - Extrema_PCFOfEPCOfELPCOfLocateExtPC myF; -}; +//! Type alias for 3D curve extremum point search for LocateExtPC. +using Extrema_EPCOfELPCOfLocateExtPC = Extrema_GGenExtPC; #endif // _Extrema_EPCOfELPCOfLocateExtPC_HeaderFile diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_EPCOfELPCOfLocateExtPC2d.hxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_EPCOfELPCOfLocateExtPC2d.hxx index 0310c382d0..cf9ab3d57f 100644 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_EPCOfELPCOfLocateExtPC2d.hxx +++ b/src/ModelingData/TKGeomBase/Extrema/Extrema_EPCOfELPCOfLocateExtPC2d.hxx @@ -17,119 +17,18 @@ #ifndef _Extrema_EPCOfELPCOfLocateExtPC2d_HeaderFile #define _Extrema_EPCOfELPCOfLocateExtPC2d_HeaderFile -#include -#include -#include - -#include +#include +#include +#include #include -class StdFail_NotDone; -class Standard_OutOfRange; -class Standard_TypeMismatch; -class Adaptor2d_Curve2d; -class Extrema_Curve2dTool; -class Extrema_POnCurv2d; -class gp_Pnt2d; -class gp_Vec2d; -class Extrema_PCFOfEPCOfELPCOfLocateExtPC2d; +#include +#include -class Extrema_EPCOfELPCOfLocateExtPC2d -{ -public: - DEFINE_STANDARD_ALLOC - - Standard_EXPORT Extrema_EPCOfELPCOfLocateExtPC2d(); - - //! It calculates all the distances. - //! The function F(u)=distance(P,C(u)) has an extremum - //! when g(u)=dF/du=0. The algorithm searches all the - //! zeros inside the definition range of the curve. - //! NbU is used to locate the close points to - //! find the zeros. - //! Tol and TolU are used to decide to stop the - //! iterations according to the following condition: - //! if n is the number of iterations, - //! abs(Un-Un-1) < TolU and abs(F(Un)-F(Un-1)) < Tol. - Standard_EXPORT Extrema_EPCOfELPCOfLocateExtPC2d(const gp_Pnt2d& P, - const Adaptor2d_Curve2d& C, - const Standard_Integer NbU, - const Standard_Real TolU, - const Standard_Real TolF); - - //! It calculates all the distances. - //! The function F(u)=distance(P,C(u)) has an extremum - //! when g(u)=dF/du=0. The algorithm searches all the - //! zeros inside the definition range of the curve. - //! NbU is used to locate the close points to - //! find the zeros. - //! Zeros are searched between umin and usup. - //! Tol and TolU are used to decide to stop the - //! iterations according to the following condition: - //! if n is the number of iterations, - //! abs(Un-Un-1) < TolU and abs(F(Un)-F(Un-1)) < Tol. - Standard_EXPORT Extrema_EPCOfELPCOfLocateExtPC2d(const gp_Pnt2d& P, - const Adaptor2d_Curve2d& C, - const Standard_Integer NbU, - const Standard_Real Umin, - const Standard_Real Usup, - const Standard_Real TolU, - const Standard_Real TolF); - - //! sets the fields of the algorithm. - Standard_EXPORT void Initialize(const Adaptor2d_Curve2d& C, - const Standard_Integer NbU, - const Standard_Real TolU, - const Standard_Real TolF); - - //! sets the fields of the algorithm. - Standard_EXPORT void Initialize(const Adaptor2d_Curve2d& C, - const Standard_Integer NbU, - const Standard_Real Umin, - const Standard_Real Usup, - const Standard_Real TolU, - const Standard_Real TolF); - - //! sets the fields of the algorithm. - Standard_EXPORT void Initialize(const Adaptor2d_Curve2d& C); - - //! sets the fields of the algorithm. - Standard_EXPORT void Initialize(const Standard_Integer NbU, - const Standard_Real Umin, - const Standard_Real Usup, - const Standard_Real TolU, - const Standard_Real TolF); - - //! the algorithm is done with the point P. - //! An exception is raised if the fields have not - //! been initialized. - Standard_EXPORT void Perform(const gp_Pnt2d& P); - - //! True if the distances are found. - Standard_EXPORT Standard_Boolean IsDone() const; - - //! Returns the number of extremum distances. - Standard_EXPORT Standard_Integer NbExt() const; - - //! Returns the value of the Nth extremum square distance. - Standard_EXPORT Standard_Real SquareDistance(const Standard_Integer N) const; - - //! Returns True if the Nth extremum distance is a - //! minimum. - Standard_EXPORT Standard_Boolean IsMin(const Standard_Integer N) const; - - //! Returns the point of the Nth extremum distance. - Standard_EXPORT const Extrema_POnCurv2d& Point(const Standard_Integer N) const; - -protected: -private: - Standard_Boolean myDone; - Standard_Boolean myInit; - Standard_Integer mynbsample; - Standard_Real myumin; - Standard_Real myusup; - Standard_Real mytolu; - Standard_Real mytolF; - Extrema_PCFOfEPCOfELPCOfLocateExtPC2d myF; -}; +//! Type alias for 2D curve extremum point search for LocateExtPC. +using Extrema_EPCOfELPCOfLocateExtPC2d = Extrema_GGenExtPC; #endif // _Extrema_EPCOfELPCOfLocateExtPC2d_HeaderFile diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_EPCOfELPCOfLocateExtPC2d_0.cxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_EPCOfELPCOfLocateExtPC2d_0.cxx deleted file mode 100644 index 631089d97d..0000000000 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_EPCOfELPCOfLocateExtPC2d_0.cxx +++ /dev/null @@ -1,48 +0,0 @@ -// Created on: 1991-02-26 -// Created by: Isabelle GRIGNON -// Copyright (c) 1991-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 - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define Curve Adaptor2d_Curve2d -#define Curve_hxx -#define Tool Extrema_Curve2dTool -#define Tool_hxx -#define POnC Extrema_POnCurv2d -#define POnC_hxx -#define Pnt gp_Pnt2d -#define Pnt_hxx -#define Vec gp_Vec2d -#define Vec_hxx -#define Extrema_PCF Extrema_PCFOfEPCOfELPCOfLocateExtPC2d -#define Extrema_PCF_hxx -#define Extrema_SeqPCOfPCF Extrema_SequenceOfPOnCurv2d -#define Extrema_SeqPCOfPCF_hxx -#define Extrema_SeqPCOfPCF Extrema_SequenceOfPOnCurv2d -#define Extrema_SeqPCOfPCF_hxx -#define Extrema_GenExtPC Extrema_EPCOfELPCOfLocateExtPC2d -#define Extrema_GenExtPC_hxx -#include diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_EPCOfELPCOfLocateExtPC_0.cxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_EPCOfELPCOfLocateExtPC_0.cxx deleted file mode 100644 index 82d4e7ca41..0000000000 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_EPCOfELPCOfLocateExtPC_0.cxx +++ /dev/null @@ -1,48 +0,0 @@ -// Created on: 1991-02-26 -// Created by: Isabelle GRIGNON -// Copyright (c) 1991-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 - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define Curve Adaptor3d_Curve -#define Curve_hxx -#define Tool Extrema_CurveTool -#define Tool_hxx -#define POnC Extrema_POnCurv -#define POnC_hxx -#define Pnt gp_Pnt -#define Pnt_hxx -#define Vec gp_Vec -#define Vec_hxx -#define Extrema_PCF Extrema_PCFOfEPCOfELPCOfLocateExtPC -#define Extrema_PCF_hxx -#define Extrema_SeqPCOfPCF Extrema_SequenceOfPOnCurv -#define Extrema_SeqPCOfPCF_hxx -#define Extrema_SeqPCOfPCF Extrema_SequenceOfPOnCurv -#define Extrema_SeqPCOfPCF_hxx -#define Extrema_GenExtPC Extrema_EPCOfELPCOfLocateExtPC -#define Extrema_GenExtPC_hxx -#include diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_EPCOfExtPC.hxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_EPCOfExtPC.hxx index d311bbf0bd..613af98c78 100644 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_EPCOfExtPC.hxx +++ b/src/ModelingData/TKGeomBase/Extrema/Extrema_EPCOfExtPC.hxx @@ -17,118 +17,18 @@ #ifndef _Extrema_EPCOfExtPC_HeaderFile #define _Extrema_EPCOfExtPC_HeaderFile -#include -#include - -#include +#include +#include +#include #include -class StdFail_NotDone; -class Standard_OutOfRange; -class Standard_TypeMismatch; -class Adaptor3d_Curve; -class Extrema_CurveTool; -class Extrema_POnCurv; -class gp_Pnt; -class gp_Vec; -class Extrema_PCFOfEPCOfExtPC; +#include +#include -class Extrema_EPCOfExtPC -{ -public: - DEFINE_STANDARD_ALLOC - - Standard_EXPORT Extrema_EPCOfExtPC(); - - //! It calculates all the distances. - //! The function F(u)=distance(P,C(u)) has an extremum - //! when g(u)=dF/du=0. The algorithm searches all the - //! zeros inside the definition range of the curve. - //! NbU is used to locate the close points to - //! find the zeros. - //! Tol and TolU are used to decide to stop the - //! iterations according to the following condition: - //! if n is the number of iterations, - //! abs(Un-Un-1) < TolU and abs(F(Un)-F(Un-1)) < Tol. - Standard_EXPORT Extrema_EPCOfExtPC(const gp_Pnt& P, - const Adaptor3d_Curve& C, - const Standard_Integer NbU, - const Standard_Real TolU, - const Standard_Real TolF); - - //! It calculates all the distances. - //! The function F(u)=distance(P,C(u)) has an extremum - //! when g(u)=dF/du=0. The algorithm searches all the - //! zeros inside the definition range of the curve. - //! NbU is used to locate the close points to - //! find the zeros. - //! Zeros are searched between umin and usup. - //! Tol and TolU are used to decide to stop the - //! iterations according to the following condition: - //! if n is the number of iterations, - //! abs(Un-Un-1) < TolU and abs(F(Un)-F(Un-1)) < Tol. - Standard_EXPORT Extrema_EPCOfExtPC(const gp_Pnt& P, - const Adaptor3d_Curve& C, - const Standard_Integer NbU, - const Standard_Real Umin, - const Standard_Real Usup, - const Standard_Real TolU, - const Standard_Real TolF); - - //! sets the fields of the algorithm. - Standard_EXPORT void Initialize(const Adaptor3d_Curve& C, - const Standard_Integer NbU, - const Standard_Real TolU, - const Standard_Real TolF); - - //! sets the fields of the algorithm. - Standard_EXPORT void Initialize(const Adaptor3d_Curve& C, - const Standard_Integer NbU, - const Standard_Real Umin, - const Standard_Real Usup, - const Standard_Real TolU, - const Standard_Real TolF); - - //! sets the fields of the algorithm. - Standard_EXPORT void Initialize(const Adaptor3d_Curve& C); - - //! sets the fields of the algorithm. - Standard_EXPORT void Initialize(const Standard_Integer NbU, - const Standard_Real Umin, - const Standard_Real Usup, - const Standard_Real TolU, - const Standard_Real TolF); - - //! the algorithm is done with the point P. - //! An exception is raised if the fields have not - //! been initialized. - Standard_EXPORT void Perform(const gp_Pnt& P); - - //! True if the distances are found. - Standard_EXPORT Standard_Boolean IsDone() const; - - //! Returns the number of extremum distances. - Standard_EXPORT Standard_Integer NbExt() const; - - //! Returns the value of the Nth extremum square distance. - Standard_EXPORT Standard_Real SquareDistance(const Standard_Integer N) const; - - //! Returns True if the Nth extremum distance is a - //! minimum. - Standard_EXPORT Standard_Boolean IsMin(const Standard_Integer N) const; - - //! Returns the point of the Nth extremum distance. - Standard_EXPORT const Extrema_POnCurv& Point(const Standard_Integer N) const; - -protected: -private: - Standard_Boolean myDone; - Standard_Boolean myInit; - Standard_Integer mynbsample; - Standard_Real myumin; - Standard_Real myusup; - Standard_Real mytolu; - Standard_Real mytolF; - Extrema_PCFOfEPCOfExtPC myF; -}; +//! Type alias for 3D curve extremum point search using Extrema_CurveTool. +using Extrema_EPCOfExtPC = Extrema_GGenExtPC; #endif // _Extrema_EPCOfExtPC_HeaderFile diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_EPCOfExtPC2d.hxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_EPCOfExtPC2d.hxx index 692cafe93f..ab87177c5e 100644 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_EPCOfExtPC2d.hxx +++ b/src/ModelingData/TKGeomBase/Extrema/Extrema_EPCOfExtPC2d.hxx @@ -17,118 +17,18 @@ #ifndef _Extrema_EPCOfExtPC2d_HeaderFile #define _Extrema_EPCOfExtPC2d_HeaderFile -#include -#include - -#include +#include +#include +#include #include -class StdFail_NotDone; -class Standard_OutOfRange; -class Standard_TypeMismatch; -class Adaptor2d_Curve2d; -class Extrema_Curve2dTool; -class Extrema_POnCurv2d; -class gp_Pnt2d; -class gp_Vec2d; -class Extrema_PCFOfEPCOfExtPC2d; +#include +#include -class Extrema_EPCOfExtPC2d -{ -public: - DEFINE_STANDARD_ALLOC - - Standard_EXPORT Extrema_EPCOfExtPC2d(); - - //! It calculates all the distances. - //! The function F(u)=distance(P,C(u)) has an extremum - //! when g(u)=dF/du=0. The algorithm searches all the - //! zeros inside the definition range of the curve. - //! NbU is used to locate the close points to - //! find the zeros. - //! Tol and TolU are used to decide to stop the - //! iterations according to the following condition: - //! if n is the number of iterations, - //! abs(Un-Un-1) < TolU and abs(F(Un)-F(Un-1)) < Tol. - Standard_EXPORT Extrema_EPCOfExtPC2d(const gp_Pnt2d& P, - const Adaptor2d_Curve2d& C, - const Standard_Integer NbU, - const Standard_Real TolU, - const Standard_Real TolF); - - //! It calculates all the distances. - //! The function F(u)=distance(P,C(u)) has an extremum - //! when g(u)=dF/du=0. The algorithm searches all the - //! zeros inside the definition range of the curve. - //! NbU is used to locate the close points to - //! find the zeros. - //! Zeros are searched between umin and usup. - //! Tol and TolU are used to decide to stop the - //! iterations according to the following condition: - //! if n is the number of iterations, - //! abs(Un-Un-1) < TolU and abs(F(Un)-F(Un-1)) < Tol. - Standard_EXPORT Extrema_EPCOfExtPC2d(const gp_Pnt2d& P, - const Adaptor2d_Curve2d& C, - const Standard_Integer NbU, - const Standard_Real Umin, - const Standard_Real Usup, - const Standard_Real TolU, - const Standard_Real TolF); - - //! sets the fields of the algorithm. - Standard_EXPORT void Initialize(const Adaptor2d_Curve2d& C, - const Standard_Integer NbU, - const Standard_Real TolU, - const Standard_Real TolF); - - //! sets the fields of the algorithm. - Standard_EXPORT void Initialize(const Adaptor2d_Curve2d& C, - const Standard_Integer NbU, - const Standard_Real Umin, - const Standard_Real Usup, - const Standard_Real TolU, - const Standard_Real TolF); - - //! sets the fields of the algorithm. - Standard_EXPORT void Initialize(const Adaptor2d_Curve2d& C); - - //! sets the fields of the algorithm. - Standard_EXPORT void Initialize(const Standard_Integer NbU, - const Standard_Real Umin, - const Standard_Real Usup, - const Standard_Real TolU, - const Standard_Real TolF); - - //! the algorithm is done with the point P. - //! An exception is raised if the fields have not - //! been initialized. - Standard_EXPORT void Perform(const gp_Pnt2d& P); - - //! True if the distances are found. - Standard_EXPORT Standard_Boolean IsDone() const; - - //! Returns the number of extremum distances. - Standard_EXPORT Standard_Integer NbExt() const; - - //! Returns the value of the Nth extremum square distance. - Standard_EXPORT Standard_Real SquareDistance(const Standard_Integer N) const; - - //! Returns True if the Nth extremum distance is a - //! minimum. - Standard_EXPORT Standard_Boolean IsMin(const Standard_Integer N) const; - - //! Returns the point of the Nth extremum distance. - Standard_EXPORT const Extrema_POnCurv2d& Point(const Standard_Integer N) const; - -protected: -private: - Standard_Boolean myDone; - Standard_Boolean myInit; - Standard_Integer mynbsample; - Standard_Real myumin; - Standard_Real myusup; - Standard_Real mytolu; - Standard_Real mytolF; - Extrema_PCFOfEPCOfExtPC2d myF; -}; +//! Type alias for 2D curve extremum point search using Extrema_Curve2dTool. +using Extrema_EPCOfExtPC2d = Extrema_GGenExtPC; #endif // _Extrema_EPCOfExtPC2d_HeaderFile diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_EPCOfExtPC2d_0.cxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_EPCOfExtPC2d_0.cxx deleted file mode 100644 index 1f6be92cb1..0000000000 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_EPCOfExtPC2d_0.cxx +++ /dev/null @@ -1,48 +0,0 @@ -// Created on: 1991-02-26 -// Created by: Isabelle GRIGNON -// Copyright (c) 1991-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 - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define Curve Adaptor2d_Curve2d -#define Curve_hxx -#define Tool Extrema_Curve2dTool -#define Tool_hxx -#define POnC Extrema_POnCurv2d -#define POnC_hxx -#define Pnt gp_Pnt2d -#define Pnt_hxx -#define Vec gp_Vec2d -#define Vec_hxx -#define Extrema_PCF Extrema_PCFOfEPCOfExtPC2d -#define Extrema_PCF_hxx -#define Extrema_SeqPCOfPCF Extrema_SequenceOfPOnCurv2d -#define Extrema_SeqPCOfPCF_hxx -#define Extrema_SeqPCOfPCF Extrema_SequenceOfPOnCurv2d -#define Extrema_SeqPCOfPCF_hxx -#define Extrema_GenExtPC Extrema_EPCOfExtPC2d -#define Extrema_GenExtPC_hxx -#include diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_EPCOfExtPC_0.cxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_EPCOfExtPC_0.cxx deleted file mode 100644 index 00cf488e07..0000000000 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_EPCOfExtPC_0.cxx +++ /dev/null @@ -1,48 +0,0 @@ -// Created on: 1991-02-26 -// Created by: Isabelle GRIGNON -// Copyright (c) 1991-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 - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define Curve Adaptor3d_Curve -#define Curve_hxx -#define Tool Extrema_CurveTool -#define Tool_hxx -#define POnC Extrema_POnCurv -#define POnC_hxx -#define Pnt gp_Pnt -#define Pnt_hxx -#define Vec gp_Vec -#define Vec_hxx -#define Extrema_PCF Extrema_PCFOfEPCOfExtPC -#define Extrema_PCF_hxx -#define Extrema_SeqPCOfPCF Extrema_SequenceOfPOnCurv -#define Extrema_SeqPCOfPCF_hxx -#define Extrema_SeqPCOfPCF Extrema_SequenceOfPOnCurv -#define Extrema_SeqPCOfPCF_hxx -#define Extrema_GenExtPC Extrema_EPCOfExtPC -#define Extrema_GenExtPC_hxx -#include diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_ExtCC2d.hxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_ExtCC2d.hxx index f566b4715d..28f7910b9e 100644 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_ExtCC2d.hxx +++ b/src/ModelingData/TKGeomBase/Extrema/Extrema_ExtCC2d.hxx @@ -25,10 +25,11 @@ #include #include +#include + class Adaptor2d_Curve2d; class Extrema_POnCurv2d; class Extrema_ExtElC2d; -class Extrema_ECC2d; //! It calculates all the distance between two curves. //! These distances can be maximum or minimum. diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_ExtPC.hxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_ExtPC.hxx index 1611fe2d57..7ba085320b 100644 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_ExtPC.hxx +++ b/src/ModelingData/TKGeomBase/Extrema/Extrema_ExtPC.hxx @@ -17,126 +17,24 @@ #ifndef _Extrema_ExtPC_HeaderFile #define _Extrema_ExtPC_HeaderFile -#include -#include - -#include -#include +#include +#include #include -#include -#include -#include -#include -class StdFail_NotDone; -class Standard_OutOfRange; -class Standard_TypeMismatch; -class Adaptor3d_Curve; -class Extrema_CurveTool; -class Extrema_ExtPElC; -class gp_Pnt; -class gp_Vec; -class Extrema_POnCurv; -class Extrema_EPCOfExtPC; -class Extrema_PCFOfEPCOfExtPC; +#include +#include +#include +#include +#include +#include -class Extrema_ExtPC -{ -public: - DEFINE_STANDARD_ALLOC - - Standard_EXPORT Extrema_ExtPC(); - - //! It calculates all the distances. - //! The function F(u)=distance(P,C(u)) has an extremum - //! when g(u)=dF/du=0. The algorithm searches all the - //! zeros inside the definition range of the curve. - //! Zeros are searched between uinf and usup. - //! Tol is used to decide to stop the - //! iterations according to the following condition: - //! if n is the number of iterations, - //! the algorithm stops when abs(F(Un)-F(Un-1)) < Tol. - Standard_EXPORT Extrema_ExtPC(const gp_Pnt& P, - const Adaptor3d_Curve& C, - const Standard_Real Uinf, - const Standard_Real Usup, - const Standard_Real TolF = 1.0e-10); - - //! It calculates all the distances. - //! The function F(u)=distance(P,C(u)) has an extremum - //! when g(u)=dF/du=0. The algorithm searches all the - //! zeros inside the definition range of the curve. - //! Tol is used to decide to stop the - //! iterations according to the following condition: - //! if n is the number of iterations, - //! the algorithm stops when abs(F(Un)-F(Un-1)) < Tol. - Standard_EXPORT Extrema_ExtPC(const gp_Pnt& P, - const Adaptor3d_Curve& C, - const Standard_Real TolF = 1.0e-10); - - //! initializes the fields of the algorithm. - Standard_EXPORT void Initialize(const Adaptor3d_Curve& C, - const Standard_Real Uinf, - const Standard_Real Usup, - const Standard_Real TolF = 1.0e-10); - - //! An exception is raised if the fields have not been - //! initialized. - Standard_EXPORT void Perform(const gp_Pnt& P); - - //! True if the distances are found. - Standard_EXPORT Standard_Boolean IsDone() const; - - //! Returns the value of the th extremum square distance. - Standard_EXPORT Standard_Real SquareDistance(const Standard_Integer N) const; - - //! Returns the number of extremum distances. - Standard_EXPORT Standard_Integer NbExt() const; - - //! Returns True if the th extremum distance is a - //! minimum. - Standard_EXPORT Standard_Boolean IsMin(const Standard_Integer N) const; - - //! Returns the point of the th extremum distance. - Standard_EXPORT const Extrema_POnCurv& Point(const Standard_Integer N) const; - - //! if the curve is a trimmed curve, - //! dist1 is a square distance between

and the point - //! of parameter FirstParameter and - //! dist2 is a square distance between

and the point - //! of parameter LastParameter . - Standard_EXPORT void TrimmedSquareDistances(Standard_Real& dist1, - Standard_Real& dist2, - gp_Pnt& P1, - gp_Pnt& P2) const; - -protected: - Standard_EXPORT void IntervalPerform(const gp_Pnt& P); - - Standard_EXPORT void AddSol(const Standard_Real theU, - const gp_Pnt& theP, - const Standard_Real theSqDist, - const Standard_Boolean isMin); - -private: - Standard_Address myC; - gp_Pnt Pf; - gp_Pnt Pl; - Extrema_ExtPElC myExtPElC; - Extrema_SequenceOfPOnCurv mypoint; - Standard_Boolean mydone; - Standard_Real mydist1; - Standard_Real mydist2; - Extrema_EPCOfExtPC myExtPC; - Standard_Real mytolu; - Standard_Real mytolf; - Standard_Integer mysample; - Standard_Real myintuinf; - Standard_Real myintusup; - Standard_Real myuinf; - Standard_Real myusup; - GeomAbs_CurveType type; - TColStd_SequenceOfBoolean myismin; - TColStd_SequenceOfReal mySqDist; -}; +//! Type alias for 3D point-to-curve extremum computation. +using Extrema_ExtPC = Extrema_GGExtPC; #endif // _Extrema_ExtPC_HeaderFile diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_ExtPC2d.hxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_ExtPC2d.hxx index 578fcbe4b5..6711edb418 100644 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_ExtPC2d.hxx +++ b/src/ModelingData/TKGeomBase/Extrema/Extrema_ExtPC2d.hxx @@ -17,126 +17,24 @@ #ifndef _Extrema_ExtPC2d_HeaderFile #define _Extrema_ExtPC2d_HeaderFile -#include -#include - -#include -#include +#include +#include #include -#include -#include -#include -#include -class StdFail_NotDone; -class Standard_OutOfRange; -class Standard_TypeMismatch; -class Adaptor2d_Curve2d; -class Extrema_Curve2dTool; -class Extrema_ExtPElC2d; -class gp_Pnt2d; -class gp_Vec2d; -class Extrema_POnCurv2d; -class Extrema_EPCOfExtPC2d; -class Extrema_PCFOfEPCOfExtPC2d; +#include +#include +#include +#include +#include +#include -class Extrema_ExtPC2d -{ -public: - DEFINE_STANDARD_ALLOC - - Standard_EXPORT Extrema_ExtPC2d(); - - //! It calculates all the distances. - //! The function F(u)=distance(P,C(u)) has an extremum - //! when g(u)=dF/du=0. The algorithm searches all the - //! zeros inside the definition range of the curve. - //! Zeros are searched between uinf and usup. - //! Tol is used to decide to stop the - //! iterations according to the following condition: - //! if n is the number of iterations, - //! the algorithm stops when abs(F(Un)-F(Un-1)) < Tol. - Standard_EXPORT Extrema_ExtPC2d(const gp_Pnt2d& P, - const Adaptor2d_Curve2d& C, - const Standard_Real Uinf, - const Standard_Real Usup, - const Standard_Real TolF = 1.0e-10); - - //! It calculates all the distances. - //! The function F(u)=distance(P,C(u)) has an extremum - //! when g(u)=dF/du=0. The algorithm searches all the - //! zeros inside the definition range of the curve. - //! Tol is used to decide to stop the - //! iterations according to the following condition: - //! if n is the number of iterations, - //! the algorithm stops when abs(F(Un)-F(Un-1)) < Tol. - Standard_EXPORT Extrema_ExtPC2d(const gp_Pnt2d& P, - const Adaptor2d_Curve2d& C, - const Standard_Real TolF = 1.0e-10); - - //! initializes the fields of the algorithm. - Standard_EXPORT void Initialize(const Adaptor2d_Curve2d& C, - const Standard_Real Uinf, - const Standard_Real Usup, - const Standard_Real TolF = 1.0e-10); - - //! An exception is raised if the fields have not been - //! initialized. - Standard_EXPORT void Perform(const gp_Pnt2d& P); - - //! True if the distances are found. - Standard_EXPORT Standard_Boolean IsDone() const; - - //! Returns the value of the th extremum square distance. - Standard_EXPORT Standard_Real SquareDistance(const Standard_Integer N) const; - - //! Returns the number of extremum distances. - Standard_EXPORT Standard_Integer NbExt() const; - - //! Returns True if the th extremum distance is a - //! minimum. - Standard_EXPORT Standard_Boolean IsMin(const Standard_Integer N) const; - - //! Returns the point of the th extremum distance. - Standard_EXPORT const Extrema_POnCurv2d& Point(const Standard_Integer N) const; - - //! if the curve is a trimmed curve, - //! dist1 is a square distance between

and the point - //! of parameter FirstParameter and - //! dist2 is a square distance between

and the point - //! of parameter LastParameter . - Standard_EXPORT void TrimmedSquareDistances(Standard_Real& dist1, - Standard_Real& dist2, - gp_Pnt2d& P1, - gp_Pnt2d& P2) const; - -protected: - Standard_EXPORT void IntervalPerform(const gp_Pnt2d& P); - - Standard_EXPORT void AddSol(const Standard_Real theU, - const gp_Pnt2d& theP, - const Standard_Real theSqDist, - const Standard_Boolean isMin); - -private: - Standard_Address myC; - gp_Pnt2d Pf; - gp_Pnt2d Pl; - Extrema_ExtPElC2d myExtPElC; - Extrema_SequenceOfPOnCurv2d mypoint; - Standard_Boolean mydone; - Standard_Real mydist1; - Standard_Real mydist2; - Extrema_EPCOfExtPC2d myExtPC; - Standard_Real mytolu; - Standard_Real mytolf; - Standard_Integer mysample; - Standard_Real myintuinf; - Standard_Real myintusup; - Standard_Real myuinf; - Standard_Real myusup; - GeomAbs_CurveType type; - TColStd_SequenceOfBoolean myismin; - TColStd_SequenceOfReal mySqDist; -}; +//! Type alias for 2D point-to-curve extremum computation. +using Extrema_ExtPC2d = Extrema_GGExtPC; #endif // _Extrema_ExtPC2d_HeaderFile diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_ExtPC2d_0.cxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_ExtPC2d_0.cxx deleted file mode 100644 index 4e70564ac5..0000000000 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_ExtPC2d_0.cxx +++ /dev/null @@ -1,53 +0,0 @@ -// Created on: 1991-02-26 -// Created by: Isabelle GRIGNON -// Copyright (c) 1991-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 - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define TheCurve Adaptor2d_Curve2d -#define TheCurve_hxx -#define TheCurveTool Extrema_Curve2dTool -#define TheCurveTool_hxx -#define TheExtPElC Extrema_ExtPElC2d -#define TheExtPElC_hxx -#define ThePoint gp_Pnt2d -#define ThePoint_hxx -#define TheVector gp_Vec2d -#define TheVector_hxx -#define ThePOnC Extrema_POnCurv2d -#define ThePOnC_hxx -#define TheSequenceOfPOnC Extrema_SequenceOfPOnCurv2d -#define TheSequenceOfPOnC_hxx -#define Extrema_EPC Extrema_EPCOfExtPC2d -#define Extrema_EPC_hxx -#define Extrema_PCFOfEPC Extrema_PCFOfEPCOfExtPC2d -#define Extrema_PCFOfEPC_hxx -#define Extrema_PCFOfEPC Extrema_PCFOfEPCOfExtPC2d -#define Extrema_PCFOfEPC_hxx -#define Extrema_GExtPC Extrema_ExtPC2d -#define Extrema_GExtPC_hxx -#include diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_ExtPC_0.cxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_ExtPC_0.cxx deleted file mode 100644 index 5359a9b56d..0000000000 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_ExtPC_0.cxx +++ /dev/null @@ -1,53 +0,0 @@ -// Created on: 1991-02-26 -// Created by: Isabelle GRIGNON -// Copyright (c) 1991-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 - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define TheCurve Adaptor3d_Curve -#define TheCurve_hxx -#define TheCurveTool Extrema_CurveTool -#define TheCurveTool_hxx -#define TheExtPElC Extrema_ExtPElC -#define TheExtPElC_hxx -#define ThePoint gp_Pnt -#define ThePoint_hxx -#define TheVector gp_Vec -#define TheVector_hxx -#define ThePOnC Extrema_POnCurv -#define ThePOnC_hxx -#define TheSequenceOfPOnC Extrema_SequenceOfPOnCurv -#define TheSequenceOfPOnC_hxx -#define Extrema_EPC Extrema_EPCOfExtPC -#define Extrema_EPC_hxx -#define Extrema_PCFOfEPC Extrema_PCFOfEPCOfExtPC -#define Extrema_PCFOfEPC_hxx -#define Extrema_PCFOfEPC Extrema_PCFOfEPCOfExtPC -#define Extrema_PCFOfEPC_hxx -#define Extrema_GExtPC Extrema_ExtPC -#define Extrema_GExtPC_hxx -#include diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_FuncExtCC.gxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_FuncExtCC.gxx deleted file mode 100644 index 179f707fc2..0000000000 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_FuncExtCC.gxx +++ /dev/null @@ -1,726 +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. - -// Modified by MPS : 21-05-97 PRO 7598 -// Le nombre de solutions rendu est mySqDist.Length() et non -// mySqDist.Length()/2 -// ajout des valeurs absolues dans le test d'orthogonalite de -// GetStateNumber() - -/*----------------------------------------------------------------------------- -Fonctions permettant de rechercher une distance extremale entre 2 courbes -C1 et C2 (en partant de points approches C1(u0) et C2(v0)). -Cette classe herite de math_FunctionSetWithDerivatives et est utilisee par -l'algorithme math_FunctionSetRoot. -Si on note Du et Dv, les derivees en u et v, les 2 fonctions a annuler sont: -{ F1(u,v) = (C2(v)-C1(u)).Du(u)/||Du|| } -{ F2(u,v) = (C2(v)-C1(u)).Dv(v)||Dv|| } -Si on note Duu et Dvv, les derivees secondes de C1 et C2, les derivees de F1 -et F2 sont egales a: -{ Duf1(u,v) = -||Du|| + C1C2.Duu/||Du||- F1(u,v)*Duu*Du/||Du||**2 -{ Dvf1(u,v) = Dv.Du/||Du|| -{ Duf2(u,v) = -Du.Dv/||Dv|| -{ Dvf2(u,v) = ||Dv|| + C2C1.Dvv/||Dv||- F2(u,v)*Dv*Dvv/||Dv||**2 - -----------------------------------------------------------------------------*/ - -#include - -static const Standard_Real MinTol = 1.e-20; -static const Standard_Real TolFactor = 1.e-12; -static const Standard_Real MinStep = 1e-7; - -static const Standard_Integer MaxOrder = 3; - -//================================================================================================= - -Standard_Real Extrema_FuncExtCC::SearchOfTolerance(const Standard_Address C) -{ - const Standard_Integer NPoint = 10; - Standard_Real aStartParam, anEndParam; - - if (C == myC1) - { - aStartParam = myUinfium; - anEndParam = myUsupremum; - } - else if (C == myC2) - { - aStartParam = myVinfium; - anEndParam = myVsupremum; - } - else - { - // Warning: No curve for tolerance computing! - return MinTol; - } - - const Standard_Real aStep = (anEndParam - aStartParam) / (Standard_Real)NPoint; - - Standard_Integer aNum = 0; - Standard_Real aMax = -Precision::Infinite(); // Maximum value of 1st derivative - //(it is computed with using NPoint point) - - do - { - Standard_Real u = aStartParam + aNum * aStep; // parameter for every point - if (u > anEndParam) - u = anEndParam; - - Pnt Ptemp; // empty point (is not used below) - Vec VDer; // 1st derivative vector - Tool1::D1(*((Curve1*)C), u, Ptemp, VDer); - Standard_Real vm = VDer.Magnitude(); - if (vm > aMax) - aMax = vm; - } while (++aNum < NPoint + 1); - - return std::max(aMax * TolFactor, MinTol); -} - -//================================================================================================= - -Extrema_FuncExtCC::Extrema_FuncExtCC(const Standard_Real thetol) - : myC1(0), - myC2(0), - myTol(thetol) -{ - math_Vector V1(1, 2), V2(1, 2); - V1(1) = 0.0; - V2(1) = 0.0; - V1(2) = 0.0; - V2(2) = 0.0; - SubIntervalInitialize(V1, V2); - myMaxDerivOrderC1 = 0; - myTolC1 = MinTol; - myMaxDerivOrderC2 = 0; - myTolC2 = MinTol; -} - -//================================================================================================= - -Extrema_FuncExtCC::Extrema_FuncExtCC(const Curve1& C1, const Curve2& C2, const Standard_Real thetol) - : myC1((Standard_Address)&C1), - myC2((Standard_Address)&C2), - myTol(thetol) -{ - math_Vector V1(1, 2), V2(1, 2); - V1(1) = Tool1::FirstParameter(*((Curve1*)myC1)); - V2(1) = Tool1::LastParameter(*((Curve1*)myC1)); - V1(2) = Tool2::FirstParameter(*((Curve2*)myC2)); - V2(2) = Tool2::LastParameter(*((Curve2*)myC2)); - SubIntervalInitialize(V1, V2); - - switch (Tool1::GetType(*((Curve1*)myC1))) - { - case GeomAbs_BezierCurve: - case GeomAbs_BSplineCurve: - case GeomAbs_OffsetCurve: - case GeomAbs_OtherCurve: - myMaxDerivOrderC1 = MaxOrder; - myTolC1 = SearchOfTolerance((Standard_Address)&C1); - break; - default: - myMaxDerivOrderC1 = 0; - myTolC1 = MinTol; - break; - } - - switch (Tool2::GetType(*((Curve2*)myC2))) - { - case GeomAbs_BezierCurve: - case GeomAbs_BSplineCurve: - case GeomAbs_OffsetCurve: - case GeomAbs_OtherCurve: - myMaxDerivOrderC2 = MaxOrder; - myTolC2 = SearchOfTolerance((Standard_Address)&C2); - break; - default: - myMaxDerivOrderC2 = 0; - myTolC2 = MinTol; - break; - } -} - -//================================================================================================= - -void Extrema_FuncExtCC::SetCurve(const Standard_Integer theRank, const Curve1& C) -{ - Standard_OutOfRange_Raise_if(theRank < 1 || theRank > 2, "Extrema_FuncExtCC::SetCurve()") - - if (theRank == 1) - { - myC1 = (Standard_Address)&C; - switch (/*Tool1::GetType(*((Curve1*)myC1))*/ C.GetType()) - { - case GeomAbs_BezierCurve: - case GeomAbs_BSplineCurve: - case GeomAbs_OffsetCurve: - case GeomAbs_OtherCurve: - myMaxDerivOrderC1 = MaxOrder; - myTolC1 = SearchOfTolerance((Standard_Address)&C); - break; - default: - myMaxDerivOrderC1 = 0; - myTolC1 = MinTol; - break; - } - } - else if (theRank == 2) - { - myC2 = (Standard_Address)&C; - switch (/*Tool2::GetType(*((Curve2*)myC2))*/ C.GetType()) - { - case GeomAbs_BezierCurve: - case GeomAbs_BSplineCurve: - case GeomAbs_OffsetCurve: - case GeomAbs_OtherCurve: - myMaxDerivOrderC2 = MaxOrder; - myTolC2 = SearchOfTolerance((Standard_Address)&C); - break; - default: - myMaxDerivOrderC2 = 0; - myTolC2 = MinTol; - break; - } - } -} - -//================================================================================================= - -Standard_Boolean Extrema_FuncExtCC::Value(const math_Vector& UV, math_Vector& F) -{ - myU = UV(1); - myV = UV(2); - Tool1::D1(*((Curve1*)myC1), myU, myP1, myDu); - Tool2::D1(*((Curve2*)myC2), myV, myP2, myDv); - - Vec P1P2(myP1, myP2); - - Standard_Real Ndu = myDu.Magnitude(); - - if (myMaxDerivOrderC1 != 0) - { - if (Ndu <= myTolC1) - { - // Derivative is approximated by Taylor-series - const Standard_Real DivisionFactor = 1.e-3; - Standard_Real du; - if ((myUsupremum >= RealLast()) || (myUinfium <= RealFirst())) - du = 0.0; - else - du = myUsupremum - myUinfium; - - const Standard_Real aDelta = std::max(du * DivisionFactor, MinStep); - - Standard_Integer n = 1; // Derivative order - Vec V; - Standard_Boolean IsDeriveFound; - - do - { - V = Tool1::DN(*((Curve1*)myC1), myU, ++n); - Ndu = V.Magnitude(); - IsDeriveFound = (Ndu > myTolC1); - } while (!IsDeriveFound && n < myMaxDerivOrderC1); - - if (IsDeriveFound) - { - Standard_Real u; - - if (myU - myUinfium < aDelta) - u = myU + aDelta; - else - u = myU - aDelta; - - Pnt P1, P2; - Tool1::D0(*((Curve1*)myC1), std::min(myU, u), P1); - Tool1::D0(*((Curve1*)myC1), std::max(myU, u), P2); - - Vec V1(P1, P2); - Standard_Real aDirFactor = V.Dot(V1); - - if (aDirFactor < 0.0) - myDu = -V; - else - myDu = V; - } // if(IsDeriveFound) - else - { - // Derivative is approximated by three points - - Pnt Ptemp; //(0,0,0)-coordinate - Pnt P1, P2, P3; - Standard_Boolean IsParameterGrown; - - if (myU - myUinfium < 2 * aDelta) - { - Tool1::D0(*((Curve1*)myC1), myU, P1); - Tool1::D0(*((Curve1*)myC1), myU + aDelta, P2); - Tool1::D0(*((Curve1*)myC1), myU + 2 * aDelta, P3); - IsParameterGrown = Standard_True; - } - else - { - Tool1::D0(*((Curve1*)myC1), myU - 2 * aDelta, P1); - Tool1::D0(*((Curve1*)myC1), myU - aDelta, P2); - Tool1::D0(*((Curve1*)myC1), myU, P3); - IsParameterGrown = Standard_False; - } - - Vec V1(Ptemp, P1), V2(Ptemp, P2), V3(Ptemp, P3); - - if (IsParameterGrown) - myDu = -3 * V1 + 4 * V2 - V3; - else - myDu = V1 - 4 * V2 + 3 * V3; - } // else of if(IsDeriveFound) - Ndu = myDu.Magnitude(); - } // if (Ndu <= myTolC1) condition - } // if(myMaxDerivOrder != 0) - - if (Ndu <= MinTol) - { - // Warning: 1st derivative of C1 is equal to zero! - return Standard_False; - } - - Standard_Real Ndv = myDv.Magnitude(); - - if (myMaxDerivOrderC2 != 0) - { - if (Ndv <= myTolC2) - { - const Standard_Real DivisionFactor = 1.e-3; - Standard_Real dv; - if ((myVsupremum >= RealLast()) || (myVinfium <= RealFirst())) - dv = 0.0; - else - dv = myVsupremum - myVinfium; - - const Standard_Real aDelta = std::max(dv * DivisionFactor, MinStep); - - // Derivative is approximated by Taylor-series - - Standard_Integer n = 1; // Derivative order - Vec V; - Standard_Boolean IsDeriveFound; - - do - { - V = Tool2::DN(*((Curve2*)myC2), myV, ++n); - Ndv = V.Magnitude(); - IsDeriveFound = (Ndv > myTolC2); - } while (!IsDeriveFound && n < myMaxDerivOrderC2); - - if (IsDeriveFound) - { - Standard_Real v; - - if (myV - myVinfium < aDelta) - v = myV + aDelta; - else - v = myV - aDelta; - - Pnt P1, P2; - Tool2::D0(*((Curve2*)myC2), std::min(myV, v), P1); - Tool2::D0(*((Curve2*)myC2), std::max(myV, v), P2); - - Vec V1(P1, P2); - Standard_Real aDirFactor = V.Dot(V1); - - if (aDirFactor < 0.0) - myDv = -V; - else - myDv = V; - } // if(IsDeriveFound) - else - { - // Derivative is approximated by three points - - Pnt Ptemp; //(0,0,0)-coordinate - Pnt P1, P2, P3; - Standard_Boolean IsParameterGrown; - - if (myV - myVinfium < 2 * aDelta) - { - Tool2::D0(*((Curve2*)myC2), myV, P1); - Tool2::D0(*((Curve2*)myC2), myV + aDelta, P2); - Tool2::D0(*((Curve2*)myC2), myV + 2 * aDelta, P3); - IsParameterGrown = Standard_True; - } - else - { - Tool2::D0(*((Curve2*)myC2), myV - 2 * aDelta, P1); - Tool2::D0(*((Curve2*)myC2), myV - aDelta, P2); - Tool2::D0(*((Curve2*)myC2), myV, P3); - IsParameterGrown = Standard_False; - } - - Vec V1(Ptemp, P1), V2(Ptemp, P2), V3(Ptemp, P3); - - if (IsParameterGrown) - myDv = -3 * V1 + 4 * V2 - V3; - else - myDv = V1 - 4 * V2 + 3 * V3; - } // else of if(IsDeriveFound) - - Ndv = myDv.Magnitude(); - } // if (Ndv <= myTolC2) - } // if(myMaxDerivOrder != 0) - - if (Ndv <= MinTol) - { - // 1st derivative of C2 is equal to zero! - return Standard_False; - } - - F(1) = P1P2.Dot(myDu) / Ndu; - F(2) = P1P2.Dot(myDv) / Ndv; - return Standard_True; -} - -//============================================================================= - -Standard_Boolean Extrema_FuncExtCC::Derivatives(const math_Vector& UV, math_Matrix& Df) -{ - math_Vector F(1, 2); - return Values(UV, F, Df); -} - -//============================================================================= - -Standard_Boolean Extrema_FuncExtCC::Values(const math_Vector& UV, math_Vector& F, math_Matrix& Df) -{ - myU = UV(1); - myV = UV(2); - - if (Value(UV, F) == Standard_False) // Computes F, myDu, myDv - { - // Warning: No function value found! - return Standard_False; - } // if(Value(UV, F) == Standard_False) - - Vec Du, Dv, Duu, Dvv; - Tool1::D2(*((Curve1*)myC1), myU, myP1, Du, Duu); - Tool2::D2(*((Curve2*)myC2), myV, myP2, Dv, Dvv); - - // Calling of "Value(...)" function change class member values. - // After running it is necessary to return to previous values. - const Standard_Real myU_old = myU, myV_old = myV; - const Pnt myP1_old = myP1, myP2_old = myP2; - const Vec myDu_old = myDu, myDv_old = myDv; - - // Attention: aDelta value must be greater than same value for "Value(...)" - // function to avoid of points' collisions. - - const Standard_Real DivisionFactor = 0.01; - - Standard_Real du; - if ((myUsupremum >= RealLast()) || (myUinfium <= RealFirst())) - du = 0.0; - else - du = myUsupremum - myUinfium; - - const Standard_Real aDeltaU = std::max(du * DivisionFactor, MinStep); - - Standard_Real dv; - if ((myVsupremum >= RealLast()) || (myVinfium <= RealFirst())) - dv = 0.0; - else - dv = myVsupremum - myVinfium; - - const Standard_Real aDeltaV = std::max(dv * DivisionFactor, MinStep); - - Vec P1P2(myP1, myP2); - - if ((myMaxDerivOrderC1 != 0) && (Du.Magnitude() <= myTolC1)) - { - // Derivative is approximated by three points - - math_Vector FF1(1, 2), FF2(1, 2), FF3(1, 2); - Standard_Real F1, F2, F3; - - /////////////////////////// Search of DF1_u derivative (begin) /////////////////// - if (myU - myUinfium < 2 * aDeltaU) - { - F1 = F(1); - math_Vector UV2(1, 2), UV3(1, 2); - UV2(1) = myU + aDeltaU; - UV2(2) = myV; - UV3(1) = myU + 2 * aDeltaU; - UV3(2) = myV; - if (!((Value(UV2, FF2)) && (Value(UV3, FF3)))) - { - // There are many points close to singularity points and which have zero-derivative. - // Try to decrease aDelta variable's value. - return Standard_False; - } - - F2 = FF2(1); - F3 = FF3(1); - - Df(1, 1) = (-3 * F1 + 4 * F2 - F3) / (2.0 * aDeltaU); - } // if(myU-myUinfium < 2*aDeltaU) - else - { - F3 = F(1); - math_Vector UV2(1, 2), UV1(1, 2); - UV2(1) = myU - aDeltaU; - UV2(2) = myV; - UV1(1) = myU - 2 * aDeltaU; - UV1(2) = myV; - - if (!((Value(UV2, FF2)) && (Value(UV1, FF1)))) - { - // There are many points close to singularity points and which have zero-derivative. - // Try to decrease aDelta variable's value. - return Standard_False; - } - - F1 = FF1(1); - F2 = FF2(1); - - Df(1, 1) = (F1 - 4 * F2 + 3 * F3) / (2.0 * aDeltaU); - } // else of if(myU-myUinfium < 2*aDeltaU) condition - /////////////////////////// Search of DF1_u derivative (end) /////////////////// - - // Return to previous values - myU = myU_old; - myV = myV_old; - - /////////////////////////// Search of DF1_v derivative (begin) /////////////////// - if (myV - myVinfium < 2 * aDeltaV) - { - F1 = F(1); - math_Vector UV2(1, 2), UV3(1, 2); - UV2(1) = myU; - UV2(2) = myV + aDeltaV; - UV3(1) = myU; - UV3(2) = myV + 2 * aDeltaV; - - if (!((Value(UV2, FF2)) && (Value(UV3, FF3)))) - { - // There are many points close to singularity points and which have zero-derivative. - // Try to decrease aDelta variable's value. - return Standard_False; - } - F2 = FF2(1); - F3 = FF3(1); - - Df(1, 2) = (-3 * F1 + 4 * F2 - F3) / (2.0 * aDeltaV); - } // if(myV-myVinfium < 2*aDeltaV) - else - { - F3 = F(1); - math_Vector UV2(1, 2), UV1(1, 2); - UV2(1) = myU; - UV2(2) = myV - aDeltaV; - UV1(1) = myU; - UV1(2) = myV - 2 * aDeltaV; - if (!((Value(UV2, FF2)) && (Value(UV1, FF1)))) - { - // There are many points close to singularity points and which have zero-derivative. - // Try to decrease aDelta variable's value. - return Standard_False; - } - - F1 = FF1(1); - F2 = FF2(1); - - Df(1, 2) = (F1 - 4 * F2 + 3 * F3) / (2.0 * aDeltaV); - } // else of if(myV-myVinfium < 2*aDeltaV) - /////////////////////////// Search of DF1_v derivative (end) /////////////////// - - // Return to previous values - myU = myU_old; - myV = myV_old; - myP1 = myP1_old, myP2 = myP2_old; - myDu = myDu_old, myDv = myDv_old; - } // if((myMaxDerivOrderC1 != 0) && (Du.Magnitude() <= myTolC1)) - else - { - const Standard_Real Ndu = myDu.Magnitude(); - Df(1, 1) = -Ndu + (P1P2.Dot(Duu) / Ndu) - F(1) * (myDu.Dot(Duu) / (Ndu * Ndu)); - Df(1, 2) = myDv.Dot(myDu) / Ndu; - } // else of if((myMaxDerivOrderC1 != 0) && (Du.Magnitude() <= myTolC1)) - - if ((myMaxDerivOrderC2 != 0) && (Dv.Magnitude() <= myTolC2)) - { - // Derivative is approximated by three points - - math_Vector FF1(1, 2), FF2(1, 2), FF3(1, 2); - Standard_Real F1, F2, F3; - - /////////////////////////// Search of DF2_v derivative (begin) /////////////////// - if (myV - myVinfium < 2 * aDeltaV) - { - F1 = F(2); - math_Vector UV2(1, 2), UV3(1, 2); - UV2(1) = myU; - UV2(2) = myV + aDeltaV; - UV3(1) = myU; - UV3(2) = myV + 2 * aDeltaV; - - if (!((Value(UV2, FF2)) && (Value(UV3, FF3)))) - { - // There are many points close to singularity points and which have zero-derivative. - // Try to decrease aDelta variable's value. - return Standard_False; - } - - F2 = FF2(2); - F3 = FF3(2); - - Df(2, 2) = (-3 * F1 + 4 * F2 - F3) / (2.0 * aDeltaV); - - } // if(myV-myVinfium < 2*aDeltaV) - else - { - F3 = F(2); - math_Vector UV2(1, 2), UV1(1, 2); - UV2(1) = myU; - UV2(2) = myV - aDeltaV; - UV1(1) = myU; - UV1(2) = myV - 2 * aDeltaV; - - if (!((Value(UV2, FF2)) && (Value(UV1, FF1)))) - { - // There are many points close to singularity points and which have zero-derivative. - // Try to decrease aDelta variable's value. - return Standard_False; - } - - F1 = FF1(2); - F2 = FF2(2); - - Df(2, 2) = (F1 - 4 * F2 + 3 * F3) / (2.0 * aDeltaV); - } // else of if(myV-myVinfium < 2*aDeltaV) - /////////////////////////// Search of DF2_v derivative (end) /////////////////// - - // Return to previous values - myU = myU_old; - myV = myV_old; - - /////////////////////////// Search of DF2_u derivative (begin) /////////////////// - if (myU - myUinfium < 2 * aDeltaU) - { - F1 = F(2); - math_Vector UV2(1, 2), UV3(1, 2); - UV2(1) = myU + aDeltaU; - UV2(2) = myV; - UV3(1) = myU + 2 * aDeltaU; - UV3(2) = myV; - if (!((Value(UV2, FF2)) && (Value(UV3, FF3)))) - { - // There are many points close to singularity points and which have zero-derivative. - // Try to decrease aDelta variable's value. - return Standard_False; - } - - F2 = FF2(2); - F3 = FF3(2); - - Df(2, 1) = (-3 * F1 + 4 * F2 - F3) / (2.0 * aDeltaU); - } // if(myU-myUinfium < 2*aDelta) - else - { - F3 = F(2); - math_Vector UV2(1, 2), UV1(1, 2); - UV2(1) = myU - aDeltaU; - UV2(2) = myV; - UV1(1) = myU - 2 * aDeltaU; - UV1(2) = myV; - - if (!((Value(UV2, FF2)) && (Value(UV1, FF1)))) - { - // There are many points close to singularity points - // and which have zero-derivative. - // Try to decrease aDelta variable's value. - return Standard_False; - } - - F1 = FF1(2); - F2 = FF2(2); - - Df(2, 1) = (F1 - 4 * F2 + 3 * F3) / (2.0 * aDeltaU); - } // else of if(myU-myUinfium < 2*aDeltaU) - /////////////////////////// Search of DF2_u derivative (end) /////////////////// - - // Return to previous values - myU = myU_old; - myV = myV_old; - myP1 = myP1_old; - myP2 = myP2_old; - myDu = myDu_old; - myDv = myDv_old; - } // if((myMaxDerivOrderC2 != 0) && (Dv.Magnitude() <= myTolC2)) - else - { - Standard_Real Ndv = myDv.Magnitude(); - Df(2, 2) = Ndv + (P1P2.Dot(Dvv) / Ndv) - F(2) * (myDv.Dot(Dvv) / (Ndv * Ndv)); - Df(2, 1) = -myDu.Dot(myDv) / Ndv; - } // else of if((myMaxDerivOrderC2 != 0) && (Dv.Magnitude() <= myTolC2)) - - return Standard_True; - -} // end of function - -//============================================================================= - -Standard_Integer Extrema_FuncExtCC::GetStateNumber() -{ - Vec Du(myDu), Dv(myDv); - Vec P1P2(myP1, myP2); - - Standard_Real mod = Du.Magnitude(); - if (mod > myTolC1) - { - Du /= mod; - } - mod = Dv.Magnitude(); - if (mod > myTolC2) - { - Dv /= mod; - } - - if (std::abs(P1P2.Dot(Du)) <= myTol && std::abs(P1P2.Dot(Dv)) <= myTol) - { - mySqDist.Append(myP1.SquareDistance(myP2)); - myPoints.Append(POnC(myU, myP1)); - myPoints.Append(POnC(myV, myP2)); - } - return 0; -} - -//============================================================================= - -void Extrema_FuncExtCC::Points(const Standard_Integer N, POnC& P1, POnC& P2) const -{ - P1 = myPoints.Value(2 * N - 1); - P2 = myPoints.Value(2 * N); -} - -//============================================================================= - -void Extrema_FuncExtCC::SubIntervalInitialize(const math_Vector& theInfBound, - const math_Vector& theSupBound) -{ - myUinfium = theInfBound(1); - myUsupremum = theSupBound(1); - myVinfium = theInfBound(2); - myVsupremum = theSupBound(2); -} - -//============================================================================= diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_FuncExtCC.lxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_FuncExtCC.lxx deleted file mode 100644 index 405047da94..0000000000 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_FuncExtCC.lxx +++ /dev/null @@ -1,61 +0,0 @@ -// 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. - -//============================================================================= -inline void Extrema_FuncExtCC::SetTolerance(const Standard_Real theTol) -{ - myTol = theTol; -} - -//============================================================================= - -inline Standard_Integer Extrema_FuncExtCC::NbVariables() const -{ - return 2; -} - -//============================================================================= - -inline Standard_Integer Extrema_FuncExtCC::NbEquations() const -{ - return 2; -} - -//============================================================================= - -inline Standard_Integer Extrema_FuncExtCC::NbExt() const -{ - return mySqDist.Length(); -} - -//============================================================================= - -inline Standard_Real Extrema_FuncExtCC::SquareDistance(const Standard_Integer N) const -{ - return mySqDist.Value(N); -} - -//============================================================================= - -inline Standard_Address Extrema_FuncExtCC::CurvePtr(const Standard_Integer theRank) const -{ - Standard_OutOfRange_Raise_if(theRank < 1 || theRank > 2, - "Extrema_FuncExtCC::SetCurve()") return (theRank == 1 ? myC1 : myC2); -} - -//============================================================================= - -inline Standard_Real Extrema_FuncExtCC::Tolerance() const -{ - return myTol; -} diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_FuncExtPC.gxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_FuncExtPC.gxx deleted file mode 100644 index d2e5302516..0000000000 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_FuncExtPC.gxx +++ /dev/null @@ -1,438 +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 -#include -static const Standard_Real TolFactor = 1.e-12; -static const Standard_Real MinTol = 1.e-20; -static const Standard_Real MinStep = 1e-7; - -static const Standard_Integer MaxOrder = 3; - -/*----------------------------------------------------------------------------- -Fonction permettant de rechercher une distance extremale entre un point P et -une courbe C (en partant d'un point approche C(u0)). -Cette classe herite de math_FunctionWithDerivative et est utilisee par -les algorithmes math_FunctionRoot et math_FunctionRoots. -Si on note D1c et D2c les derivees premiere et seconde: -{ F(u) = (C(u)-P).D1c(u)/ ||Du||} -{ DF(u) = ||Du|| + (C(u)-P).D2c(u)/||Du|| - F(u)*Duu*Du/||Du||**2 - - -{ F(u) = (C(u)-P).D1c(u) } -{ DF(u) = D1c(u).D1c(u) + (C(u)-P).D2c(u) -= ||D1c(u)|| ** 2 + (C(u)-P).D2c(u) } -----------------------------------------------------------------------------*/ - -Standard_Real Extrema_FuncExtPC::SearchOfTolerance() -{ - const Standard_Integer NPoint = 10; - const Standard_Real aStep = (myUsupremum - myUinfium) / (Standard_Real)NPoint; - - Standard_Integer aNum = 0; - Standard_Real aMax = -Precision::Infinite(); // Maximum value of 1st derivative - //(it is computed with using NPoint point) - - do - { - Standard_Real u = myUinfium + aNum * aStep; // parameter for every point - if (u > myUsupremum) - u = myUsupremum; - - Pnt Ptemp; // empty point (is not used below) - Vec VDer; // 1st derivative vector - Tool::D1(*((Curve*)myC), u, Ptemp, VDer); - - if (Precision::IsInfinite(VDer.X()) || Precision::IsInfinite(VDer.Y())) - { - continue; - } - - Standard_Real vm = VDer.Magnitude(); - if (vm > aMax) - aMax = vm; - } while (++aNum < NPoint + 1); - - return std::max(aMax * TolFactor, MinTol); -} - -//============================================================================= - -Extrema_FuncExtPC::Extrema_FuncExtPC() - : myU(0.), - myD1f(0.) -{ - myPinit = Standard_False; - myCinit = Standard_False; - myD1Init = Standard_False; - - SubIntervalInitialize(0.0, 0.0); - myMaxDerivOrder = 0; - myTol = MinTol; -} - -//============================================================================= - -Extrema_FuncExtPC::Extrema_FuncExtPC(const Pnt& P, const Curve& C) - : myU(0.), - myD1f(0.) -{ - myP = P; - myC = (Standard_Address)&C; - myPinit = Standard_True; - myCinit = Standard_True; - myD1Init = Standard_False; - - SubIntervalInitialize(Tool::FirstParameter(*((Curve*)myC)), Tool::LastParameter(*((Curve*)myC))); - - switch (Tool::GetType(*((Curve*)myC))) - { - case GeomAbs_BezierCurve: - case GeomAbs_BSplineCurve: - case GeomAbs_OffsetCurve: - case GeomAbs_OtherCurve: - myMaxDerivOrder = MaxOrder; - myTol = SearchOfTolerance(); - break; - default: - myMaxDerivOrder = 0; - myTol = MinTol; - break; - } -} - -//============================================================================= - -void Extrema_FuncExtPC::Initialize(const Curve& C) -{ - myC = (Standard_Address)&C; - myCinit = Standard_True; - myPoint.Clear(); - mySqDist.Clear(); - myIsMin.Clear(); - - SubIntervalInitialize(Tool::FirstParameter(*((Curve*)myC)), Tool::LastParameter(*((Curve*)myC))); - - switch (Tool::GetType(*((Curve*)myC))) - { - case GeomAbs_BezierCurve: - case GeomAbs_BSplineCurve: - case GeomAbs_OffsetCurve: - case GeomAbs_OtherCurve: - myMaxDerivOrder = MaxOrder; - myTol = SearchOfTolerance(); - break; - default: - myMaxDerivOrder = 0; - myTol = MinTol; - break; - } -} - -//============================================================================= - -void Extrema_FuncExtPC::SetPoint(const Pnt& P) -{ - myP = P; - myPinit = Standard_True; - myPoint.Clear(); - mySqDist.Clear(); - myIsMin.Clear(); -} - -//============================================================================= - -Standard_Boolean Extrema_FuncExtPC::Value(const Standard_Real U, Standard_Real& F) -{ - if (!myPinit || !myCinit) - throw Standard_TypeMismatch("No init"); - - myU = U; - Vec D1c; - Tool::D1(*((Curve*)myC), myU, myPc, D1c); - - if (Precision::IsInfinite(D1c.X()) || Precision::IsInfinite(D1c.Y())) - { - F = Precision::Infinite(); - return Standard_False; - } - - Standard_Real Ndu = D1c.Magnitude(); - - if (myMaxDerivOrder != 0) - { - if (Ndu <= myTol) // Cas Singulier (PMN 22/04/1998) - { - const Standard_Real DivisionFactor = 1.e-3; - Standard_Real du; - if ((myUsupremum >= RealLast()) || (myUinfium <= RealFirst())) - du = 0.0; - else - du = myUsupremum - myUinfium; - - const Standard_Real aDelta = std::max(du * DivisionFactor, MinStep); - // Derivative is approximated by Taylor-series - - Standard_Integer n = 1; // Derivative order - Vec V; - Standard_Boolean IsDeriveFound; - - do - { - V = Tool::DN(*((Curve*)myC), myU, ++n); - Ndu = V.Magnitude(); - IsDeriveFound = (Ndu > myTol); - } while (!IsDeriveFound && n < myMaxDerivOrder); - - if (IsDeriveFound) - { - Standard_Real u; - - if (myU - myUinfium < aDelta) - u = myU + aDelta; - else - u = myU - aDelta; - - Pnt P1, P2; - Tool::D0(*((Curve*)myC), std::min(myU, u), P1); - Tool::D0(*((Curve*)myC), std::max(myU, u), P2); - - Vec V1(P1, P2); - Standard_Real aDirFactor = V.Dot(V1); - - if (aDirFactor < 0.0) - D1c = -V; - else - D1c = V; - } // if(IsDeriveFound) - else - { - // Derivative is approximated by three points - - Pnt Ptemp; //(0,0,0)-coordinate - Pnt P1, P2, P3; - Standard_Boolean IsParameterGrown; - - if (myU - myUinfium < 2 * aDelta) - { - Tool::D0(*((Curve*)myC), myU, P1); - Tool::D0(*((Curve*)myC), myU + aDelta, P2); - Tool::D0(*((Curve*)myC), myU + 2 * aDelta, P3); - IsParameterGrown = Standard_True; - } - else - { - Tool::D0(*((Curve*)myC), myU - 2 * aDelta, P1); - Tool::D0(*((Curve*)myC), myU - aDelta, P2); - Tool::D0(*((Curve*)myC), myU, P3); - IsParameterGrown = Standard_False; - } - - Vec V1(Ptemp, P1), V2(Ptemp, P2), V3(Ptemp, P3); - - if (IsParameterGrown) - D1c = -3 * V1 + 4 * V2 - V3; - else - D1c = V1 - 4 * V2 + 3 * V3; - } - Ndu = D1c.Magnitude(); - } //(if (Ndu <= myTol)) condition - } // if(myMaxDerivOrder != 0) - - if (Ndu <= MinTol) - { - // Warning: 1st derivative is equal to zero! - return Standard_False; - } - - Vec PPc(myP, myPc); - F = PPc.Dot(D1c) / Ndu; - return Standard_True; -} - -//============================================================================= - -Standard_Boolean Extrema_FuncExtPC::Derivative(const Standard_Real U, Standard_Real& D1f) -{ - if (!myPinit || !myCinit) - throw Standard_TypeMismatch(); - Standard_Real F; - return Values(U, F, D1f); /* on fait appel a Values pour simplifier la - sauvegarde de l'etat. */ -} - -//============================================================================= - -Standard_Boolean Extrema_FuncExtPC::Values(const Standard_Real U, - Standard_Real& F, - Standard_Real& D1f) -{ - if (!myPinit || !myCinit) - throw Standard_TypeMismatch("No init"); - - Pnt myPc_old = myPc, myP_old = myP; - - if (Value(U, F) == Standard_False) - { - // Warning: No function value found!; - - myD1Init = Standard_False; - return Standard_False; - } - - myU = U; - myPc = myPc_old; - myP = myP_old; - - Vec D1c, D2c; - Tool::D2(*((Curve*)myC), myU, myPc, D1c, D2c); - - Standard_Real Ndu = D1c.Magnitude(); - if (Ndu <= myTol) // Cas Singulier (PMN 22/04/1998) - { - // Derivative is approximated by three points - - // Attention: aDelta value must be greater than same value for "Value(...)" - // function to avoid of points' collisions. - const Standard_Real DivisionFactor = 0.01; - Standard_Real du; - if ((myUsupremum >= RealLast()) || (myUinfium <= RealFirst())) - du = 0.0; - else - du = myUsupremum - myUinfium; - - const Standard_Real aDelta = std::max(du * DivisionFactor, MinStep); - - Standard_Real F1, F2, F3; - - if (myU - myUinfium < 2 * aDelta) - { - F1 = F; - // const Standard_Real U1 = myU; - const Standard_Real U2 = myU + aDelta; - const Standard_Real U3 = myU + aDelta * 2.0; - - if (!((Value(U2, F2)) && (Value(U3, F3)))) - { - // There are many points close to singularity points and - // which have zero-derivative. Try to decrease aDelta variable's value. - - myD1Init = Standard_False; - return Standard_False; - } - - // After calling of Value(...) function variable myU will be redeterminated. - // So we must return it previous value. - D1f = (-3 * F1 + 4 * F2 - F3) / (2.0 * aDelta); - } - else - { - F3 = F; - const Standard_Real U1 = myU - aDelta * 2.0; - const Standard_Real U2 = myU - aDelta; - // const Standard_Real U3 = myU; - - if (!((Value(U2, F2)) && (Value(U1, F1)))) - { - // There are many points close to singularity points and - // which have zero-derivative. Try to decrease aDelta variable's value. - myD1Init = Standard_False; - return Standard_False; - } - // After calling of Value(...) function variable myU will be redeterminated. - // So we must return it previous value. - D1f = (F1 - 4 * F2 + 3 * F3) / (2.0 * aDelta); - } - myU = U; - myPc = myPc_old; - myP = myP_old; - } - else - { - Vec PPc(myP, myPc); - D1f = Ndu + (PPc.Dot(D2c) / Ndu) - F * (D1c.Dot(D2c)) / (Ndu * Ndu); - } - - myD1f = D1f; - - myD1Init = Standard_True; - return Standard_True; -} - -//============================================================================= - -Standard_Integer Extrema_FuncExtPC::GetStateNumber() -{ - if (!myPinit || !myCinit) - throw Standard_TypeMismatch(); - mySqDist.Append(myPc.SquareDistance(myP)); - - // It is necessary to always compute myD1f. - myD1Init = Standard_True; - Standard_Real FF, DD; - Values(myU, FF, DD); - - Standard_Integer IntVal = 0; - if (myD1f > 0.0) - { - IntVal = 1; - } - - myIsMin.Append(IntVal); - myPoint.Append(POnC(myU, myPc)); - return 0; -} - -//============================================================================= - -Standard_Integer Extrema_FuncExtPC::NbExt() const -{ - return mySqDist.Length(); -} - -//============================================================================= - -Standard_Real Extrema_FuncExtPC::SquareDistance(const Standard_Integer N) const -{ - if (!myPinit || !myCinit) - throw Standard_TypeMismatch(); - return mySqDist.Value(N); -} - -//================================================================================================= - -Standard_Boolean Extrema_FuncExtPC::IsMin(const Standard_Integer N) const -{ - if (!myPinit || !myCinit) - throw Standard_TypeMismatch(); - return (myIsMin.Value(N) == 1); -} - -//================================================================================================= - -const POnC& Extrema_FuncExtPC::Point(const Standard_Integer N) const -{ - if (!myPinit || !myCinit) - throw Standard_TypeMismatch(); - return myPoint.Value(N); -} - -//============================================================================= - -void Extrema_FuncExtPC::SubIntervalInitialize(const Standard_Real theUfirst, - const Standard_Real theUlast) -{ - myUinfium = theUfirst; - myUsupremum = theUlast; -} diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_GCurveLocator.hxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_GCurveLocator.hxx new file mode 100644 index 0000000000..3857ba388c --- /dev/null +++ b/src/ModelingData/TKGeomBase/Extrema/Extrema_GCurveLocator.hxx @@ -0,0 +1,131 @@ +// 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. + +#ifndef _Extrema_GCurveLocator_HeaderFile +#define _Extrema_GCurveLocator_HeaderFile + +#include +#include +#include + +#include + +//! Template class for locating the closest point on a curve to a given point. +//! Among a set of sampled points on the curve, finds the one closest to the target. +//! +//! @tparam TheCurve the curve type +//! @tparam TheCurveTool the curve tool providing curve operations +//! @tparam ThePOnC the point-on-curve type +//! @tparam ThePoint the point type (gp_Pnt or gp_Pnt2d) +template +class Extrema_GCurveLocator +{ +public: + DEFINE_STANDARD_ALLOC + + //! Among a set of points {C(ui), i=1,NbU}, locate the point + //! P=C(uj) such that: + //! distance(P,C) = Min{distance(P,C(ui))} + //! @param theP the target point + //! @param theC the curve to sample + //! @param theNbU the number of sample points + //! @param thePapp the result point on curve + static void Locate(const ThePoint& theP, const TheCurve& theC, const int theNbU, ThePOnC& thePapp) + { + if (theNbU < 2) + { + throw Standard_OutOfRange(); + } + + double aU = TheCurveTool::FirstParameter(theC); + double aPasU = (TheCurveTool::LastParameter(theC) - aU) / (theNbU - 1); + double aDist2Min = RealLast(); + double aUMin = 0; + ThePoint aPntMin; + double aDist2; + ThePoint aPt; + + for (int aNoSample = 1; aNoSample < theNbU; aNoSample++, aU += aPasU) + { + aPt = TheCurveTool::Value(theC, aU); + aDist2 = aPt.SquareDistance(theP); + if (aDist2 < aDist2Min) + { + aDist2Min = aDist2; + aUMin = aU; + aPntMin = aPt; + } + } + thePapp.SetValues(aUMin, aPntMin); + } + + //! Among a set of points {C(ui), i=1,NbU}, locate the point + //! P=C(uj) such that: + //! distance(P,C) = Min{distance(P,C(ui))} + //! The search is done between theUmin and theUsup. + //! @param theP the target point + //! @param theC the curve to sample + //! @param theNbU the number of sample points + //! @param theUmin the minimum parameter value + //! @param theUsup the maximum parameter value + //! @param thePapp the result point on curve + static void Locate(const ThePoint& theP, + const TheCurve& theC, + const int theNbU, + const double theUmin, + const double theUsup, + ThePOnC& thePapp) + { + if (theNbU < 2) + { + throw Standard_OutOfRange(); + } + + double aUinf = TheCurveTool::FirstParameter(theC); + double aUlast = TheCurveTool::LastParameter(theC); + + double aU1 = std::min(aUinf, aUlast); + double aU2 = std::max(aUinf, aUlast); + double aU11 = std::min(theUmin, theUsup); + double aU12 = std::max(theUmin, theUsup); + + if (aU11 < aU1 - RealEpsilon()) + aU11 = aU1; + if (aU12 > aU2 + RealEpsilon()) + aU12 = aU2; + + double aU = aU11; + double aPasU = (aU12 - aU) / (theNbU - 1); + double aDist2Min = RealLast(); + double aUMin = 0; + ThePoint aPntMin; + double aDist2; + ThePoint aPt; + + for (int aNoSample = 1; aNoSample < theNbU; aNoSample++, aU += aPasU) + { + aPt = TheCurveTool::Value(theC, aU); + aDist2 = aPt.SquareDistance(theP); + if (aDist2 < aDist2Min) + { + aDist2Min = aDist2; + aUMin = aU; + aPntMin = aPt; + } + } + thePapp.SetValues(aUMin, aPntMin); + } +}; + +#endif // _Extrema_GCurveLocator_HeaderFile diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_GExtPC.gxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_GExtPC.gxx deleted file mode 100644 index 5e8b12bed4..0000000000 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_GExtPC.gxx +++ /dev/null @@ -1,634 +0,0 @@ -// Created on: 1992-10-19 -// Created by: Laurent PAINNOT -// Copyright (c) 1992-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. - -// Modified by cma, Fri Dec 10 18:11:56 1993 - -#include Extrema_EPC_hxx -#include ThePOnC_hxx -#include TheSequenceOfPOnC_hxx -#include ThePoint_hxx -#include TheVector_hxx -#include TheExtPElC_hxx -#include -#include -#include -#include -#include -#include -#include -#include - -//================================================================================================= - -void Extrema_GExtPC::Perform(const ThePoint& P) -{ - mySqDist.Clear(); - mypoint.Clear(); - myismin.Clear(); - Standard_Integer i, NbExt, n; - Standard_Real U; - mysample = 17; - constexpr Standard_Real t3d = Precision::Confusion(); - if (Precision::IsInfinite(myuinf)) - mydist1 = RealLast(); - else - { - Pf = TheCurveTool::Value(*((TheCurve*)myC), myuinf); - mydist1 = P.SquareDistance(Pf); - } - - if (Precision::IsInfinite(myusup)) - mydist2 = RealLast(); - else - { - Pl = TheCurveTool::Value(*((TheCurve*)myC), myusup); - mydist2 = P.SquareDistance(Pl); - } - - TheCurve& aCurve = *((TheCurve*)myC); - - switch (type) - { - case GeomAbs_Circle: { - myExtPElC.Perform(P, TheCurveTool::Circle(aCurve), t3d, myuinf, myusup); - } - break; - case GeomAbs_Ellipse: { - myExtPElC.Perform(P, TheCurveTool::Ellipse(aCurve), t3d, myuinf, myusup); - } - break; - case GeomAbs_Parabola: { - myExtPElC.Perform(P, TheCurveTool::Parabola(aCurve), t3d, myuinf, myusup); - } - break; - case GeomAbs_Hyperbola: { - myExtPElC.Perform(P, TheCurveTool::Hyperbola(aCurve), t3d, myuinf, myusup); - } - break; - case GeomAbs_Line: { - myExtPElC.Perform(P, TheCurveTool::Line(aCurve), t3d, myuinf, myusup); - } - break; - case GeomAbs_BezierCurve: { - myintuinf = myuinf; - myintusup = myusup; - mysample = (TheCurveTool::Bezier(aCurve))->NbPoles() * 2; - myExtPC.Initialize(aCurve); - IntervalPerform(P); - return; - } - case GeomAbs_BSplineCurve: { - const Standard_Integer aFirstIdx = TheCurveTool::BSpline(aCurve)->FirstUKnotIndex(), - aLastIdx = TheCurveTool::BSpline(aCurve)->LastUKnotIndex(); - // const reference can not be used due to implementation of BRep_Adaptor. - TColStd_Array1OfReal aKnots(aFirstIdx, aLastIdx); - TheCurveTool::BSpline(aCurve)->Knots(aKnots); - - // Workaround to work with: - // blend, where knots may be moved from parameter space. - Standard_Real aPeriodJump = 0.0; - // Avoid problem with too close knots. - const Standard_Real aTolCoeff = (myusup - myuinf) * Precision::PConfusion(); - if (TheCurveTool::IsPeriodic(aCurve)) - { - Standard_Integer aPeriodShift = - Standard_Integer((myuinf - aKnots(aFirstIdx)) / TheCurveTool::Period(aCurve)); - - if (myuinf < aKnots(aFirstIdx) - aTolCoeff) - aPeriodShift--; - - aPeriodJump = TheCurveTool::Period(aCurve) * aPeriodShift; - } - - Standard_Integer anIdx; - - // Find first and last used knot. - Standard_Integer aFirstUsedKnot = aFirstIdx, aLastUsedKnot = aLastIdx; - for (anIdx = aFirstIdx; anIdx <= aLastIdx; anIdx++) - { - Standard_Real aKnot = aKnots(anIdx) + aPeriodJump; - if (myuinf >= aKnot - aTolCoeff) - aFirstUsedKnot = anIdx; - else - break; - } - for (anIdx = aLastIdx; anIdx >= aFirstIdx; anIdx--) - { - Standard_Real aKnot = aKnots(anIdx) + aPeriodJump; - if (myusup <= aKnot + aTolCoeff) - aLastUsedKnot = anIdx; - else - break; - } - - if (aFirstUsedKnot == aLastUsedKnot) - { - // Degenerated case: - // Some bounds lies out of curve param space. - // In this case build one interval with [myuinf, myusup]. - // Parameters of these indexes will be redefined. - aFirstUsedKnot = aFirstIdx; - aLastUsedKnot = aFirstIdx + 1; - } - - mysample = (TheCurveTool::BSpline(aCurve))->Degree() + 1; - - if (mysample == 2) - { - // BSpline of first degree, direct searching extrema for each knot interval - ThePoint aPmin; - Standard_Real tmin = 0., distmin = RealLast(); - Standard_Real aMin1 = 0., aMin2 = 0.; - myExtPC.Initialize(aCurve); - for (anIdx = aFirstUsedKnot; anIdx < aLastUsedKnot; anIdx++) - { - Standard_Real aF = aKnots(anIdx) + aPeriodJump, aL = aKnots(anIdx + 1) + aPeriodJump; - - if (anIdx == aFirstUsedKnot) - { - aF = myuinf; - } - else if (anIdx == aLastUsedKnot - 1) - { - aL = myusup; - } - - ThePoint aP1, aP2; - TheCurveTool::D0(aCurve, aF, aP1); - TheCurveTool::D0(aCurve, aL, aP2); - TheVector aBase1(P, aP1), aBase2(P, aP2); - TheVector aV(aP2, aP1); - Standard_Real aVal1 = aV.Dot(aBase1); // Derivative of (C(u) - P)^2 - Standard_Real aVal2 = aV.Dot(aBase2); // Derivative of (C(u) - P)^2 - if (anIdx == aFirstUsedKnot) - { - aMin1 = P.SquareDistance(aP1); - } - else - { - aMin1 = aMin2; - if (distmin > aMin1) - { - distmin = aMin1; - tmin = aF; - aPmin = aP1; - } - } - aMin2 = P.SquareDistance(aP2); - Standard_Real aMinSqDist = std::min(aMin1, aMin2); - Standard_Real aMinDer = std::min(std::abs(aVal1), std::abs(aVal2)); - if (!(Precision::IsInfinite(aVal1) || Precision::IsInfinite(aVal2))) - { - // Derivatives have opposite signs - min or max inside of interval (sufficient - // condition). - if (aVal1 * aVal2 <= 0.0 || aMinSqDist < 100. * Precision::SquareConfusion() - || 2. * aMinDer < Precision::Confusion()) - { - myintuinf = aF; - myintusup = aL; - IntervalPerform(P); - } - } - } - if (!Precision::IsInfinite(distmin)) - { - Standard_Boolean isToAdd = Standard_True; - NbExt = mypoint.Length(); - for (i = 1; i <= NbExt && isToAdd; i++) - { - Standard_Real t = mypoint.Value(i).Parameter(); - isToAdd = (distmin < mySqDist(i)) && (std::abs(t - tmin) > mytolu); - } - if (isToAdd) - { - ThePOnC PC(tmin, aPmin); - mySqDist.Append(distmin); - myismin.Append(Standard_True); - mypoint.Append(PC); - } - } - } - else - { - - // Fill sample points. - Standard_Integer aValIdx = 1; - NCollection_Array1 aVal(1, - (mysample) * (aLastUsedKnot - aFirstUsedKnot) + 1); - NCollection_Array1 aParam(1, - (mysample) * (aLastUsedKnot - aFirstUsedKnot) + 1); - for (anIdx = aFirstUsedKnot; anIdx < aLastUsedKnot; anIdx++) - { - Standard_Real aF = aKnots(anIdx) + aPeriodJump, aL = aKnots(anIdx + 1) + aPeriodJump; - - if (anIdx == aFirstUsedKnot) - aF = myuinf; - if (anIdx == aLastUsedKnot - 1) - aL = myusup; - - Standard_Real aStep = (aL - aF) / mysample; - for (Standard_Integer aPntIdx = 0; aPntIdx < mysample; aPntIdx++) - { - Standard_Real aCurrentParam = aF + aStep * aPntIdx; - aVal(aValIdx) = TheCurveTool::Value(aCurve, aCurrentParam).SquareDistance(P); - aParam(aValIdx) = aCurrentParam; - aValIdx++; - } - } - // Fill last point. - aVal(aValIdx) = TheCurveTool::Value(aCurve, myusup).SquareDistance(P); - aParam(aValIdx) = myusup; - - myExtPC.Initialize(aCurve); - - // Find extremas. - for (anIdx = aVal.Lower() + 1; anIdx < aVal.Upper(); anIdx++) - { - if (aVal(anIdx) <= Precision::SquareConfusion()) - { - mySqDist.Append(aVal(anIdx)); - myismin.Append(Standard_True); - mypoint.Append(ThePOnC(aParam(anIdx), TheCurveTool::Value(aCurve, aParam(anIdx)))); - } - if ((aVal(anIdx) >= aVal(anIdx + 1) && aVal(anIdx) >= aVal(anIdx - 1)) - || (aVal(anIdx) <= aVal(anIdx + 1) && aVal(anIdx) <= aVal(anIdx - 1))) - { - myintuinf = aParam(anIdx - 1); - myintusup = aParam(anIdx + 1); - - IntervalPerform(P); - } - } - - // Solve on the first and last intervals. - if (mydist1 > Precision::SquareConfusion() && !Precision::IsPositiveInfinite(mydist1)) - { - ThePoint aP1, aP2; - TheVector aV1, aV2; - TheCurveTool::D1(aCurve, aParam.Value(aParam.Lower()), aP1, aV1); - TheCurveTool::D1(aCurve, aParam.Value(aParam.Lower() + 1), aP2, aV2); - TheVector aBase1(P, aP1), aBase2(P, aP2); - Standard_Real aVal1 = aV1.Dot(aBase1); // Derivative of (C(u) - P)^2 - Standard_Real aVal2 = aV2.Dot(aBase2); // Derivative of (C(u) - P)^2 - if (!(Precision::IsInfinite(aVal1) || Precision::IsInfinite(aVal2))) - { - // Derivatives have opposite signs - min or max inside of interval (sufficient - // condition). Necessary condition - when point lies on curve. Necessary condition - - // when derivative of point is too small. - if (aVal1 * aVal2 <= 0.0 || aBase1.Dot(aBase2) <= 0.0 - || 2.0 * std::abs(aVal1) < Precision::Confusion()) - { - myintuinf = aParam(aVal.Lower()); - myintusup = aParam(aVal.Lower() + 1); - IntervalPerform(P); - } - } - } - - if (mydist2 > Precision::SquareConfusion() && !Precision::IsPositiveInfinite(mydist2)) - { - ThePoint aP1, aP2; - TheVector aV1, aV2; - TheCurveTool::D1(aCurve, aParam.Value(aParam.Upper() - 1), aP1, aV1); - TheCurveTool::D1(aCurve, aParam.Value(aParam.Upper()), aP2, aV2); - TheVector aBase1(P, aP1), aBase2(P, aP2); - Standard_Real aVal1 = aV1.Dot(aBase1); // Derivative of (C(u) - P)^2 - Standard_Real aVal2 = aV2.Dot(aBase2); // Derivative of (C(u) - P)^2 - - if (!(Precision::IsInfinite(aVal1) || Precision::IsInfinite(aVal2))) - { - // Derivatives have opposite signs - min or max inside of interval (sufficient - // condition). Necessary condition - when point lies on curve. Necessary condition - - // when derivative of point is too small. - if (aVal1 * aVal2 <= 0.0 || aBase1.Dot(aBase2) <= 0.0 - || 2.0 * std::abs(aVal2) < Precision::Confusion()) - { - myintuinf = aParam(aVal.Upper() - 1); - myintusup = aParam(aVal.Upper()); - IntervalPerform(P); - } - } - } - } - mydone = Standard_True; - break; - } - default: { - const Standard_Integer aMaxSample = 17; - Standard_Boolean IntExtIsDone = Standard_False; - Standard_Boolean IntIsNotValid; - Handle(TColStd_HArray1OfReal) theHInter; - n = TheCurveTool::NbIntervals(aCurve, GeomAbs_C2); - if (n > 1) - { - theHInter = new TColStd_HArray1OfReal(1, n + 1); - TheCurveTool::Intervals(aCurve, theHInter->ChangeArray1(), GeomAbs_C2); - } - else - { - theHInter = TheCurveTool::DeflCurvIntervals(aCurve); - n = theHInter->Length() - 1; - } - mysample = std::max(mysample / n, aMaxSample); - Standard_Real maxint = 0.; - for (i = 1; i <= n; ++i) - { - Standard_Real dt = theHInter->Value(i + 1) - theHInter->Value(i); - if (maxint < dt) - { - maxint = dt; - } - } - Standard_Boolean isPeriodic = TheCurveTool::IsPeriodic(aCurve); - TheVector V1; - ThePoint PP; - Standard_Real s1 = 0.0; - Standard_Real s2 = 0.0; - myExtPC.Initialize(aCurve); - for (i = 1; i <= n; i++) - { - myintuinf = theHInter->Value(i); - myintusup = theHInter->Value(i + 1); - mysample = std::max(RealToInt(aMaxSample * (myintusup - myintuinf) / maxint), 3); - - Standard_Real anInfToCheck = myintuinf; - Standard_Real aSupToCheck = myintusup; - - if (isPeriodic) - { - Standard_Real aPeriod = TheCurveTool::Period(aCurve); - anInfToCheck = ElCLib::InPeriod(myintuinf, myuinf, myuinf + aPeriod); - aSupToCheck = myintusup + (anInfToCheck - myintuinf); - } - IntIsNotValid = (myuinf > aSupToCheck) || (myusup < anInfToCheck); - - if (IntIsNotValid) - continue; - - if (myuinf >= anInfToCheck) - anInfToCheck = myuinf; - if (myusup <= aSupToCheck) - aSupToCheck = myusup; - if ((aSupToCheck - anInfToCheck) <= mytolu) - continue; - - if (i != 1) - { - TheCurveTool::D1(aCurve, myintuinf, PP, V1); - s1 = (TheVector(P, PP)) * V1; - if (s1 * s2 < 0.0) - { - mySqDist.Append(PP.SquareDistance(P)); - myismin.Append((s1 < 0.0)); - mypoint.Append(ThePOnC(myintuinf, PP)); - } - } - if (i != n) - { - TheCurveTool::D1(aCurve, myintusup, PP, V1); - s2 = (TheVector(P, PP)) * V1; - } - - IntervalPerform(P); - IntExtIsDone = IntExtIsDone || mydone; - } - - mydone = IntExtIsDone; - break; - } - } - - // Postprocessing. - if (type == GeomAbs_BSplineCurve || type == GeomAbs_OffsetCurve || type == GeomAbs_OtherCurve) - { - // Additional checking if the point is on the first or last point of the curve - // and does not added yet. - if (mydist1 < Precision::SquareConfusion() || mydist2 < Precision::SquareConfusion()) - { - Standard_Boolean isFirstAdded = Standard_False; - Standard_Boolean isLastAdded = Standard_False; - Standard_Integer aNbPoints = mypoint.Length(); - for (i = 1; i <= aNbPoints; i++) - { - U = mypoint.Value(i).Parameter(); - if (std::abs(U - myuinf) < mytolu) - isFirstAdded = Standard_True; - else if (std::abs(myusup - U) < mytolu) - isLastAdded = Standard_True; - } - if (!isFirstAdded && mydist1 < Precision::SquareConfusion()) - { - mySqDist.Prepend(mydist1); - myismin.Prepend(Standard_True); - mypoint.Prepend(ThePOnC(myuinf, Pf)); - } - if (!isLastAdded && mydist2 < Precision::SquareConfusion()) - { - mySqDist.Append(mydist2); - myismin.Append(Standard_True); - mypoint.Append(ThePOnC(myusup, Pl)); - } - mydone = Standard_True; - } - } - else - { - // In analytical case - mydone = myExtPElC.IsDone(); - if (mydone) - { - NbExt = myExtPElC.NbExt(); - for (i = 1; i <= NbExt; i++) - { - // Verification de la validite des parametres: - ThePOnC PC = myExtPElC.Point(i); - U = PC.Parameter(); - if (TheCurveTool::IsPeriodic(aCurve)) - { - U = ElCLib::InPeriod(U, myuinf, myuinf + TheCurveTool::Period(aCurve)); - } - if ((U >= myuinf - mytolu) && (U <= myusup + mytolu)) - { - PC.SetValues(U, myExtPElC.Point(i).Value()); - mySqDist.Append(myExtPElC.SquareDistance(i)); - myismin.Append(myExtPElC.IsMin(i)); - mypoint.Append(PC); - } - } - } - } -} - -//================================================================================================= - -void Extrema_GExtPC::Initialize(const TheCurve& C, - const Standard_Real Uinf, - const Standard_Real Usup, - const Standard_Real TolF) -{ - myC = (Standard_Address)&C; - myintuinf = myuinf = Uinf; - myintusup = myusup = Usup; - mytolf = TolF; - mytolu = TheCurveTool::Resolution(*((TheCurve*)myC), Precision::Confusion()); - type = TheCurveTool::GetType(C); - mydone = Standard_False; - mydist1 = RealLast(); - mydist2 = RealLast(); - mysample = 17; -} - -//================================================================================================= - -void Extrema_GExtPC::IntervalPerform(const ThePoint& P) -{ - Standard_Integer i; - Standard_Real U; - myExtPC.Initialize(mysample, myintuinf, myintusup, mytolu, mytolf); - myExtPC.Perform(P); - mydone = myExtPC.IsDone(); - if (mydone) - { - Standard_Integer NbExt = myExtPC.NbExt(); - for (i = 1; i <= NbExt; i++) - { - // Verification de la validite des parametres pour le cas trimme: - ThePOnC PC = myExtPC.Point(i); - U = PC.Parameter(); - if (TheCurveTool::IsPeriodic(*((TheCurve*)myC))) - { - U = ElCLib::InPeriod(U, myuinf, myuinf + TheCurveTool::Period(*((TheCurve*)myC))); - } - if ((U >= myuinf - mytolu) && (U <= myusup + mytolu)) - { - AddSol(U, PC.Value(), myExtPC.SquareDistance(i), myExtPC.IsMin(i)); - } - } - } -} - -//================================================================================================= - -void Extrema_GExtPC::AddSol(const Standard_Real theU, - const ThePoint& theP, - const Standard_Real theSqDist, - const Standard_Boolean isMin) -{ - Standard_Integer i, NbExt = mypoint.Length(); - for (i = 1; i <= NbExt; i++) - { - Standard_Real t = mypoint.Value(i).Parameter(); - if (std::abs(t - theU) <= mytolu) - { - return; - } - } - ThePOnC PC(theU, theP); - mySqDist.Append(theSqDist); - myismin.Append(isMin); - mypoint.Append(PC); -} - -//================================================================================================= - -Extrema_GExtPC::Extrema_GExtPC() -{ - myC = 0; - mydone = Standard_False; - mydist1 = RealLast(); - mydist2 = RealLast(); - mytolu = 0.0; - mytolf = 0.0; - mysample = 17; - myintuinf = myintusup = myuinf = myusup = Precision::Infinite(); - type = GeomAbs_OtherCurve; -} - -//================================================================================================= - -Extrema_GExtPC::Extrema_GExtPC(const ThePoint& P, - const TheCurve& C, - const Standard_Real Uinf, - const Standard_Real Usup, - const Standard_Real TolF) -{ - Initialize(C, Uinf, Usup, TolF); - Perform(P); -} - -//================================================================================================= - -Extrema_GExtPC::Extrema_GExtPC(const ThePoint& P, const TheCurve& C, const Standard_Real TolF) -{ - Initialize(C, TheCurveTool::FirstParameter(C), TheCurveTool::LastParameter(C), TolF); - Perform(P); -} - -//================================================================================================= - -Standard_Boolean Extrema_GExtPC::IsDone() const -{ - return mydone; -} - -//================================================================================================= - -Standard_Real Extrema_GExtPC::SquareDistance(const Standard_Integer N) const -{ - if ((N < 1) || (N > NbExt())) - throw Standard_OutOfRange(); - return mySqDist.Value(N); -} - -//================================================================================================= - -Standard_Integer Extrema_GExtPC::NbExt() const -{ - if (!IsDone()) - throw StdFail_NotDone(); - return mySqDist.Length(); -} - -//================================================================================================= - -Standard_Boolean Extrema_GExtPC::IsMin(const Standard_Integer N) const -{ - if ((N < 1) || (N > NbExt())) - throw Standard_OutOfRange(); - return myismin.Value(N); -} - -//================================================================================================= - -const ThePOnC& Extrema_GExtPC::Point(const Standard_Integer N) const -{ - if ((N < 1) || (N > NbExt())) - throw Standard_OutOfRange(); - return mypoint.Value(N); -} - -//================================================================================================= - -void Extrema_GExtPC::TrimmedSquareDistances(Standard_Real& dist1, - Standard_Real& dist2, - ThePoint& P1, - ThePoint& P2) const -{ - dist1 = mydist1; - dist2 = mydist2; - P1 = Pf; - P2 = Pl; -} diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_GFuncExtCC.hxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_GFuncExtCC.hxx new file mode 100644 index 0000000000..b4d503ec4c --- /dev/null +++ b/src/ModelingData/TKGeomBase/Extrema/Extrema_GFuncExtCC.hxx @@ -0,0 +1,927 @@ +// 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. + +#ifndef _Extrema_GFuncExtCC_HeaderFile +#define _Extrema_GFuncExtCC_HeaderFile + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//! Template class for function used to find extremal distance between two curves. +//! This class inherits from math_FunctionSetWithDerivatives and is used by +//! the algorithm math_FunctionSetRoot. +//! +//! @tparam TheCurve1 Type of the first curve (e.g., Adaptor3d_Curve) +//! @tparam TheCurveTool1 Tool class for the first curve +//! @tparam TheCurve2 Type of the second curve +//! @tparam TheCurveTool2 Tool class for the second curve +//! @tparam ThePOnC Point on curve type (e.g., Extrema_POnCurv) +//! @tparam ThePoint Point type (e.g., gp_Pnt) +//! @tparam TheVector Vector type (e.g., gp_Vec) +//! @tparam TheSequenceOfPOnC Sequence of points on curve +template +class Extrema_GFuncExtCC : public math_FunctionSetWithDerivatives +{ +public: + DEFINE_STANDARD_ALLOC + + //! Default constructor with tolerance. + Extrema_GFuncExtCC(const double theTol = 1.0e-10); + + //! Constructor with curves. + Extrema_GFuncExtCC(const TheCurve1& theC1, const TheCurve2& theC2, const double theTol = 1.0e-10); + + //! Sets the curve for the specified rank (1 or 2). + void SetCurve(const int theRank, const TheCurve1& theC); + + //! Sets the tolerance. + void SetTolerance(const double theTol) { myTol = theTol; } + + //! Returns the number of variables (2). + virtual int NbVariables() const Standard_OVERRIDE { return 2; } + + //! Returns the number of equations (2). + virtual int NbEquations() const Standard_OVERRIDE { return 2; } + + //! Calculate Fi(U,V). + virtual Standard_Boolean Value(const math_Vector& theUV, math_Vector& theF) Standard_OVERRIDE; + + //! Calculate Fi'(U,V). + Standard_Boolean Derivatives(const math_Vector& theUV, math_Matrix& theDF) Standard_OVERRIDE; + + //! Calculate Fi(U,V) and Fi'(U,V). + Standard_Boolean Values(const math_Vector& theUV, + math_Vector& theF, + math_Matrix& theDF) Standard_OVERRIDE; + + //! Save the found extremum. + virtual int GetStateNumber() Standard_OVERRIDE; + + //! Return the number of found extrema. + int NbExt() const { return mySqDist.Length(); } + + //! Return the value of the Nth distance. + double SquareDistance(const int theN) const { return mySqDist.Value(theN); } + + //! Return the points of the Nth extreme distance. + void Points(const int theN, ThePOnC& theP1, ThePOnC& theP2) const; + + //! Returns a pointer to the curve specified in the constructor or in SetCurve() method. + Standard_Address CurvePtr(const int theRank) const + { + Standard_OutOfRange_Raise_if(theRank < 1 || theRank > 2, "Extrema_GFuncExtCC::CurvePtr()"); + return (theRank == 1 ? myC1 : myC2); + } + + //! Returns a tolerance specified in the constructor or in SetTolerance() method. + double Tolerance() const { return myTol; } + + //! Determines boundaries of subinterval for find of root. + void SubIntervalInitialize(const math_Vector& theUfirst, const math_Vector& theUlast); + + //! Computes a Tol value. If 1st derivative of curve |D1| +double Extrema_GFuncExtCC::SearchOfTolerance(const Standard_Address theC) +{ + const int NPoint = 10; + double aStartParam, anEndParam; + + if (theC == myC1) + { + aStartParam = myUinfium; + anEndParam = myUsupremum; + } + else if (theC == myC2) + { + aStartParam = myVinfium; + anEndParam = myVsupremum; + } + else + { + return THE_MIN_TOL; + } + + const double aStep = (anEndParam - aStartParam) / (double)NPoint; + + int aNum = 0; + double aMax = -Precision::Infinite(); + + do + { + double u = aStartParam + aNum * aStep; + if (u > anEndParam) + u = anEndParam; + + ThePoint Ptemp; + TheVector VDer; + TheCurveTool1::D1(*((TheCurve1*)theC), u, Ptemp, VDer); + double vm = VDer.Magnitude(); + if (vm > aMax) + aMax = vm; + } while (++aNum < NPoint + 1); + + return std::max(aMax * THE_TOL_FACTOR, THE_MIN_TOL); +} + +//================================================================================================== + +template +Extrema_GFuncExtCC::Extrema_GFuncExtCC(const double theTol) + : myC1(0), + myC2(0), + myTol(theTol) +{ + math_Vector V1(1, 2), V2(1, 2); + V1(1) = 0.0; + V2(1) = 0.0; + V1(2) = 0.0; + V2(2) = 0.0; + SubIntervalInitialize(V1, V2); + myMaxDerivOrderC1 = 0; + myTolC1 = THE_MIN_TOL; + myMaxDerivOrderC2 = 0; + myTolC2 = THE_MIN_TOL; +} + +//================================================================================================== + +template +Extrema_GFuncExtCC::Extrema_GFuncExtCC(const TheCurve1& theC1, + const TheCurve2& theC2, + const double theTol) + : myC1((Standard_Address)&theC1), + myC2((Standard_Address)&theC2), + myTol(theTol) +{ + math_Vector V1(1, 2), V2(1, 2); + V1(1) = TheCurveTool1::FirstParameter(*((TheCurve1*)myC1)); + V2(1) = TheCurveTool1::LastParameter(*((TheCurve1*)myC1)); + V1(2) = TheCurveTool2::FirstParameter(*((TheCurve2*)myC2)); + V2(2) = TheCurveTool2::LastParameter(*((TheCurve2*)myC2)); + SubIntervalInitialize(V1, V2); + + switch (TheCurveTool1::GetType(*((TheCurve1*)myC1))) + { + case GeomAbs_BezierCurve: + case GeomAbs_BSplineCurve: + case GeomAbs_OffsetCurve: + case GeomAbs_OtherCurve: + myMaxDerivOrderC1 = THE_MAX_ORDER; + myTolC1 = SearchOfTolerance((Standard_Address)&theC1); + break; + default: + myMaxDerivOrderC1 = 0; + myTolC1 = THE_MIN_TOL; + break; + } + + switch (TheCurveTool2::GetType(*((TheCurve2*)myC2))) + { + case GeomAbs_BezierCurve: + case GeomAbs_BSplineCurve: + case GeomAbs_OffsetCurve: + case GeomAbs_OtherCurve: + myMaxDerivOrderC2 = THE_MAX_ORDER; + myTolC2 = SearchOfTolerance((Standard_Address)&theC2); + break; + default: + myMaxDerivOrderC2 = 0; + myTolC2 = THE_MIN_TOL; + break; + } +} + +//================================================================================================== + +template +void Extrema_GFuncExtCC::SetCurve(const int theRank, const TheCurve1& theC) +{ + Standard_OutOfRange_Raise_if(theRank < 1 || theRank > 2, "Extrema_GFuncExtCC::SetCurve()") + + if (theRank == 1) + { + myC1 = (Standard_Address)&theC; + switch (theC.GetType()) + { + case GeomAbs_BezierCurve: + case GeomAbs_BSplineCurve: + case GeomAbs_OffsetCurve: + case GeomAbs_OtherCurve: + myMaxDerivOrderC1 = THE_MAX_ORDER; + myTolC1 = SearchOfTolerance((Standard_Address)&theC); + break; + default: + myMaxDerivOrderC1 = 0; + myTolC1 = THE_MIN_TOL; + break; + } + } + else if (theRank == 2) + { + myC2 = (Standard_Address)&theC; + switch (theC.GetType()) + { + case GeomAbs_BezierCurve: + case GeomAbs_BSplineCurve: + case GeomAbs_OffsetCurve: + case GeomAbs_OtherCurve: + myMaxDerivOrderC2 = THE_MAX_ORDER; + myTolC2 = SearchOfTolerance((Standard_Address)&theC); + break; + default: + myMaxDerivOrderC2 = 0; + myTolC2 = THE_MIN_TOL; + break; + } + } +} + +//================================================================================================== + +template +Standard_Boolean Extrema_GFuncExtCC::Value(const math_Vector& theUV, + math_Vector& theF) +{ + myU = theUV(1); + myV = theUV(2); + TheCurveTool1::D1(*((TheCurve1*)myC1), myU, myP1, myDu); + TheCurveTool2::D1(*((TheCurve2*)myC2), myV, myP2, myDv); + + TheVector P1P2(myP1, myP2); + + double Ndu = myDu.Magnitude(); + + if (myMaxDerivOrderC1 != 0) + { + if (Ndu <= myTolC1) + { + const double DivisionFactor = 1.e-3; + double du; + if ((myUsupremum >= RealLast()) || (myUinfium <= RealFirst())) + du = 0.0; + else + du = myUsupremum - myUinfium; + + const double aDelta = std::max(du * DivisionFactor, THE_MIN_STEP); + + int n = 1; + TheVector V; + Standard_Boolean IsDeriveFound; + + do + { + V = TheCurveTool1::DN(*((TheCurve1*)myC1), myU, ++n); + Ndu = V.Magnitude(); + IsDeriveFound = (Ndu > myTolC1); + } while (!IsDeriveFound && n < myMaxDerivOrderC1); + + if (IsDeriveFound) + { + double u; + + if (myU - myUinfium < aDelta) + u = myU + aDelta; + else + u = myU - aDelta; + + ThePoint P1, P2; + TheCurveTool1::D0(*((TheCurve1*)myC1), std::min(myU, u), P1); + TheCurveTool1::D0(*((TheCurve1*)myC1), std::max(myU, u), P2); + + TheVector V1(P1, P2); + double aDirFactor = V.Dot(V1); + + if (aDirFactor < 0.0) + myDu = -V; + else + myDu = V; + } + else + { + ThePoint Ptemp; + ThePoint P1, P2, P3; + Standard_Boolean IsParameterGrown; + + if (myU - myUinfium < 2 * aDelta) + { + TheCurveTool1::D0(*((TheCurve1*)myC1), myU, P1); + TheCurveTool1::D0(*((TheCurve1*)myC1), myU + aDelta, P2); + TheCurveTool1::D0(*((TheCurve1*)myC1), myU + 2 * aDelta, P3); + IsParameterGrown = Standard_True; + } + else + { + TheCurveTool1::D0(*((TheCurve1*)myC1), myU - 2 * aDelta, P1); + TheCurveTool1::D0(*((TheCurve1*)myC1), myU - aDelta, P2); + TheCurveTool1::D0(*((TheCurve1*)myC1), myU, P3); + IsParameterGrown = Standard_False; + } + + TheVector V1(Ptemp, P1), V2(Ptemp, P2), V3(Ptemp, P3); + + if (IsParameterGrown) + myDu = -3 * V1 + 4 * V2 - V3; + else + myDu = V1 - 4 * V2 + 3 * V3; + } + Ndu = myDu.Magnitude(); + } + } + + if (Ndu <= THE_MIN_TOL) + { + return Standard_False; + } + + double Ndv = myDv.Magnitude(); + + if (myMaxDerivOrderC2 != 0) + { + if (Ndv <= myTolC2) + { + const double DivisionFactor = 1.e-3; + double dv; + if ((myVsupremum >= RealLast()) || (myVinfium <= RealFirst())) + dv = 0.0; + else + dv = myVsupremum - myVinfium; + + const double aDelta = std::max(dv * DivisionFactor, THE_MIN_STEP); + + int n = 1; + TheVector V; + Standard_Boolean IsDeriveFound; + + do + { + V = TheCurveTool2::DN(*((TheCurve2*)myC2), myV, ++n); + Ndv = V.Magnitude(); + IsDeriveFound = (Ndv > myTolC2); + } while (!IsDeriveFound && n < myMaxDerivOrderC2); + + if (IsDeriveFound) + { + double v; + + if (myV - myVinfium < aDelta) + v = myV + aDelta; + else + v = myV - aDelta; + + ThePoint P1, P2; + TheCurveTool2::D0(*((TheCurve2*)myC2), std::min(myV, v), P1); + TheCurveTool2::D0(*((TheCurve2*)myC2), std::max(myV, v), P2); + + TheVector V1(P1, P2); + double aDirFactor = V.Dot(V1); + + if (aDirFactor < 0.0) + myDv = -V; + else + myDv = V; + } + else + { + ThePoint Ptemp; + ThePoint P1, P2, P3; + Standard_Boolean IsParameterGrown; + + if (myV - myVinfium < 2 * aDelta) + { + TheCurveTool2::D0(*((TheCurve2*)myC2), myV, P1); + TheCurveTool2::D0(*((TheCurve2*)myC2), myV + aDelta, P2); + TheCurveTool2::D0(*((TheCurve2*)myC2), myV + 2 * aDelta, P3); + IsParameterGrown = Standard_True; + } + else + { + TheCurveTool2::D0(*((TheCurve2*)myC2), myV - 2 * aDelta, P1); + TheCurveTool2::D0(*((TheCurve2*)myC2), myV - aDelta, P2); + TheCurveTool2::D0(*((TheCurve2*)myC2), myV, P3); + IsParameterGrown = Standard_False; + } + + TheVector V1(Ptemp, P1), V2(Ptemp, P2), V3(Ptemp, P3); + + if (IsParameterGrown) + myDv = -3 * V1 + 4 * V2 - V3; + else + myDv = V1 - 4 * V2 + 3 * V3; + } + + Ndv = myDv.Magnitude(); + } + } + + if (Ndv <= THE_MIN_TOL) + { + return Standard_False; + } + + theF(1) = P1P2.Dot(myDu) / Ndu; + theF(2) = P1P2.Dot(myDv) / Ndv; + return Standard_True; +} + +//================================================================================================== + +template +Standard_Boolean Extrema_GFuncExtCC::Derivatives(const math_Vector& theUV, + math_Matrix& theDF) +{ + math_Vector F(1, 2); + return Values(theUV, F, theDF); +} + +//================================================================================================== + +template +Standard_Boolean Extrema_GFuncExtCC::Values(const math_Vector& theUV, + math_Vector& theF, + math_Matrix& theDF) +{ + myU = theUV(1); + myV = theUV(2); + + if (Value(theUV, theF) == Standard_False) + { + return Standard_False; + } + + TheVector Du, Dv, Duu, Dvv; + TheCurveTool1::D2(*((TheCurve1*)myC1), myU, myP1, Du, Duu); + TheCurveTool2::D2(*((TheCurve2*)myC2), myV, myP2, Dv, Dvv); + + const double myU_old = myU, myV_old = myV; + const ThePoint myP1_old = myP1, myP2_old = myP2; + const TheVector myDu_old = myDu, myDv_old = myDv; + + const double DivisionFactor = 0.01; + + double du; + if ((myUsupremum >= RealLast()) || (myUinfium <= RealFirst())) + du = 0.0; + else + du = myUsupremum - myUinfium; + + const double aDeltaU = std::max(du * DivisionFactor, THE_MIN_STEP); + + double dv; + if ((myVsupremum >= RealLast()) || (myVinfium <= RealFirst())) + dv = 0.0; + else + dv = myVsupremum - myVinfium; + + const double aDeltaV = std::max(dv * DivisionFactor, THE_MIN_STEP); + + TheVector P1P2(myP1, myP2); + + if ((myMaxDerivOrderC1 != 0) && (Du.Magnitude() <= myTolC1)) + { + math_Vector FF1(1, 2), FF2(1, 2), FF3(1, 2); + double F1, F2, F3; + + if (myU - myUinfium < 2 * aDeltaU) + { + F1 = theF(1); + math_Vector UV2(1, 2), UV3(1, 2); + UV2(1) = myU + aDeltaU; + UV2(2) = myV; + UV3(1) = myU + 2 * aDeltaU; + UV3(2) = myV; + if (!((Value(UV2, FF2)) && (Value(UV3, FF3)))) + { + return Standard_False; + } + + F2 = FF2(1); + F3 = FF3(1); + + theDF(1, 1) = (-3 * F1 + 4 * F2 - F3) / (2.0 * aDeltaU); + } + else + { + F3 = theF(1); + math_Vector UV2(1, 2), UV1(1, 2); + UV2(1) = myU - aDeltaU; + UV2(2) = myV; + UV1(1) = myU - 2 * aDeltaU; + UV1(2) = myV; + + if (!((Value(UV2, FF2)) && (Value(UV1, FF1)))) + { + return Standard_False; + } + + F1 = FF1(1); + F2 = FF2(1); + + theDF(1, 1) = (F1 - 4 * F2 + 3 * F3) / (2.0 * aDeltaU); + } + + myU = myU_old; + myV = myV_old; + + if (myV - myVinfium < 2 * aDeltaV) + { + F1 = theF(1); + math_Vector UV2(1, 2), UV3(1, 2); + UV2(1) = myU; + UV2(2) = myV + aDeltaV; + UV3(1) = myU; + UV3(2) = myV + 2 * aDeltaV; + + if (!((Value(UV2, FF2)) && (Value(UV3, FF3)))) + { + return Standard_False; + } + F2 = FF2(1); + F3 = FF3(1); + + theDF(1, 2) = (-3 * F1 + 4 * F2 - F3) / (2.0 * aDeltaV); + } + else + { + F3 = theF(1); + math_Vector UV2(1, 2), UV1(1, 2); + UV2(1) = myU; + UV2(2) = myV - aDeltaV; + UV1(1) = myU; + UV1(2) = myV - 2 * aDeltaV; + if (!((Value(UV2, FF2)) && (Value(UV1, FF1)))) + { + return Standard_False; + } + + F1 = FF1(1); + F2 = FF2(1); + + theDF(1, 2) = (F1 - 4 * F2 + 3 * F3) / (2.0 * aDeltaV); + } + + myU = myU_old; + myV = myV_old; + myP1 = myP1_old, myP2 = myP2_old; + myDu = myDu_old, myDv = myDv_old; + } + else + { + const double Ndu = myDu.Magnitude(); + theDF(1, 1) = -Ndu + (P1P2.Dot(Duu) / Ndu) - theF(1) * (myDu.Dot(Duu) / (Ndu * Ndu)); + theDF(1, 2) = myDv.Dot(myDu) / Ndu; + } + + if ((myMaxDerivOrderC2 != 0) && (Dv.Magnitude() <= myTolC2)) + { + math_Vector FF1(1, 2), FF2(1, 2), FF3(1, 2); + double F1, F2, F3; + + if (myV - myVinfium < 2 * aDeltaV) + { + F1 = theF(2); + math_Vector UV2(1, 2), UV3(1, 2); + UV2(1) = myU; + UV2(2) = myV + aDeltaV; + UV3(1) = myU; + UV3(2) = myV + 2 * aDeltaV; + + if (!((Value(UV2, FF2)) && (Value(UV3, FF3)))) + { + return Standard_False; + } + + F2 = FF2(2); + F3 = FF3(2); + + theDF(2, 2) = (-3 * F1 + 4 * F2 - F3) / (2.0 * aDeltaV); + } + else + { + F3 = theF(2); + math_Vector UV2(1, 2), UV1(1, 2); + UV2(1) = myU; + UV2(2) = myV - aDeltaV; + UV1(1) = myU; + UV1(2) = myV - 2 * aDeltaV; + + if (!((Value(UV2, FF2)) && (Value(UV1, FF1)))) + { + return Standard_False; + } + + F1 = FF1(2); + F2 = FF2(2); + + theDF(2, 2) = (F1 - 4 * F2 + 3 * F3) / (2.0 * aDeltaV); + } + + myU = myU_old; + myV = myV_old; + + if (myU - myUinfium < 2 * aDeltaU) + { + F1 = theF(2); + math_Vector UV2(1, 2), UV3(1, 2); + UV2(1) = myU + aDeltaU; + UV2(2) = myV; + UV3(1) = myU + 2 * aDeltaU; + UV3(2) = myV; + if (!((Value(UV2, FF2)) && (Value(UV3, FF3)))) + { + return Standard_False; + } + + F2 = FF2(2); + F3 = FF3(2); + + theDF(2, 1) = (-3 * F1 + 4 * F2 - F3) / (2.0 * aDeltaU); + } + else + { + F3 = theF(2); + math_Vector UV2(1, 2), UV1(1, 2); + UV2(1) = myU - aDeltaU; + UV2(2) = myV; + UV1(1) = myU - 2 * aDeltaU; + UV1(2) = myV; + + if (!((Value(UV2, FF2)) && (Value(UV1, FF1)))) + { + return Standard_False; + } + + F1 = FF1(2); + F2 = FF2(2); + + theDF(2, 1) = (F1 - 4 * F2 + 3 * F3) / (2.0 * aDeltaU); + } + + myU = myU_old; + myV = myV_old; + myP1 = myP1_old; + myP2 = myP2_old; + myDu = myDu_old; + myDv = myDv_old; + } + else + { + double Ndv = myDv.Magnitude(); + theDF(2, 2) = Ndv + (P1P2.Dot(Dvv) / Ndv) - theF(2) * (myDv.Dot(Dvv) / (Ndv * Ndv)); + theDF(2, 1) = -myDu.Dot(myDv) / Ndv; + } + + return Standard_True; +} + +//================================================================================================== + +template +int Extrema_GFuncExtCC::GetStateNumber() +{ + TheVector Du(myDu), Dv(myDv); + TheVector P1P2(myP1, myP2); + + double mod = Du.Magnitude(); + if (mod > myTolC1) + { + Du /= mod; + } + mod = Dv.Magnitude(); + if (mod > myTolC2) + { + Dv /= mod; + } + + if (std::abs(P1P2.Dot(Du)) <= myTol && std::abs(P1P2.Dot(Dv)) <= myTol) + { + mySqDist.Append(myP1.SquareDistance(myP2)); + myPoints.Append(ThePOnC(myU, myP1)); + myPoints.Append(ThePOnC(myV, myP2)); + } + return 0; +} + +//================================================================================================== + +template +void Extrema_GFuncExtCC::Points(const int theN, + ThePOnC& theP1, + ThePOnC& theP2) const +{ + theP1 = myPoints.Value(2 * theN - 1); + theP2 = myPoints.Value(2 * theN); +} + +//================================================================================================== + +template +void Extrema_GFuncExtCC::SubIntervalInitialize(const math_Vector& theInfBound, + const math_Vector& theSupBound) +{ + myUinfium = theInfBound(1); + myUsupremum = theSupBound(1); + myVinfium = theInfBound(2); + myVsupremum = theSupBound(2); +} + +#endif // _Extrema_GFuncExtCC_HeaderFile diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_GFuncExtPC.hxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_GFuncExtPC.hxx new file mode 100644 index 0000000000..840b3f96b8 --- /dev/null +++ b/src/ModelingData/TKGeomBase/Extrema/Extrema_GFuncExtPC.hxx @@ -0,0 +1,482 @@ +// Created on: 1991-02-26 +// Created by: Isabelle GRIGNON +// Copyright (c) 1991-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. + +#ifndef _Extrema_GFuncExtPC_HeaderFile +#define _Extrema_GFuncExtPC_HeaderFile + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +//! Template class for computing extremal distance function between a point and a curve. +//! Searches for a parameter value u such that dist(P, C(u)) passes through an extremum. +//! Inherits from math_FunctionWithDerivative and is used by math_FunctionRoot and +//! math_FunctionRoots algorithms. +//! +//! If D1c and D2c are the first and second derivatives: +//! F(u) = (C(u)-P).D1c(u) / ||D1c|| +//! DF(u) = ||D1c|| + (C(u)-P).D2c(u)/||D1c|| - F(u)*D2c.D1c/||D1c||^2 +//! +//! @tparam TheCurve Curve type (e.g., Adaptor3d_Curve, Adaptor2d_Curve2d) +//! @tparam TheCurveTool Tool for curve operations +//! @tparam ThePOnC Point on curve type +//! @tparam ThePoint Point type (e.g., gp_Pnt, gp_Pnt2d) +//! @tparam TheVector Vector type (e.g., gp_Vec, gp_Vec2d) +//! @tparam TheSeqPOnC Sequence of points on curve type +template +class Extrema_GFuncExtPC : public math_FunctionWithDerivative +{ +public: + DEFINE_STANDARD_ALLOC + + //! Default constructor. + Extrema_GFuncExtPC() + : myC(nullptr), + myU(0.0), + myD1f(0.0), + myPinit(false), + myCinit(false), + myD1Init(false), + myTol(MinTol), + myMaxDerivOrder(0), + myUinfium(0.0), + myUsupremum(0.0) + { + } + + //! Constructor with point and curve initialization. + //! @param theP Point to compute distance from + //! @param theC Curve to compute distance to + Extrema_GFuncExtPC(const ThePoint& theP, const TheCurve& theC) + : myP(theP), + myC(const_cast(&theC)), + myU(0.0), + myD1f(0.0), + myPinit(true), + myCinit(true), + myD1Init(false) + { + SubIntervalInitialize(TheCurveTool::FirstParameter(theC), TheCurveTool::LastParameter(theC)); + + switch (TheCurveTool::GetType(theC)) + { + case GeomAbs_BezierCurve: + case GeomAbs_BSplineCurve: + case GeomAbs_OffsetCurve: + case GeomAbs_OtherCurve: + myMaxDerivOrder = MaxOrder; + myTol = SearchOfTolerance(); + break; + default: + myMaxDerivOrder = 0; + myTol = MinTol; + break; + } + } + + //! Sets the curve field. + //! @param theC Curve to set + void Initialize(const TheCurve& theC) + { + myC = const_cast(&theC); + myCinit = true; + myPoint.Clear(); + mySqDist.Clear(); + myIsMin.Clear(); + + SubIntervalInitialize(TheCurveTool::FirstParameter(theC), TheCurveTool::LastParameter(theC)); + + switch (TheCurveTool::GetType(theC)) + { + case GeomAbs_BezierCurve: + case GeomAbs_BSplineCurve: + case GeomAbs_OffsetCurve: + case GeomAbs_OtherCurve: + myMaxDerivOrder = MaxOrder; + myTol = SearchOfTolerance(); + break; + default: + myMaxDerivOrder = 0; + myTol = MinTol; + break; + } + } + + //! Sets the point field. + //! @param theP Point to set + void SetPoint(const ThePoint& theP) + { + myP = theP; + myPinit = true; + myPoint.Clear(); + mySqDist.Clear(); + myIsMin.Clear(); + } + + //! Calculation of F(u). + //! @param theU Parameter value + //! @param theF Output function value + //! @return True if computation succeeded + bool Value(const double theU, double& theF) override + { + if (!myPinit || !myCinit) + { + throw Standard_TypeMismatch("No init"); + } + + myU = theU; + TheVector D1c; + TheCurveTool::D1(*myC, myU, myPc, D1c); + + if (Precision::IsInfinite(D1c.X()) || Precision::IsInfinite(D1c.Y())) + { + theF = Precision::Infinite(); + return false; + } + + double Ndu = D1c.Magnitude(); + + if (myMaxDerivOrder != 0) + { + if (Ndu <= myTol) // Singular case + { + const double DivisionFactor = 1.e-3; + double du; + if ((myUsupremum >= RealLast()) || (myUinfium <= RealFirst())) + du = 0.0; + else + du = myUsupremum - myUinfium; + + const double aDelta = std::max(du * DivisionFactor, MinStep); + // Derivative is approximated by Taylor-series + + int n = 1; // Derivative order + TheVector V; + bool IsDeriveFound; + + do + { + V = TheCurveTool::DN(*myC, myU, ++n); + Ndu = V.Magnitude(); + IsDeriveFound = (Ndu > myTol); + } while (!IsDeriveFound && n < myMaxDerivOrder); + + if (IsDeriveFound) + { + double u; + + if (myU - myUinfium < aDelta) + u = myU + aDelta; + else + u = myU - aDelta; + + ThePoint P1, P2; + TheCurveTool::D0(*myC, std::min(myU, u), P1); + TheCurveTool::D0(*myC, std::max(myU, u), P2); + + TheVector V1(P1, P2); + double aDirFactor = V.Dot(V1); + + if (aDirFactor < 0.0) + D1c = -V; + else + D1c = V; + } + else + { + // Derivative is approximated by three points + ThePoint Ptemp; + ThePoint P1, P2, P3; + bool IsParameterGrown; + + if (myU - myUinfium < 2 * aDelta) + { + TheCurveTool::D0(*myC, myU, P1); + TheCurveTool::D0(*myC, myU + aDelta, P2); + TheCurveTool::D0(*myC, myU + 2 * aDelta, P3); + IsParameterGrown = true; + } + else + { + TheCurveTool::D0(*myC, myU - 2 * aDelta, P1); + TheCurveTool::D0(*myC, myU - aDelta, P2); + TheCurveTool::D0(*myC, myU, P3); + IsParameterGrown = false; + } + + TheVector V1(Ptemp, P1), V2(Ptemp, P2), V3(Ptemp, P3); + + if (IsParameterGrown) + D1c = -3 * V1 + 4 * V2 - V3; + else + D1c = V1 - 4 * V2 + 3 * V3; + } + Ndu = D1c.Magnitude(); + } + } + + if (Ndu <= MinTol) + { + // Warning: 1st derivative is equal to zero! + return false; + } + + TheVector PPc(myP, myPc); + theF = PPc.Dot(D1c) / Ndu; + return true; + } + + //! Calculation of F'(u). + //! @param theU Parameter value + //! @param theDF Output derivative value + //! @return True if computation succeeded + bool Derivative(const double theU, double& theDF) override + { + if (!myPinit || !myCinit) + { + throw Standard_TypeMismatch(); + } + double F; + return Values(theU, F, theDF); + } + + //! Calculation of F(u) and F'(u). + //! @param theU Parameter value + //! @param theF Output function value + //! @param theDF Output derivative value + //! @return True if computation succeeded + bool Values(const double theU, double& theF, double& theDF) override + { + if (!myPinit || !myCinit) + { + throw Standard_TypeMismatch("No init"); + } + + ThePoint myPc_old = myPc, myP_old = myP; + + if (Value(theU, theF) == false) + { + myD1Init = false; + return false; + } + + myU = theU; + myPc = myPc_old; + myP = myP_old; + + TheVector D1c, D2c; + TheCurveTool::D2(*myC, myU, myPc, D1c, D2c); + + double Ndu = D1c.Magnitude(); + if (Ndu <= myTol) // Singular case + { + // Derivative is approximated by three points + const double DivisionFactor = 0.01; + double du; + if ((myUsupremum >= RealLast()) || (myUinfium <= RealFirst())) + du = 0.0; + else + du = myUsupremum - myUinfium; + + const double aDelta = std::max(du * DivisionFactor, MinStep); + + double F1, F2, F3; + + if (myU - myUinfium < 2 * aDelta) + { + F1 = theF; + const double U2 = myU + aDelta; + const double U3 = myU + aDelta * 2.0; + + if (!((Value(U2, F2)) && (Value(U3, F3)))) + { + myD1Init = false; + return false; + } + + theDF = (-3 * F1 + 4 * F2 - F3) / (2.0 * aDelta); + } + else + { + F3 = theF; + const double U1 = myU - aDelta * 2.0; + const double U2 = myU - aDelta; + + if (!((Value(U2, F2)) && (Value(U1, F1)))) + { + myD1Init = false; + return false; + } + + theDF = (F1 - 4 * F2 + 3 * F3) / (2.0 * aDelta); + } + myU = theU; + myPc = myPc_old; + myP = myP_old; + } + else + { + TheVector PPc(myP, myPc); + theDF = Ndu + (PPc.Dot(D2c) / Ndu) - theF * (D1c.Dot(D2c)) / (Ndu * Ndu); + } + + myD1f = theDF; + + myD1Init = true; + return true; + } + + //! Save the found extremum. + //! @return State number + int GetStateNumber() override + { + if (!myPinit || !myCinit) + { + throw Standard_TypeMismatch(); + } + mySqDist.Append(myPc.SquareDistance(myP)); + + // It is necessary to always compute myD1f. + myD1Init = true; + double FF, DD; + Values(myU, FF, DD); + + int IntVal = 0; + if (myD1f > 0.0) + { + IntVal = 1; + } + + myIsMin.Append(IntVal); + myPoint.Append(ThePOnC(myU, myPc)); + return 0; + } + + //! Return the number of found extrema. + int NbExt() const { return mySqDist.Length(); } + + //! Returns the Nth square distance. + //! @param theN Index of extremum + double SquareDistance(const int theN) const + { + if (!myPinit || !myCinit) + { + throw Standard_TypeMismatch(); + } + return mySqDist.Value(theN); + } + + //! Shows if the Nth distance is a minimum. + //! @param theN Index of extremum + bool IsMin(const int theN) const + { + if (!myPinit || !myCinit) + { + throw Standard_TypeMismatch(); + } + return (myIsMin.Value(theN) == 1); + } + + //! Returns the Nth extremum point. + //! @param theN Index of extremum + const ThePOnC& Point(const int theN) const + { + if (!myPinit || !myCinit) + { + throw Standard_TypeMismatch(); + } + return myPoint.Value(theN); + } + + //! Determines boundaries of subinterval for root finding. + //! @param theUfirst First parameter bound + //! @param theUlast Last parameter bound + void SubIntervalInitialize(const double theUfirst, const double theUlast) + { + myUinfium = theUfirst; + myUsupremum = theUlast; + } + + //! Computes a tolerance value. If 1st derivative of curve |D1| < Tol, + //! it is considered D1=0. + double SearchOfTolerance() + { + const int NPoint = 10; + const double aStep = (myUsupremum - myUinfium) / static_cast(NPoint); + + int aNum = 0; + double aMax = -Precision::Infinite(); + + do + { + double u = myUinfium + aNum * aStep; + if (u > myUsupremum) + u = myUsupremum; + + ThePoint Ptemp; + TheVector VDer; + TheCurveTool::D1(*myC, u, Ptemp, VDer); + + if (Precision::IsInfinite(VDer.X()) || Precision::IsInfinite(VDer.Y())) + { + continue; + } + + double vm = VDer.Magnitude(); + if (vm > aMax) + aMax = vm; + } while (++aNum < NPoint + 1); + + return std::max(aMax * TolFactor, MinTol); + } + +private: + static constexpr double TolFactor = 1.e-12; + static constexpr double MinTol = 1.e-20; + static constexpr double MinStep = 1.e-7; + static constexpr int MaxOrder = 3; + + ThePoint myP; + TheCurve* myC; + double myU; + ThePoint myPc; + double myD1f; + TColStd_SequenceOfReal mySqDist; + TColStd_SequenceOfInteger myIsMin; + TheSeqPOnC myPoint; + bool myPinit; + bool myCinit; + bool myD1Init; + double myTol; + int myMaxDerivOrder; + double myUinfium; + double myUsupremum; +}; + +#endif // _Extrema_GFuncExtPC_HeaderFile diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_GGExtPC.hxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_GGExtPC.hxx new file mode 100644 index 0000000000..036fa40a28 --- /dev/null +++ b/src/ModelingData/TKGeomBase/Extrema/Extrema_GGExtPC.hxx @@ -0,0 +1,658 @@ +// Created on: 1992-10-19 +// Created by: Laurent PAINNOT +// Copyright (c) 1992-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. + +#ifndef _Extrema_GGExtPC_HeaderFile +#define _Extrema_GGExtPC_HeaderFile + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//! Generic class for computing extremal distances between a point and a curve. +//! +//! This template class provides comprehensive extremum search functionality, +//! handling different curve types (lines, circles, ellipses, parabolas, +//! hyperbolas, Bezier, BSpline, and general curves) with optimized algorithms. +//! +//! @tparam TheCurve The curve type (e.g., Adaptor3d_Curve, Adaptor2d_Curve2d) +//! @tparam TheCurveTool The curve tool providing static methods +//! @tparam TheExtPElC The elementary curve extremum class +//! @tparam ThePoint The point type (e.g., gp_Pnt, gp_Pnt2d) +//! @tparam TheVector The vector type (e.g., gp_Vec, gp_Vec2d) +//! @tparam ThePOnC The point-on-curve type +//! @tparam TheSequenceOfPOnC The sequence of points on curve +//! @tparam TheEPC The general extremum point-curve class +template +class Extrema_GGExtPC +{ +public: + DEFINE_STANDARD_ALLOC + + //! Default constructor. + Extrema_GGExtPC() + : myC(nullptr), + mydone(false), + mydist1(RealLast()), + mydist2(RealLast()), + mytolu(0.0), + mytolf(0.0), + mysample(17), + myintuinf(Precision::Infinite()), + myintusup(Precision::Infinite()), + myuinf(Precision::Infinite()), + myusup(Precision::Infinite()), + type(GeomAbs_OtherCurve) + { + } + + //! Calculates all extremum distances between point P and curve C + //! within the specified parameter range. + //! @param theP The point + //! @param theC The curve + //! @param theUinf Lower bound of parameter range + //! @param theUsup Upper bound of parameter range + //! @param theTolF Tolerance on function value (default 1.0e-10) + Extrema_GGExtPC(const ThePoint& theP, + const TheCurve& theC, + const double theUinf, + const double theUsup, + const double theTolF = 1.0e-10) + { + Initialize(theC, theUinf, theUsup, theTolF); + Perform(theP); + } + + //! Calculates all extremum distances between point P and curve C + //! using the full curve parameter range. + //! @param theP The point + //! @param theC The curve + //! @param theTolF Tolerance on function value (default 1.0e-10) + Extrema_GGExtPC(const ThePoint& theP, const TheCurve& theC, const double theTolF = 1.0e-10) + { + Initialize(theC, + TheCurveTool::FirstParameter(theC), + TheCurveTool::LastParameter(theC), + theTolF); + Perform(theP); + } + + //! Initializes the algorithm with curve and parameter range. + //! @param theC The curve + //! @param theUinf Lower bound of parameter range + //! @param theUsup Upper bound of parameter range + //! @param theTolF Tolerance on function value (default 1.0e-10) + void Initialize(const TheCurve& theC, + const double theUinf, + const double theUsup, + const double theTolF = 1.0e-10) + { + myC = const_cast(&theC); + myintuinf = myuinf = theUinf; + myintusup = myusup = theUsup; + mytolf = theTolF; + mytolu = TheCurveTool::Resolution(*myC, Precision::Confusion()); + type = TheCurveTool::GetType(theC); + mydone = false; + mydist1 = RealLast(); + mydist2 = RealLast(); + mysample = 17; + } + + //! Performs the extremum computation for the given point. + //! @param theP The point to find extrema from + void Perform(const ThePoint& theP) + { + mySqDist.Clear(); + mypoint.Clear(); + myismin.Clear(); + int i, NbExt, n; + double U; + mysample = 17; + constexpr double t3d = Precision::Confusion(); + + if (Precision::IsInfinite(myuinf)) + mydist1 = RealLast(); + else + { + Pf = TheCurveTool::Value(*myC, myuinf); + mydist1 = theP.SquareDistance(Pf); + } + + if (Precision::IsInfinite(myusup)) + mydist2 = RealLast(); + else + { + Pl = TheCurveTool::Value(*myC, myusup); + mydist2 = theP.SquareDistance(Pl); + } + + TheCurve& aCurve = *myC; + + switch (type) + { + case GeomAbs_Circle: { + myExtPElC.Perform(theP, TheCurveTool::Circle(aCurve), t3d, myuinf, myusup); + break; + } + case GeomAbs_Ellipse: { + myExtPElC.Perform(theP, TheCurveTool::Ellipse(aCurve), t3d, myuinf, myusup); + break; + } + case GeomAbs_Parabola: { + myExtPElC.Perform(theP, TheCurveTool::Parabola(aCurve), t3d, myuinf, myusup); + break; + } + case GeomAbs_Hyperbola: { + myExtPElC.Perform(theP, TheCurveTool::Hyperbola(aCurve), t3d, myuinf, myusup); + break; + } + case GeomAbs_Line: { + myExtPElC.Perform(theP, TheCurveTool::Line(aCurve), t3d, myuinf, myusup); + break; + } + case GeomAbs_BezierCurve: { + myintuinf = myuinf; + myintusup = myusup; + mysample = (TheCurveTool::Bezier(aCurve))->NbPoles() * 2; + myExtPC.Initialize(aCurve); + IntervalPerform(theP); + return; + } + case GeomAbs_BSplineCurve: { + const int aFirstIdx = TheCurveTool::BSpline(aCurve)->FirstUKnotIndex(), + aLastIdx = TheCurveTool::BSpline(aCurve)->LastUKnotIndex(); + TColStd_Array1OfReal aKnots(aFirstIdx, aLastIdx); + TheCurveTool::BSpline(aCurve)->Knots(aKnots); + + double aPeriodJump = 0.0; + const double aTolCoeff = (myusup - myuinf) * Precision::PConfusion(); + if (TheCurveTool::IsPeriodic(aCurve)) + { + int aPeriodShift = int((myuinf - aKnots(aFirstIdx)) / TheCurveTool::Period(aCurve)); + if (myuinf < aKnots(aFirstIdx) - aTolCoeff) + aPeriodShift--; + aPeriodJump = TheCurveTool::Period(aCurve) * aPeriodShift; + } + + int anIdx; + int aFirstUsedKnot = aFirstIdx, aLastUsedKnot = aLastIdx; + for (anIdx = aFirstIdx; anIdx <= aLastIdx; anIdx++) + { + double aKnot = aKnots(anIdx) + aPeriodJump; + if (myuinf >= aKnot - aTolCoeff) + aFirstUsedKnot = anIdx; + else + break; + } + for (anIdx = aLastIdx; anIdx >= aFirstIdx; anIdx--) + { + double aKnot = aKnots(anIdx) + aPeriodJump; + if (myusup <= aKnot + aTolCoeff) + aLastUsedKnot = anIdx; + else + break; + } + + if (aFirstUsedKnot == aLastUsedKnot) + { + aFirstUsedKnot = aFirstIdx; + aLastUsedKnot = aFirstIdx + 1; + } + + mysample = (TheCurveTool::BSpline(aCurve))->Degree() + 1; + + if (mysample == 2) + { + ThePoint aPmin; + double tmin = 0., distmin = RealLast(); + double aMin1 = 0., aMin2 = 0.; + myExtPC.Initialize(aCurve); + for (anIdx = aFirstUsedKnot; anIdx < aLastUsedKnot; anIdx++) + { + double aF = aKnots(anIdx) + aPeriodJump, aL = aKnots(anIdx + 1) + aPeriodJump; + + if (anIdx == aFirstUsedKnot) + aF = myuinf; + else if (anIdx == aLastUsedKnot - 1) + aL = myusup; + + ThePoint aP1, aP2; + TheCurveTool::D0(aCurve, aF, aP1); + TheCurveTool::D0(aCurve, aL, aP2); + TheVector aBase1(theP, aP1), aBase2(theP, aP2); + TheVector aV(aP2, aP1); + double aVal1 = aV.Dot(aBase1); + double aVal2 = aV.Dot(aBase2); + if (anIdx == aFirstUsedKnot) + aMin1 = theP.SquareDistance(aP1); + else + { + aMin1 = aMin2; + if (distmin > aMin1) + { + distmin = aMin1; + tmin = aF; + aPmin = aP1; + } + } + aMin2 = theP.SquareDistance(aP2); + double aMinSqDist = std::min(aMin1, aMin2); + double aMinDer = std::min(std::abs(aVal1), std::abs(aVal2)); + if (!(Precision::IsInfinite(aVal1) || Precision::IsInfinite(aVal2))) + { + if (aVal1 * aVal2 <= 0.0 || aMinSqDist < 100. * Precision::SquareConfusion() + || 2. * aMinDer < Precision::Confusion()) + { + myintuinf = aF; + myintusup = aL; + IntervalPerform(theP); + } + } + } + if (!Precision::IsInfinite(distmin)) + { + bool isToAdd = true; + NbExt = mypoint.Length(); + for (i = 1; i <= NbExt && isToAdd; i++) + { + double t = mypoint.Value(i).Parameter(); + isToAdd = (distmin < mySqDist(i)) && (std::abs(t - tmin) > mytolu); + } + if (isToAdd) + { + ThePOnC PC(tmin, aPmin); + mySqDist.Append(distmin); + myismin.Append(true); + mypoint.Append(PC); + } + } + } + else + { + int aValIdx = 1; + NCollection_Array1 aVal(1, (mysample) * (aLastUsedKnot - aFirstUsedKnot) + 1); + NCollection_Array1 aParam(1, (mysample) * (aLastUsedKnot - aFirstUsedKnot) + 1); + for (anIdx = aFirstUsedKnot; anIdx < aLastUsedKnot; anIdx++) + { + double aF = aKnots(anIdx) + aPeriodJump, aL = aKnots(anIdx + 1) + aPeriodJump; + + if (anIdx == aFirstUsedKnot) + aF = myuinf; + if (anIdx == aLastUsedKnot - 1) + aL = myusup; + + double aStep = (aL - aF) / mysample; + for (int aPntIdx = 0; aPntIdx < mysample; aPntIdx++) + { + double aCurrentParam = aF + aStep * aPntIdx; + aVal(aValIdx) = TheCurveTool::Value(aCurve, aCurrentParam).SquareDistance(theP); + aParam(aValIdx) = aCurrentParam; + aValIdx++; + } + } + aVal(aValIdx) = TheCurveTool::Value(aCurve, myusup).SquareDistance(theP); + aParam(aValIdx) = myusup; + + myExtPC.Initialize(aCurve); + + for (anIdx = aVal.Lower() + 1; anIdx < aVal.Upper(); anIdx++) + { + if (aVal(anIdx) <= Precision::SquareConfusion()) + { + mySqDist.Append(aVal(anIdx)); + myismin.Append(true); + mypoint.Append(ThePOnC(aParam(anIdx), TheCurveTool::Value(aCurve, aParam(anIdx)))); + } + if ((aVal(anIdx) >= aVal(anIdx + 1) && aVal(anIdx) >= aVal(anIdx - 1)) + || (aVal(anIdx) <= aVal(anIdx + 1) && aVal(anIdx) <= aVal(anIdx - 1))) + { + myintuinf = aParam(anIdx - 1); + myintusup = aParam(anIdx + 1); + IntervalPerform(theP); + } + } + + if (mydist1 > Precision::SquareConfusion() && !Precision::IsPositiveInfinite(mydist1)) + { + ThePoint aP1, aP2; + TheVector aV1, aV2; + TheCurveTool::D1(aCurve, aParam.Value(aParam.Lower()), aP1, aV1); + TheCurveTool::D1(aCurve, aParam.Value(aParam.Lower() + 1), aP2, aV2); + TheVector aBase1(theP, aP1), aBase2(theP, aP2); + double aVal1 = aV1.Dot(aBase1); + double aVal2 = aV2.Dot(aBase2); + if (!(Precision::IsInfinite(aVal1) || Precision::IsInfinite(aVal2))) + { + if (aVal1 * aVal2 <= 0.0 || aBase1.Dot(aBase2) <= 0.0 + || 2.0 * std::abs(aVal1) < Precision::Confusion()) + { + myintuinf = aParam(aVal.Lower()); + myintusup = aParam(aVal.Lower() + 1); + IntervalPerform(theP); + } + } + } + + if (mydist2 > Precision::SquareConfusion() && !Precision::IsPositiveInfinite(mydist2)) + { + ThePoint aP1, aP2; + TheVector aV1, aV2; + TheCurveTool::D1(aCurve, aParam.Value(aParam.Upper() - 1), aP1, aV1); + TheCurveTool::D1(aCurve, aParam.Value(aParam.Upper()), aP2, aV2); + TheVector aBase1(theP, aP1), aBase2(theP, aP2); + double aVal1 = aV1.Dot(aBase1); + double aVal2 = aV2.Dot(aBase2); + + if (!(Precision::IsInfinite(aVal1) || Precision::IsInfinite(aVal2))) + { + if (aVal1 * aVal2 <= 0.0 || aBase1.Dot(aBase2) <= 0.0 + || 2.0 * std::abs(aVal2) < Precision::Confusion()) + { + myintuinf = aParam(aVal.Upper() - 1); + myintusup = aParam(aVal.Upper()); + IntervalPerform(theP); + } + } + } + } + mydone = true; + break; + } + default: { + constexpr int aMaxSample = 17; + bool IntExtIsDone = false; + bool IntIsNotValid; + Handle(TColStd_HArray1OfReal) theHInter; + n = TheCurveTool::NbIntervals(aCurve, GeomAbs_C2); + if (n > 1) + { + theHInter = new TColStd_HArray1OfReal(1, n + 1); + TheCurveTool::Intervals(aCurve, theHInter->ChangeArray1(), GeomAbs_C2); + } + else + { + theHInter = TheCurveTool::DeflCurvIntervals(aCurve); + n = theHInter->Length() - 1; + } + mysample = std::max(mysample / n, aMaxSample); + double maxint = 0.; + for (i = 1; i <= n; ++i) + { + double dt = theHInter->Value(i + 1) - theHInter->Value(i); + if (maxint < dt) + maxint = dt; + } + bool isPeriodic = TheCurveTool::IsPeriodic(aCurve); + TheVector V1; + ThePoint PP; + double s1 = 0.0; + double s2 = 0.0; + myExtPC.Initialize(aCurve); + for (i = 1; i <= n; i++) + { + myintuinf = theHInter->Value(i); + myintusup = theHInter->Value(i + 1); + mysample = std::max(RealToInt(aMaxSample * (myintusup - myintuinf) / maxint), 3); + + double anInfToCheck = myintuinf; + double aSupToCheck = myintusup; + + if (isPeriodic) + { + double aPeriod = TheCurveTool::Period(aCurve); + anInfToCheck = ElCLib::InPeriod(myintuinf, myuinf, myuinf + aPeriod); + aSupToCheck = myintusup + (anInfToCheck - myintuinf); + } + IntIsNotValid = (myuinf > aSupToCheck) || (myusup < anInfToCheck); + + if (IntIsNotValid) + continue; + + if (myuinf >= anInfToCheck) + anInfToCheck = myuinf; + if (myusup <= aSupToCheck) + aSupToCheck = myusup; + if ((aSupToCheck - anInfToCheck) <= mytolu) + continue; + + if (i != 1) + { + TheCurveTool::D1(aCurve, myintuinf, PP, V1); + s1 = (TheVector(theP, PP)) * V1; + if (s1 * s2 < 0.0) + { + mySqDist.Append(PP.SquareDistance(theP)); + myismin.Append((s1 < 0.0)); + mypoint.Append(ThePOnC(myintuinf, PP)); + } + } + if (i != n) + { + TheCurveTool::D1(aCurve, myintusup, PP, V1); + s2 = (TheVector(theP, PP)) * V1; + } + + IntervalPerform(theP); + IntExtIsDone = IntExtIsDone || mydone; + } + + mydone = IntExtIsDone; + break; + } + } + + // Postprocessing + if (type == GeomAbs_BSplineCurve || type == GeomAbs_OffsetCurve || type == GeomAbs_OtherCurve) + { + if (mydist1 < Precision::SquareConfusion() || mydist2 < Precision::SquareConfusion()) + { + bool isFirstAdded = false; + bool isLastAdded = false; + int aNbPoints = mypoint.Length(); + for (i = 1; i <= aNbPoints; i++) + { + U = mypoint.Value(i).Parameter(); + if (std::abs(U - myuinf) < mytolu) + isFirstAdded = true; + else if (std::abs(myusup - U) < mytolu) + isLastAdded = true; + } + if (!isFirstAdded && mydist1 < Precision::SquareConfusion()) + { + mySqDist.Prepend(mydist1); + myismin.Prepend(true); + mypoint.Prepend(ThePOnC(myuinf, Pf)); + } + if (!isLastAdded && mydist2 < Precision::SquareConfusion()) + { + mySqDist.Append(mydist2); + myismin.Append(true); + mypoint.Append(ThePOnC(myusup, Pl)); + } + mydone = true; + } + } + else + { + mydone = myExtPElC.IsDone(); + if (mydone) + { + NbExt = myExtPElC.NbExt(); + for (i = 1; i <= NbExt; i++) + { + ThePOnC PC = myExtPElC.Point(i); + U = PC.Parameter(); + if (TheCurveTool::IsPeriodic(aCurve)) + { + U = ElCLib::InPeriod(U, myuinf, myuinf + TheCurveTool::Period(aCurve)); + } + if ((U >= myuinf - mytolu) && (U <= myusup + mytolu)) + { + PC.SetValues(U, myExtPElC.Point(i).Value()); + mySqDist.Append(myExtPElC.SquareDistance(i)); + myismin.Append(myExtPElC.IsMin(i)); + mypoint.Append(PC); + } + } + } + } + } + + //! Returns true if the distances are found. + bool IsDone() const { return mydone; } + + //! Returns the Nth extremum square distance. + //! @param theN Index of the extremum (1-based) + //! @return Square distance value + double SquareDistance(const int theN) const + { + if ((theN < 1) || (theN > NbExt())) + throw Standard_OutOfRange(); + return mySqDist.Value(theN); + } + + //! Returns the number of extremum distances. + //! @return Number of extrema found + int NbExt() const + { + if (!IsDone()) + throw StdFail_NotDone(); + return mySqDist.Length(); + } + + //! Returns true if the Nth extremum distance is a minimum. + //! @param theN Index of the extremum (1-based) + //! @return true if minimum, false if maximum + bool IsMin(const int theN) const + { + if ((theN < 1) || (theN > NbExt())) + throw Standard_OutOfRange(); + return myismin.Value(theN); + } + + //! Returns the point of the Nth extremum distance. + //! @param theN Index of the extremum (1-based) + //! @return The point on curve + const ThePOnC& Point(const int theN) const + { + if ((theN < 1) || (theN > NbExt())) + throw Standard_OutOfRange(); + return mypoint.Value(theN); + } + + //! Returns the distances at curve endpoints. + //! @param[out] theDist1 Square distance to first point + //! @param[out] theDist2 Square distance to last point + //! @param[out] theP1 First point on curve + //! @param[out] theP2 Last point on curve + void TrimmedSquareDistances(double& theDist1, + double& theDist2, + ThePoint& theP1, + ThePoint& theP2) const + { + theDist1 = mydist1; + theDist2 = mydist2; + theP1 = Pf; + theP2 = Pl; + } + +protected: + //! Performs extremum search on the current interval. + void IntervalPerform(const ThePoint& theP) + { + int i; + double U; + myExtPC.Initialize(mysample, myintuinf, myintusup, mytolu, mytolf); + myExtPC.Perform(theP); + mydone = myExtPC.IsDone(); + if (mydone) + { + int NbExt = myExtPC.NbExt(); + for (i = 1; i <= NbExt; i++) + { + ThePOnC PC = myExtPC.Point(i); + U = PC.Parameter(); + if (TheCurveTool::IsPeriodic(*myC)) + { + U = ElCLib::InPeriod(U, myuinf, myuinf + TheCurveTool::Period(*myC)); + } + if ((U >= myuinf - mytolu) && (U <= myusup + mytolu)) + { + AddSol(U, PC.Value(), myExtPC.SquareDistance(i), myExtPC.IsMin(i)); + } + } + } + } + + //! Adds a solution if not already present. + void AddSol(const double theU, const ThePoint& theP, const double theSqDist, const bool isMin) + { + int i, NbExt = mypoint.Length(); + for (i = 1; i <= NbExt; i++) + { + double t = mypoint.Value(i).Parameter(); + if (std::abs(t - theU) <= mytolu) + { + return; + } + } + ThePOnC PC(theU, theP); + mySqDist.Append(theSqDist); + myismin.Append(isMin); + mypoint.Append(PC); + } + +private: + TheCurve* myC; + ThePoint Pf; + ThePoint Pl; + TheExtPElC myExtPElC; + TheSequenceOfPOnC mypoint; + bool mydone; + double mydist1; + double mydist2; + TheEPC myExtPC; + double mytolu; + double mytolf; + int mysample; + double myintuinf; + double myintusup; + double myuinf; + double myusup; + GeomAbs_CurveType type; + TColStd_SequenceOfBoolean myismin; + TColStd_SequenceOfReal mySqDist; +}; + +#endif // _Extrema_GGExtPC_HeaderFile diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_GGenExtCC.hxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_GGenExtCC.hxx new file mode 100644 index 0000000000..bdda986cca --- /dev/null +++ b/src/ModelingData/TKGeomBase/Extrema/Extrema_GGenExtCC.hxx @@ -0,0 +1,906 @@ +// Created on: 1995-07-18 +// Created by: Modelistation +// 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. + +#ifndef _Extrema_GGenExtCC_HeaderFile +#define _Extrema_GGenExtCC_HeaderFile + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef M_SQRT2 + #define M_SQRT2 1.41421356237309504880168872420969808 +#endif + +//! Template class for computing extremal distances between two curves. +//! The function F(u,v)=distance(C1(u),C2(v)) has an extremum when gradient(f)=0. +//! The algorithm uses Evtushenko's global optimization solver. +//! +//! @tparam TheCurve1 Type of the first curve (e.g., Adaptor3d_Curve) +//! @tparam TheCurveTool1 Tool class for the first curve +//! @tparam TheCurve2 Type of the second curve +//! @tparam TheCurveTool2 Tool class for the second curve +//! @tparam ThePOnC Point on curve type (e.g., Extrema_POnCurv) +//! @tparam ThePoint Point type (e.g., gp_Pnt) +//! @tparam TheExtPC Point-to-curve extremum class (e.g., Extrema_ExtPC) +template +class Extrema_GGenExtCC +{ +public: + DEFINE_STANDARD_ALLOC + + //! Default constructor. + Extrema_GGenExtCC(); + + //! Constructor with two curves. + Extrema_GGenExtCC(const TheCurve1& theC1, const TheCurve2& theC2); + + //! Constructor with two curves and parameter bounds. + Extrema_GGenExtCC(const TheCurve1& theC1, + const TheCurve2& theC2, + const double theUinf, + const double theUsup, + const double theVinf, + const double theVsup); + + //! Sets parameters for computation. + void SetParams(const TheCurve1& theC1, + const TheCurve2& theC2, + const double theUinf, + const double theUsup, + const double theVinf, + const double theVsup); + + //! Sets the tolerance. + void SetTolerance(const double theTol); + + //! Set flag for single extrema computation. + void SetSingleSolutionFlag(const Standard_Boolean theFlag); + + //! Get flag for single extrema computation. + Standard_Boolean GetSingleSolutionFlag() const; + + //! Performs calculations. + void Perform(); + + //! Returns True if the distances are found. + Standard_Boolean IsDone() const; + + //! Returns state of myParallel flag. + Standard_Boolean IsParallel() const; + + //! Returns the number of extremum distances. + int NbExt() const; + + //! Returns the value of the Nth square extremum distance. + double SquareDistance(const int theN = 1) const; + + //! Returns the points of the Nth extremum distance. + void Points(const int theN, ThePOnC& theP1, ThePOnC& theP2) const; + +private: + Standard_Boolean myIsFindSingleSolution; + Standard_Boolean myParallel; + double myCurveMinTol; + math_Vector myLowBorder; + math_Vector myUppBorder; + TColStd_SequenceOfReal myPoints1; + TColStd_SequenceOfReal myPoints2; + Standard_Address myC[2]; + Standard_Boolean myDone; +}; + +//================================================================================================== +// Static helper functions +//================================================================================================== + +namespace +{ +// Comparator, used in std::sort. +inline Standard_Boolean Extrema_GGenExtCC_comp(const gp_XY& theA, const gp_XY& theB) +{ + if (theA.X() < theB.X()) + { + return Standard_True; + } + else + { + if (theA.X() == theB.X()) + { + if (theA.Y() < theB.Y()) + return Standard_True; + } + } + return Standard_False; +} + +inline void Extrema_GGenExtCC_ChangeIntervals(Handle(TColStd_HArray1OfReal)& theInts, + const int theNbInts) +{ + int aNbInts = theInts->Length() - 1; + int aNbAdd = theNbInts - aNbInts; + Handle(TColStd_HArray1OfReal) aNewInts = new TColStd_HArray1OfReal(1, theNbInts + 1); + int aNbLast = theInts->Length(); + int i; + if (aNbInts == 1) + { + aNewInts->SetValue(1, theInts->First()); + aNewInts->SetValue(theNbInts + 1, theInts->Last()); + double dt = (theInts->Last() - theInts->First()) / theNbInts; + double t = theInts->First() + dt; + for (i = 2; i <= theNbInts; ++i, t += dt) + { + aNewInts->SetValue(i, t); + } + theInts = aNewInts; + return; + } + for (i = 1; i <= aNbLast; ++i) + { + aNewInts->SetValue(i, theInts->Value(i)); + } + while (aNbAdd > 0) + { + double anLIntMax = -1.; + int aMaxInd = -1; + for (i = 1; i < aNbLast; ++i) + { + double anL = aNewInts->Value(i + 1) - aNewInts->Value(i); + if (anL > anLIntMax) + { + anLIntMax = anL; + aMaxInd = i; + } + } + + double t = (aNewInts->Value(aMaxInd + 1) + aNewInts->Value(aMaxInd)) / 2.; + for (i = aNbLast; i > aMaxInd; --i) + { + aNewInts->SetValue(i + 1, aNewInts->Value(i)); + } + aNbLast++; + aNbAdd--; + aNewInts->SetValue(aMaxInd + 1, t); + } + theInts = aNewInts; +} + +class Extrema_GGenExtCC_PointsInspector : public NCollection_CellFilter_InspectorXY +{ +public: + typedef gp_XY Target; + + Extrema_GGenExtCC_PointsInspector(const double theTol) + { + myTol = theTol * theTol; + myIsFind = Standard_False; + } + + void ClearFind() { myIsFind = Standard_False; } + + Standard_Boolean isFind() { return myIsFind; } + + void SetCurrent(const gp_XY& theCurPnt) { myCurrent = theCurPnt; } + + NCollection_CellFilter_Action Inspect(const Target& theObject) + { + gp_XY aPt = myCurrent.Subtracted(theObject); + const double aSQDist = aPt.SquareModulus(); + if (aSQDist < myTol) + { + myIsFind = Standard_True; + } + return CellFilter_Keep; + } + +private: + double myTol; + gp_XY myCurrent; + Standard_Boolean myIsFind; +}; + +template +double Extrema_GGenExtCC_ProjPOnC(const ThePointType& theP, TheExtPCType& theProjTool) +{ + double aDist = ::RealLast(); + theProjTool.Perform(theP); + if (theProjTool.IsDone() && theProjTool.NbExt()) + { + for (int i = 1; i <= theProjTool.NbExt(); ++i) + { + double aD = theProjTool.SquareDistance(i); + if (aD < aDist) + aDist = aD; + } + } + return aDist; +} +} // namespace + +//================================================================================================== +// Implementation +//================================================================================================== + +//================================================================================================== + +template +Extrema_GGenExtCC:: + Extrema_GGenExtCC() + : myIsFindSingleSolution(Standard_False), + myParallel(Standard_False), + myCurveMinTol(Precision::PConfusion()), + myLowBorder(1, 2), + myUppBorder(1, 2), + myDone(Standard_False) +{ + myC[0] = myC[1] = 0; +} + +//================================================================================================== + +template +Extrema_GGenExtCC:: + Extrema_GGenExtCC(const TheCurve1& theC1, const TheCurve2& theC2) + : myIsFindSingleSolution(Standard_False), + myParallel(Standard_False), + myCurveMinTol(Precision::PConfusion()), + myLowBorder(1, 2), + myUppBorder(1, 2), + myDone(Standard_False) +{ + myC[0] = (Standard_Address)&theC1; + myC[1] = (Standard_Address)&theC2; + myLowBorder(1) = theC1.FirstParameter(); + myLowBorder(2) = theC2.FirstParameter(); + myUppBorder(1) = theC1.LastParameter(); + myUppBorder(2) = theC2.LastParameter(); +} + +//================================================================================================== + +template +Extrema_GGenExtCC:: + Extrema_GGenExtCC(const TheCurve1& theC1, + const TheCurve2& theC2, + const double theUinf, + const double theUsup, + const double theVinf, + const double theVsup) + : myIsFindSingleSolution(Standard_False), + myParallel(Standard_False), + myCurveMinTol(Precision::PConfusion()), + myLowBorder(1, 2), + myUppBorder(1, 2), + myDone(Standard_False) +{ + myC[0] = (Standard_Address)&theC1; + myC[1] = (Standard_Address)&theC2; + myLowBorder(1) = theUinf; + myLowBorder(2) = theVinf; + myUppBorder(1) = theUsup; + myUppBorder(2) = theVsup; +} + +//================================================================================================== + +template +void Extrema_GGenExtCC::SetParams(const TheCurve1& theC1, + const TheCurve2& theC2, + const double theUinf, + const double theUsup, + const double theVinf, + const double theVsup) +{ + myC[0] = (Standard_Address)&theC1; + myC[1] = (Standard_Address)&theC2; + myLowBorder(1) = theUinf; + myLowBorder(2) = theVinf; + myUppBorder(1) = theUsup; + myUppBorder(2) = theVsup; +} + +//================================================================================================== + +template +void Extrema_GGenExtCC::SetTolerance(const double theTol) +{ + myCurveMinTol = theTol; +} + +//================================================================================================== + +template +void Extrema_GGenExtCC::SetSingleSolutionFlag(const Standard_Boolean theFlag) +{ + myIsFindSingleSolution = theFlag; +} + +//================================================================================================== + +template +Standard_Boolean Extrema_GGenExtCC::GetSingleSolutionFlag() const +{ + return myIsFindSingleSolution; +} + +//================================================================================================== + +template +void Extrema_GGenExtCC::Perform() +{ + myDone = Standard_False; + myParallel = Standard_False; + + TheCurve1& C1 = *(TheCurve1*)myC[0]; + TheCurve2& C2 = *(TheCurve2*)myC[1]; + + int aNbInter[2]; + GeomAbs_Shape aContinuity = GeomAbs_C2; + aNbInter[0] = C1.NbIntervals(aContinuity); + aNbInter[1] = C2.NbIntervals(aContinuity); + + if (aNbInter[0] * aNbInter[1] > 100) + { + aContinuity = GeomAbs_C1; + aNbInter[0] = C1.NbIntervals(aContinuity); + aNbInter[1] = C2.NbIntervals(aContinuity); + } + + double anL[2]; + int indmax = -1, indmin = -1; + const double mult = 20.; + if (!(Precision::IsInfinite(C1.FirstParameter()) || Precision::IsInfinite(C1.LastParameter()) + || Precision::IsInfinite(C2.FirstParameter()) || Precision::IsInfinite(C2.LastParameter()))) + { + anL[0] = GCPnts_AbscissaPoint::Length(C1); + anL[1] = GCPnts_AbscissaPoint::Length(C2); + if (anL[0] / aNbInter[0] > mult * anL[1] / aNbInter[1]) + { + indmax = 0; + indmin = 1; + } + else if (anL[1] / aNbInter[1] > mult * anL[0] / aNbInter[0]) + { + indmax = 1; + indmin = 0; + } + } + int aNbIntOpt = 0; + if (indmax >= 0) + { + aNbIntOpt = RealToInt(anL[indmax] * aNbInter[indmin] / anL[indmin] / (mult / 4.)) + 1; + if (aNbIntOpt > 100 || aNbIntOpt < aNbInter[indmax]) + { + indmax = -1; + } + else + { + if (aNbIntOpt * aNbInter[indmin] > 100) + { + aNbIntOpt = 100 / aNbInter[indmin]; + if (aNbIntOpt < aNbInter[indmax]) + { + indmax = -1; + } + } + } + } + + Handle(TColStd_HArray1OfReal) anIntervals1 = new TColStd_HArray1OfReal(1, aNbInter[0] + 1); + Handle(TColStd_HArray1OfReal) anIntervals2 = new TColStd_HArray1OfReal(1, aNbInter[1] + 1); + C1.Intervals(anIntervals1->ChangeArray1(), aContinuity); + C2.Intervals(anIntervals2->ChangeArray1(), aContinuity); + if (indmax >= 0) + { + if (indmax == 0) + { + Extrema_GGenExtCC_ChangeIntervals(anIntervals1, aNbIntOpt); + aNbInter[0] = anIntervals1->Length() - 1; + } + else + { + Extrema_GGenExtCC_ChangeIntervals(anIntervals2, aNbIntOpt); + aNbInter[1] = anIntervals2->Length() - 1; + } + } + if (C1.IsClosed() && aNbInter[0] == 1) + { + Extrema_GGenExtCC_ChangeIntervals(anIntervals1, 3); + aNbInter[0] = anIntervals1->Length() - 1; + } + if (C2.IsClosed() && aNbInter[1] == 1) + { + Extrema_GGenExtCC_ChangeIntervals(anIntervals2, 3); + aNbInter[1] = anIntervals2->Length() - 1; + } + + const double aMaxLC = 10000.; + double aLC = 100.0; + const double aMaxDer1 = 1.0 / C1.Resolution(1.0); + const double aMaxDer2 = 1.0 / C2.Resolution(1.0); + double aMaxDer = std::max(aMaxDer1, aMaxDer2) * M_SQRT2; + if (aLC > aMaxDer) + aLC = aMaxDer; + + Standard_Boolean isConstLockedFlag = Standard_False; + const double aCR = 0.001; + if (aMaxDer1 / aMaxDer < aCR || aMaxDer2 / aMaxDer < aCR) + { + isConstLockedFlag = Standard_True; + } + if (aMaxDer > aMaxLC) + { + aLC = aMaxLC; + isConstLockedFlag = Standard_True; + } + if (C1.GetType() == GeomAbs_Line) + { + aMaxDer = 1.0 / C2.Resolution(1.0); + if (aLC > aMaxDer) + { + isConstLockedFlag = Standard_True; + aLC = aMaxDer; + } + } + if (C2.GetType() == GeomAbs_Line) + { + aMaxDer = 1.0 / C1.Resolution(1.0); + if (aLC > aMaxDer) + { + isConstLockedFlag = Standard_True; + aLC = aMaxDer; + } + } + + Extrema_GlobOptFuncCCC2 aFunc(C1, C2); + if (aLC < aMaxLC || aMaxDer > aMaxLC) + { + math_Vector aT(1, 2), aG(1, 2); + double aF, aMaxG = 0.; + double t1, t2, dt1, dt2; + int n1 = 21, n2 = 21, i1, i2; + dt1 = (C1.LastParameter() - C1.FirstParameter()) / (n1 - 1); + dt2 = (C2.LastParameter() - C2.FirstParameter()) / (n2 - 1); + for (i1 = 1, t1 = C1.FirstParameter(); i1 <= n1; ++i1, t1 += dt1) + { + aT(1) = t1; + for (i2 = 1, t2 = C2.FirstParameter(); i2 <= n2; ++i2, t2 += dt2) + { + aT(2) = t2; + aFunc.Values(aT, aF, aG); + double aMod = aG(1) * aG(1) + aG(2) * aG(2); + aMaxG = std::max(aMaxG, aMod); + } + } + aMaxG = std::sqrt(aMaxG); + if (aMaxG > aMaxDer) + { + aLC = std::min(aMaxG, aMaxLC); + isConstLockedFlag = Standard_True; + } + if (aMaxG > 100. * aMaxLC) + { + aLC = 100. * aMaxLC; + isConstLockedFlag = Standard_True; + } + else if (aMaxG < 0.1 * aMaxDer) + { + isConstLockedFlag = Standard_True; + } + } + math_GlobOptMin aFinder(&aFunc, myLowBorder, myUppBorder, aLC); + aFinder.SetLipConstState(isConstLockedFlag); + aFinder.SetContinuity(aContinuity == GeomAbs_C2 ? 2 : 1); + double aDiscTol = 1.0e-2; + double aValueTol = 1.0e-2; + double aSameTol = myCurveMinTol / (aDiscTol); + aFinder.SetTol(aDiscTol, aSameTol); + aFinder.SetFunctionalMinimalValue(0.0); + + const double aCellSize = std::max(std::max(anIntervals1->Last() - anIntervals1->First(), + anIntervals2->Last() - anIntervals2->First()) + * Precision::PConfusion() / (2.0 * M_SQRT2), + Precision::PConfusion()); + Extrema_GGenExtCC_PointsInspector anInspector(aCellSize); + NCollection_CellFilter aFilter(aCellSize); + NCollection_Vector aPnts; + + int i, j, k; + math_Vector aFirstBorderInterval(1, 2); + math_Vector aSecondBorderInterval(1, 2); + double aF = RealLast(); + double aCurrF = RealLast(); + for (i = 1; i <= aNbInter[0]; i++) + { + for (j = 1; j <= aNbInter[1]; j++) + { + aFirstBorderInterval(1) = anIntervals1->Value(i); + aFirstBorderInterval(2) = anIntervals2->Value(j); + aSecondBorderInterval(1) = anIntervals1->Value(i + 1); + aSecondBorderInterval(2) = anIntervals2->Value(j + 1); + + aFinder.SetLocalParams(aFirstBorderInterval, aSecondBorderInterval); + aFinder.Perform(GetSingleSolutionFlag()); + + aCurrF = aFinder.GetF(); + if (aCurrF >= aF + aSameTol * aValueTol) + { + continue; + } + + if (aCurrF > aF - aSameTol * aValueTol) + { + if (aCurrF < aF) + aF = aCurrF; + } + else + { + aF = aCurrF; + aFilter.Reset(aCellSize); + aPnts.Clear(); + } + + math_Vector sol(1, 2); + for (k = 1; k <= aFinder.NbExtrema(); k++) + { + aFinder.Points(k, sol); + gp_XY aPnt2d(sol(1), sol(2)); + + gp_XY aXYmin = anInspector.Shift(aPnt2d, -aCellSize); + gp_XY aXYmax = anInspector.Shift(aPnt2d, aCellSize); + + anInspector.ClearFind(); + anInspector.SetCurrent(aPnt2d); + aFilter.Inspect(aXYmin, aXYmax, anInspector); + if (!anInspector.isFind()) + { + aFilter.Add(aPnt2d, aPnt2d); + aPnts.Append(gp_XY(sol(1), sol(2))); + } + } + } + } + + const int aNbSol = aPnts.Length(); + if (aNbSol == 0) + { + myDone = Standard_False; + return; + } + + myDone = Standard_True; + + if (aNbSol == 1) + { + const gp_XY& aSol = aPnts.First(); + myPoints1.Append(aSol.X()); + myPoints2.Append(aSol.Y()); + return; + } + + std::sort(aPnts.begin(), aPnts.end(), Extrema_GGenExtCC_comp); + + TColStd_ListOfInteger aSolutions; + + Standard_Boolean bSaveSolution = Standard_True; + Standard_Boolean bDirsCoinside = Standard_True; + Standard_Boolean bDifferentSolutions = Standard_False; + + Standard_Boolean isParallel = Standard_True; + double aVal = 0.0; + math_Vector aVec(1, 2, 0.0); + + for (int anIdx = 0; anIdx < aNbSol - 1; anIdx++) + { + const gp_XY& aCurrent = aPnts(anIdx); + const gp_XY& aNext = aPnts(anIdx + 1); + + aVec(1) = (aCurrent.X() + aNext.X()) * 0.5; + aVec(2) = (aCurrent.Y() + aNext.Y()) * 0.5; + + aFunc.Value(aVec, aVal); + if (std::abs(aVal - aF) < Precision::Confusion()) + { + if (bSaveSolution) + { + aSolutions.Append(anIdx); + bSaveSolution = Standard_False; + } + } + else + { + isParallel = Standard_False; + aSolutions.Append(anIdx); + bSaveSolution = Standard_True; + } + + if (!bDifferentSolutions) + { + if (aNext.X() > aCurrent.X()) + { + if (aNext.Y() > aCurrent.Y()) + { + bDifferentSolutions = Standard_True; + bDirsCoinside = Standard_True; + } + else if (aNext.Y() < aCurrent.Y()) + { + bDifferentSolutions = Standard_True; + bDirsCoinside = Standard_False; + } + } + } + } + aSolutions.Append(aNbSol - 1); + + if (!bDifferentSolutions) + isParallel = Standard_False; + + if (isParallel) + { + double aT1[2] = {myLowBorder(1), myUppBorder(1)}; + double aT2[2] = {bDirsCoinside ? myLowBorder(2) : myUppBorder(2), + bDirsCoinside ? myUppBorder(2) : myLowBorder(2)}; + + TheExtPC anExtPC1, anExtPC2; + anExtPC1.Initialize(C1, myLowBorder(1), myUppBorder(1)); + anExtPC2.Initialize(C2, myLowBorder(2), myUppBorder(2)); + + for (int iT = 0; isParallel && (iT < 2); ++iT) + { + double aDist1 = + Extrema_GGenExtCC_ProjPOnC(C1.Value(aT1[iT]), anExtPC2); + double aDist2 = + Extrema_GGenExtCC_ProjPOnC(C2.Value(aT2[iT]), anExtPC1); + isParallel = (std::abs(std::min(aDist1, aDist2) - aF * aF) < Precision::Confusion()); + } + } + + if (isParallel) + { + const gp_XY& aSol = aPnts.First(); + myPoints1.Append(aSol.X()); + myPoints2.Append(aSol.Y()); + myParallel = Standard_True; + } + else + { + TColStd_ListIteratorOfListOfInteger aItSol(aSolutions); + for (; aItSol.More(); aItSol.Next()) + { + const gp_XY& aSol = aPnts(aItSol.Value()); + myPoints1.Append(aSol.X()); + myPoints2.Append(aSol.Y()); + } + } +} + +//================================================================================================== + +template +Standard_Boolean Extrema_GGenExtCC::IsDone() const +{ + return myDone; +} + +//================================================================================================== + +template +Standard_Boolean Extrema_GGenExtCC::IsParallel() const +{ + if (!IsDone()) + throw StdFail_NotDone(); + return myParallel; +} + +//================================================================================================== + +template +int Extrema_GGenExtCC::NbExt() const +{ + if (!IsDone()) + throw StdFail_NotDone(); + return myPoints1.Length(); +} + +//================================================================================================== + +template +double Extrema_GGenExtCC::SquareDistance(const int theN) const +{ + if (theN < 1 || theN > NbExt()) + { + throw Standard_OutOfRange(); + } + + return TheCurveTool1::Value(*((TheCurve1*)myC[0]), myPoints1(theN)) + .SquareDistance(TheCurveTool2::Value(*((TheCurve2*)myC[1]), myPoints2(theN))); +} + +//================================================================================================== + +template +void Extrema_GGenExtCC::Points(const int theN, ThePOnC& theP1, ThePOnC& theP2) const +{ + if (theN < 1 || theN > NbExt()) + { + throw Standard_OutOfRange(); + } + + theP1.SetValues(myPoints1(theN), TheCurveTool1::Value(*((TheCurve1*)myC[0]), myPoints1(theN))); + theP2.SetValues(myPoints2(theN), TheCurveTool2::Value(*((TheCurve2*)myC[1]), myPoints2(theN))); +} + +#endif // _Extrema_GGenExtCC_HeaderFile diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_GGenExtPC.hxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_GGenExtPC.hxx new file mode 100644 index 0000000000..4f2f604a6a --- /dev/null +++ b/src/ModelingData/TKGeomBase/Extrema/Extrema_GGenExtPC.hxx @@ -0,0 +1,236 @@ +// Created on: 1995-07-18 +// Created by: Modelistation +// 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. + +#ifndef _Extrema_GGenExtPC_HeaderFile +#define _Extrema_GGenExtPC_HeaderFile + +#include +#include + +#include +#include +#include + +//! Generic class for finding extremal distances between a point and a curve. +//! +//! This template class searches for all parameter values u where the distance +//! function F(u) = distance(P, C(u)) has an extremum, i.e., where dF/du = 0. +//! +//! @tparam TheCurve The curve type (e.g., Adaptor3d_Curve, Adaptor2d_Curve2d) +//! @tparam TheTool The curve tool providing static methods (FirstParameter, LastParameter) +//! @tparam ThePOnC The point-on-curve type (e.g., Extrema_POnCurv, Extrema_POnCurv2d) +//! @tparam ThePoint The point type (e.g., gp_Pnt, gp_Pnt2d) +//! @tparam ThePCF The point-curve function type for extremum computation +template +class Extrema_GGenExtPC +{ +public: + DEFINE_STANDARD_ALLOC + + //! Default constructor. + Extrema_GGenExtPC() + : myDone(false), + myInit(false), + mynbsample(0), + myumin(0.0), + myusup(0.0), + mytolu(0.0), + mytolF(0.0) + { + } + + //! Calculates all extremum distances between point P and curve C. + //! @param theP The point + //! @param theC The curve + //! @param theNbSample Number of sample points for root finding + //! @param theTolU Tolerance on parameter u + //! @param theTolF Tolerance on function value + Extrema_GGenExtPC(const ThePoint& theP, + const TheCurve& theC, + const int theNbSample, + const double theTolU, + const double theTolF) + : myF(theP, theC) + { + Initialize(theC, theNbSample, theTolU, theTolF); + Perform(theP); + } + + //! Calculates all extremum distances in a given parameter range. + //! @param theP The point + //! @param theC The curve + //! @param theNbSample Number of sample points for root finding + //! @param theUmin Lower bound of parameter range + //! @param theUsup Upper bound of parameter range + //! @param theTolU Tolerance on parameter u + //! @param theTolF Tolerance on function value + Extrema_GGenExtPC(const ThePoint& theP, + const TheCurve& theC, + const int theNbSample, + const double theUmin, + const double theUsup, + const double theTolU, + const double theTolF) + : myF(theP, theC) + { + Initialize(theC, theNbSample, theUmin, theUsup, theTolU, theTolF); + Perform(theP); + } + + //! Initializes the algorithm with the full curve parameter range. + //! @param theC The curve + //! @param theNbU Number of sample points + //! @param theTolU Tolerance on parameter u + //! @param theTolF Tolerance on function value + void Initialize(const TheCurve& theC, + const int theNbU, + const double theTolU, + const double theTolF) + { + myInit = true; + mynbsample = theNbU; + mytolu = theTolU; + mytolF = theTolF; + myF.Initialize(theC); + myumin = TheTool::FirstParameter(theC); + myusup = TheTool::LastParameter(theC); + } + + //! Initializes the algorithm with a specified parameter range. + //! @param theC The curve + //! @param theNbU Number of sample points + //! @param theUmin Lower bound of parameter range + //! @param theUsup Upper bound of parameter range + //! @param theTolU Tolerance on parameter u + //! @param theTolF Tolerance on function value + void Initialize(const TheCurve& theC, + const int theNbU, + const double theUmin, + const double theUsup, + const double theTolU, + const double theTolF) + { + myInit = true; + mynbsample = theNbU; + mytolu = theTolU; + mytolF = theTolF; + myF.Initialize(theC); + myumin = theUmin; + myusup = theUsup; + } + + //! Initializes only the parameter range and tolerances. + //! @param theNbU Number of sample points + //! @param theUmin Lower bound of parameter range + //! @param theUsup Upper bound of parameter range + //! @param theTolU Tolerance on parameter u + //! @param theTolF Tolerance on function value + void Initialize(const int theNbU, + const double theUmin, + const double theUsup, + const double theTolU, + const double theTolF) + { + mynbsample = theNbU; + mytolu = theTolU; + mytolF = theTolF; + myumin = theUmin; + myusup = theUsup; + } + + //! Initializes the curve for the function. + //! @param theC The curve + void Initialize(const TheCurve& theC) { myF.Initialize(theC); } + + //! Performs the extremum search for the given point. + //! @param theP The point to find extrema from + void Perform(const ThePoint& theP) + { + myF.SetPoint(theP); + myF.SubIntervalInitialize(myumin, myusup); + myDone = false; + + math_FunctionRoots S(myF, myumin, myusup, mynbsample, mytolu, mytolF, mytolF); + if (!S.IsDone() || S.IsAllNull()) + { + return; + } + + myDone = true; + } + + //! Returns true if the distances are found. + bool IsDone() const { return myDone; } + + //! Returns the number of extremum distances. + //! @return Number of extrema found + int NbExt() const + { + if (!IsDone()) + { + throw StdFail_NotDone(); + } + return myF.NbExt(); + } + + //! Returns the Nth extremum square distance. + //! @param theN Index of the extremum (1-based) + //! @return Square distance value + double SquareDistance(const int theN) const + { + if ((theN < 1) || (theN > NbExt())) + { + throw Standard_OutOfRange(); + } + return myF.SquareDistance(theN); + } + + //! Returns true if the Nth extremum distance is a minimum. + //! @param theN Index of the extremum (1-based) + //! @return true if minimum, false if maximum + bool IsMin(const int theN) const + { + if ((theN < 1) || (theN > NbExt())) + { + throw Standard_OutOfRange(); + } + return myF.IsMin(theN); + } + + //! Returns the point of the Nth extremum distance. + //! @param theN Index of the extremum (1-based) + //! @return The point on curve + const ThePOnC& Point(const int theN) const + { + if ((theN < 1) || (theN > NbExt())) + { + throw Standard_OutOfRange(); + } + return myF.Point(theN); + } + +private: + bool myDone; + bool myInit; + int mynbsample; + double myumin; + double myusup; + double mytolu; + double mytolF; + ThePCF myF; +}; + +#endif // _Extrema_GGenExtPC_HeaderFile diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_GLocateExtPC.gxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_GLocateExtPC.gxx deleted file mode 100644 index 58c9ed2c96..0000000000 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_GLocateExtPC.gxx +++ /dev/null @@ -1,367 +0,0 @@ -// Created on: 1993-12-14 -// Created by: Christophe MARION -// Copyright (c) 1993-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. - -// 05-Jun-00 : hla : meme type de corr. que xab : dans la methode "Perform", -// suppression du test mal a propos "myintuinf > myintusup" avec -// "return" a la suite. -// 05-Sep-95 : xab : correction d'un probleme de determination d'intervalle -// de recherche - -#include Extrema_ELPC_hxx -#include ThePOnC_hxx -#include ThePoint_hxx -#include TheVector_hxx -#include -#include -#include -#include -#include - -//================================================================================================= - -Extrema_GLocateExtPC::Extrema_GLocateExtPC() - : myC(NULL), - mydist2(0.0), - myismin(Standard_False), - myDone(Standard_False), - myumin(0.0), - myusup(0.0), - mytol(0.0), - type(GeomAbs_OtherCurve), - numberext(0) -{ -} - -//================================================================================================= - -Extrema_GLocateExtPC::Extrema_GLocateExtPC(const ThePoint& P, - const TheCurve& C, - const Standard_Real U0, - const Standard_Real TolF) -{ - Initialize(C, TheCurveTool::FirstParameter(C), TheCurveTool::LastParameter(C), TolF); - Perform(P, U0); -} - -//================================================================================================= - -Extrema_GLocateExtPC::Extrema_GLocateExtPC(const ThePoint& P, - const TheCurve& C, - const Standard_Real U0, - const Standard_Real Umin, - const Standard_Real Usup, - const Standard_Real TolF) -{ - Initialize(C, Umin, Usup, TolF); - Perform(P, U0); -} - -//================================================================================================= - -void Extrema_GLocateExtPC::Initialize(const TheCurve& C, - const Standard_Real Umin, - const Standard_Real Usup, - const Standard_Real TolF) -{ - myC = (Standard_Address)&C; - mytol = TolF; - myumin = Umin; - myusup = Usup; - type = TheCurveTool::GetType(C); - Standard_Real tolu = TheCurveTool::Resolution(C, Precision::Confusion()); - if ((type == GeomAbs_BSplineCurve) || (type == GeomAbs_BezierCurve) - || (type == GeomAbs_OffsetCurve) || (type == GeomAbs_OtherCurve)) - { - myLocExtPC.Initialize(C, Umin, Usup, tolu); - } - else - { - myExtremPC.Initialize(C, Umin, Usup, tolu); - } -} - -//================================================================================================= - -void Extrema_GLocateExtPC::Perform(const ThePoint& P, const Standard_Real U0) -{ - Standard_Integer i, i1, i2, inter; - Standard_Real Par, valU, valU2 = RealLast(), local_u0; - Standard_Real myintuinf = 0, myintusup = 0; - local_u0 = U0; - switch (type) - { - case GeomAbs_OtherCurve: - case GeomAbs_OffsetCurve: - case GeomAbs_BSplineCurve: { - // La recherche de l extremum est faite intervalle continu C2 par - // intervalle continu C2 de la courbe - Standard_Integer n = TheCurveTool::NbIntervals(*((TheCurve*)myC), GeomAbs_C2); - TColStd_Array1OfReal theInter(1, n + 1); - TheCurveTool::Intervals(*((TheCurve*)myC), theInter, GeomAbs_C2); - // - // be gentle with the caller - // - if (local_u0 < myumin) - { - local_u0 = myumin; - } - else if (local_u0 > myusup) - { - local_u0 = myusup; - } - // Recherche de l intervalle ou se trouve U0 - Standard_Boolean found = Standard_False; - inter = 1; - while (!found && inter <= n) - { - // Intervalle commun a l intervalle C2 courant de la courbe et a - // l intervalle total de recherche de l'extremum (hla : au cas ou - // myintuinf > myintusup, c est que les 2 intervalles ne s intersectent - // pas, mais il n'y avait aucune raison de sortir en "return") - myintuinf = std::max(theInter(inter), myumin); - myintusup = std::min(theInter(inter + 1), myusup); - if ((local_u0 >= myintuinf) && (local_u0 < myintusup)) - found = Standard_True; - inter++; - } - - if (found) - inter--; // IFV 16.06.00 - inter is increased after found! - - // Essai sur l intervalle trouve - myLocExtPC.Initialize((*((TheCurve*)myC)), myintuinf, myintusup, mytol); - myLocExtPC.Perform(P, local_u0); - myDone = myLocExtPC.IsDone(); - if (myDone) - { - mypp = myLocExtPC.Point(); - myismin = myLocExtPC.IsMin(); - mydist2 = myLocExtPC.SquareDistance(); - } - else - { - Standard_Integer k = 1; - // Essai sur les intervalles alentours: - i1 = inter; - i2 = inter; - Standard_Real s1inf, s2inf, s1sup, s2sup; - ThePoint P1; - TheVector V1; - TheCurveTool::D1(*((TheCurve*)myC), myintuinf, P1, V1); - s2inf = (TheVector(P, P1) * V1); - TheCurveTool::D1(*((TheCurve*)myC), myintusup, P1, V1); - s1sup = (TheVector(P, P1) * V1); - - while (!myDone && (i2 > 0) && (i1 <= n)) - { - i1 = inter + k; - i2 = inter - k; - if (i1 <= n) - { - myintuinf = std::max(theInter(i1), myumin); - myintusup = std::min(theInter(i1 + 1), myusup); - if (myintuinf < myintusup) - { - TheCurveTool::D1(*((TheCurve*)myC), myintuinf, P1, V1); - s2sup = (TheVector(P, P1) * V1); - if (Precision::IsInfinite(s2sup) || Precision::IsInfinite(s1sup)) - { - break; - } - if (s1sup * s2sup <= RealEpsilon()) - { - // extremum: - myDone = Standard_True; - mypp.SetValues(myintuinf, P1); - myismin = (s1sup <= 0.0); - mydist2 = P.SquareDistance(P1); - break; - } - - TheCurveTool::D1(*((TheCurve*)myC), myintusup, P1, V1); - s1sup = (TheVector(P, P1) * V1); - myLocExtPC.Initialize((*((TheCurve*)myC)), myintuinf, myintusup, mytol); - myLocExtPC.Perform(P, (myintuinf + myintusup) * 0.5); - myDone = myLocExtPC.IsDone(); - if (myDone) - { - mypp = myLocExtPC.Point(); - myismin = myLocExtPC.IsMin(); - mydist2 = myLocExtPC.SquareDistance(); - break; - } - } - } - - if (i2 > 0) - { - myintuinf = std::max(theInter(i2), myumin); - myintusup = std::min(theInter(i2 + 1), myusup); - if (myintuinf < myintusup) - { - TheCurveTool::D1(*((TheCurve*)myC), myintusup, P1, V1); - s1inf = (TheVector(P, P1) * V1); - if (Precision::IsInfinite(s2inf) || Precision::IsInfinite(s1inf)) - { - break; - } - if (s1inf * s2inf <= RealEpsilon()) - { - // extremum: - myDone = Standard_True; - mypp.SetValues(myintusup, P1); - myismin = (s1inf <= 0.0); - mydist2 = P.SquareDistance(P1); - break; - } - - TheCurveTool::D1(*((TheCurve*)myC), myintuinf, P1, V1); - s2inf = (TheVector(P, P1) * V1); - myLocExtPC.Initialize((*((TheCurve*)myC)), myintuinf, myintusup, mytol); - myLocExtPC.Perform(P, (myintuinf + myintusup) * 0.5); - myDone = myLocExtPC.IsDone(); - - if (myDone) - { - mypp = myLocExtPC.Point(); - myismin = myLocExtPC.IsMin(); - mydist2 = myLocExtPC.SquareDistance(); - break; - } - } - } - - k++; - } - } - } - - break; - - case GeomAbs_BezierCurve: { - myLocExtPC.Perform(P, U0); - myDone = myLocExtPC.IsDone(); - } - - break; - default: { - myExtremPC.Perform(P); - numberext = 0; - if (myExtremPC.IsDone()) - { - for (i = 1; i <= myExtremPC.NbExt(); i++) - { - Par = myExtremPC.Point(i).Parameter(); - valU = std::abs(Par - U0); - if (valU <= valU2) - { - valU2 = valU; - numberext = i; - myDone = Standard_True; - } - } - } - - if (numberext == 0) - myDone = Standard_False; - - break; - } - } -} - -//================================================================================================= - -Standard_Boolean Extrema_GLocateExtPC::IsDone() const -{ - return myDone; -} - -//================================================================================================= - -Standard_Real Extrema_GLocateExtPC::SquareDistance() const -{ - if (!IsDone()) - { - throw StdFail_NotDone(); - } - Standard_Real d = 0; - if ((type == GeomAbs_BezierCurve)) - { - d = myLocExtPC.SquareDistance(); - } - else if (type == GeomAbs_BSplineCurve || type == GeomAbs_OffsetCurve - || type == GeomAbs_OtherCurve) - { - d = mydist2; - } - else - { - if (numberext != 0) - { - d = myExtremPC.SquareDistance(numberext); - } - } - return d; -} - -//================================================================================================= - -Standard_Boolean Extrema_GLocateExtPC::IsMin() const -{ - if (!IsDone()) - { - throw StdFail_NotDone(); - } - Standard_Boolean b = 0; - if ((type == GeomAbs_BezierCurve)) - { - b = myLocExtPC.IsMin(); - } - else if (type == GeomAbs_BSplineCurve || type == GeomAbs_OffsetCurve - || type == GeomAbs_OtherCurve) - { - b = myismin; - } - else - { - if (numberext != 0) - { - b = myExtremPC.IsMin(numberext); - } - } - return b; -} - -//================================================================================================= - -const ThePOnC& Extrema_GLocateExtPC::Point() const -{ - if (!IsDone()) - { - throw StdFail_NotDone(); - } - if (type == GeomAbs_BezierCurve) - { - return myLocExtPC.Point(); - } - else if (type == GeomAbs_BSplineCurve || type == GeomAbs_OffsetCurve - || type == GeomAbs_OtherCurve) - { - return mypp; - } - return myExtremPC.Point(numberext); -} diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_GLocateExtPC.hxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_GLocateExtPC.hxx new file mode 100644 index 0000000000..be26c07c61 --- /dev/null +++ b/src/ModelingData/TKGeomBase/Extrema/Extrema_GLocateExtPC.hxx @@ -0,0 +1,399 @@ +// Created on: 1993-12-14 +// Created by: Christophe MARION +// Copyright (c) 1993-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. + +#ifndef _Extrema_GLocateExtPC_HeaderFile +#define _Extrema_GLocateExtPC_HeaderFile + +#include +#include + +#include +#include +#include +#include +#include + +#include + +//! Template class for locating extremum of distance between a point and a curve. +//! Calculates the distance with a close point. The close point is defined by +//! the parameter value U0. The function F(u)=distance(P,C(u)) has an extremum +//! when g(u)=dF/du=0. The algorithm searches a zero near the close point. +//! +//! @tparam TheCurve Curve type (e.g., Adaptor3d_Curve, Adaptor2d_Curve2d) +//! @tparam TheCurveTool Tool for curve operations +//! @tparam ThePoint Point type (e.g., gp_Pnt, gp_Pnt2d) +//! @tparam TheVector Vector type (e.g., gp_Vec, gp_Vec2d) +//! @tparam ThePOnC Point on curve type +//! @tparam TheELPC Extended local projection curve type +//! @tparam TheLocEPC Local extremum point curve type +template +class Extrema_GLocateExtPC +{ +public: + DEFINE_STANDARD_ALLOC + + //! Default constructor. + Extrema_GLocateExtPC() + : myC(nullptr), + mydist2(0.0), + myismin(false), + myDone(false), + myumin(0.0), + myusup(0.0), + mytol(0.0), + type(GeomAbs_OtherCurve), + numberext(0) + { + } + + //! Calculates the distance with a close point. + //! The close point is defined by the parameter value U0. + //! TolF is used to decide to stop the iterations. + //! At the nth iteration, the criteria is: abs(Un - Un-1) < TolF. + Extrema_GLocateExtPC(const ThePoint& theP, + const TheCurve& theC, + const double theU0, + const double theTolF) + { + Initialize(theC, + TheCurveTool::FirstParameter(theC), + TheCurveTool::LastParameter(theC), + theTolF); + Perform(theP, theU0); + } + + //! Calculates the distance with a close point. + //! The close point is defined by the parameter value U0. + //! Zeros are searched between Umin and Usup. + //! TolF is used to decide to stop the iterations. + //! At the nth iteration, the criteria is: abs(Un - Un-1) < TolF. + Extrema_GLocateExtPC(const ThePoint& theP, + const TheCurve& theC, + const double theU0, + const double theUmin, + const double theUsup, + const double theTolF) + { + Initialize(theC, theUmin, theUsup, theTolF); + Perform(theP, theU0); + } + + //! Sets the fields of the algorithm. + void Initialize(const TheCurve& theC, + const double theUmin, + const double theUsup, + const double theTolF) + { + myC = const_cast(&theC); + mytol = theTolF; + myumin = theUmin; + myusup = theUsup; + type = TheCurveTool::GetType(theC); + double tolu = TheCurveTool::Resolution(theC, Precision::Confusion()); + if ((type == GeomAbs_BSplineCurve) || (type == GeomAbs_BezierCurve) + || (type == GeomAbs_OffsetCurve) || (type == GeomAbs_OtherCurve)) + { + myLocExtPC.Initialize(theC, theUmin, theUsup, tolu); + } + else + { + myExtremPC.Initialize(theC, theUmin, theUsup, tolu); + } + } + + //! Performs the algorithm with point P and initial parameter U0. + void Perform(const ThePoint& theP, const double theU0) + { + int i, i1, i2, inter; + double Par, valU, valU2 = RealLast(), local_u0; + double myintuinf = 0, myintusup = 0; + local_u0 = theU0; + switch (type) + { + case GeomAbs_OtherCurve: + case GeomAbs_OffsetCurve: + case GeomAbs_BSplineCurve: { + // Search for extremum is done interval by continuous C2 interval + int n = TheCurveTool::NbIntervals(*myC, GeomAbs_C2); + TColStd_Array1OfReal theInter(1, n + 1); + TheCurveTool::Intervals(*myC, theInter, GeomAbs_C2); + // + // be gentle with the caller + // + if (local_u0 < myumin) + { + local_u0 = myumin; + } + else if (local_u0 > myusup) + { + local_u0 = myusup; + } + // Search for interval containing U0 + bool found = false; + inter = 1; + while (!found && inter <= n) + { + myintuinf = std::max(theInter(inter), myumin); + myintusup = std::min(theInter(inter + 1), myusup); + if ((local_u0 >= myintuinf) && (local_u0 < myintusup)) + found = true; + inter++; + } + + if (found) + inter--; // IFV 16.06.00 - inter is increased after found! + + // Try on found interval + myLocExtPC.Initialize(*myC, myintuinf, myintusup, mytol); + myLocExtPC.Perform(theP, local_u0); + myDone = myLocExtPC.IsDone(); + if (myDone) + { + mypp = myLocExtPC.Point(); + myismin = myLocExtPC.IsMin(); + mydist2 = myLocExtPC.SquareDistance(); + } + else + { + int k = 1; + // Try on neighboring intervals: + i1 = inter; + i2 = inter; + double s1inf, s2inf, s1sup, s2sup; + ThePoint P1; + TheVector V1; + TheCurveTool::D1(*myC, myintuinf, P1, V1); + s2inf = (TheVector(theP, P1) * V1); + TheCurveTool::D1(*myC, myintusup, P1, V1); + s1sup = (TheVector(theP, P1) * V1); + + while (!myDone && (i2 > 0) && (i1 <= n)) + { + i1 = inter + k; + i2 = inter - k; + if (i1 <= n) + { + myintuinf = std::max(theInter(i1), myumin); + myintusup = std::min(theInter(i1 + 1), myusup); + if (myintuinf < myintusup) + { + TheCurveTool::D1(*myC, myintuinf, P1, V1); + s2sup = (TheVector(theP, P1) * V1); + if (Precision::IsInfinite(s2sup) || Precision::IsInfinite(s1sup)) + { + break; + } + if (s1sup * s2sup <= RealEpsilon()) + { + // extremum: + myDone = true; + mypp.SetValues(myintuinf, P1); + myismin = (s1sup <= 0.0); + mydist2 = theP.SquareDistance(P1); + break; + } + + TheCurveTool::D1(*myC, myintusup, P1, V1); + s1sup = (TheVector(theP, P1) * V1); + myLocExtPC.Initialize(*myC, myintuinf, myintusup, mytol); + myLocExtPC.Perform(theP, (myintuinf + myintusup) * 0.5); + myDone = myLocExtPC.IsDone(); + if (myDone) + { + mypp = myLocExtPC.Point(); + myismin = myLocExtPC.IsMin(); + mydist2 = myLocExtPC.SquareDistance(); + break; + } + } + } + + if (i2 > 0) + { + myintuinf = std::max(theInter(i2), myumin); + myintusup = std::min(theInter(i2 + 1), myusup); + if (myintuinf < myintusup) + { + TheCurveTool::D1(*myC, myintusup, P1, V1); + s1inf = (TheVector(theP, P1) * V1); + if (Precision::IsInfinite(s2inf) || Precision::IsInfinite(s1inf)) + { + break; + } + if (s1inf * s2inf <= RealEpsilon()) + { + // extremum: + myDone = true; + mypp.SetValues(myintusup, P1); + myismin = (s1inf <= 0.0); + mydist2 = theP.SquareDistance(P1); + break; + } + + TheCurveTool::D1(*myC, myintuinf, P1, V1); + s2inf = (TheVector(theP, P1) * V1); + myLocExtPC.Initialize(*myC, myintuinf, myintusup, mytol); + myLocExtPC.Perform(theP, (myintuinf + myintusup) * 0.5); + myDone = myLocExtPC.IsDone(); + + if (myDone) + { + mypp = myLocExtPC.Point(); + myismin = myLocExtPC.IsMin(); + mydist2 = myLocExtPC.SquareDistance(); + break; + } + } + } + + k++; + } + } + } + + break; + + case GeomAbs_BezierCurve: { + myLocExtPC.Perform(theP, theU0); + myDone = myLocExtPC.IsDone(); + } + + break; + default: { + myExtremPC.Perform(theP); + numberext = 0; + if (myExtremPC.IsDone()) + { + for (i = 1; i <= myExtremPC.NbExt(); i++) + { + Par = myExtremPC.Point(i).Parameter(); + valU = std::abs(Par - theU0); + if (valU <= valU2) + { + valU2 = valU; + numberext = i; + myDone = true; + } + } + } + + if (numberext == 0) + myDone = false; + + break; + } + } + } + + //! Returns True if the distance is found. + bool IsDone() const { return myDone; } + + //! Returns the value of the extremum square distance. + double SquareDistance() const + { + if (!IsDone()) + { + throw StdFail_NotDone(); + } + double d = 0; + if ((type == GeomAbs_BezierCurve)) + { + d = myLocExtPC.SquareDistance(); + } + else if (type == GeomAbs_BSplineCurve || type == GeomAbs_OffsetCurve + || type == GeomAbs_OtherCurve) + { + d = mydist2; + } + else + { + if (numberext != 0) + { + d = myExtremPC.SquareDistance(numberext); + } + } + return d; + } + + //! Returns True if the extremum distance is a minimum. + bool IsMin() const + { + if (!IsDone()) + { + throw StdFail_NotDone(); + } + bool b = false; + if ((type == GeomAbs_BezierCurve)) + { + b = myLocExtPC.IsMin(); + } + else if (type == GeomAbs_BSplineCurve || type == GeomAbs_OffsetCurve + || type == GeomAbs_OtherCurve) + { + b = myismin; + } + else + { + if (numberext != 0) + { + b = myExtremPC.IsMin(numberext); + } + } + return b; + } + + //! Returns the point of the extremum distance. + const ThePOnC& Point() const + { + if (!IsDone()) + { + throw StdFail_NotDone(); + } + if (type == GeomAbs_BezierCurve) + { + return myLocExtPC.Point(); + } + else if (type == GeomAbs_BSplineCurve || type == GeomAbs_OffsetCurve + || type == GeomAbs_OtherCurve) + { + return mypp; + } + return myExtremPC.Point(numberext); + } + +private: + ThePOnC mypp; + TheCurve* myC; + double mydist2; + bool myismin; + bool myDone; + double myumin; + double myusup; + double mytol; + TheLocEPC myLocExtPC; + TheELPC myExtremPC; + GeomAbs_CurveType type; + int numberext; +}; + +#endif // _Extrema_GLocateExtPC_HeaderFile diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_GenExtCC.gxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_GenExtCC.gxx deleted file mode 100644 index 9a7a1fffe6..0000000000 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_GenExtCC.gxx +++ /dev/null @@ -1,701 +0,0 @@ -// Created on: 1995-07-18 -// Created by: Modelistation -// 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 - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifndef M_SQRT2 - #define M_SQRT2 1.41421356237309504880168872420969808 -#endif - -// Comparator, used in std::sort. -static Standard_Boolean comp(const gp_XY& theA, const gp_XY& theB) -{ - if (theA.X() < theB.X()) - { - return Standard_True; - } - else - { - if (theA.X() == theB.X()) - { - if (theA.Y() < theB.Y()) - return Standard_True; - } - } - - return Standard_False; -} - -static void ChangeIntervals(Handle(TColStd_HArray1OfReal)& theInts, - const Standard_Integer theNbInts) -{ - Standard_Integer aNbInts = theInts->Length() - 1; - Standard_Integer aNbAdd = theNbInts - aNbInts; - Handle(TColStd_HArray1OfReal) aNewInts = new TColStd_HArray1OfReal(1, theNbInts + 1); - Standard_Integer aNbLast = theInts->Length(); - Standard_Integer i; - if (aNbInts == 1) - { - aNewInts->SetValue(1, theInts->First()); - aNewInts->SetValue(theNbInts + 1, theInts->Last()); - Standard_Real dt = (theInts->Last() - theInts->First()) / theNbInts; - Standard_Real t = theInts->First() + dt; - for (i = 2; i <= theNbInts; ++i, t += dt) - { - aNewInts->SetValue(i, t); - } - theInts = aNewInts; - return; - } - // - for (i = 1; i <= aNbLast; ++i) - { - aNewInts->SetValue(i, theInts->Value(i)); - } - // - while (aNbAdd > 0) - { - Standard_Real anLIntMax = -1.; - Standard_Integer aMaxInd = -1; - for (i = 1; i < aNbLast; ++i) - { - Standard_Real anL = aNewInts->Value(i + 1) - aNewInts->Value(i); - if (anL > anLIntMax) - { - anLIntMax = anL; - aMaxInd = i; - } - } - - Standard_Real t = (aNewInts->Value(aMaxInd + 1) + aNewInts->Value(aMaxInd)) / 2.; - for (i = aNbLast; i > aMaxInd; --i) - { - aNewInts->SetValue(i + 1, aNewInts->Value(i)); - } - aNbLast++; - aNbAdd--; - aNewInts->SetValue(aMaxInd + 1, t); - } - theInts = aNewInts; -} - -class Extrema_CCPointsInspector : public NCollection_CellFilter_InspectorXY -{ -public: - typedef gp_XY Target; - - //! Constructor; remembers the tolerance - Extrema_CCPointsInspector(const Standard_Real theTol) - { - myTol = theTol * theTol; - myIsFind = Standard_False; - } - - void ClearFind() { myIsFind = Standard_False; } - - Standard_Boolean isFind() { return myIsFind; } - - //! Set current point to search for coincidence - void SetCurrent(const gp_XY& theCurPnt) { myCurrent = theCurPnt; } - - //! Implementation of inspection method - NCollection_CellFilter_Action Inspect(const Target& theObject) - { - gp_XY aPt = myCurrent.Subtracted(theObject); - const Standard_Real aSQDist = aPt.SquareModulus(); - if (aSQDist < myTol) - { - myIsFind = Standard_True; - } - - return CellFilter_Keep; - } - -private: - Standard_Real myTol; - gp_XY myCurrent; - Standard_Boolean myIsFind; -}; - -//======================================================================= -// function : ProjPOnC -// purpose : Projects the point on the curve and returns the minimal -// projection distance -//======================================================================= -static Standard_Real ProjPOnC(const Pnt& theP, Extrema_GExtPC& theProjTool) -{ - Standard_Real aDist = ::RealLast(); - theProjTool.Perform(theP); - if (theProjTool.IsDone() && theProjTool.NbExt()) - { - for (Standard_Integer i = 1; i <= theProjTool.NbExt(); ++i) - { - Standard_Real aD = theProjTool.SquareDistance(i); - if (aD < aDist) - aDist = aD; - } - } - return aDist; -} - -//================================================================================================= - -Extrema_GenExtCC::Extrema_GenExtCC() - : myIsFindSingleSolution(Standard_False), - myParallel(Standard_False), - myCurveMinTol(Precision::PConfusion()), - myLowBorder(1, 2), - myUppBorder(1, 2), - myDone(Standard_False) -{ - myC[0] = myC[1] = 0; -} - -//================================================================================================= - -Extrema_GenExtCC::Extrema_GenExtCC(const Curve1& C1, const Curve2& C2) - : myIsFindSingleSolution(Standard_False), - myParallel(Standard_False), - myCurveMinTol(Precision::PConfusion()), - myLowBorder(1, 2), - myUppBorder(1, 2), - myDone(Standard_False) -{ - myC[0] = (Standard_Address)&C1; - myC[1] = (Standard_Address)&C2; - myLowBorder(1) = C1.FirstParameter(); - myLowBorder(2) = C2.FirstParameter(); - myUppBorder(1) = C1.LastParameter(); - myUppBorder(2) = C2.LastParameter(); -} - -//================================================================================================= - -Extrema_GenExtCC::Extrema_GenExtCC(const Curve1& C1, - const Curve2& C2, - const Standard_Real Uinf, - const Standard_Real Usup, - const Standard_Real Vinf, - const Standard_Real Vsup) - : myIsFindSingleSolution(Standard_False), - myParallel(Standard_False), - myCurveMinTol(Precision::PConfusion()), - myLowBorder(1, 2), - myUppBorder(1, 2), - myDone(Standard_False) -{ - myC[0] = (Standard_Address)&C1; - myC[1] = (Standard_Address)&C2; - myLowBorder(1) = Uinf; - myLowBorder(2) = Vinf; - myUppBorder(1) = Usup; - myUppBorder(2) = Vsup; -} - -//================================================================================================= - -void Extrema_GenExtCC::SetParams(const Curve1& C1, - const Curve2& C2, - const Standard_Real Uinf, - const Standard_Real Usup, - const Standard_Real Vinf, - const Standard_Real Vsup) -{ - myC[0] = (Standard_Address)&C1; - myC[1] = (Standard_Address)&C2; - myLowBorder(1) = Uinf; - myLowBorder(2) = Vinf; - myUppBorder(1) = Usup; - myUppBorder(2) = Vsup; -} - -//================================================================================================= - -void Extrema_GenExtCC::SetTolerance(Standard_Real theTol) -{ - myCurveMinTol = theTol; -} - -//================================================================================================= - -void Extrema_GenExtCC::Perform() -{ - myDone = Standard_False; - myParallel = Standard_False; - - Curve1& C1 = *(Curve1*)myC[0]; - Curve2& C2 = *(Curve2*)myC[1]; - - Standard_Integer aNbInter[2]; - GeomAbs_Shape aContinuity = GeomAbs_C2; - aNbInter[0] = C1.NbIntervals(aContinuity); - aNbInter[1] = C2.NbIntervals(aContinuity); - - if (aNbInter[0] * aNbInter[1] > 100) - { - aContinuity = GeomAbs_C1; - aNbInter[0] = C1.NbIntervals(aContinuity); - aNbInter[1] = C2.NbIntervals(aContinuity); - } - - Standard_Real anL[2]; - Standard_Integer indmax = -1, indmin = -1; - const Standard_Real mult = 20.; - if (!(Precision::IsInfinite(C1.FirstParameter()) || Precision::IsInfinite(C1.LastParameter()) - || Precision::IsInfinite(C2.FirstParameter()) || Precision::IsInfinite(C2.LastParameter()))) - { - anL[0] = GCPnts_AbscissaPoint::Length(C1); - anL[1] = GCPnts_AbscissaPoint::Length(C2); - if (anL[0] / aNbInter[0] > mult * anL[1] / aNbInter[1]) - { - indmax = 0; - indmin = 1; - } - else if (anL[1] / aNbInter[1] > mult * anL[0] / aNbInter[0]) - { - indmax = 1; - indmin = 0; - } - } - Standard_Integer aNbIntOpt = 0; - if (indmax >= 0) - { - aNbIntOpt = RealToInt(anL[indmax] * aNbInter[indmin] / anL[indmin] / (mult / 4.)) + 1; - if (aNbIntOpt > 100 || aNbIntOpt < aNbInter[indmax]) - { - indmax = -1; - } - else - { - if (aNbIntOpt * aNbInter[indmin] > 100) - { - aNbIntOpt = 100 / aNbInter[indmin]; - if (aNbIntOpt < aNbInter[indmax]) - { - indmax = -1; - } - } - } - } - - Handle(TColStd_HArray1OfReal) anIntervals1 = new TColStd_HArray1OfReal(1, aNbInter[0] + 1); - Handle(TColStd_HArray1OfReal) anIntervals2 = new TColStd_HArray1OfReal(1, aNbInter[1] + 1); - C1.Intervals(anIntervals1->ChangeArray1(), aContinuity); - C2.Intervals(anIntervals2->ChangeArray1(), aContinuity); - if (indmax >= 0) - { - if (indmax == 0) - { - // Change anIntervals1 - ChangeIntervals(anIntervals1, aNbIntOpt); - aNbInter[0] = anIntervals1->Length() - 1; - } - else - { - // Change anIntervals2; - ChangeIntervals(anIntervals2, aNbIntOpt); - aNbInter[1] = anIntervals2->Length() - 1; - } - } - if (C1.IsClosed() && aNbInter[0] == 1) - { - ChangeIntervals(anIntervals1, 3); - aNbInter[0] = anIntervals1->Length() - 1; - } - if (C2.IsClosed() && aNbInter[1] == 1) - { - ChangeIntervals(anIntervals2, 3); - aNbInter[1] = anIntervals2->Length() - 1; - } - - // Lipchitz constant computation. - const Standard_Real aMaxLC = 10000.; - Standard_Real aLC = 100.0; // Default value. - const Standard_Real aMaxDer1 = 1.0 / C1.Resolution(1.0); - const Standard_Real aMaxDer2 = 1.0 / C2.Resolution(1.0); - Standard_Real aMaxDer = std::max(aMaxDer1, aMaxDer2) * M_SQRT2; - if (aLC > aMaxDer) - aLC = aMaxDer; - - // Change constant value according to the concrete curve types. - Standard_Boolean isConstLockedFlag = Standard_False; - // To prevent LipConst to became too small - const Standard_Real aCR = 0.001; - if (aMaxDer1 / aMaxDer < aCR || aMaxDer2 / aMaxDer < aCR) - { - isConstLockedFlag = Standard_True; - } - if (aMaxDer > aMaxLC) - { - aLC = aMaxLC; - isConstLockedFlag = Standard_True; - } - if (C1.GetType() == GeomAbs_Line) - { - aMaxDer = 1.0 / C2.Resolution(1.0); - if (aLC > aMaxDer) - { - isConstLockedFlag = Standard_True; - aLC = aMaxDer; - } - } - if (C2.GetType() == GeomAbs_Line) - { - aMaxDer = 1.0 / C1.Resolution(1.0); - if (aLC > aMaxDer) - { - isConstLockedFlag = Standard_True; - aLC = aMaxDer; - } - } - - Extrema_GlobOptFuncCCC2 aFunc(C1, C2); - if (aLC < aMaxLC || aMaxDer > aMaxLC) - { - // Estimation of Lipschitz constant by gradient of optimization function - // using sampling in parameter space. - math_Vector aT(1, 2), aG(1, 2); - Standard_Real aF, aMaxG = 0.; - Standard_Real t1, t2, dt1, dt2; - Standard_Integer n1 = 21, n2 = 21, i1, i2; - dt1 = (C1.LastParameter() - C1.FirstParameter()) / (n1 - 1); - dt2 = (C2.LastParameter() - C2.FirstParameter()) / (n2 - 1); - for (i1 = 1, t1 = C1.FirstParameter(); i1 <= n1; ++i1, t1 += dt1) - { - aT(1) = t1; - for (i2 = 1, t2 = C2.FirstParameter(); i2 <= n2; ++i2, t2 += dt2) - { - aT(2) = t2; - aFunc.Values(aT, aF, aG); - Standard_Real aMod = aG(1) * aG(1) + aG(2) * aG(2); - aMaxG = std::max(aMaxG, aMod); - } - } - aMaxG = std::sqrt(aMaxG); - if (aMaxG > aMaxDer) - { - aLC = std::min(aMaxG, aMaxLC); - isConstLockedFlag = Standard_True; - } - if (aMaxG > 100. * aMaxLC) - { - aLC = 100. * aMaxLC; - isConstLockedFlag = Standard_True; - } - else if (aMaxG < 0.1 * aMaxDer) - { - isConstLockedFlag = Standard_True; - } - } - math_GlobOptMin aFinder(&aFunc, myLowBorder, myUppBorder, aLC); - aFinder.SetLipConstState(isConstLockedFlag); - aFinder.SetContinuity(aContinuity == GeomAbs_C2 ? 2 : 1); - Standard_Real aDiscTol = 1.0e-2; - Standard_Real aValueTol = 1.0e-2; - Standard_Real aSameTol = myCurveMinTol / (aDiscTol); - aFinder.SetTol(aDiscTol, aSameTol); - aFinder.SetFunctionalMinimalValue(0.0); // Best distance cannot be lower than 0.0. - - // Size computed to have cell index inside of int32 value. - const Standard_Real aCellSize = std::max(std::max(anIntervals1->Last() - anIntervals1->First(), - anIntervals2->Last() - anIntervals2->First()) - * Precision::PConfusion() / (2.0 * M_SQRT2), - Precision::PConfusion()); - Extrema_CCPointsInspector anInspector(aCellSize); - NCollection_CellFilter aFilter(aCellSize); - NCollection_Vector aPnts; - - Standard_Integer i, j, k; - math_Vector aFirstBorderInterval(1, 2); - math_Vector aSecondBorderInterval(1, 2); - Standard_Real aF = RealLast(); // Best functional value. - Standard_Real aCurrF = RealLast(); // Current functional value computed on current interval. - for (i = 1; i <= aNbInter[0]; i++) - { - for (j = 1; j <= aNbInter[1]; j++) - { - aFirstBorderInterval(1) = anIntervals1->Value(i); - aFirstBorderInterval(2) = anIntervals2->Value(j); - aSecondBorderInterval(1) = anIntervals1->Value(i + 1); - aSecondBorderInterval(2) = anIntervals2->Value(j + 1); - - aFinder.SetLocalParams(aFirstBorderInterval, aSecondBorderInterval); - aFinder.Perform(GetSingleSolutionFlag()); - - // Check that solution found on current interval is not worse than previous. - aCurrF = aFinder.GetF(); - if (aCurrF >= aF + aSameTol * aValueTol) - { - continue; - } - - // Clean previously computed solution if current one is better. - if (aCurrF > aF - aSameTol * aValueTol) - { - if (aCurrF < aF) - aF = aCurrF; - } - else - { - aF = aCurrF; - aFilter.Reset(aCellSize); - aPnts.Clear(); - } - - // Save found solutions avoiding repetitions. - math_Vector sol(1, 2); - for (k = 1; k <= aFinder.NbExtrema(); k++) - { - aFinder.Points(k, sol); - gp_XY aPnt2d(sol(1), sol(2)); - - gp_XY aXYmin = anInspector.Shift(aPnt2d, -aCellSize); - gp_XY aXYmax = anInspector.Shift(aPnt2d, aCellSize); - - anInspector.ClearFind(); - anInspector.SetCurrent(aPnt2d); - aFilter.Inspect(aXYmin, aXYmax, anInspector); - if (!anInspector.isFind()) - { - // Point is out of close cells, add new one. - aFilter.Add(aPnt2d, aPnt2d); - aPnts.Append(gp_XY(sol(1), sol(2))); - } - } - } - } - - const Standard_Integer aNbSol = aPnts.Length(); - if (aNbSol == 0) - { - // No solutions. - myDone = Standard_False; - return; - } - - myDone = Standard_True; - - if (aNbSol == 1) - { - // Single solution - const gp_XY& aSol = aPnts.First(); - myPoints1.Append(aSol.X()); - myPoints2.Append(aSol.Y()); - return; - } - - // More than one solution is found. - // Check for infinity solutions case, for this: - // Sort points lexicographically and check midpoint between each two neighboring points. - // If all midpoints functional value is acceptable then check the projection distances - // of the bounding points of the curves onto the opposite curves. - // If these distances are also acceptable set myParallel flag to true and return one solution. - std::sort(aPnts.begin(), aPnts.end(), comp); - - // Solutions to pass into result. - // If the parallel segment is found, save only extreme solutions on that segment. - // The first and last solutions will always be the extreme ones, thus save them unconditionally. - TColStd_ListOfInteger aSolutions; - - // Manages the addition of the solution into result. - // Set it to TRUE to add the first solution. - Standard_Boolean bSaveSolution = Standard_True; - - // Define direction of the second curve relatively the first one - // (it will be needed for projection). - Standard_Boolean bDirsCoinside = Standard_True; - // Check also if the found solutions are not concentrated in one point - // on any of the curves. And if they are, avoid marking the curves as parallel. - Standard_Boolean bDifferentSolutions = Standard_False; - - Standard_Boolean isParallel = Standard_True; - Standard_Real aVal = 0.0; - math_Vector aVec(1, 2, 0.0); - - // Iterate on all solutions and collect the extreme solutions on all parallel segments. - for (Standard_Integer anIdx = 0; anIdx < aNbSol - 1; anIdx++) - { - const gp_XY& aCurrent = aPnts(anIdx); - const gp_XY& aNext = aPnts(anIdx + 1); - - aVec(1) = (aCurrent.X() + aNext.X()) * 0.5; - aVec(2) = (aCurrent.Y() + aNext.Y()) * 0.5; - - aFunc.Value(aVec, aVal); - if (std::abs(aVal - aF) < Precision::Confusion()) - { - // It seems the parallel segment is found. - // Save only extreme solutions on that segment. - if (bSaveSolution) - { - // Add current solution as the beginning of the parallel segment. - aSolutions.Append(anIdx); - // Do not keep the next solution in current parallel segment. - bSaveSolution = Standard_False; - } - } - else - { - // Mid point does not satisfy the tolerance criteria, curves are not parallel. - isParallel = Standard_False; - // Add current solution as the last one in previous parallel segment. - aSolutions.Append(anIdx); - // Save also the next solution as the first one in next parallel segment. - bSaveSolution = Standard_True; - } - - if (!bDifferentSolutions) - { - if (aNext.X() > aCurrent.X()) - { - if (aNext.Y() > aCurrent.Y()) - { - bDifferentSolutions = Standard_True; - bDirsCoinside = Standard_True; - } - else if (aNext.Y() < aCurrent.Y()) - { - bDifferentSolutions = Standard_True; - bDirsCoinside = Standard_False; - } - } - } - } - // Save the last solution - aSolutions.Append(aNbSol - 1); - - if (!bDifferentSolutions) - isParallel = Standard_False; - - if (isParallel) - { - // For the check on parallel case it is also necessary to check additionally - // if the ends of the curves do not diverge. For this, project the bounding - // points of the curves on the opposite curves and check the distances. - - Standard_Real aT1[2] = {myLowBorder(1), myUppBorder(1)}; - Standard_Real aT2[2] = {bDirsCoinside ? myLowBorder(2) : myUppBorder(2), - bDirsCoinside ? myUppBorder(2) : myLowBorder(2)}; - - Extrema_GExtPC anExtPC1, anExtPC2; - anExtPC1.Initialize(C1, myLowBorder(1), myUppBorder(1)); - anExtPC2.Initialize(C2, myLowBorder(2), myUppBorder(2)); - - for (Standard_Integer iT = 0; isParallel && (iT < 2); ++iT) - { - Standard_Real aDist1 = ProjPOnC(C1.Value(aT1[iT]), anExtPC2); - Standard_Real aDist2 = ProjPOnC(C2.Value(aT2[iT]), anExtPC1); - isParallel = (std::abs(std::min(aDist1, aDist2) - aF * aF) < Precision::Confusion()); - } - } - - if (isParallel) - { - // Keep only one solution - const gp_XY& aSol = aPnts.First(); - myPoints1.Append(aSol.X()); - myPoints2.Append(aSol.Y()); - myParallel = Standard_True; - } - else - { - // Keep all saved solutions - TColStd_ListIteratorOfListOfInteger aItSol(aSolutions); - for (; aItSol.More(); aItSol.Next()) - { - const gp_XY& aSol = aPnts(aItSol.Value()); - myPoints1.Append(aSol.X()); - myPoints2.Append(aSol.Y()); - } - } -} - -//================================================================================================= - -Standard_Boolean Extrema_GenExtCC::IsDone() const -{ - return myDone; -} - -//================================================================================================= - -Standard_Boolean Extrema_GenExtCC::IsParallel() const -{ - if (!IsDone()) - throw StdFail_NotDone(); - return myParallel; -} - -//================================================================================================= - -Standard_Integer Extrema_GenExtCC::NbExt() const -{ - if (!IsDone()) - throw StdFail_NotDone(); - return myPoints1.Length(); -} - -//================================================================================================= - -Standard_Real Extrema_GenExtCC::SquareDistance(const Standard_Integer N) const -{ - if (N < 1 || N > NbExt()) - { - throw Standard_OutOfRange(); - } - - return Tool1::Value(*((Curve1*)myC[0]), myPoints1(N)) - .SquareDistance(Tool2::Value(*((Curve2*)myC[1]), myPoints2(N))); -} - -//================================================================================================= - -void Extrema_GenExtCC::Points(const Standard_Integer N, POnC& P1, POnC& P2) const -{ - if (N < 1 || N > NbExt()) - { - throw Standard_OutOfRange(); - } - - P1.SetValues(myPoints1(N), Tool1::Value(*((Curve1*)myC[0]), myPoints1(N))); - P2.SetValues(myPoints2(N), Tool2::Value(*((Curve2*)myC[1]), myPoints2(N))); -} - -//================================================================================================= - -void Extrema_GenExtCC::SetSingleSolutionFlag(const Standard_Boolean theFlag) -{ - myIsFindSingleSolution = theFlag; -} - -//================================================================================================= - -Standard_Boolean Extrema_GenExtCC::GetSingleSolutionFlag() const -{ - return myIsFindSingleSolution; -} diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_GenExtPC.gxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_GenExtPC.gxx deleted file mode 100644 index fde83f080e..0000000000 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_GenExtPC.gxx +++ /dev/null @@ -1,213 +0,0 @@ -// Created on: 1995-07-18 -// Created by: Modelistation -// 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 -#include -#include -#include -#include - -//================================================================================================= - -Extrema_GenExtPC::Extrema_GenExtPC() - : myDone(Standard_False), - myInit(Standard_False), - mynbsample(0), - myumin(0.0), - myusup(0.0), - mytolu(0.0), - mytolF(0.0) -{ -} - -//================================================================================================= - -Extrema_GenExtPC::Extrema_GenExtPC(const Pnt& P, - const Curve& C, - const Standard_Integer NbSample, - const Standard_Real TolU, - const Standard_Real TolF) - : myF(P, C) -{ - Initialize(C, NbSample, TolU, TolF); - Perform(P); -} - -//================================================================================================= - -Extrema_GenExtPC::Extrema_GenExtPC(const Pnt& P, - const Curve& C, - const Standard_Integer NbSample, - const Standard_Real Umin, - const Standard_Real Usup, - const Standard_Real TolU, - const Standard_Real TolF) - : myF(P, C) -{ - Initialize(C, NbSample, Umin, Usup, TolU, TolF); - Perform(P); -} - -//================================================================================================= - -void Extrema_GenExtPC::Initialize(const Curve& C, - const Standard_Integer NbU, - const Standard_Real TolU, - const Standard_Real TolF) -{ - myInit = Standard_True; - mynbsample = NbU; - mytolu = TolU; - mytolF = TolF; - myF.Initialize(C); - myumin = Tool::FirstParameter(C); - myusup = Tool::LastParameter(C); -} - -//================================================================================================= - -void Extrema_GenExtPC::Initialize(const Curve& C, - const Standard_Integer NbU, - const Standard_Real Umin, - const Standard_Real Usup, - const Standard_Real TolU, - const Standard_Real TolF) -{ - myInit = Standard_True; - mynbsample = NbU; - mytolu = TolU; - mytolF = TolF; - myF.Initialize(C); - myumin = Umin; - myusup = Usup; -} - -//================================================================================================= - -void Extrema_GenExtPC::Initialize(const Standard_Integer NbU, - const Standard_Real Umin, - const Standard_Real Usup, - const Standard_Real TolU, - const Standard_Real TolF) -{ - mynbsample = NbU; - mytolu = TolU; - mytolF = TolF; - myumin = Umin; - myusup = Usup; -} - -//================================================================================================= - -void Extrema_GenExtPC::Initialize(const Curve& C) -{ - myF.Initialize(C); -} - -//================================================================================================= - -void Extrema_GenExtPC::Perform(const Pnt& P) -/*----------------------------------------------------------------------------- -Fonction: - Recherche des valeurs de parametre u telle que dist(P,C(u)) passe - par un extremum. - -Methode: - Si U est solution, alors (C(U)-P).C'(U) = 0. - Le probleme consiste a rechercher les racines de cette fonction - dans l'intervalle de definition de la courbe. - On utilise la classe math_FunctionRoots avec les arguments de - construction suivant: - - F: Extrema_FuncExtPC cree a partir de P et C, - - Uinf: borne inferieure de l'intervalle de definition, - - Usup: borne superieure de l'intervalle de definition, - - NbSample, - - TolU, - - TolF, - - TolF. ------------------------------------------------------------------------------*/ -{ - myF.SetPoint(P); - myF.SubIntervalInitialize(myumin, myusup); - myDone = Standard_False; - - math_FunctionRoots S(myF, myumin, myusup, mynbsample, mytolu, mytolF, mytolF); - if (!S.IsDone() || S.IsAllNull()) - { - return; - } - - myDone = Standard_True; -} - -//================================================================================================= - -Standard_Boolean Extrema_GenExtPC::IsDone() const -{ - - return myDone; -} - -//================================================================================================= - -Standard_Integer Extrema_GenExtPC::NbExt() const -{ - - if (!IsDone()) - { - throw StdFail_NotDone(); - } - return myF.NbExt(); -} - -//================================================================================================= - -Standard_Real Extrema_GenExtPC::SquareDistance(const Standard_Integer N) const -{ - if ((N < 1) || (N > NbExt())) - { - throw Standard_OutOfRange(); - } - - return myF.SquareDistance(N); -} - -//================================================================================================= - -Standard_Boolean Extrema_GenExtPC::IsMin(const Standard_Integer N) const -{ - - if ((N < 1) || (N > NbExt())) - { - throw Standard_OutOfRange(); - } - - return myF.IsMin(N); -} - -//================================================================================================= - -const POnC& Extrema_GenExtPC::Point(const Standard_Integer N) const -{ - if ((N < 1) || (N > NbExt())) - { - throw Standard_OutOfRange(); - } - - return myF.Point(N); -} - -//============================================================================= diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_GenLocateExtCC.gxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_GenLocateExtCC.gxx deleted file mode 100644 index 250881ca86..0000000000 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_GenLocateExtCC.gxx +++ /dev/null @@ -1,139 +0,0 @@ -// Created on: 1995-07-18 -// Created by: Modelistation -// 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 -#include -#include - -//================================================================================================= - -Extrema_GenLocateExtCC::Extrema_GenLocateExtCC(const Curve1& C1, - const Curve2& C2, - const Standard_Real U0, - const Standard_Real V0, - const Standard_Real TolU, - const Standard_Real TolV) -/*----------------------------------------------------------------------------- -Fonction: - Recherche du couple de valeurs de parametre (U,V) tel que: - - dist(C1(u),C2(v)) passe par un extremum, - - (U,V) soit la solution la plus proche de (U0,V0). - -Methode: - Si (u,v) est solution, alors: - { F1(u,v)=(C1(u)-C2(v)).dC1/du(u) = 0. - { F2(u,v)=(C1(u)-C2(v)).dC2/dv(v) = 0. - Le probleme consiste a rechercher, dans les intervalles de definition - des courbes, la racine du systeme la plus proche de (U0,V0). - On utilise la classe math_FunctionSetRoot avec les arguments de construction - suivants: - - F: Extrema_FuncExtCC cree a partir de C1 et C2, - - math_Vector(U0,V0), - - math_Vector(TolU,TolV), - - math_Vector(Uinf,Usup), - - math_Vector(Vinf,Vsup), - - 100. . ------------------------------------------------------------------------------*/ -{ - myDone = Standard_False; - mySqDist = RealLast(); - - Standard_Real Uinf = Tool1::FirstParameter(C1); - Standard_Real Usup = Tool1::LastParameter(C1); - Standard_Real Uu; - if (Uinf > Usup) - { - Uu = Uinf; - Uinf = Usup; - Usup = Uu; - } - - Standard_Real Vinf = Tool2::FirstParameter(C2); - Standard_Real Vsup = Tool2::LastParameter(C2); - if (Vinf > Vsup) - { - Uu = Vinf; - Vinf = Vsup; - Vsup = Uu; - } - - Extrema_CCLocF F(C1, C2); - math_Vector Tol(1, 2); - Tol(1) = TolU; - Tol(2) = TolV; - Standard_Real Tolf = 1.e-10; - - math_Vector Start(1, 2); - math_Vector Uuinf(1, 2); - math_Vector Uusup(1, 2); - - Start(1) = U0; - Start(2) = V0; - - Uuinf(1) = Uinf; - Uuinf(2) = Vinf; - Uusup(1) = Usup; - Uusup(2) = Vsup; - - math_FunctionSetRoot S(F, Tol); - S.Perform(F, Start, Uuinf, Uusup); - - if (S.IsDone() && F.NbExt() > 0) - { - mySqDist = F.SquareDistance(1); - F.Points(1, myPoint1, myPoint2); - Start(1) = myPoint1.Parameter(); - Start(2) = myPoint2.Parameter(); - math_Vector Ff(1, 2); - F.Value(Start, Ff); - // cout << "Ff(1) = "<