summaryrefslogtreecommitdiff
path: root/src/TopOpeBRep/TopOpeBRep_FFTransitionTool.cxx
blob: ebd2cefcae59c78c9f2f9605f9c84ff14b99058b (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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
// File:	TopOpeBRep_FFTransitionTool.cxx
// Created:	Thu Oct 27 11:14:38 1994
// Author:	Jean Yves LEBEY
//		<jyl@bravox>

#include <TopOpeBRepDS_SolidSurfaceInterference.hxx>
#include <TopOpeBRepDS_CurvePointInterference.hxx>
#include <TopOpeBRepDS_SurfaceCurveInterference.hxx>
#include <TopAbs.hxx>
#include <IntSurf_Transition.hxx>
#include <IntSurf_TypeTrans.hxx>
#include <IntSurf_Situation.hxx>
#include <TopOpeBRep_FFTransitionTool.ixx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS.hxx>
#include <BRep_Tool.hxx>
#include <Geom_Surface.hxx>
#include <Geom_Curve.hxx>
#include <GeomAPI_ProjectPointOnCurve.hxx>
#include <gp_Vec.hxx>

#ifdef DEB
Standard_IMPORT Standard_Boolean TopOpeBRepDS_GettraceDSF();
#endif

//-----------------------------------------------------------------------
//function : TransitionToOrientation
//purpose  : static
//-----------------------------------------------------------------------

static Standard_Boolean TransitionToOrientation
(const IntSurf_Transition& T, 
 TopAbs_Orientation& O)
{
  Standard_Boolean Odefined = Standard_True;
  TopAbs_Orientation result = TopAbs_FORWARD;
  IntSurf_TypeTrans trans;
  IntSurf_Situation situa;

  trans = T.TransitionType();

  switch (trans) {
    
  case IntSurf_In  : result = TopAbs_FORWARD; break;
  case IntSurf_Out : result = TopAbs_REVERSED; break;
    
  case IntSurf_Touch :
    situa = T.Situation();
    switch (situa) {
    case IntSurf_Inside  : result = TopAbs_INTERNAL;  break;
    case IntSurf_Outside : result = TopAbs_EXTERNAL; break;
    case IntSurf_Unknown :
    Odefined = Standard_False;
#ifdef DEB
//    if ( TopOpeBRepDS_GettraceDSF() ) { 
//      cout<<"TopOpeBRepDS:TransitionToOrientation : unknown situation"<<endl;
//    }
#endif
    break;
    }
    break;

  case IntSurf_Undecided :
  Odefined = Standard_False;
#ifdef DEB
//  if ( TopOpeBRepDS_GettraceDSF() ) { 
//    cout<<"TopOpeBRepDS:TransitionToOrientation : undecided transition"<<endl;
//  }
#endif
  break;
  }

  O = result;
  return Odefined;
}


//=======================================================================
//function : ProcessLineTransition
//purpose  : compute the transition of the intersection
//         : point <P> on the intersected shape of index <Index> (1 or 2)
//         : for a line crossing an edge
//=======================================================================

TopOpeBRepDS_Transition TopOpeBRep_FFTransitionTool::ProcessLineTransition
  (const TopOpeBRep_VPointInter &P,
   const Standard_Integer Index,
   const TopAbs_Orientation EdgeOrientation)
{
  TopOpeBRepDS_Transition TT;

  if ((EdgeOrientation==TopAbs_INTERNAL)||(EdgeOrientation==TopAbs_EXTERNAL)) {
    TT.Set(EdgeOrientation);
  }
  else {
    TopAbs_Orientation O;
    
    IntSurf_Transition T; {
    switch (Index) {
    case 1 : T = P.TransitionLineArc1(); break;
    case 2 : T = P.TransitionLineArc2(); break;
    }
    Standard_Boolean Odefined = ::TransitionToOrientation(T,O);
    if (Odefined) {
      if (EdgeOrientation == TopAbs_REVERSED) O = TopAbs::Complement(O);
      TT.Set(O);
    }
    else {
      TT.Set(TopAbs_UNKNOWN,TopAbs_UNKNOWN);
    }
    }
  }
  return TT;
}

//=======================================================================
//function : ProcessLineTransition
//purpose  : compute the transition of point P on line L, P lying on
//           neither of the intersecting shapes
//=======================================================================

TopOpeBRepDS_Transition TopOpeBRep_FFTransitionTool::ProcessLineTransition
(const TopOpeBRep_VPointInter &P, const TopOpeBRep_LineInter& LI)
{
  TopOpeBRepDS_Transition TT;
  TopAbs_Orientation result;
  
  // P.IsOnDomS1() and P.IsOnDomS2() are both false

  Standard_Integer nbv = LI.NbVPoint();
  TopOpeBRep_VPointInter P1 = LI.VPoint(1);
  Standard_Real par1 = P1.ParameterOnLine();
  TopOpeBRep_VPointInter Pn = LI.VPoint(nbv);
  Standard_Real parn = Pn.ParameterOnLine();

  Standard_Real par = P.ParameterOnLine();
  if      ( par == par1 ) result = TopAbs_FORWARD;
  else if ( par == parn ) result = TopAbs_REVERSED;
  else result = TopAbs_INTERNAL;

  TT.Set(result);
  return TT;
}


//=======================================================================
//function : ProcessEdgeTransition
//purpose  : compute the transition from the transition of the intersection
//         : point <P> on the intersected shape of index <Index> (1 or 2)
//         : for an edge on a line on a Face
//=======================================================================

TopOpeBRepDS_Transition TopOpeBRep_FFTransitionTool::ProcessEdgeTransition
  (const TopOpeBRep_VPointInter &P,
   const Standard_Integer Index,
   const TopAbs_Orientation FaceTransition)
{
  TopOpeBRepDS_Transition TT;

  if ((FaceTransition == TopAbs_INTERNAL) || 
      (FaceTransition == TopAbs_EXTERNAL)) {
    TT.Set(FaceTransition);
  }
  else {
    IntSurf_Transition T;
    if      ( Index == 1 ) T = P.TransitionOnS1();
    else if ( Index == 2 ) T = P.TransitionOnS2();
    
    TopAbs_Orientation O;
    Standard_Boolean defined = ::TransitionToOrientation(T,O);
    if (defined) {
      if (FaceTransition == TopAbs_REVERSED) O = TopAbs::Complement(O);
      TT.Set(O);
    }
    else {
      TT.Set(TopAbs_UNKNOWN,TopAbs_UNKNOWN);
    }
  }

  return TT;
}


//=======================================================================
//function : ProcessFaceTransition
//purpose  : compute the transition from a Line
//=======================================================================

TopOpeBRepDS_Transition TopOpeBRep_FFTransitionTool::ProcessFaceTransition
  (const TopOpeBRep_LineInter& L,
   const Standard_Integer Index,
   const TopAbs_Orientation FaceOrientation)
{
  // If Index == 1, on first shape
  // If Index == 2, on second shape
  TopOpeBRepDS_Transition TT;

  if ((FaceOrientation == TopAbs_INTERNAL) || 
      (FaceOrientation == TopAbs_EXTERNAL)) {
    TT.Set(FaceOrientation);
  }
  else {
    Standard_Boolean Odefined = Standard_True;
#ifdef DEB
    TopAbs_Orientation O;
#else
    TopAbs_Orientation O = TopAbs_FORWARD;
#endif

    IntSurf_TypeTrans trans;
    trans = (Index == 1) ? L.TransitionOnS1() : L.TransitionOnS2();

    switch (trans) {
    
    case IntSurf_In  : O = TopAbs_FORWARD; break;

    case IntSurf_Out : O = TopAbs_REVERSED; break;
      
    case IntSurf_Touch : {     

      IntSurf_Situation situa;
      situa = (Index == 1 ) ? L.SituationS1() : L.SituationS2();

      switch (situa) {	

      case IntSurf_Inside  : O = TopAbs_INTERNAL; break;

      case IntSurf_Outside : O = TopAbs_EXTERNAL; break;

      case IntSurf_Unknown :

	Odefined = Standard_False;
#ifdef DEB
	if ( TopOpeBRepDS_GettraceDSF() ) { 
	  cout<<"ProcessFaceTransition : unknown situation"<<endl;
	}
#endif
	break;
      }
      break;
      } // case Touch

    case IntSurf_Undecided :

    Odefined = Standard_False;
#ifdef DEB
    if ( TopOpeBRepDS_GettraceDSF() ) { 
      cout<<"ProcessFaceTransition : undecided transition"<<endl;
    }
#endif
    break;

    } // trans
  
    if (Odefined) {
      if (FaceOrientation == TopAbs_REVERSED) O = TopAbs::Complement(O);
      TT.Set(O);
    }
    else {
      TT.Set(TopAbs_UNKNOWN,TopAbs_UNKNOWN);
    }
  }

  return TT;
}


// -------------------------------------------------
// input : P1 : point 
// input : C2 : courbe, FC2,LC2 : bornes de C2
// output : T2 = parametre de P1 sur C2
// -------------------------------------------------
static Standard_Boolean FUN_ProjectPoint(const gp_Pnt& P1,
					 const Handle(Geom_Curve)& C2,
					 const Standard_Real FC2, 
					 const Standard_Real LC2, 
					 Standard_Real& T2)
{
  if ( C2.IsNull() ) {
    return Standard_False;
  }
  Standard_Real res = Standard_False;
  
  GeomAPI_ProjectPointOnCurve mydist(P1,C2,FC2,LC2);
  if ( mydist.Extrema().IsDone() ) {
    if ( mydist.NbPoints() ) {
      T2 = mydist.LowerDistanceParameter();
      res = Standard_True;
    }
  }
//#ifdef DEB
//  return res; // BUG ???
//#else
  return (Standard_Boolean ) res ;
//#endif

}

// -------------------------------------------------
// input : S1,U1,V1,C1,T1 avec D0(S1(U1,V1)) = D0(C1(T1))
// input : C2,FC2,LC2 : courbe, bornes de C2
// output : Trans : transition sur C1 en T1 en croisant C2
// -------------------------------------------------
static Standard_Boolean FUN_GeomTrans(const Handle(Geom_Surface)& S1,
				      const Standard_Real U1,
				      const Standard_Real V1,
				      const Handle(Geom_Curve)& C1,
				      const Standard_Real T1,
				      const Handle(Geom_Curve)& C2,
				      const Standard_Real FC2,
				      const Standard_Real LC2,
				      TopOpeBRepDS_Transition& Trans)
{
  if ( C1.IsNull() || C2.IsNull() ) {
    return Standard_False;
  }
  
  // P1 : D0(C1(T1), D1_C1 : D1(C1(T1))
  gp_Pnt P1; gp_Vec D1_C1; C1->D1(T1,P1,D1_C1);
  
  // D1_C2 : D1(C2(P1))
  Standard_Real T2 = 0; 
  Standard_Boolean projok = ::FUN_ProjectPoint(P1,C2,FC2,LC2,T2);
  if ( !projok ) {
    return Standard_False;
  }
  gp_Pnt P2; gp_Vec D1_C2; C2->D1(T2,P2,D1_C2);
  
  // N1 : D1(S1(U1,V1))
  gp_Vec N1,D1U,D1V; 
  gp_Pnt PS;
  S1->D1(U1,V1,PS,D1U,D1V);
  D1U.Normalize();
  D1V.Normalize();
  N1 = D1U.Crossed(D1V);
  N1.Normalize();
  
  gp_Vec N1D1_C1 = N1.Crossed(D1_C1);
  Standard_Real dot = N1D1_C1.Dot(D1_C2);
  if ( dot > 0 ) {
    Trans.Before(TopAbs_OUT);
    Trans.After(TopAbs_IN);
  }
  else {
    Trans.Before(TopAbs_IN);
    Trans.After(TopAbs_OUT);
  }
  
  return Standard_True;
}
 
//=======================================================================
//function : ProcessEdgeONTransition
//purpose  : 
//=======================================================================

TopOpeBRepDS_Transition TopOpeBRep_FFTransitionTool::ProcessEdgeONTransition
(const TopOpeBRep_VPointInter& VP,
 const Standard_Integer ShapeIndex,
 const TopoDS_Shape& RR,
 const TopoDS_Shape& EE,
 const TopoDS_Shape& FF)
{
 const TopoDS_Edge& R = TopoDS::Edge(RR);
 const TopoDS_Edge& E = TopoDS::Edge(EE);
 const TopoDS_Face& F = TopoDS::Face(FF);

 TopAbs_Orientation oriE = E.Orientation();
 
 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F);
 Standard_Real U = 0,V = 0;
 if      (ShapeIndex == 1) VP.ParametersOnS1(U,V);
 else if (ShapeIndex == 2) VP.ParametersOnS2(U,V);
 
 Standard_Real fE,lE;
 const Handle(Geom_Curve)& CE = BRep_Tool::Curve(E,fE,lE);
 Standard_Real TE = VP.EdgeParameter(ShapeIndex);
 
 Standard_Real fR,lR;
 const Handle(Geom_Curve)& CR = BRep_Tool::Curve(R,fR,lR);
 
 TopOpeBRepDS_Transition Trans;
 Standard_Boolean transok = ::FUN_GeomTrans(S,U,V,CE,TE,CR,fR,lR,Trans);
 if ( transok ) {
   // Trans : transition sur R en croisant l'arete E orientee dans la face F
   if (oriE == TopAbs_REVERSED) Trans = Trans.Complement();
 }
 
  return Trans;
}