0032485: Modeling Algorithms - Add Clone() function for adapters
[occt.git] / src / GeomEvaluator / GeomEvaluator_OffsetCurve.hxx
1 // Created on: 2015-09-21
2 // Copyright (c) 2015 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #ifndef _GeomEvaluator_OffsetCurve_HeaderFile
16 #define _GeomEvaluator_OffsetCurve_HeaderFile
17
18 #include <Geom_Curve.hxx>
19 #include <GeomAdaptor_Curve.hxx>
20 #include <GeomEvaluator_Curve.hxx>
21 #include <gp_Dir.hxx>
22
23 //! Allows to calculate values and derivatives for offset curves in 3D
24 class GeomEvaluator_OffsetCurve : public GeomEvaluator_Curve
25 {
26 public:
27   //! Initialize evaluator by curve
28   Standard_EXPORT GeomEvaluator_OffsetCurve(
29       const Handle(Geom_Curve)& theBase,
30       const Standard_Real theOffset,
31       const gp_Dir& theDirection);
32   //! Initialize evaluator by curve adaptor
33   Standard_EXPORT GeomEvaluator_OffsetCurve(
34       const Handle(GeomAdaptor_Curve)& theBase,
35       const Standard_Real theOffset,
36       const gp_Dir& theDirection);
37
38   //! Change the offset value
39   void SetOffsetValue(Standard_Real theOffset)
40   { myOffset = theOffset; }
41
42   void SetOffsetDirection(const gp_Dir& theDirection)
43   { myOffsetDir = theDirection; }
44
45   //! Value of curve
46   Standard_EXPORT void D0(const Standard_Real theU,
47                           gp_Pnt& theValue) const Standard_OVERRIDE;
48   //! Value and first derivatives of curve
49   Standard_EXPORT void D1(const Standard_Real theU,
50                           gp_Pnt& theValue, gp_Vec& theD1) const Standard_OVERRIDE;
51   //! Value, first and second derivatives of curve
52   Standard_EXPORT void D2(const Standard_Real theU,
53                           gp_Pnt& theValue, gp_Vec& theD1, gp_Vec& theD2) const Standard_OVERRIDE;
54   //! Value, first, second and third derivatives of curve
55   Standard_EXPORT void D3(const Standard_Real theU,
56                           gp_Pnt& theValue, gp_Vec& theD1,
57                           gp_Vec& theD2, gp_Vec& theD3) const Standard_OVERRIDE;
58   //! Calculates N-th derivatives of curve, where N = theDeriv. Raises if N < 1
59   Standard_EXPORT gp_Vec DN(const Standard_Real theU,
60                             const Standard_Integer theDeriv) const Standard_OVERRIDE;
61
62   Standard_EXPORT virtual Handle(GeomEvaluator_Curve) ShallowCopy() const Standard_OVERRIDE;
63
64   DEFINE_STANDARD_RTTIEXT(GeomEvaluator_OffsetCurve,GeomEvaluator_Curve)
65
66 private:
67   //! Recalculate D1 values of base curve into D0 value of offset curve
68   void CalculateD0(      gp_Pnt& theValue,
69                    const gp_Vec& theD1) const;
70   //! Recalculate D2 values of base curve into D1 values of offset curve
71   void CalculateD1(      gp_Pnt& theValue,
72                          gp_Vec& theD1,
73                    const gp_Vec& theD2) const;
74   //! Recalculate D3 values of base curve into D2 values of offset curve
75   void CalculateD2(      gp_Pnt& theValue,
76                          gp_Vec& theD1,
77                          gp_Vec& theD2,
78                    const gp_Vec& theD3,
79                    const Standard_Boolean theIsDirChange) const;
80   //! Recalculate D3 values of base curve into D3 values of offset curve
81   void CalculateD3(      gp_Pnt& theValue,
82                          gp_Vec& theD1,
83                          gp_Vec& theD2,
84                          gp_Vec& theD3,
85                    const gp_Vec& theD4,
86                    const Standard_Boolean theIsDirChange) const;
87
88   //! Calculate value of base curve/adaptor
89   void BaseD0(const Standard_Real theU, gp_Pnt& theValue) const;
90   //! Calculate value and first derivatives of base curve/adaptor
91   void BaseD1(const Standard_Real theU,
92               gp_Pnt& theValue, gp_Vec& theD1) const;
93   //! Calculate value, first and second derivatives of base curve/adaptor
94   void BaseD2(const Standard_Real theU,
95               gp_Pnt& theValue, gp_Vec& theD1, gp_Vec& theD2) const;
96   //! Calculate value, first, second and third derivatives of base curve/adaptor
97   void BaseD3(const Standard_Real theU,
98               gp_Pnt& theValue, gp_Vec& theD1, gp_Vec& theD2, gp_Vec& theD3) const;
99   //! Calculate value and derivatives till 4th of base curve/adaptor
100   void BaseD4(const Standard_Real theU,
101               gp_Pnt& theValue, gp_Vec& theD1, gp_Vec& theD2, gp_Vec& theD3, gp_Vec& theD4) const;
102   //! Calculate N-th derivative of base curve/adaptor
103   gp_Vec BaseDN(const Standard_Real theU, const Standard_Integer theDeriv) const;
104
105   // Recalculate derivatives in the singular point
106   // Returns true if the direction of derivatives is changed
107   Standard_Boolean AdjustDerivative(const Standard_Integer theMaxDerivative,
108                                     const Standard_Real theU,
109                                           gp_Vec& theD1,
110                                           gp_Vec& theD2,
111                                           gp_Vec& theD3,
112                                           gp_Vec& theD4) const;
113
114 private:
115   Handle(Geom_Curve)         myBaseCurve;
116   Handle(GeomAdaptor_Curve) myBaseAdaptor;
117
118   Standard_Real myOffset;    ///< offset value
119   gp_Dir        myOffsetDir; ///< offset direction
120 };
121
122 DEFINE_STANDARD_HANDLE(GeomEvaluator_OffsetCurve, GeomEvaluator_Curve)
123
124
125 #endif // _GeomEvaluator_OffsetCurve_HeaderFile