1 -- Created on: 1996-05-14
2 -- Created by: Philippe MANGIN / Jeannine PANCIATICI
3 -- Copyright (c) 1996-1999 Matra Datavision
4 -- Copyright (c) 1999-2014 OPEN CASCADE SAS
6 -- This file is part of Open CASCADE Technology software library.
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.
14 -- Alternatively, this file may be used under the terms of Open CASCADE
15 -- commercial license or contractual agreement.
17 -- Igor FEOKTISTOV - correction 14/12/98
20 generic class Variational from AppParCurves
22 ToolLine as any) -- as ToolLine(MultiLine)
25 ---Purpose: This class is used to smooth N points with constraints
26 -- by minimization of quadratic criterium but also
27 -- variational criterium in order to obtain " fair Curve "
30 uses Matrix from math,
32 HArray1OfReal from TColStd,
33 Array1OfReal from TColStd,
34 HArray1OfInteger from TColStd,
36 HArray1OfConstraintCouple from AppParCurves,
37 MultiBSpCurve from AppParCurves,
38 SmoothCriterion from AppParCurves,
40 Assembly from FEmTool,
42 Constraint from AppParCurves
44 raises OutOfRange from Standard,
45 DimensionError from Standard,
46 DomainError from Standard,
47 ConstructionError from Standard,
49 VectorWithNullMagnitude from gp
51 class MyCriterion instantiates LinearCriteria from AppParCurves
52 (MultiLine, ToolLine);
56 Create(SSP: MultiLine;
57 FirstPoint, LastPoint: Integer;
58 TheConstraints: HArray1OfConstraintCouple;
59 MaxDegree: Integer = 14;
60 MaxSegment: Integer = 100;
61 Continuity : Shape from GeomAbs = GeomAbs_C2;
62 WithMinMax : Boolean = Standard_False;
63 WithCutting: Boolean = Standard_True;
64 Tolerance : Real = 1.0;
65 NbIterations: Integer = 2)
66 ---Purpose: Constructor.
67 -- Initialization of the fields.
68 -- warning : Nc0 : number of PassagePoint consraints
69 -- Nc2 : number of TangencyPoint constraints
70 -- Nc3 : number of CurvaturePoint constraints
72 -- ((MaxDegree-Continuity)*MaxSegment -Nc0 - 2*Nc1
75 -- The problem is over-constrained.
77 -- Limitation : The MultiLine has to be composed by
78 -- only one Line ( Dimension 2 or 3).
80 returns Variational from AppParCurves;
83 Approximate(me : in out)
84 ---Purpose: Makes the approximation with the current fields.
85 raises NotDone from StdFail
90 -- ==================== The Selectors ===========================
93 ---Purpose: returns True if the creation is done
94 -- and correspond to the current fields.
100 ---Purpose: returns True if the approximation is ok
101 -- and correspond to the current fields.
105 IsOverConstrained(me)
106 ---Purpose: returns True if the problem is overconstrained
107 -- in this case, approximation cannot be done.
112 ---Purpose: returns all the BSpline curves approximating the
113 -- MultiLine SSP after minimization of the parameter.
115 returns MultiBSpCurve from AppParCurves
116 raises NotDone from StdFail
121 ---Purpose: returns the maximum of the distances between
122 -- the points of the multiline and the approximation
125 raises NotDone from StdFail
129 ---Purpose: returns the index of the MultiPoint of ErrorMax
132 raises NotDone from StdFail
137 ---Purpose: returns the quadratic average of the distances between
138 -- the points of the multiline and the approximation
141 raises NotDone from StdFail
144 Distance(me : in out ; mat : out Matrix from math)
145 ---Purpose: returns the distances between the points of the
146 -- multiline and the approximation curves.
147 raises NotDone from StdFail
151 ---Purpose: returns the average error between
152 -- the MultiLine and the approximation.
155 raises NotDone from StdFail
159 ---Purpose: returns the parameters uses to the approximations
160 ---C++: return const&
162 returns HArray1OfReal
163 raises NotDone from StdFail
167 ---Purpose: returns the knots uses to the approximations
168 ---C++: return const&
169 returns HArray1OfReal
170 raises NotDone from StdFail
173 Criterium(me; VFirstOrder,
175 VThirdOrder : out Real)
176 ---Purpose: returns the values of the quality criterium.
177 raises NotDone from StdFail
181 Percent1, Percent2, Percent3 : out Real)
182 ---Purpose: returns the Weights (as percent) associed to the criterium used in
187 ---Purpose: returns the Maximum Degree used in the approximation
192 ---Purpose: returns the Maximum of segment used in the approximation
197 ---Purpose: returns the Continuity used in the approximation
198 returns Shape from GeomAbs
203 ---Purpose: returns if the approximation search to minimize the
204 -- maximum Error or not.
209 ---Purpose: returns if the approximation can insert new Knots or not.
214 ---Purpose: returns the tolerance used in the approximation.
219 ---Purpose: returns the number of iterations used in the approximation.
223 Dump(me ; o : in out OStream)
224 ---Purpose: Prints on the stream o information on the current state
226 -- MaxError,MaxErrorIndex,AverageError,QuadraticError,Criterium
227 -- Distances,Degre,Nombre de poles, parametres, noeuds
230 SetConstraints(me:in out; aConstrainst:HArray1OfConstraintCouple)
231 ---Purpose: Define the constraints to approximate
232 -- If this value is incompatible with the others fields
233 -- this method modify nothing and returns false
237 SetParameters(me:in out; param : HArray1OfReal)
238 ---Purpose: Defines the parameters used by the approximations.
239 raises DimensionError
242 SetKnots(me:in out; knots : HArray1OfReal)
243 ---Purpose: Defines the knots used by the approximations
244 -- If this value is incompatible with the others fields
245 -- this method modify nothing and returns false
247 raises DimensionError,
251 SetMaxDegree(me: in out; Degree : Integer)
252 ---Purpose: Define the Maximum Degree used in the approximation
253 -- If this value is incompatible with the others fields
254 -- this method modify nothing and returns false
258 SetMaxSegment(me: in out; NbSegment : Integer)
259 ---Purpose: Define the maximum number of segments used in the approximation
260 -- If this value is incompatible with the others fields
261 -- this method modify nothing and returns false
265 SetContinuity(me: in out; C : Shape from GeomAbs)
266 ---Purpose: Define the Continuity used in the approximation
267 -- If this value is incompatible with the others fields
268 -- this method modify nothing and returns false
270 raises ConstructionError from Standard
274 SetWithMinMax(me: in out; MinMax : Boolean)
275 ---Purpose: Define if the approximation search to minimize the
276 -- maximum Error or not.
279 SetWithCutting(me : in out; Cutting : Boolean )
280 ---Purpose: Define if the approximation can insert new Knots or not.
281 -- If this value is incompatible with the others fields
282 -- this method modify nothing and returns false
286 SetCriteriumWeight(me : in out;
287 Percent1, Percent2, Percent3 : Real)
288 ---Purpose: define the Weights (as percent) associed to the criterium used in
291 raises DomainError -- if Percent <= 0
294 SetCriteriumWeight(me : in out;
297 ---Purpose: define the Weight (as percent) associed to the
298 -- criterium Order used in the optimization : Others
299 -- weights are updated.
300 raises DomainError, -- if Percent < 0
301 OutOfRange -- if Order < 1 or Order > 3
304 SetTolerance(me:in out; Tol : Real)
305 ---Purpose: define the tolerance used in the approximation.
308 SetNbIterations(me:in out; Iter : Integer)
309 ---Purpose: define the number of iterations used in the approximation.
310 raises DomainError -- if Iter < 1
314 -- ====================== The Private methods ======================
316 TheMotor(me : in out;
317 J : in out SmoothCriterion from AppParCurves;
318 WQuadratic, WQuality : Real;
319 TheCurve : in out Curve from FEmTool;
320 Ecarts : out Array1OfReal from TColStd) is private;
322 Adjusting(me : in out;
323 J : in out SmoothCriterion from AppParCurves;
324 WQuadratic, WQuality : in out Real;
325 TheCurve : in out Curve from FEmTool;
326 Ecarts : out Array1OfReal from TColStd) is private;
329 J : in out SmoothCriterion from AppParCurves;
330 A : in out Assembly from FEmTool;
331 ToAssemble : in Boolean;
333 Curve : out Curve from FEmTool;
334 Parameters : Array1OfReal from TColStd) is private;
336 Project(me; C : Curve from FEmTool;
337 Ti : Array1OfReal from TColStd;
338 ProjTi : out Array1OfReal from TColStd;
339 Distance : out Array1OfReal from TColStd;
340 NumPoints : out Integer;
341 MaxErr, QuaErr, AveErr : out Real;
342 NbIterations: Integer=2) is private;
344 ACR(me; Curve : in out Curve from FEmTool;
345 Ti : in out Array1OfReal from TColStd;
346 Decima: Integer) is private;
348 SplitCurve(me; InCurve : Curve from FEmTool;
349 Ti : Array1OfReal from TColStd;
351 OutCurve: out Curve from FEmTool;
352 iscut : out Boolean) is private;
355 raises NotDone from StdFail,
356 ConstructionError from Standard,
357 DimensionError from Standard
360 InitSmoothCriterion(me : in out)
363 InitParameters(me : in out; Length : out Real)
364 raises ConstructionError from Standard
367 InitCriterionEstimations(me; Length : Real; J1, J2, J3 : out Real)
370 EstTangent(me; ipnt : Integer; VTang : out Vector from math)
373 EstSecnd(me; ipnt : Integer; VTang1, VTang2 : Vector from math;
374 Length : Real; VScnd : out Vector from math)
377 InitCutting(me; aBase : Base from PLib; CurvTol : Real;
378 aCurve : out Curve from FEmTool)
379 raises ConstructionError from Standard
382 AssemblingConstraints(me; Curve : Curve from FEmTool;
383 Parameters : Array1OfReal from TColStd;
384 CBLONG : Real from Standard;
385 A : out Assembly from FEmTool)
388 InitTthetaF(me : in out; ndimen : Integer from Standard;
389 typcon : Constraint from AppParCurves;
390 begin : Integer from Standard;
391 jndex : Integer from Standard)
397 -- Description of the points to smooth and the constraints
401 myDimension : Integer;
402 myFirstPoint : Integer;
403 myLastPoint : Integer;
404 myNbPoints : Integer;
405 myTabPoints : HArray1OfReal;
406 myConstraints : HArray1OfConstraintCouple;
407 myNbConstraints : Integer;
408 myTabConstraints : HArray1OfReal;
409 myNbPassPoints : Integer;
410 myNbTangPoints : Integer;
411 myNbCurvPoints : Integer;
412 myTypConstraints : HArray1OfInteger;
413 myTtheta : HArray1OfReal;
414 myTfthet : HArray1OfReal;
416 -- Context parameters
417 myMaxDegree : Integer;
418 myMaxSegment : Integer;
419 myNbIterations: Integer;
423 myContinuity : Shape from GeomAbs;
425 myWithMinMax : Boolean;
426 myWithCutting: Boolean;
428 myCriterium : Real[4];
429 mySmoothCriterion : SmoothCriterion from AppParCurves;
432 myParameters : HArray1OfReal;
433 myKnots : HArray1OfReal;
434 myMBSpCurve : MultiBSpCurve;
437 myMaxErrorIndex: Integer;
438 myAverageError : Real;
439 myIsCreated : Boolean;
441 myIsOverConstr : Boolean;