summaryrefslogtreecommitdiff
path: root/src/TopTrans/TopTrans_CurveTransition.cxx
blob: d00b430896496346793a5a0c7c563f501bcd9a48 (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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
// File:	TopTrans_CurveTransition.cxx
// Created:	Thu Jan 23 18:57:37 1992
// Author:	Didier PIFFAULT
//		<dpf@sdsun1>
// Copyright:	Matra Datavision 1992

#include <TopTrans_CurveTransition.ixx>
#include <TopAbs.hxx>

#define GREATER 1
#define SAME 0
#define LOWER -1

//=======================================================================
//function : TopTrans_CurveTransition
//purpose  : Empty Constructor.
//=======================================================================

TopTrans_CurveTransition::TopTrans_CurveTransition ()
{
}

//=======================================================================
//function : Reset
//purpose  : Initializer for a complex curve transition with the elements
//           of the intersecting curve.
//=======================================================================

void TopTrans_CurveTransition::Reset (const gp_Dir& Tgt,
				      const gp_Dir& Norm,
				      const Standard_Real Curv)
{
       myTgt=Tgt; myNorm=Norm; myCurv=Curv; Init=Standard_True;
}

//=======================================================================
//function : Reset
//purpose  : Initializer for a complex curve transition with the elements
//           of the intersecting straight line.
//=======================================================================

void TopTrans_CurveTransition::Reset (const gp_Dir& Tgt)
{
       myTgt=Tgt; myCurv=0.; Init=Standard_True;
}

//=======================================================================
//function : Compare
//purpose  : Compare the elements of  an interference  on  an intersected
//           curve with the interference stored in the complex Transition.
//=======================================================================

void TopTrans_CurveTransition::Compare (const Standard_Real Tole,
					const gp_Dir& T,
					const gp_Dir& N,
					const Standard_Real C,
					const TopAbs_Orientation St,
					const TopAbs_Orientation Or)
{
  // S is the transition, how the curve cross the boundary
  // O is the orientation, how the intersection is set on the boundary
  TopAbs_Orientation S = St;
  TopAbs_Orientation O = Or;

  // adjustment for INTERNAL transition
  if (S == TopAbs_INTERNAL) {
    if (T * myTgt < 0)
      S = TopAbs::Reverse(O);
    else
      S = O;
  }

  // It is the first comparaison for this complex transition 
  if (Init) {
    Init=Standard_False;
    TgtFirst =T;
    NormFirst=N;
    CurvFirst=C;
    TranFirst=S;
    TgtLast  =T;
    NormLast =N;
    CurvLast =C;
    TranLast =S;
    switch (O) {
      // Interference en fin d'arete il faut inverser la tangente 
    case TopAbs_REVERSED :
      TgtFirst.Reverse();
      TgtLast.Reverse();
      break;
    case TopAbs_INTERNAL :
      // Interference en milieu d'arete il faut inverser en fonction de la
      // position de la tangente de reference
      if (myTgt*T>0) TgtFirst.Reverse();
      else           TgtLast.Reverse();
      break;
    case TopAbs_FORWARD :
    case TopAbs_EXTERNAL :
      break;
    }
  }

  // Compare with the existent first and last transition :
  else {
    Standard_Boolean FirstSet=Standard_False;
    Standard_Real cosAngWithT=myTgt*T;
    switch (O) {
    case TopAbs_REVERSED :
      cosAngWithT= -cosAngWithT;
      break;
    case TopAbs_INTERNAL :
      if (cosAngWithT>0) cosAngWithT=-cosAngWithT;
      break;
    case TopAbs_FORWARD :
    case TopAbs_EXTERNAL :
      break;
    }
    Standard_Real cosAngWith1=myTgt*TgtFirst;
    
    switch (Compare(cosAngWithT, cosAngWith1, Tole)) {
      
    case LOWER :
      // If the angle is greater than the first the new become the first
      FirstSet=Standard_True;
      TgtFirst =T;
      switch (O) {
      case TopAbs_REVERSED :
	TgtFirst.Reverse();
	break;
      case TopAbs_INTERNAL :
	if (myTgt*T>0) TgtFirst.Reverse();
	break;
      case TopAbs_FORWARD :
      case TopAbs_EXTERNAL :
	break;
      }
      NormFirst=N;
      CurvFirst=C;
      TranFirst=S;
      break;

    case SAME :
      // If same angles we look at the Curvature
      if (IsBefore(Tole, cosAngWithT, N, C, NormFirst, CurvFirst)) {
        FirstSet=Standard_True;
	TgtFirst =T;
	switch (O) {
	case TopAbs_REVERSED :
	  TgtFirst.Reverse();
	  break;
	case TopAbs_INTERNAL :
	  if (myTgt*T>0) TgtFirst.Reverse();
	  break;
	case TopAbs_FORWARD :
	case TopAbs_EXTERNAL :
	  break;
	}
	NormFirst=N;
	CurvFirst=C;
	TranFirst=S;
      }
      break;
  
    case GREATER:
      break;
    }

    if (!FirstSet || O==TopAbs_INTERNAL) {
      // Dans les cas de tangence le premier peut etre aussi le dernier
      if (O==TopAbs_INTERNAL) cosAngWithT=-cosAngWithT;
      Standard_Real cosAngWith2=myTgt*TgtLast;
      
      switch (Compare(cosAngWithT, cosAngWith2, Tole)) {
	
      case GREATER:
	// If the angle is lower than the last the new become the last
	TgtLast  =T;
	switch (O) {
	case TopAbs_REVERSED :
	  TgtLast.Reverse();
	  break;
	case TopAbs_INTERNAL :
	  if (myTgt*T<0) TgtLast.Reverse();
	  break;
	case TopAbs_FORWARD :
	case TopAbs_EXTERNAL :
	  break;
	}
	NormLast =N;
	CurvLast =C;
	TranLast =S;
	break;
	
      case SAME:
	// If the angle is the same we look at the curvature
	if (IsBefore(Tole, cosAngWithT, NormLast, CurvLast, N, C)) {
	  TgtLast =T;
	  switch (O) {
	  case TopAbs_REVERSED :
	    TgtLast.Reverse();
	    break;
	  case TopAbs_INTERNAL :
	    if (myTgt*T<0) TgtLast.Reverse();
	    break;
	  case TopAbs_FORWARD :
	  case TopAbs_EXTERNAL :
	    break;
	  }
	  NormLast=N;
	  CurvLast=C;
	  TranLast=S;
	}
      }
    }
  }
}

//=======================================================================
//function : StateBefore
//purpose  : Give the state of the curv before the interference.
//=======================================================================

TopAbs_State TopTrans_CurveTransition::StateBefore () const
{
  if (Init) return TopAbs_UNKNOWN;
  switch (TranFirst)
    {
    case TopAbs_FORWARD  :
    case TopAbs_EXTERNAL :
      return TopAbs_OUT;
    case TopAbs_REVERSED :
    case TopAbs_INTERNAL :
      return TopAbs_IN;
    }
  return TopAbs_OUT;
}

//=======================================================================
//function : StateAfter
//purpose  : give the state of the curve after the interference.
//=======================================================================

TopAbs_State TopTrans_CurveTransition::StateAfter () const
{
  if (Init) return TopAbs_UNKNOWN;
  switch (TranLast)
    {
    case TopAbs_FORWARD  :
    case TopAbs_INTERNAL :
      return TopAbs_IN;
    case TopAbs_REVERSED :
    case TopAbs_EXTERNAL :
      return TopAbs_OUT;
    }
  return TopAbs_OUT;
}


//=======================================================================
//function : IsBefore
//purpose  : Compare the curvature of the two transition and return true
//           if T1 is before T2
//=======================================================================

Standard_Boolean TopTrans_CurveTransition::IsBefore
  (const Standard_Real    Tole,
   const Standard_Real    CosAngl,
   const gp_Dir&          N1, 
   const Standard_Real    C1,
   const gp_Dir&          N2,
   const Standard_Real    C2) const
{
  Standard_Real TN1=myTgt*N1;
  Standard_Real TN2=myTgt*N2;
  Standard_Boolean OneBefore=Standard_False;

  if (Abs(TN1)<=Tole || Abs(TN2)<=Tole) {
    // Tangent : The first is the interference which have the nearest curvature
    //           from the reference.
    if (myCurv==0) {
      // The reference is straight
      // The first is the interference which have the lowest curvature.
      if (C1<C2) OneBefore=Standard_True;
//  Modified by Sergey KHROMOV - Wed Dec 27 17:08:49 2000 Begin
      if (CosAngl>0)
	OneBefore=!OneBefore;
//  Modified by Sergey KHROMOV - Wed Dec 27 17:08:50 2000 End
    }
    else {
      // The reference is curv 
      // The first is the interference which have the nearest curvature
      // in the direction
      Standard_Real deltaC1, deltaC2;
      if (C1==0. || myCurv==0.) {
	deltaC1=C1-myCurv;
      }
      else {
	deltaC1=(C1-myCurv)*(N1*myNorm);
      }
      if (C2==0. || myCurv==0.) {
	deltaC2=C2-myCurv;
      }
      else {
	deltaC2=(C2-myCurv)*(N2*myNorm);
      }
      if (deltaC1 < deltaC2) OneBefore=Standard_True;
      if (CosAngl>0) OneBefore=!OneBefore;
    }
  }
  else if (TN1<0) {
    // Before the first interference we are in the curvature
    if (TN2>0) {
      // Before the second  interference we are out the curvature
      // The first interference is before  /* ->)( */
      OneBefore=Standard_True;
    }
    else {
      // Before the second interference we are in the curvature
      if (C1>C2) {
	// We choice the greater curvature
	// The first interference is before   /* ->)) */
	OneBefore=Standard_True;
      }
    }
  }
  else if (TN1>0) {
    // Before the first interference we are out the curvature
    if (TN2>0) {
      // Before the second interference we are out the curvature /* ->(( */
      if (C1<C2) {
	// We choice the lower curvature
	// The first interference is before 
	OneBefore=Standard_True;
      }
    }
  }
  return OneBefore;
}


//=======================================================================
//function : Compare
//purpose  : Compare two angles
//=======================================================================

Standard_Integer TopTrans_CurveTransition::Compare(const Standard_Real Ang1, 
					  const Standard_Real Ang2,
					  const Standard_Real Tole) const
{
  Standard_Integer res=SAME;
  if (Ang1 - Ang2 > Tole) res=GREATER;
  else if (Ang2 - Ang1 > Tole) res=LOWER;

  return res;
}