summaryrefslogtreecommitdiff
path: root/src/Law/Law_Composite.cxx
blob: e4922ad5ed7b814ac02cb69a36bc770bf2add87a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
// File:	Law_Composite.cxx
// Created:	Fri Mar 29 17:41:05 1996
// Author:	Laurent BOURESCHE
//		<lbo@phylox>

// pmn -> 17/01/1996 added : Continuity, (Nb)Intervals, D2, Trim

#include <Law_Composite.ixx>
#include <ElCLib.hxx>
#include <Law_ListIteratorOfLaws.hxx>
#include <Law_Laws.hxx>

#include <TColStd_HArray1OfReal.hxx>
#include <Standard_NotImplemented.hxx>

//=======================================================================
//function : Law_Composite
//purpose  : 
//=======================================================================

Law_Composite::Law_Composite() 
                :  first(-1.e100),last(1.e100), 
		   periodic(Standard_False),
		   TFirst(-1.e100), TLast(1.e100), PTol(0.)
		  
{
}
//=======================================================================
//function : Law_Composite
//purpose  : 
//=======================================================================

Law_Composite::Law_Composite(const Standard_Real First,
			     const Standard_Real Last,
			     const Standard_Real Tol) :
			     first(-1.e100),last(1.e100),
			     periodic(Standard_False),
			     TFirst(First), TLast(Last),PTol(Tol) 
			     
{
}

//=======================================================================
//function : Continuity
//purpose  : 
//=======================================================================
GeomAbs_Shape Law_Composite::Continuity() const 
{
  Standard_NotImplemented::Raise("Law_Composite::Continuity()");
  return GeomAbs_C0;
}

//=======================================================================
//function : NbIntervals
//purpose  : On ne se casse pas la tete, on decoupe pour chaque composant
//=======================================================================
Standard_Integer Law_Composite::NbIntervals(const GeomAbs_Shape S) const 
{
 Law_ListIteratorOfLaws It(funclist);
 Handle(Law_Function) func;
 Standard_Integer nbr_interval =0;

 for(; It.More(); It.Next()){
   func = It.Value();
   nbr_interval += func->NbIntervals(S);
 }
 return nbr_interval;
}

//=======================================================================
//function : Intervals
//purpose  : Meme simplifications....
//=======================================================================
void Law_Composite::Intervals(TColStd_Array1OfReal& T, const GeomAbs_Shape S) const 
{
  Law_ListIteratorOfLaws It(funclist);
  Handle(Law_Function) func;
  Handle(TColStd_HArray1OfReal) LocT;
  Standard_Integer nb_index, Iloc, IGlob=2;

  func = funclist.First();
  func->Bounds(T(1),T(2));

  for(; It.More(); It.Next()){
    func = It.Value();
    nb_index = func->NbIntervals(S)+1;
    LocT = new (TColStd_HArray1OfReal)(1, nb_index);
    func->Intervals(LocT->ChangeArray1(), S);
    for (Iloc=2; Iloc<=nb_index; Iloc++, IGlob++) {
      T(IGlob) = LocT->Value(Iloc);
    }
  }
}

//=======================================================================
//function : Value
//purpose  : 
//=======================================================================

Standard_Real Law_Composite::Value(const Standard_Real X)
{
  Standard_Real W = X;
  Prepare(W);
  return curfunc->Value(W);
}


//=======================================================================
//function : D1
//purpose  : 
//=======================================================================

void Law_Composite::D1(const Standard_Real X, Standard_Real& F, Standard_Real& D)
{
  Standard_Real W = X;
  Prepare(W);
  curfunc->D1(W,F,D);
}

//=======================================================================
//function : D2
//purpose  : 
//=======================================================================

void Law_Composite::D2(const Standard_Real X, 
		       Standard_Real& F, 
		       Standard_Real& D, 
		       Standard_Real& D2)
{
  Standard_Real W = X;
  Prepare(W);
  curfunc->D2(W,F,D,D2);
}

//=======================================================================
//function : Trim
//purpose  : ne garde que la partie utile dans le champs.
//=======================================================================

Handle(Law_Function) Law_Composite::Trim(const Standard_Real PFirst, 
				      const Standard_Real PLast, 
				      const Standard_Real Tol) const 
{
  Handle(Law_Composite) l = new (Law_Composite)(PFirst, PLast, Tol );
  l->ChangeLaws() = funclist;
  return l;
}

//=======================================================================
//function : Bounds
//purpose  : 
//=======================================================================

void Law_Composite::Bounds(Standard_Real& PFirst, Standard_Real& PLast)
{
  PFirst = first;
  PLast = last;
}

//=======================================================================
//function : Prepare
//purpose  : 
// Lorsque le parametre est pres d'un "noeud" on determine la loi en
// fonction du signe de tol:
//   - negatif -> Loi precedente au noeud.
//   - positif -> Loi consecutive au noeud. 
//=======================================================================

void Law_Composite::Prepare(Standard_Real& W)
{
  Standard_Real f,l, Wtest, Eps;
  if (W-TFirst < TLast-W) { Eps = PTol; }
  else                    { Eps = -PTol;}

  if(curfunc.IsNull()){
    curfunc = funclist.Last();
    curfunc->Bounds(f,last);
    curfunc = funclist.First();
    curfunc->Bounds(first,l);
  }
  
  Wtest = W+Eps; //Decalage pour discriminer les noeuds
  if(periodic){
    Wtest = ElCLib::InPeriod(Wtest,first,last);
    W = Wtest-Eps;
  }

  curfunc->Bounds(f,l); 
  if(f <= Wtest && Wtest <= l) return; 
  if(W <= first) {
    curfunc = funclist.First();
  }
  else if(W >= last) {
    curfunc = funclist.Last();
  }
  else{
    Law_ListIteratorOfLaws It(funclist);
    for(; It.More(); It.Next()){
      curfunc = It.Value();
      curfunc->Bounds(f,l);
      if (f <= Wtest && Wtest <= l) return;
    }
  }
}


//=======================================================================
//function : ChangeElementaryLaw
//purpose  : 
//=======================================================================

Handle(Law_Function)& Law_Composite::ChangeElementaryLaw(const Standard_Real W)
{
  Standard_Real WW = W;
  Prepare(WW);
  return curfunc;
}

//=======================================================================
//function : ChangeLaws
//purpose  : 
//=======================================================================

Law_Laws& Law_Composite::ChangeLaws()
{
  return funclist;
}

//=======================================================================
//function : IsPeriodic
//purpose  : 
//=======================================================================

Standard_Boolean Law_Composite::IsPeriodic() const 
{
  return periodic;
}

//=======================================================================
//function : SetPeriodic
//purpose  : 
//=======================================================================

void Law_Composite::SetPeriodic()
{
  periodic = Standard_True;
}