0023024: Update headers of OCCT files
[occt.git] / src / AppParCurves / AppParCurves_Variational.cdl
1 -- Created on: 1996-05-14
2 -- Created by: Philippe MANGIN / Jeannine PANCIATICI
3 -- Copyright (c) 1996-1999 Matra Datavision
4 -- Copyright (c) 1999-2012 OPEN CASCADE SAS
5 --
6 -- The content of this file is subject to the Open CASCADE Technology Public
7 -- License Version 6.5 (the "License"). You may not use the content of this file
8 -- except in compliance with the License. Please obtain a copy of the License
9 -- at http://www.opencascade.org and read it completely before using this file.
10 --
11 -- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 -- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 --
14 -- The Original Code and all software distributed under the License is
15 -- distributed on an "AS IS" basis, without warranty of any kind, and the
16 -- Initial Developer hereby disclaims all such warranties, including without
17 -- limitation, any warranties of merchantability, fitness for a particular
18 -- purpose or non-infringement. Please see the License for the specific terms
19 -- and conditions governing the rights and limitations under the License.
20
21 --              Igor  FEOKTISTOV  -  correction  14/12/98
22
23
24 generic class Variational from AppParCurves                 
25                     (MultiLine   as any;
26                      ToolLine    as any)   -- as ToolLine(MultiLine)
27
28
29     ---Purpose: This class is used to smooth N points with constraints
30     --          by   minimization  of quadratic  criterium   but  also
31     --          variational criterium in order to obtain " fair Curve "
32     --          
33
34 uses Matrix                    from math,
35      Vector                    from math,
36      HArray1OfReal             from TColStd, 
37      Array1OfReal              from TColStd, 
38      HArray1OfInteger          from TColStd,
39      Shape                     from GeomAbs,       
40      HArray1OfConstraintCouple from AppParCurves,
41      MultiBSpCurve             from AppParCurves,  
42      SmoothCriterion           from AppParCurves, 
43      Curve                     from FEmTool,
44      Assembly                  from FEmTool, 
45      Base                      from PLib,
46      Constraint                from AppParCurves
47
48 raises OutOfRange from Standard,
49        DimensionError from Standard,
50        DomainError from Standard,
51        ConstructionError from Standard,
52        NotDone    from StdFail,
53        VectorWithNullMagnitude from gp
54
55     class MyCriterion instantiates LinearCriteria from AppParCurves 
56                 (MultiLine, ToolLine); 
57     
58
59 is
60     Create(SSP: MultiLine; 
61            FirstPoint, LastPoint: Integer;
62            TheConstraints: HArray1OfConstraintCouple;
63            MaxDegree: Integer = 14;
64            MaxSegment: Integer = 100;
65            Continuity : Shape from GeomAbs = GeomAbs_C2;
66            WithMinMax : Boolean = Standard_False;
67            WithCutting: Boolean = Standard_True;
68            Tolerance : Real = 1.0;
69            NbIterations: Integer = 2)
70         ---Purpose: Constructor.   
71         --            Initialization of   the   fields.
72         --            warning :  Nc0 : number of PassagePoint consraints
73         --                       Nc2 : number  of  TangencyPoint constraints 
74         --                       Nc3 : number of    CurvaturePoint   constraints
75         --            if
76         --            ((MaxDegree-Continuity)*MaxSegment -Nc0  - 2*Nc1
77         --             -3*Nc2)
78         --            is  negative 
79         --            The problem is over-constrained.
80         --            
81         --            Limitation : The MultiLine has to be composed by
82         --            only one Line ( Dimension 2 or 3).
83            
84     returns Variational from AppParCurves;
85     
86
87     Approximate(me : in out)
88       ---Purpose: Makes the approximation with the current fields.
89     raises NotDone from StdFail
90     is static;
91     
92
93     
94 --   ====================  The Selectors  =========================== 
95
96     IsCreated(me)
97         ---Purpose: returns True if the creation is done    
98         --          and correspond  to the current fields.
99     returns Boolean
100     is static;
101
102  
103     IsDone(me)
104         ---Purpose: returns True if the  approximation is ok    
105         --          and correspond  to the current fields.
106     returns Boolean
107     is static;
108     
109     IsOverConstrained(me)
110         ---Purpose: returns True if the problem is overconstrained
111         --          in this case, approximation cannot be done.
112     returns Boolean
113     is static;
114     
115     Value(me)
116         ---Purpose: returns all the BSpline curves approximating the
117         --          MultiLine SSP after minimization of the parameter.
118
119     returns MultiBSpCurve from AppParCurves
120     raises NotDone from StdFail
121     is static;
122     
123     
124     MaxError(me)
125         ---Purpose: returns the maximum of the distances between 
126         --          the points of the multiline and the approximation 
127         --          curves.  
128     returns Real 
129     raises NotDone from StdFail
130     is static;
131     
132     MaxErrorIndex(me)
133         ---Purpose: returns the index of the MultiPoint of ErrorMax  
134     returns Integer 
135     
136     raises NotDone from StdFail
137     is static;
138
139     
140     QuadraticError(me)
141         ---Purpose: returns the quadratic average of the distances between 
142         --          the points of the multiline and the approximation 
143         --          curves.
144     returns Real
145     raises NotDone from StdFail
146         is static;
147     
148     Distance(me : in out ; mat : out Matrix from math)    
149         ---Purpose: returns the distances between the points of the 
150         --          multiline and the approximation curves.
151     raises NotDone from StdFail
152     is static;
153     
154     AverageError(me)
155        ---Purpose: returns the average error between          
156        --          the MultiLine and the approximation.
157
158     returns Real
159     raises NotDone from StdFail
160     is static;
161     
162     Parameters(me)   
163         ---Purpose: returns the parameters uses to the approximations
164         ---C++: return const&
165
166     returns HArray1OfReal
167     raises NotDone from StdFail
168     is static;
169     
170     Knots(me)   
171         ---Purpose: returns the knots uses to the approximations
172         ---C++: return const&
173     returns HArray1OfReal
174     raises NotDone from StdFail
175     is static;
176     
177     Criterium(me; VFirstOrder,  
178                   VSecondOrder,  
179                   VThirdOrder : out Real) 
180     ---Purpose: returns the values of the quality criterium.      
181     raises NotDone from StdFail
182     is static;
183     
184     CriteriumWeight(me ; 
185                     Percent1,  Percent2, Percent3 : out Real)
186     ---Purpose: returns the Weights (as percent) associed  to the criterium used in
187     --          the  optimization.
188     is static;          
189     
190     MaxDegree(me)   
191     ---Purpose: returns the Maximum Degree used in the approximation 
192     returns Integer
193     is static;
194     
195     MaxSegment(me)
196      ---Purpose: returns the Maximum of segment used in the approximation 
197     returns Integer
198     is static;   
199     
200     Continuity(me)
201     ---Purpose: returns the Continuity used in the approximation 
202     returns Shape from GeomAbs
203     is static;   
204     
205     
206     WithMinMax(me)
207     ---Purpose: returns if the  approximation  search to  minimize the
208     --          maximum Error or not.
209     returns Boolean
210     is static;   
211     
212     WithCutting(me)
213     ---Purpose: returns if the  approximation can insert new Knots or not.
214     returns Boolean
215     is static;  
216
217     Tolerance(me)
218     ---Purpose: returns the tolerance used in the approximation.
219     returns Real
220     is static;
221     
222     NbIterations(me)  
223     ---Purpose: returns the number of iterations used in the approximation.
224     returns Integer
225     is static;
226     
227     Dump(me ; o : in out OStream)
228         ---Purpose: Prints on the stream o information on the current state 
229         --          of the object.
230         --          MaxError,MaxErrorIndex,AverageError,QuadraticError,Criterium
231         --          Distances,Degre,Nombre de poles, parametres, noeuds    
232     is static;
233
234     SetConstraints(me:in out; aConstrainst:HArray1OfConstraintCouple) 
235         ---Purpose: Define the constraints to approximate
236     --          If this value is incompatible with the others fields
237     --          this method modify nothing and returns false 
238     returns Boolean
239     is static;
240     
241     SetParameters(me:in out; param : HArray1OfReal)   
242         ---Purpose: Defines the parameters used by the approximations.  
243     raises DimensionError
244     is static;
245     
246     SetKnots(me:in out; knots : HArray1OfReal)   
247         ---Purpose: Defines the knots used by the approximations
248     --          If this value is incompatible with the others fields
249     --          this method modify nothing and returns false 
250     returns Boolean
251     raises DimensionError,
252            DomainError
253     is static;
254         
255     SetMaxDegree(me: in out; Degree : Integer)   
256     ---Purpose: Define the Maximum Degree used in the approximation
257     --          If this value is incompatible with the others fields
258     --          this method modify nothing and returns false 
259     returns Boolean
260     is static;
261     
262     SetMaxSegment(me: in out;  NbSegment : Integer)   
263     ---Purpose: Define the maximum number of segments used in the approximation
264     --          If this value is incompatible with the others fields
265     --          this method modify nothing and returns false 
266     returns Boolean
267     is static;   
268     
269     SetContinuity(me: in out; C : Shape from GeomAbs)
270     ---Purpose: Define the Continuity used in the approximation 
271     --          If this value is incompatible with the others fields
272     --          this method modify nothing and returns false 
273     returns Boolean         
274     raises ConstructionError from Standard
275     is static;   
276     
277     
278     SetWithMinMax(me: in out; MinMax : Boolean)
279     ---Purpose: Define if the  approximation  search to  minimize the
280     --          maximum Error or not.
281     is static;   
282     
283     SetWithCutting(me : in out; Cutting : Boolean )
284     ---Purpose: Define if the  approximation can insert new Knots or not.
285     --          If this value is incompatible with the others fields
286     --          this method modify nothing and returns false 
287     returns Boolean
288     is static;  
289
290     SetCriteriumWeight(me : in out; 
291                        Percent1,  Percent2, Percent3 : Real)
292     ---Purpose: define the Weights (as percent) associed to the criterium used in
293     --          the  optimization.
294     --          
295     raises DomainError -- if Percent <= 0
296     is static;                  
297                                                                         
298     SetCriteriumWeight(me : in out; 
299                        Order : Integer;
300                        Percent : Real)
301     ---Purpose: define the  Weight   (as  percent)  associed  to   the
302     --          criterium   Order used in   the optimization  : Others
303     --          weights are updated.           
304     raises DomainError,  -- if Percent < 0
305            OutOfRange   -- if Order < 1 or Order > 3     
306     is static;
307   
308     SetTolerance(me:in out; Tol : Real)
309     ---Purpose: define the tolerance used in the approximation.
310     is static;
311     
312     SetNbIterations(me:in out; Iter : Integer)  
313     ---Purpose: define the number of iterations used in the approximation.
314     raises DomainError  -- if Iter < 1
315     is static; 
316
317       
318 --   ====================== The Private methods ======================   
319        
320     TheMotor(me  :  in  out; 
321              J  :  in  out SmoothCriterion from AppParCurves; 
322              WQuadratic,  WQuality  :  Real;          
323              TheCurve : in  out  Curve from  FEmTool; 
324              Ecarts : out  Array1OfReal  from  TColStd)  is  private; 
325
326     Adjusting(me  :  in  out; 
327               J  :  in  out SmoothCriterion from AppParCurves; 
328               WQuadratic,  WQuality  :  in  out  Real;                
329               TheCurve : in  out  Curve from  FEmTool; 
330               Ecarts : out  Array1OfReal  from  TColStd)  is  private; 
331       
332     Optimization(me;   
333                  J  :  in  out SmoothCriterion from AppParCurves; 
334                  A  :  in  out Assembly  from  FEmTool; 
335                  ToAssemble  : in  Boolean;      
336                  EpsDeg  :  Real; 
337                  Curve  :  out  Curve  from  FEmTool; 
338                  Parameters  :  Array1OfReal  from  TColStd)  is  private;    
339
340     Project(me;  C  :  Curve from  FEmTool;   
341                  Ti  :  Array1OfReal  from  TColStd; 
342                  ProjTi    :  out  Array1OfReal from  TColStd;  
343                  Distance  :  out  Array1OfReal from  TColStd; 
344                  NumPoints  :  out  Integer; 
345                  MaxErr,  QuaErr,  AveErr  :  out  Real; 
346                  NbIterations: Integer=2)  is  private; 
347
348     ACR(me;  Curve : in  out  Curve from  FEmTool; 
349              Ti    : in  out  Array1OfReal from  TColStd; 
350              Decima: Integer)  is  private; 
351
352     SplitCurve(me;  InCurve :  Curve from  FEmTool; 
353                     Ti      :  Array1OfReal from  TColStd;  
354                     CurveTol:  Real;
355                     OutCurve:  out Curve from  FEmTool; 
356                     iscut   :  out Boolean)  is  private; 
357                                      
358     Init(me : in out) 
359     raises NotDone from StdFail,
360            ConstructionError from Standard,
361            DimensionError from Standard
362     is private; 
363      
364     InitSmoothCriterion(me  :  in  out)   
365     is  private; 
366      
367     InitParameters(me  :  in  out;  Length  :  out  Real) 
368     raises  ConstructionError from Standard
369     is  private; 
370        
371     InitCriterionEstimations(me;  Length  :  Real;  J1,  J2,  J3  :  out  Real) 
372     is  private; 
373      
374     EstTangent(me;  ipnt  :  Integer;  VTang  :  out  Vector  from  math) 
375     is  private;
376  
377     EstSecnd(me;  ipnt  :  Integer;  VTang1,  VTang2  :  Vector  from  math; 
378                   Length  :  Real;  VScnd  :  out  Vector  from  math) 
379     is  private;
380  
381     InitCutting(me;  aBase  :  Base  from  PLib; CurvTol  :  Real;  
382                      aCurve  :  out  Curve   from  FEmTool) 
383     raises  ConstructionError from Standard
384     is  private;  
385      
386     AssemblingConstraints(me;  Curve  :  Curve  from  FEmTool; 
387                               Parameters  :  Array1OfReal  from  TColStd; 
388                               CBLONG  :  Real  from  Standard; 
389                               A  :  out  Assembly  from  FEmTool) 
390     is  private;  
391     
392     InitTthetaF(me : in out;  ndimen  :  Integer  from  Standard;
393                               typcon  :  Constraint  from  AppParCurves;
394                               begin   :  Integer  from  Standard; 
395                               jndex   :  Integer  from  Standard)
396     returns  Boolean
397     is  private;
398                               
399
400 fields
401      -- Description of the points to smooth and the constraints
402 mySSP  :  MultiLine;
403 myNbP3d  : Integer;
404 myNbP2d : Integer;
405 myDimension : Integer;
406 myFirstPoint : Integer;
407 myLastPoint : Integer;
408 myNbPoints : Integer;
409 myTabPoints : HArray1OfReal;
410 myConstraints : HArray1OfConstraintCouple;
411 myNbConstraints : Integer;
412 myTabConstraints : HArray1OfReal;
413 myNbPassPoints : Integer;
414 myNbTangPoints : Integer;
415 myNbCurvPoints : Integer;
416 myTypConstraints : HArray1OfInteger; 
417 myTtheta  :  HArray1OfReal; 
418 myTfthet  :  HArray1OfReal;
419
420      -- Context parameters
421 myMaxDegree  : Integer;
422 myMaxSegment : Integer;
423 myNbIterations: Integer;
424 myTolerance : Real; 
425
426      -- Options
427 myContinuity : Shape from GeomAbs;
428 myNivCont : Integer;
429 myWithMinMax : Boolean;
430 myWithCutting: Boolean;
431 myPercent    : Real[3];
432 myCriterium  : Real[4]; 
433 mySmoothCriterion  :  SmoothCriterion  from  AppParCurves; 
434
435      -- output
436 myParameters  : HArray1OfReal;
437 myKnots      : HArray1OfReal;
438 myMBSpCurve  : MultiBSpCurve;
439
440 myMaxError     : Real;
441 myMaxErrorIndex: Integer;
442 myAverageError : Real;
443 myIsCreated      : Boolean;
444 myIsDone         : Boolean;
445 myIsOverConstr : Boolean;
446
447 end Variational;