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

7fd59977 | 1 | -- File: AppParCurves_BSpGradient.cdl |

2 | -- Created: Wed Sep 22 10:23:14 1993 | |

3 | -- Author: Modelistation | |

4 | -- <model@zerox> | |

5 | ---Copyright: Matra Datavision 1993 | |

6 | ||

7 | ||

8 | ||

9 | generic class BSpGradient from AppParCurves | |

10 | (MultiLine as any; | |

11 | ToolLine as any) -- as ToolLine(MultiLine) | |

12 | ||

13 | ||

14 | ---Purpose: This algorithm uses the algorithms LeastSquare, | |

15 | -- ResConstraint and a gradient method to approximate a set | |

16 | -- of points (AppDef_MultiLine) with a minimization of the | |

17 | -- sum(square(|F(i)-Qi|)) by changing the parameter. | |

18 | -- The algorithm used is from of the mathematical | |

19 | -- package: math_BFGS, a gradient method. | |

20 | ||

21 | ||

22 | ||

23 | uses Vector from math, | |

24 | MultipleVarFunctionWithGradient from math, | |

25 | MultiBSpCurve from AppParCurves, | |

26 | HArray1OfConstraintCouple from AppParCurves, | |

27 | Array1OfReal from TColStd, | |

28 | Array1OfInteger from TColStd | |

29 | ||

30 | ||

31 | raises OutOfRange from Standard, | |

32 | NotDone from StdFail | |

33 | ||

34 | ||

35 | private class BSpParLeastSquare instantiates LeastSquare from AppParCurves | |

36 | (MultiLine, ToolLine); | |

37 | ||

38 | private class BSpParFunction instantiates BSpFunction from AppParCurves | |

39 | (MultiLine, ToolLine, BSpParLeastSquare); | |

40 | ||

41 | ||

42 | class BSpGradient_BFGS from AppParCurves | |

43 | inherits BFGS from math | |

44 | uses MultipleVarFunctionWithGradient from math, | |

45 | Vector from math | |

46 | ||

47 | is | |

48 | ||

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

50 | StartingPoint : Vector from math ; | |

51 | Tolerance3d : Real from Standard ; | |

52 | Tolerance2d : Real from Standard ; | |

53 | Eps : Real from Standard ; | |

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

55 | ||

56 | IsSolutionReached ( me ; | |

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

58 | returns Boolean from Standard is redefined ; | |

59 | ||

60 | fields | |

61 | ||

62 | myTol3d : Real from Standard ; | |

63 | myTol2d : Real from Standard ; | |

64 | ||

65 | end BSpGradient_BFGS from AppParCurves ; | |

66 | is | |

67 | ||

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

69 | TheConstraints: HArray1OfConstraintCouple; | |

70 | Parameters: in out Vector; | |

71 | Knots: Array1OfReal; Mults: Array1OfInteger; | |

72 | Deg: Integer; | |

73 | Tol3d, Tol2d: Real; NbIterations: Integer = 1) | |

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

75 | -- where Pui describe the approximating BSpline curves'Poles | |

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

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

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

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

80 | ||

81 | returns BSpGradient from AppParCurves; | |

82 | ||

83 | ||

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

85 | TheConstraints: HArray1OfConstraintCouple; | |

86 | Parameters: in out Vector; | |

87 | Knots: Array1OfReal; Mults: Array1OfInteger; | |

88 | Deg: Integer; | |

89 | Tol3d, Tol2d: Real; NbIterations: Integer; | |

90 | lambda1, lambda2: Real) | |

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

92 | -- where Pui describe the approximating BSpline curves'Poles | |

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

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

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

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

97 | ||

98 | returns BSpGradient from AppParCurves; | |

99 | ||

100 | ||

101 | Perform(me: in out; SSP: MultiLine; FirstPoint, LastPoint: Integer; | |

102 | TheConstraints: HArray1OfConstraintCouple; | |

103 | Parameters: in out Vector; | |

104 | Knots: Array1OfReal; Mults: Array1OfInteger; | |

105 | Deg: Integer; | |

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

107 | is static protected; | |

108 | ||

109 | ||

110 | IsDone(me) | |

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

112 | ||

113 | returns Boolean | |

114 | is static; | |

115 | ||

116 | ||

117 | Value(me) | |

118 | ---Purpose: returns all the BSpline curves approximating the | |

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

120 | ||

121 | returns MultiBSpCurve from AppParCurves | |

122 | raises NotDone from StdFail | |

123 | is static; | |

124 | ||

125 | ||

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

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

128 | -- approximation. | |

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

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

131 | ||

132 | returns Real | |

133 | raises NotDone from StdFail, | |

134 | OutOfRange from Standard | |

135 | is static; | |

136 | ||

137 | ||

138 | MaxError3d(me) | |

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

140 | -- new approximation. | |

141 | ||

142 | returns Real | |

143 | raises NotDone from StdFail | |

144 | is static; | |

145 | ||

146 | ||

147 | MaxError2d(me) | |

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

149 | -- new approximation. | |

150 | ||

151 | returns Real | |

152 | raises NotDone from StdFail | |

153 | is static; | |

154 | ||

155 | ||

156 | AverageError(me) | |

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

158 | -- new approximation. | |

159 | ||

160 | returns Real | |

161 | raises NotDone from StdFail | |

162 | is static; | |

163 | ||

164 | ||

165 | fields | |

166 | ||

167 | SCU: MultiBSpCurve from AppParCurves; | |

168 | ParError: Vector from math; | |

169 | AvError: Real; | |

170 | MError3d: Real; | |

171 | MError2d: Real; | |

172 | mylambda1: Real; | |

173 | mylambda2: Real; | |

174 | Done: Boolean; | |

175 | ||

176 | end BSpGradient from AppParCurves; |