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
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.
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.
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.
21 -- Igor FEOKTISTOV - correction 14/12/98
24 generic class Variational from AppParCurves
26 ToolLine as any) -- as ToolLine(MultiLine)
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 "
34 uses Matrix from math,
36 HArray1OfReal from TColStd,
37 Array1OfReal from TColStd,
38 HArray1OfInteger from TColStd,
40 HArray1OfConstraintCouple from AppParCurves,
41 MultiBSpCurve from AppParCurves,
42 SmoothCriterion from AppParCurves,
44 Assembly from FEmTool,
46 Constraint from AppParCurves
48 raises OutOfRange from Standard,
49 DimensionError from Standard,
50 DomainError from Standard,
51 ConstructionError from Standard,
53 VectorWithNullMagnitude from gp
55 class MyCriterion instantiates LinearCriteria from AppParCurves
56 (MultiLine, ToolLine);
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
76 -- ((MaxDegree-Continuity)*MaxSegment -Nc0 - 2*Nc1
79 -- The problem is over-constrained.
81 -- Limitation : The MultiLine has to be composed by
82 -- only one Line ( Dimension 2 or 3).
84 returns Variational from AppParCurves;
87 Approximate(me : in out)
88 ---Purpose: Makes the approximation with the current fields.
89 raises NotDone from StdFail
94 -- ==================== The Selectors ===========================
97 ---Purpose: returns True if the creation is done
98 -- and correspond to the current fields.
104 ---Purpose: returns True if the approximation is ok
105 -- and correspond to the current fields.
109 IsOverConstrained(me)
110 ---Purpose: returns True if the problem is overconstrained
111 -- in this case, approximation cannot be done.
116 ---Purpose: returns all the BSpline curves approximating the
117 -- MultiLine SSP after minimization of the parameter.
119 returns MultiBSpCurve from AppParCurves
120 raises NotDone from StdFail
125 ---Purpose: returns the maximum of the distances between
126 -- the points of the multiline and the approximation
129 raises NotDone from StdFail
133 ---Purpose: returns the index of the MultiPoint of ErrorMax
136 raises NotDone from StdFail
141 ---Purpose: returns the quadratic average of the distances between
142 -- the points of the multiline and the approximation
145 raises NotDone from StdFail
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
155 ---Purpose: returns the average error between
156 -- the MultiLine and the approximation.
159 raises NotDone from StdFail
163 ---Purpose: returns the parameters uses to the approximations
164 ---C++: return const&
166 returns HArray1OfReal
167 raises NotDone from StdFail
171 ---Purpose: returns the knots uses to the approximations
172 ---C++: return const&
173 returns HArray1OfReal
174 raises NotDone from StdFail
177 Criterium(me; VFirstOrder,
179 VThirdOrder : out Real)
180 ---Purpose: returns the values of the quality criterium.
181 raises NotDone from StdFail
185 Percent1, Percent2, Percent3 : out Real)
186 ---Purpose: returns the Weights (as percent) associed to the criterium used in
191 ---Purpose: returns the Maximum Degree used in the approximation
196 ---Purpose: returns the Maximum of segment used in the approximation
201 ---Purpose: returns the Continuity used in the approximation
202 returns Shape from GeomAbs
207 ---Purpose: returns if the approximation search to minimize the
208 -- maximum Error or not.
213 ---Purpose: returns if the approximation can insert new Knots or not.
218 ---Purpose: returns the tolerance used in the approximation.
223 ---Purpose: returns the number of iterations used in the approximation.
227 Dump(me ; o : in out OStream)
228 ---Purpose: Prints on the stream o information on the current state
230 -- MaxError,MaxErrorIndex,AverageError,QuadraticError,Criterium
231 -- Distances,Degre,Nombre de poles, parametres, noeuds
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
241 SetParameters(me:in out; param : HArray1OfReal)
242 ---Purpose: Defines the parameters used by the approximations.
243 raises DimensionError
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
251 raises DimensionError,
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
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
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
274 raises ConstructionError from Standard
278 SetWithMinMax(me: in out; MinMax : Boolean)
279 ---Purpose: Define if the approximation search to minimize the
280 -- maximum Error or not.
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
290 SetCriteriumWeight(me : in out;
291 Percent1, Percent2, Percent3 : Real)
292 ---Purpose: define the Weights (as percent) associed to the criterium used in
295 raises DomainError -- if Percent <= 0
298 SetCriteriumWeight(me : in out;
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
308 SetTolerance(me:in out; Tol : Real)
309 ---Purpose: define the tolerance used in the approximation.
312 SetNbIterations(me:in out; Iter : Integer)
313 ---Purpose: define the number of iterations used in the approximation.
314 raises DomainError -- if Iter < 1
318 -- ====================== The Private methods ======================
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;
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;
333 J : in out SmoothCriterion from AppParCurves;
334 A : in out Assembly from FEmTool;
335 ToAssemble : in Boolean;
337 Curve : out Curve from FEmTool;
338 Parameters : Array1OfReal from TColStd) is private;
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;
348 ACR(me; Curve : in out Curve from FEmTool;
349 Ti : in out Array1OfReal from TColStd;
350 Decima: Integer) is private;
352 SplitCurve(me; InCurve : Curve from FEmTool;
353 Ti : Array1OfReal from TColStd;
355 OutCurve: out Curve from FEmTool;
356 iscut : out Boolean) is private;
359 raises NotDone from StdFail,
360 ConstructionError from Standard,
361 DimensionError from Standard
364 InitSmoothCriterion(me : in out)
367 InitParameters(me : in out; Length : out Real)
368 raises ConstructionError from Standard
371 InitCriterionEstimations(me; Length : Real; J1, J2, J3 : out Real)
374 EstTangent(me; ipnt : Integer; VTang : out Vector from math)
377 EstSecnd(me; ipnt : Integer; VTang1, VTang2 : Vector from math;
378 Length : Real; VScnd : out Vector from math)
381 InitCutting(me; aBase : Base from PLib; CurvTol : Real;
382 aCurve : out Curve from FEmTool)
383 raises ConstructionError from Standard
386 AssemblingConstraints(me; Curve : Curve from FEmTool;
387 Parameters : Array1OfReal from TColStd;
388 CBLONG : Real from Standard;
389 A : out Assembly from FEmTool)
392 InitTthetaF(me : in out; ndimen : Integer from Standard;
393 typcon : Constraint from AppParCurves;
394 begin : Integer from Standard;
395 jndex : Integer from Standard)
401 -- Description of the points to smooth and the constraints
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;
420 -- Context parameters
421 myMaxDegree : Integer;
422 myMaxSegment : Integer;
423 myNbIterations: Integer;
427 myContinuity : Shape from GeomAbs;
429 myWithMinMax : Boolean;
430 myWithCutting: Boolean;
432 myCriterium : Real[4];
433 mySmoothCriterion : SmoothCriterion from AppParCurves;
436 myParameters : HArray1OfReal;
437 myKnots : HArray1OfReal;
438 myMBSpCurve : MultiBSpCurve;
441 myMaxErrorIndex: Integer;
442 myAverageError : Real;
443 myIsCreated : Boolean;
445 myIsOverConstr : Boolean;