summaryrefslogtreecommitdiff
path: root/src/BRepIntCurveSurface/BRepIntCurveSurface_Inter.cxx
blob: bad89a32fd912d41b17e6134e96567bcf303c7b5 (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
// File:	BRepIntCurveSurface_Inter.cxx
// Created:	Mon Feb  7 15:52:37 1994
// Author:	Modelistation
//		<model@nonox>
//-Copyright:	 Matra Datavision 1994


#include <BRepIntCurveSurface_Inter.ixx>
#include <Geom_Line.hxx>
#include <TopAbs_ShapeEnum.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Face.hxx>
#include <BRepAdaptor_Surface.hxx>
#include <BRepAdaptor_HSurface.hxx>
#include <GeomAdaptor_HCurve.hxx>
#include <BRepTopAdaptor_TopolTool.hxx>
#include <BRepAdaptor_HSurface.hxx>

//modified by NIZNHY-PKV Sun Dec 15 16:57:10 2002 f
/*
static Standard_Real currentU,currentV;
TopAbs_State currentstate;
static Handle(BRepTopAdaptor_TopolTool) FastClass
       = new  BRepTopAdaptor_TopolTool();

static Handle(BRepAdaptor_HSurface) SurfForFastClass
       = new  BRepAdaptor_HSurface();
*/
//modified by NIZNHY-PKV Sun Dec 15 16:57:14 2002 t

//===========================================================================
//function :BRepIntCurveSurface_Inter::BRepIntCurveSurface_Inte
//purpose  : 
//===========================================================================
BRepIntCurveSurface_Inter::BRepIntCurveSurface_Inter()
     : empty(Standard_True) 
{
//modified by NIZNHY-PKV Sun Dec 15 16:58:10 2002 f
  FastClass = new  BRepTopAdaptor_TopolTool();
  SurfForFastClass = new  BRepAdaptor_HSurface();
//modified by NIZNHY-PKV Sun Dec 15 16:58:13 2002 t
}

void BRepIntCurveSurface_Inter::Init(const TopoDS_Shape& ashape,
				     const GeomAdaptor_Curve& acurve,
				     const Standard_Real tol) { 
  empty = Standard_False;
  curveisaline = Standard_False;
  curve = acurve;
  explorer.Init(ashape,TopAbs_FACE);
  currentnbpoints = 0;
  tolerance = tol;
  Find();
}

void BRepIntCurveSurface_Inter::Init(const TopoDS_Shape& ashape,
				     const gp_Lin&       aline,
				     const Standard_Real tol) { 
  empty = Standard_False;
  curveisaline = Standard_True;
  line = aline;
  Handle(Geom_Line) geomline = new Geom_Line(aline);
  curve.Load(geomline);
  explorer.Init(ashape,TopAbs_FACE);
  currentnbpoints = 0;
  tolerance = tol;
  Find();
}

Standard_Boolean BRepIntCurveSurface_Inter::More() const {
  return(explorer.More());
}

void BRepIntCurveSurface_Inter::Next() { 
  Find();
}

void BRepIntCurveSurface_Inter::Find() { 

  static Standard_Real UMin = 0.0;
  static Standard_Real UMax = 0.0;
  static Standard_Real VMin = 0.0;
  static Standard_Real VMax = 0.0;
  static Standard_Real PeriodU = 0.0;
  static Standard_Real PeriodV = 0.0;
  
  if(currentnbpoints) { 
    while(currentindex < currentnbpoints) { 
      currentindex++;
      Standard_Real U = intcs.Point(currentindex).U();
      Standard_Real V = intcs.Point(currentindex).V();
      //-------------------------------------------------------
      //-- On Cherche a recadrer le point U,V ds la face UV
      //-- 
      if(PeriodU) { 
	while(U>UMin) 
	  U-=PeriodU;
      }
      if(PeriodV) { 
	while(V>VMin)
	  V-=PeriodV;
      }
//    Standard_Real UInit = U;
      Standard_Real VInit = V;
      do { //-- Boucle Sur U  
	V = VInit;
	do { //-- Boucle sur V
	  gp_Pnt2d Puv(U,V);
	  //--- 
	  //-- classifier.Perform(TopoDS::Face(explorer.Current()),Puv,tolerance);
	  currentstate = FastClass->Classify(Puv,tolerance); //-- MODIF
	  //-- TopAbs_State currentstate = classifier.State();

	  if(currentstate == TopAbs_ON || currentstate == TopAbs_IN) { 
	    currentU = U;
	    currentV = V;	
	    return; 	
	  }
	  V+=PeriodV;	    
	}
	while(PeriodV && V< VMax);
	U+=PeriodU;
      }
      while(PeriodU && U<UMax);
    }
    explorer.Next();
  }
  
  if(explorer.More()) { 
    //---------------------------------------------
    BRepAdaptor_Surface brepadaptsurf;
    
    TopoDS_Face face=TopoDS::Face(explorer.Current());
    face.Orientation(TopAbs_FORWARD);
    
    brepadaptsurf.Initialize(face,Standard_True);
    //----------------------------------------------
    //-- Mise a jour des variables PeriodU,PeriodV
    //--

    SurfForFastClass->ChangeSurface().Initialize(face); //-- MODIF
//    SurfForFastClass->ChangeSurface().Initialize(TopoDS::Face(face)); //-- MODIF
    FastClass->Initialize(SurfForFastClass); //-- MODIF
 
    if( brepadaptsurf.Surface().IsUPeriodic()) { 
      PeriodU = brepadaptsurf.Surface().UPeriod();
      UMin = brepadaptsurf.Surface().FirstUParameter();
      UMax = brepadaptsurf.Surface().LastUParameter();
    }
    else { 
      PeriodU = 0.0;
    }
    if( brepadaptsurf.Surface().IsVPeriodic()) { 
      PeriodV = brepadaptsurf.Surface().VPeriod();
      VMin = brepadaptsurf.Surface().FirstVParameter();
      VMax = brepadaptsurf.Surface().LastVParameter();
    }
    else { 
      PeriodV = 0.0;
    }

    //----------------------------------------------
    Handle(GeomAdaptor_HCurve)   HC = new GeomAdaptor_HCurve(curve);
    Handle(BRepAdaptor_HSurface) HS = new BRepAdaptor_HSurface(brepadaptsurf);
    //----------------------------------------------
    //-- intcs.Perform(curve,brepadaptsurf);
    intcs.Perform(HC,HS);

    currentindex = 0;
    currentnbpoints = intcs.NbPoints();
    if(currentnbpoints) { 
      Find();
    }
    else { 
      explorer.Next();
      Find(); 
    }
  }
  else { 
    currentnbpoints=0; 
  }
}


IntCurveSurface_IntersectionPoint BRepIntCurveSurface_Inter::Point() const {
  if(currentindex==0) 
    StdFail_NotDone::Raise();
  const IntCurveSurface_IntersectionPoint& ICPS = intcs.Point(currentindex);
  return(IntCurveSurface_IntersectionPoint(ICPS.Pnt(),
					   currentU,     // ICPS.U(),
					   currentV,     // ICPS.V(),
					   ICPS.W(),
					   ICPS.Transition()));
  //-- return(intcs.Point(currentindex));
}

Standard_Real BRepIntCurveSurface_Inter::U() const {
  if(currentindex==0) 
    StdFail_NotDone::Raise();
  //-- return(intcs.Point(currentindex).U());
  return(currentU);
}

Standard_Real BRepIntCurveSurface_Inter::V() const {
  if(currentindex==0) 
    StdFail_NotDone::Raise();
  //-- return(intcs.Point(currentindex).V());
  return(currentV);
}

Standard_Real BRepIntCurveSurface_Inter::W() const {
  if(currentindex==0) 
    StdFail_NotDone::Raise();
  return(intcs.Point(currentindex).W());
}

TopAbs_State BRepIntCurveSurface_Inter::State() const {
  if(currentindex==0) 
    StdFail_NotDone::Raise();
  //-- return(classifier.State());
  return(currentstate);
}

IntCurveSurface_TransitionOnCurve BRepIntCurveSurface_Inter::Transition() const {
  if(currentindex==0) 
    StdFail_NotDone::Raise();
  return(intcs.Point(currentindex).Transition());
}

const TopoDS_Face& BRepIntCurveSurface_Inter::Face() const { 
  return(TopoDS::Face(explorer.Current()));
}

const gp_Pnt& BRepIntCurveSurface_Inter::Pnt() const { 
  if(currentindex==0) 
    StdFail_NotDone::Raise();
  return(intcs.Point(currentindex).Pnt());
}