b311480e |
1 | -- Created on: 1993-09-22 |
2 | -- Created by: Modelistation |
3 | -- Copyright (c) 1993-1999 Matra Datavision |
973c2be1 |
4 | -- Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | -- |
973c2be1 |
6 | -- This file is part of Open CASCADE Technology software library. |
b311480e |
7 | -- |
d5f74e42 |
8 | -- This library is free software; you can redistribute it and/or modify it under |
9 | -- the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | -- by the Free Software Foundation, with special exception defined in the file |
11 | -- OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | -- distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | -- |
973c2be1 |
14 | -- Alternatively, this file may be used under the terms of Open CASCADE |
15 | -- commercial license or contractual agreement. |
7fd59977 |
16 | |
17 | generic class BSpGradient from AppParCurves |
18 | (MultiLine as any; |
19 | ToolLine as any) -- as ToolLine(MultiLine) |
20 | |
21 | |
22 | ---Purpose: This algorithm uses the algorithms LeastSquare, |
23 | -- ResConstraint and a gradient method to approximate a set |
24 | -- of points (AppDef_MultiLine) with a minimization of the |
25 | -- sum(square(|F(i)-Qi|)) by changing the parameter. |
26 | -- The algorithm used is from of the mathematical |
27 | -- package: math_BFGS, a gradient method. |
ff8178ef |
28 | -- The Result is a Bspline set. |
7fd59977 |
29 | |
30 | |
31 | uses Vector from math, |
32 | MultipleVarFunctionWithGradient from math, |
33 | MultiBSpCurve from AppParCurves, |
34 | HArray1OfConstraintCouple from AppParCurves, |
35 | Array1OfReal from TColStd, |
36 | Array1OfInteger from TColStd |
37 | |
38 | |
39 | raises OutOfRange from Standard, |
40 | NotDone from StdFail |
41 | |
42 | |
43 | private class BSpParLeastSquare instantiates LeastSquare from AppParCurves |
44 | (MultiLine, ToolLine); |
45 | |
46 | private class BSpParFunction instantiates BSpFunction from AppParCurves |
47 | (MultiLine, ToolLine, BSpParLeastSquare); |
48 | |
49 | |
50 | class BSpGradient_BFGS from AppParCurves |
51 | inherits BFGS from math |
52 | uses MultipleVarFunctionWithGradient from math, |
53 | Vector from math |
54 | |
55 | is |
56 | |
57 | Create ( F : in out MultipleVarFunctionWithGradient from math ; |
58 | StartingPoint : Vector from math ; |
59 | Tolerance3d : Real from Standard ; |
60 | Tolerance2d : Real from Standard ; |
61 | Eps : Real from Standard ; |
62 | NbIterations : Integer from Standard = 200 ); |
63 | |
64 | IsSolutionReached ( me ; |
65 | F : in out MultipleVarFunctionWithGradient from math ) |
66 | returns Boolean from Standard is redefined ; |
67 | |
68 | fields |
69 | |
70 | myTol3d : Real from Standard ; |
71 | myTol2d : Real from Standard ; |
72 | |
73 | end BSpGradient_BFGS from AppParCurves ; |
74 | is |
75 | |
76 | Create(SSP: MultiLine; FirstPoint, LastPoint: Integer; |
77 | TheConstraints: HArray1OfConstraintCouple; |
78 | Parameters: in out Vector; |
79 | Knots: Array1OfReal; Mults: Array1OfInteger; |
80 | Deg: Integer; |
81 | Tol3d, Tol2d: Real; NbIterations: Integer = 1) |
82 | ---Purpose: Tries to minimize the sum (square(||Qui - Bi*Pi||)) |
83 | -- where Pui describe the approximating BSpline curves'Poles |
84 | -- and Qi the MultiLine points with a parameter ui. |
85 | -- In this algorithm, the parameters ui are the unknowns. |
86 | -- The tolerance required on this sum is given by Tol. |
87 | -- The desired degree of the resulting curve is Deg. |
88 | |
89 | returns BSpGradient from AppParCurves; |
90 | |
91 | |
92 | Create(SSP: MultiLine; FirstPoint, LastPoint: Integer; |
93 | TheConstraints: HArray1OfConstraintCouple; |
94 | Parameters: in out Vector; |
95 | Knots: Array1OfReal; Mults: Array1OfInteger; |
96 | Deg: Integer; |
97 | Tol3d, Tol2d: Real; NbIterations: Integer; |
98 | lambda1, lambda2: Real) |
99 | ---Purpose: Tries to minimize the sum (square(||Qui - Bi*Pi||)) |
100 | -- where Pui describe the approximating BSpline curves'Poles |
101 | -- and Qi the MultiLine points with a parameter ui. |
102 | -- In this algorithm, the parameters ui are the unknowns. |
103 | -- The tolerance required on this sum is given by Tol. |
104 | -- The desired degree of the resulting curve is Deg. |
105 | |
106 | returns BSpGradient from AppParCurves; |
107 | |
108 | |
109 | Perform(me: in out; SSP: MultiLine; FirstPoint, LastPoint: Integer; |
110 | TheConstraints: HArray1OfConstraintCouple; |
111 | Parameters: in out Vector; |
112 | Knots: Array1OfReal; Mults: Array1OfInteger; |
113 | Deg: Integer; |
114 | Tol3d, Tol2d: Real; NbIterations: Integer = 200) |
115 | is static protected; |
116 | |
117 | |
118 | IsDone(me) |
119 | ---Purpose: returns True if all has been correctly done. |
120 | |
121 | returns Boolean |
122 | is static; |
123 | |
124 | |
125 | Value(me) |
126 | ---Purpose: returns all the BSpline curves approximating the |
127 | -- MultiLine SSP after minimization of the parameter. |
128 | |
129 | returns MultiBSpCurve from AppParCurves |
130 | raises NotDone from StdFail |
131 | is static; |
132 | |
133 | |
134 | Error(me; Index: Integer) |
135 | ---Purpose: returns the difference between the old and the new |
136 | -- approximation. |
137 | -- An exception is raised if NotDone. |
138 | -- An exception is raised if Index<1 or Index>NbParameters. |
139 | |
140 | returns Real |
141 | raises NotDone from StdFail, |
142 | OutOfRange from Standard |
143 | is static; |
144 | |
145 | |
146 | MaxError3d(me) |
147 | ---Purpose: returns the maximum difference between the old and the |
148 | -- new approximation. |
149 | |
150 | returns Real |
151 | raises NotDone from StdFail |
152 | is static; |
153 | |
154 | |
155 | MaxError2d(me) |
156 | ---Purpose: returns the maximum difference between the old and the |
157 | -- new approximation. |
158 | |
159 | returns Real |
160 | raises NotDone from StdFail |
161 | is static; |
162 | |
163 | |
164 | AverageError(me) |
165 | ---Purpose: returns the average error between the old and the |
166 | -- new approximation. |
167 | |
168 | returns Real |
169 | raises NotDone from StdFail |
170 | is static; |
171 | |
172 | |
173 | fields |
174 | |
175 | SCU: MultiBSpCurve from AppParCurves; |
176 | ParError: Vector from math; |
177 | AvError: Real; |
178 | MError3d: Real; |
179 | MError2d: Real; |
180 | mylambda1: Real; |
181 | mylambda2: Real; |
89bc1237 |
182 | myIsLambdaDefined: Boolean; |
7fd59977 |
183 | Done: Boolean; |
184 | |
185 | end BSpGradient from AppParCurves; |