Commit | Line | Data |
---|---|---|

b311480e | 1 | -- Created on: 1991-07-25 |

2 | -- Created by: Laurent PAINNOT | |

3 | -- Copyright (c) 1991-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 | -- |

973c2be1 | 8 | -- This library is free software; you can redistribute it and / or modify it |

9 | -- under the terms of the GNU Lesser General Public version 2.1 as published | |

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 Gradient 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. | |

28 | ||

29 | ||

30 | ||

31 | uses Vector from math, | |

32 | MultipleVarFunctionWithGradient from math, | |

33 | MultiCurve from AppParCurves, | |

34 | HArray1OfConstraintCouple from AppParCurves | |

35 | ||

36 | ||

37 | raises OutOfRange from Standard, | |

38 | NotDone from StdFail | |

39 | ||

40 | ||

41 | private class ParLeastSquare instantiates LeastSquare from AppParCurves | |

42 | (MultiLine, ToolLine); | |

43 | ||

44 | private class ResConstraint instantiates ResolConstraint from AppParCurves | |

45 | (MultiLine, ToolLine); | |

46 | ||

47 | private class ParFunction instantiates Function from AppParCurves | |

48 | (MultiLine, ToolLine, ParLeastSquare, ResConstraint); | |

49 | ||

50 | class Gradient_BFGS from AppParCurves | |

51 | inherits BFGS from math | |

52 | uses MultipleVarFunctionWithGradient from math, | |

53 | Vector from math | |

54 | is | |

55 | ||

56 | Create ( F : in out MultipleVarFunctionWithGradient from math ; | |

57 | StartingPoint : Vector from math ; | |

58 | Tolerance3d : Real from Standard ; | |

59 | Tolerance2d : Real from Standard ; | |

60 | Eps : Real from Standard ; | |

61 | NbIterations : Integer from Standard = 200 ); | |

62 | ||

63 | IsSolutionReached ( me ; | |

64 | F : in out MultipleVarFunctionWithGradient from math ) | |

65 | returns Boolean from Standard is redefined ; | |

66 | ||

67 | fields | |

68 | ||

69 | myTol3d : Real from Standard ; | |

70 | myTol2d : Real from Standard ; | |

71 | ||

72 | end Gradient_BFGS from AppParCurves ; | |

73 | ||

74 | is | |

75 | ||

76 | Create(SSP: MultiLine; FirstPoint, LastPoint: Integer; | |

77 | TheConstraints: HArray1OfConstraintCouple; | |

78 | Parameters: in out Vector; Deg: Integer; | |

79 | Tol3d, Tol2d: Real; NbIterations: Integer = 200) | |

80 | ---Purpose: Tries to minimize the sum (square(||Qui - Bi*Pi||)) | |

81 | -- where Pui describe the approximating Bezier curves'Poles | |

82 | -- and Qi the MultiLine points with a parameter ui. | |

83 | -- In this algorithm, the parameters ui are the unknowns. | |

84 | -- The tolerance required on this sum is given by Tol. | |

85 | -- The desired degree of the resulting curve is Deg. | |

86 | ||

87 | returns Gradient from AppParCurves; | |

88 | ||

89 | ||

90 | IsDone(me) | |

91 | ---Purpose: returns True if all has been correctly done. | |

92 | ||

93 | returns Boolean | |

94 | is static; | |

95 | ||

96 | ||

97 | Value(me) | |

98 | ---Purpose: returns all the Bezier curves approximating the | |

99 | -- MultiLine SSP after minimization of the parameter. | |

100 | ||

101 | returns MultiCurve from AppParCurves | |

102 | raises NotDone from StdFail | |

103 | is static; | |

104 | ||

105 | ||

106 | Error(me; Index: Integer) | |

107 | ---Purpose: returns the difference between the old and the new | |

108 | -- approximation. | |

109 | -- An exception is raised if NotDone. | |

110 | -- An exception is raised if Index<1 or Index>NbParameters. | |

111 | ||

112 | returns Real | |

113 | raises NotDone from StdFail, | |

114 | OutOfRange from Standard | |

115 | is static; | |

116 | ||

117 | ||

118 | MaxError3d(me) | |

119 | ---Purpose: returns the maximum difference between the old and the | |

120 | -- new approximation. | |

121 | ||

122 | returns Real | |

123 | raises NotDone from StdFail | |

124 | is static; | |

125 | ||

126 | ||

127 | MaxError2d(me) | |

128 | ---Purpose: returns the maximum difference between the old and the | |

129 | -- new approximation. | |

130 | ||

131 | returns Real | |

132 | raises NotDone from StdFail | |

133 | is static; | |

134 | ||

135 | ||

136 | AverageError(me) | |

137 | ---Purpose: returns the average error between the old and the | |

138 | -- new approximation. | |

139 | ||

140 | returns Real | |

141 | raises NotDone from StdFail | |

142 | is static; | |

143 | ||

144 | ||

145 | fields | |

146 | ||

147 | SCU: MultiCurve from AppParCurves; | |

148 | ParError: Vector from math; | |

149 | AvError: Real; | |

150 | MError3d: Real; | |

151 | MError2d: Real; | |

152 | Done: Boolean; | |

153 | ||

154 | end Gradient from AppParCurves; |