7fd59977 |
1 | -- File: LeastSquare.cdl |
2 | -- Created: Thu Jul 25 17:24:41 1991 |
3 | -- Author: Laurent PAINNOT |
4 | -- <lpa@topsn3> |
5 | ---Copyright: Matra Datavision 1991, 1992 |
6 | |
7 | |
8 | |
9 | generic class LeastSquare from AppParCurves |
10 | (MultiLine as any; |
11 | ToolLine as any) -- as ToolLine(MultiLine) |
12 | |
13 | |
14 | ---Purpose: This class describes the least square fitting of a |
15 | -- MultiLine using the Householder method from the |
16 | -- mathematical package. |
17 | -- The problem to solve is the following one: |
18 | -- minimizing the sum(|C(ui)- Qi|)2 where Qi are the points of |
19 | -- the MultiLine and C(ui) the points of the approximating |
20 | -- curves. |
21 | |
22 | |
23 | |
24 | uses Matrix from math, |
25 | Vector from math, |
26 | IntegerVector from math, |
27 | Constraint from AppParCurves, |
28 | MultiCurve from AppParCurves, |
29 | MultiBSpCurve from AppParCurves, |
30 | Array1OfInteger from TColStd, |
31 | Array1OfReal from TColStd, |
32 | HArray1OfInteger from TColStd, |
33 | HArray1OfReal from TColStd |
34 | |
35 | |
36 | raises NotDone from StdFail, |
37 | OutOfRange from Standard, |
38 | DimensionError from Standard, |
39 | NoSuchObject from Standard |
40 | |
41 | is |
42 | |
43 | Create(SSP: MultiLine; FirstPoint, LastPoint: Integer; |
44 | FirstCons, LastCons: Constraint; |
45 | Parameters: Vector from math; NbPol: Integer) |
46 | ---Purpose: given a MultiLine, this algorithm computes the least |
47 | -- square resolution using the Householder-QR method. |
48 | -- If the first and/or the last point is a constraint |
49 | -- point, the value of the tangency or curvature is |
50 | -- computed in the resolution. |
51 | -- NbPol is the number of control points wanted |
52 | -- for the approximating curves. |
53 | -- The system to solve is the following: |
54 | -- A X = B. |
55 | -- Where A is the Bernstein matrix computed with the |
56 | -- parameters, B the points coordinates and X the poles |
57 | -- solutions. |
58 | -- The matrix A is the same for each coordinate x, y and z |
59 | -- and is also the same for each MultiLine point because |
60 | -- they are approximated in parallel(so with the same |
61 | -- parameter, only the vector B changes). |
62 | |
63 | returns LeastSquare from AppParCurves |
64 | raises DimensionError from Standard; |
65 | |
66 | |
67 | |
68 | Create(SSP: MultiLine; FirstPoint, LastPoint: Integer; |
69 | FirstCons, LastCons: Constraint; NbPol: Integer) |
70 | ---Purpose: Initializes the fields of the object. |
71 | |
72 | returns LeastSquare; |
73 | |
74 | |
75 | Create(SSP: MultiLine; Knots: Array1OfReal; Mults: Array1OfInteger; |
76 | FirstPoint, LastPoint: Integer; |
77 | FirstCons, LastCons: Constraint; |
78 | Parameters: Vector from math; NbPol: Integer) |
79 | ---Purpose: given a MultiLine, this algorithm computes the least |
80 | -- square resolution using the Householder-QR method. |
81 | -- If the first and/or the last point is a constraint |
82 | -- point, the value of the tangency or curvature is |
83 | -- computed in the resolution. |
84 | -- Deg is the degree wanted for the approximating curves. |
85 | -- The system to solve is the following: |
86 | -- A X = B. |
87 | -- Where A is the BSpline functions matrix computed with |
88 | -- <parameters>, B the points coordinates and X the poles |
89 | -- solutions. |
90 | -- The matrix A is the same for each coordinate x, y and z |
91 | -- and is also the same for each MultiLine point because |
92 | -- they are approximated in parallel(so with the same |
93 | -- parameter, only the vector B changes). |
94 | |
95 | returns LeastSquare from AppParCurves |
96 | raises DimensionError from Standard; |
97 | |
98 | |
99 | |
100 | Create(SSP: MultiLine; Knots: Array1OfReal; Mults: Array1OfInteger; |
101 | FirstPoint, LastPoint: Integer; |
102 | FirstCons, LastCons: Constraint; NbPol: Integer) |
103 | ---Purpose: Initializes the fields of the object. |
104 | |
105 | returns LeastSquare; |
106 | |
107 | |
108 | |
109 | Init(me: in out; SSP: MultiLine; FirstPoint, LastPoint: Integer) |
110 | ---Purpose: is used by the constuctors above. |
111 | |
112 | is static protected; |
113 | |
114 | |
115 | Perform(me: in out; Parameters: Vector) |
116 | ---Purpose: Is used after having initialized the fields. |
117 | -- The case "CurvaturePoint" is not treated in this method. |
118 | |
119 | is static; |
120 | |
121 | |
122 | Perform(me: in out; Parameters: Vector; |
123 | l1, l2: Real) |
124 | ---Purpose: Is used after having initialized the fields. |
125 | |
126 | is static; |
127 | |
128 | |
129 | ---------------------------------------------------------------------- |
130 | -- for the two following methods, vectors <V> must be constructed |
131 | -- as follow: |
132 | -- V(v1x, v1y, v1z, ....., vnx, vny, vnz, v1x, v1y, ....., vmx, vmy) |
133 | -- 3d curve 3d curve 2d curve 2d curve |
134 | -- |
135 | -- the length of V must be Nb3dpoints*3 + Nb2dpoints*2 |
136 | |
137 | |
138 | Perform(me: in out; Parameters: Vector; |
139 | V1t, V2t: Vector; |
140 | l1, l2: Real) |
141 | ---Purpose: Is used after having initialized the fields. |
142 | --- <V1t> is the tangent vector at the first point. |
143 | --- <V2t> is the tangent vector at the last point. |
144 | is static; |
145 | |
146 | Perform(me: in out; Parameters: Vector; |
147 | V1t, V2t, V1c, V2c: Vector; |
148 | l1, l2: Real) |
149 | ---Purpose: Is used after having initialized the fields. |
150 | --- <V1t> is the tangent vector at the first point. |
151 | --- <V2t> is the tangent vector at the last point. |
152 | --- <V1c> is the tangent vector at the first point. |
153 | --- <V2c> is the tangent vector at the last point. |
154 | |
155 | is static; |
156 | |
157 | |
158 | ------------------------------- |
159 | --- Result methods: |
160 | ------------------------------- |
161 | |
162 | |
163 | IsDone(me) |
164 | ---Purpose: returns True if all has been correctly done. |
165 | |
166 | returns Boolean |
167 | is static; |
168 | |
169 | |
170 | BezierValue(me: in out) |
171 | ---Purpose: returns the result of the approximation, i.e. all the |
172 | -- Curves. |
173 | -- An exception is raised if NotDone. |
174 | |
175 | returns MultiCurve from AppParCurves |
176 | raises NotDone from StdFail, |
177 | NoSuchObject from Standard |
178 | is static; |
179 | |
180 | |
181 | BSplineValue(me: in out) |
182 | ---Purpose: returns the result of the approximation, i.e. all the |
183 | -- Curves. |
184 | -- An exception is raised if NotDone. |
185 | ---C++: return const & |
186 | |
187 | returns MultiBSpCurve from AppParCurves |
188 | raises NotDone from StdFail, |
189 | NoSuchObject from Standard |
190 | is static; |
191 | |
192 | |
193 | FunctionMatrix(me) |
194 | ---Purpose: returns the function matrix used to approximate the |
195 | -- set. |
196 | ---C++: return const & |
197 | |
198 | returns Matrix from math |
199 | raises NotDone from StdFail |
200 | is static; |
201 | |
202 | |
203 | |
204 | DerivativeFunctionMatrix(me) |
205 | ---Purpose: returns the derivative function matrix used |
206 | -- to approximate the set. |
207 | ---C++: return const & |
208 | |
209 | returns Matrix from math |
210 | raises NotDone from StdFail |
211 | is static; |
212 | |
213 | |
214 | ErrorGradient(me: in out; Grad: in out Vector; |
215 | F: in out Real; MaxE3d, MaxE2d: in out Real) |
216 | ---Purpose: returns the maximum errors between the MultiLine |
217 | -- and the approximation curves. F is the sum of the square |
218 | -- distances. Grad is the derivative vector of the |
219 | -- function F. |
220 | |
221 | is static; |
222 | |
223 | |
224 | Distance(me: in out) |
225 | ---Purpose: returns the distances between the points of the |
226 | -- multiline and the approximation curves. |
227 | ---C++: return const& |
228 | |
229 | returns Matrix from math |
230 | is static; |
231 | |
232 | |
233 | Error(me: in out; F: in out Real; |
234 | MaxE3d, MaxE2d: in out Real) |
235 | ---Purpose: returns the maximum errors between the MultiLine |
236 | -- and the approximation curves. F is the sum of the square |
237 | -- distances. |
238 | |
239 | is static; |
240 | |
241 | |
242 | FirstLambda(me) |
243 | ---Purpose: returns the value (P2 - P1)/ V1 if the first point |
244 | -- was a tangency point. |
245 | |
246 | returns Real |
247 | is static; |
248 | |
249 | |
250 | LastLambda(me) |
251 | ---Purpose: returns the value (PN - PN-1)/ VN if the last point |
252 | -- was a tangency point. |
253 | |
254 | returns Real |
255 | is static; |
256 | |
257 | |
258 | Points(me) |
259 | ---Purpose: returns the matrix of points value. |
260 | ---C++: return const& |
261 | |
262 | returns Matrix |
263 | is static; |
264 | |
265 | |
266 | Poles(me) |
267 | ---Purpose: returns the matrix of resulting control points value. |
268 | ---C++: return const& |
269 | |
270 | returns Matrix |
271 | is static; |
272 | |
273 | |
274 | KIndex(me) |
275 | ---Purpose: Returns the indexes of the first non null values of |
276 | -- A and DA. |
277 | -- The values are non null from Index(ieme point) +1 |
278 | -- to Index(ieme point) + degree +1. |
279 | ---C++: return const& |
280 | |
281 | returns IntegerVector |
282 | is static; |
283 | |
284 | |
285 | |
286 | ------------------------------- |
287 | --- internal methods: |
288 | ------------------------------- |
289 | |
290 | NbBColumns(me; SSP: MultiLine) |
291 | ---Purpose: returns the number of second member columns. |
292 | -- Is used internally to initialize the fields. |
293 | returns Integer |
294 | is static protected; |
295 | |
296 | |
297 | TheFirstPoint(me; FirstCons: Constraint; FirstPoint: Integer) |
298 | ---Purpose: returns the first point beeing fitted. |
299 | returns Integer |
300 | is static protected; |
301 | |
302 | |
303 | TheLastPoint(me; LastCons: Constraint; LastPoint: Integer) |
304 | ---Purpose: returns the last point beeing fitted. |
305 | returns Integer |
306 | is static protected; |
307 | |
308 | |
309 | Affect(me: in out; SSP: MultiLine; Index: Integer; |
310 | Cons: in out Constraint; Vt, Vc: in out Vector) |
311 | ---Purpose: Affects the fields in the case of a constraint point. |
312 | is static protected; |
313 | |
314 | |
315 | ComputeFunction(me: in out; Parameters: Vector) |
316 | ---Purpose: |
317 | is static protected; |
318 | |
319 | |
320 | SearchIndex(me: in out; Index: in out IntegerVector) |
321 | is static protected; |
322 | |
323 | |
324 | MakeTAA(me: in out; TheA, TheB: in out Vector) |
325 | ---Purpose: computes internal matrixes for the resolution |
326 | is static protected; |
327 | |
328 | MakeTAA(me: in out; TheA: in out Vector) |
329 | ---Purpose: computes internal matrixes for the resolution |
330 | is static protected; |
331 | |
332 | MakeTAA(me: in out; TheA: in out Vector; TheB: in out Matrix) |
333 | ---Purpose: computes internal matrixes for the resolution |
334 | is static protected; |
335 | |
336 | fields |
337 | |
338 | |
339 | FirstConstraint : Constraint from AppParCurves; |
340 | LastConstraint : Constraint from AppParCurves; |
341 | SCU: MultiBSpCurve from AppParCurves; |
342 | myknots: HArray1OfReal from TColStd; |
343 | mymults: HArray1OfInteger from TColStd; |
344 | mypoles: Matrix from math; |
345 | A: Matrix from math; |
346 | DA: Matrix from math; |
347 | B2: Matrix from math; |
348 | mypoints: Matrix from math; |
349 | Vflatknots: Vector from math; |
350 | Vec1t: Vector from math; |
351 | Vec1c: Vector from math; |
352 | Vec2t: Vector from math; |
353 | Vec2c: Vector from math; |
354 | theError: Matrix from math; |
355 | myindex: IntegerVector from math; |
356 | |
357 | ERR3d: Real; |
358 | ERR2d: Real; |
359 | lambda1: Real; |
360 | lambda2: Real; |
361 | |
362 | FirstP: Integer; |
363 | LastP: Integer; |
364 | Nlignes: Integer; |
365 | Ninc: Integer; |
366 | NA: Integer; |
367 | myfirstp: Integer; |
368 | mylastp: Integer; |
369 | resinit: Integer; |
370 | resfin: Integer; |
371 | nbP2d: Integer; |
372 | nbP: Integer; |
373 | |
374 | nbpoles: Integer; |
375 | deg: Integer; |
376 | |
377 | done: Boolean; |
378 | iscalculated : Boolean; |
379 | isready : Boolean; |
380 | end LeastSquare; |
381 | |