0024428: Implementation of LGPL license
[occt.git] / src / AppParCurves / AppParCurves_Variational_4.gxx
CommitLineData
b311480e 1// Created on: 1998-12-08
2// Created by: Igor FEOKTISTOV
3// Copyright (c) 1998-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17void AppParCurves_Variational::ACR(Handle(FEmTool_Curve)& Curve,
18 TColStd_Array1OfReal& Ti,
19 const Standard_Integer Decima) const
20{
21
22 const Standard_Real Eps = 1.e-8;
23
24 TColStd_Array1OfReal& Knots = Curve->Knots();
25 Standard_Integer NbrPnt = Ti.Length(), TiFirst = Ti.Lower(), TiLast = Ti.Upper(),
26 KFirst = Knots.Lower(), KLast = Knots.Upper();
27
28 Standard_Real CbLong, DeltaT, VTest, UNew, UOld, DU, TPara, TOld, DTInv, Ratio;
29 Standard_Integer ipnt, ii, IElm, IOld, POld, PCnt, ICnt=0;
30 Standard_Integer NbCntr = myNbPassPoints + myNbTangPoints + myNbCurvPoints;
31
32 // (1) Calcul de la longueur de courbe
33
34 Curve->Length(Ti(TiFirst), Ti(TiLast), CbLong);
35
36 // (2) Mise de l'acr dans Ti
37
38 if(NbrPnt >= 2) {
39
40 // (2.0) Initialisation
41 DeltaT = (Ti(TiLast) - Ti(TiFirst)) / Decima;
42 VTest = Ti(TiFirst) + DeltaT;
43
44 if(NbCntr > 0) {
45 PCnt = myTypConstraints->Value(1) - myFirstPoint + TiFirst;
46 ICnt = 1;
47 }
48 else
49 PCnt = TiLast + 1;
50
51 UOld = 0.;
52
53 TOld = Ti(TiFirst);
54 POld = TiFirst;
55
56 IElm = KFirst;
57 IOld = IElm;
58
59 Ti(TiFirst) = 0.;
60
61 for(ipnt = TiFirst + 1; ipnt <= TiLast; ipnt++) {
62
63 while((ICnt <= NbCntr) && (PCnt < ipnt)) {
64 ICnt++;
65 PCnt = myTypConstraints->Value(2*ICnt-1) - myFirstPoint + TiFirst;
66 }
67
68 TPara = Ti(ipnt);
69
70 if(TPara >= VTest || PCnt == ipnt) {
71
72 if ( Ti(TiLast) - TPara <= 1.e-2*DeltaT) {
73 ipnt = TiLast;
74 TPara = Ti(ipnt);
75 }
76 // (2.2), (2.3) Cacul la longueur de courbe
77 Curve->Length(Ti(TiFirst), TPara, UNew);
78
79 UNew /= CbLong;
80
81 while(Knots(IElm + 1) < TPara && IElm < KLast - 1) IElm++;
82
83 // (2.4) Mise a jours des parametres de decoupe
84 DTInv = 1. / (TPara - TOld);
85 DU = UNew - UOld;
86
87 for(ii = IOld+1; ii <= IElm; ii++) {
88 Ratio = (Knots(ii) - TOld) * DTInv;
89 Knots(ii) = UOld + Ratio * DU;
90 }
91
92 // (2.5) Mise a jours des parametres de points.
93
94 //Very strange loop, because it never works (POld+1 > ipnt-1)
95 for(ii = POld+1; ii <= ipnt-1; ii++) {
96 Ratio = ( Ti(ii) - TOld ) * DTInv;
97 Ti(ii) = UOld + Ratio * DU;
98 }
99
100 Ti(ipnt) = UNew;
101
102 UOld = UNew;
103 IOld = IElm;
104 TOld = TPara;
105 POld = ipnt;
106
107 }
108 // --> Nouveau seuil parametrique pour le decimage
109
110 if(TPara >= VTest) {
111// ii = RealToInt((TPara - VTest + Eps) / DeltaT);
112// VTest += (ii + 1) * DeltaT;
113 VTest += Ceiling((TPara - VTest + Eps) / DeltaT) * DeltaT;
114 if(VTest > 1. - Eps) VTest = 1.;
115 }
116 }
117 }
118
119 // --- On ajuste les valeurs extremes
120
121 Ti(TiFirst) = 0.;
122 Ti(TiLast) = 1.;
123 ii = TiLast - 1;
124 while ( Ti(ii) > Knots(KLast) ) {
125 Ti(ii) = 1.;
126 --ii;
127 }
128 Knots(KFirst) = 0.;
129 Knots(KLast) = 1.;
130
131}
132
133