7fd59977 |
1 | // File: IntCurvesFace_Intersector.cxx |
2 | // Created: Mon Jun 3 10:08:13 1996 |
3 | // Author: Laurent BUCHARD |
4 | // <lbr@sherlox.paris1.matra-dtv.fr> |
5 | |
6 | |
7 | // Modified by skv - Wed Sep 3 16:14:10 2003 OCC578 |
8 | |
9 | |
10 | #define OPTIMISATION 1 |
11 | |
12 | |
13 | #include <IntCurvesFace_Intersector.ixx> |
14 | |
15 | #include <IntCurveSurface_ThePolyhedronToolOfHInter.hxx> |
16 | #include <Bnd_BoundSortBox.hxx> |
17 | |
18 | #include <IntCurveSurface_IntersectionPoint.hxx> |
19 | #include <gp_Lin.hxx> |
20 | #include <TopoDS_Face.hxx> |
21 | #include <TopAbs.hxx> |
22 | |
23 | |
24 | #include <IntCurveSurface_HInter.hxx> |
25 | #include <BRepAdaptor_HSurface.hxx> |
26 | #include <Geom_Line.hxx> |
27 | #include <gp_Pnt2d.hxx> |
28 | #include <BRepClass_FaceClassifier.hxx> |
29 | |
30 | #include <GeomAdaptor_Curve.hxx> |
31 | |
32 | #include <GeomAdaptor_HCurve.hxx> |
33 | #include <BRepAdaptor_HSurface.hxx> |
34 | |
35 | |
36 | |
37 | #include <Adaptor3d_HSurfaceTool.hxx> |
38 | #include <IntCurveSurface_TheHCurveTool.hxx> |
39 | #include <Adaptor3d_HCurve.hxx> |
40 | #include <Bnd_Box.hxx> |
41 | #include <Intf_Tool.hxx> |
42 | #include <IntCurveSurface_ThePolyhedronOfHInter.hxx> |
43 | #include <IntCurveSurface_ThePolygonOfHInter.hxx> |
44 | #include <IntCurveSurface_SequenceOfPnt.hxx> |
45 | |
46 | |
47 | |
48 | GeomAbs_SurfaceType IntCurvesFace_Intersector::SurfaceType() const { |
49 | return(Adaptor3d_HSurfaceTool::GetType(Hsurface)); |
50 | } |
51 | |
52 | |
53 | //============================================================================ |
54 | IntCurvesFace_Intersector::IntCurvesFace_Intersector(const TopoDS_Face& Face, |
55 | const Standard_Real aTol) |
56 | : |
57 | Tol(aTol),done(Standard_False),nbpnt(0),PtrOnPolyhedron(NULL),PtrOnBndBounding(NULL) |
58 | { |
59 | BRepAdaptor_Surface surface; |
60 | face = Face; |
61 | surface.Initialize(Face,Standard_True); |
62 | Hsurface = new BRepAdaptor_HSurface(surface); |
63 | myTopolTool = new BRepTopAdaptor_TopolTool(Hsurface); |
64 | |
65 | GeomAbs_SurfaceType SurfaceType = Adaptor3d_HSurfaceTool::GetType(Hsurface); |
66 | if( (SurfaceType != GeomAbs_Plane) |
67 | && (SurfaceType != GeomAbs_Cylinder) |
68 | && (SurfaceType != GeomAbs_Cone) |
69 | && (SurfaceType != GeomAbs_Sphere) |
70 | && (SurfaceType != GeomAbs_Torus)) { |
71 | Standard_Integer nbsu,nbsv; |
72 | Standard_Real U0,V0,U1,V1; |
73 | U0 = Hsurface->FirstUParameter(); |
74 | U1 = Hsurface->LastUParameter(); |
75 | V0 = Hsurface->FirstVParameter(); |
76 | V1 = Hsurface->LastVParameter(); |
77 | //-- nbsu = Adaptor3d_HSurfaceTool::NbSamplesU(Hsurface,U0,U1); |
78 | //-- nbsv = Adaptor3d_HSurfaceTool::NbSamplesV(Hsurface,V0,V1); |
79 | nbsu = myTopolTool->NbSamplesU(); |
80 | nbsv = myTopolTool->NbSamplesV(); |
81 | if(nbsu>40) nbsu = 40; |
82 | if(nbsv>40) nbsv = 40; |
83 | //-- printf("\n IntCurvesFace_Intersector : nbsu=(%3d)->%3d nbsv=(%3d)->%3d",myTopolTool->NbSamplesU(),nbsu,myTopolTool->NbSamplesV(),nbsv); |
84 | PtrOnPolyhedron = (IntCurveSurface_ThePolyhedronOfHInter *) new IntCurveSurface_ThePolyhedronOfHInter(Hsurface,nbsu,nbsv,U0,V0,U1,V1); |
85 | } |
86 | } |
87 | //============================================================================ |
88 | |
89 | void IntCurvesFace_Intersector::InternalCall(const IntCurveSurface_HInter &HICS, |
90 | const Standard_Real parinf,const Standard_Real parsup) { |
91 | if(HICS.IsDone()) { |
92 | for(Standard_Integer index=HICS.NbPoints(); index>=1; index--) { |
93 | const IntCurveSurface_IntersectionPoint& HICSPointindex = HICS.Point(index); |
94 | gp_Pnt2d Puv(HICSPointindex.U(),HICSPointindex.V()); |
95 | |
96 | TopAbs_State currentstate = myTopolTool->Classify(Puv,Tol); |
97 | if(currentstate==TopAbs_IN || currentstate==TopAbs_ON) { |
98 | Standard_Real HICSW = HICSPointindex.W(); |
99 | if(HICSW >= parinf && HICSW <= parsup ) { |
100 | Standard_Real U = HICSPointindex.U(); |
101 | Standard_Real V = HICSPointindex.V(); |
102 | Standard_Real W = HICSW; |
103 | IntCurveSurface_TransitionOnCurve transition = HICSPointindex.Transition(); |
104 | gp_Pnt pnt = HICSPointindex.Pnt(); |
105 | // state = currentstate; |
106 | // Modified by skv - Wed Sep 3 16:14:10 2003 OCC578 Begin |
107 | Standard_Integer anIntState = (currentstate == TopAbs_IN) ? 0 : 1; |
108 | // Modified by skv - Wed Sep 3 16:14:11 2003 OCC578 End |
109 | |
110 | if(transition != IntCurveSurface_Tangent && face.Orientation()==TopAbs_REVERSED) { |
111 | if(transition == IntCurveSurface_In) |
112 | transition = IntCurveSurface_Out; |
113 | else |
114 | transition = IntCurveSurface_In; |
115 | } |
116 | //----- Insertion du point |
117 | if(nbpnt==0) { |
118 | IntCurveSurface_IntersectionPoint PPP(pnt,U,V,W,transition); |
119 | SeqPnt.Append(PPP); |
120 | // Modified by skv - Wed Sep 3 16:14:10 2003 OCC578 Begin |
121 | mySeqState.Append(anIntState); |
122 | // Modified by skv - Wed Sep 3 16:14:11 2003 OCC578 End |
123 | } |
124 | else { |
125 | Standard_Integer i = 1; |
126 | Standard_Integer b = nbpnt+1; |
127 | while(i<=nbpnt) { |
128 | const IntCurveSurface_IntersectionPoint& Pnti=SeqPnt.Value(i); |
129 | Standard_Real wi = Pnti.W(); |
130 | if(wi >= W) { b=i; i=nbpnt; } |
131 | i++; |
132 | } |
133 | IntCurveSurface_IntersectionPoint PPP(pnt,U,V,W,transition); |
134 | // Modified by skv - Wed Sep 3 16:14:10 2003 OCC578 Begin |
135 | // if(b>nbpnt) { SeqPnt.Append(PPP); } |
136 | // else if(b>0) { SeqPnt.InsertBefore(b,PPP); } |
137 | if(b>nbpnt) { |
138 | SeqPnt.Append(PPP); |
139 | mySeqState.Append(anIntState); |
140 | } else if(b>0) { |
141 | SeqPnt.InsertBefore(b,PPP); |
142 | mySeqState.InsertBefore(b, anIntState); |
143 | } |
144 | // Modified by skv - Wed Sep 3 16:14:11 2003 OCC578 End |
145 | } |
146 | |
147 | |
148 | nbpnt++; |
149 | } |
150 | } //-- classifier state is IN or ON |
151 | } //-- Loop on Intersection points. |
152 | } //-- HICS.IsDone() |
153 | } |
154 | |
155 | //-------------------------------------------------------------------------------- |
156 | |
157 | |
158 | |
159 | |
160 | void IntCurvesFace_Intersector::Perform(const gp_Lin& L,const Standard_Real ParMin,const Standard_Real ParMax) { |
161 | done = Standard_True; |
162 | SeqPnt.Clear(); |
163 | // Modified by skv - Wed Sep 3 16:14:10 2003 OCC578 Begin |
164 | mySeqState.Clear(); |
165 | // Modified by skv - Wed Sep 3 16:14:11 2003 OCC578 End |
166 | nbpnt = 0; |
167 | IntCurveSurface_HInter HICS; |
168 | |
169 | Handle(Geom_Line) geomline = new Geom_Line(L); |
170 | GeomAdaptor_Curve LL(geomline); |
171 | |
172 | //-- |
173 | Handle(GeomAdaptor_HCurve) HLL = new GeomAdaptor_HCurve(LL); |
174 | //-- |
175 | Standard_Real parinf=ParMin; |
176 | Standard_Real parsup=ParMax; |
177 | |
178 | if(PtrOnPolyhedron == NULL) { |
179 | HICS.Perform(HLL,Hsurface); |
180 | } |
181 | else { |
182 | Intf_Tool bndTool; |
183 | Bnd_Box boxLine; |
184 | bndTool.LinBox(L,((IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron)->Bounding(),boxLine); |
185 | if(bndTool.NbSegments() == 0) |
186 | return; |
187 | for(Standard_Integer nbseg=1; nbseg<= bndTool.NbSegments(); nbseg++) { |
188 | Standard_Real pinf = bndTool.BeginParam(nbseg); |
189 | Standard_Real psup = bndTool.EndParam(nbseg); |
190 | Standard_Real pppp = 0.05*(psup-pinf); |
191 | pinf-=pppp; |
192 | psup+=pppp; |
193 | if((psup - pinf)<1e-10) { pinf-=1e-10; psup+=1e-10; } |
194 | if(nbseg==1) { parinf=pinf; parsup=psup; } |
195 | else { |
196 | if(parinf>pinf) parinf = pinf; |
197 | if(parsup<psup) parsup = psup; |
198 | } |
199 | } |
200 | if(parinf>ParMax) { return; } |
201 | if(parsup<ParMin) { return; } |
202 | if(parinf<ParMin) parinf=ParMin; |
203 | if(parsup>ParMax) parsup=ParMax; |
204 | if(parinf>(parsup-1e-9)) return; |
205 | IntCurveSurface_ThePolygonOfHInter polygon(HLL, |
206 | parinf, |
207 | parsup, |
208 | 2); |
209 | #if OPTIMISATION |
210 | if(PtrOnBndBounding==NULL) { |
211 | PtrOnBndBounding = (Bnd_BoundSortBox *) new Bnd_BoundSortBox(); |
212 | IntCurveSurface_ThePolyhedronOfHInter *thePolyh=(IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron; |
213 | ((Bnd_BoundSortBox *)(PtrOnBndBounding))->Initialize(IntCurveSurface_ThePolyhedronToolOfHInter::Bounding(*thePolyh), |
214 | IntCurveSurface_ThePolyhedronToolOfHInter::ComponentsBounding(*thePolyh)); |
215 | } |
216 | HICS.Perform(HLL, |
217 | polygon, |
218 | Hsurface, |
219 | *((IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron), |
220 | *((Bnd_BoundSortBox *)PtrOnBndBounding)); |
221 | #else |
222 | HICS.Perform(HLL, |
223 | polygon, |
224 | Hsurface, |
225 | *((IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron)); |
226 | #endif |
227 | } |
228 | |
229 | InternalCall(HICS,parinf,parsup); |
230 | |
231 | #if 0 |
232 | if(HICS.IsDone()) { |
233 | for(Standard_Integer index=HICS.NbPoints(); index>=1; index--) { |
234 | const IntCurveSurface_IntersectionPoint& HICSPointindex = HICS.Point(index); |
235 | gp_Pnt2d Puv(HICSPointindex.U(),HICSPointindex.V()); |
236 | |
237 | TopAbs_State currentstate = myTopolTool->Classify(Puv,Tol); |
238 | if(currentstate==TopAbs_IN || currentstate==TopAbs_ON) { |
239 | Standard_Real HICSW = HICSPointindex.W(); |
240 | if(HICSW >= parinf && HICSW <= parsup ) { |
241 | Standard_Real U = HICSPointindex.U(); |
242 | Standard_Real V = HICSPointindex.V(); |
243 | Standard_Real W = HICSW; |
244 | IntCurveSurface_TransitionOnCurve transition = HICSPointindex.Transition(); |
245 | gp_Pnt pnt = HICSPointindex.Pnt(); |
246 | // state = currentstate; |
247 | // Modified by skv - Wed Sep 3 16:14:10 2003 OCC578 Begin |
248 | Standard_Integer anIntState = (currentstate == TopAbs_IN) ? 0 : 1; |
249 | // Modified by skv - Wed Sep 3 16:14:11 2003 OCC578 End |
250 | |
251 | if(face.Orientation()==TopAbs_REVERSED) { |
252 | if(transition == IntCurveSurface_In) |
253 | transition = IntCurveSurface_Out; |
254 | else |
255 | transition = IntCurveSurface_In; |
256 | } |
257 | //----- Insertion du point |
258 | if(nbpnt==0) { |
259 | IntCurveSurface_IntersectionPoint PPP(pnt,U,V,W,transition); |
260 | SeqPnt.Append(PPP); |
261 | // Modified by skv - Wed Sep 3 16:14:10 2003 OCC578 Begin |
262 | mySeqState.Append(anIntState); |
263 | // Modified by skv - Wed Sep 3 16:14:11 2003 OCC578 End |
264 | } |
265 | else { |
266 | Standard_Integer i = 1; |
267 | Standard_Integer b = nbpnt+1; |
268 | while(i<=nbpnt) { |
269 | const IntCurveSurface_IntersectionPoint& Pnti=SeqPnt.Value(i); |
270 | Standard_Real wi = Pnti.W(); |
271 | if(wi >= W) { b=i; i=nbpnt; } |
272 | i++; |
273 | } |
274 | IntCurveSurface_IntersectionPoint PPP(pnt,U,V,W,transition); |
275 | // Modified by skv - Wed Sep 3 16:14:10 2003 OCC578 Begin |
276 | // if(b>nbpnt) { SeqPnt.Append(PPP); } |
277 | // else if(b>0) { SeqPnt.InsertBefore(b,PPP); } |
278 | if(b>nbpnt) { |
279 | SeqPnt.Append(PPP); |
280 | mySeqState.Append(anIntState); |
281 | } else if(b>0) { |
282 | SeqPnt.InsertBefore(b,PPP); |
283 | mySeqState.InsertBefore(b, anIntState); |
284 | } |
285 | // Modified by skv - Wed Sep 3 16:14:11 2003 OCC578 End |
286 | } |
287 | |
288 | |
289 | nbpnt++; |
290 | } |
291 | } //-- classifier state is IN or ON |
292 | } //-- Loop on Intersection points. |
293 | } //-- HICS.IsDone() |
294 | #endif |
295 | } |
296 | |
297 | |
298 | |
299 | //============================================================================ |
300 | void IntCurvesFace_Intersector::Perform(const Handle(Adaptor3d_HCurve)& HCu,const Standard_Real ParMin,const Standard_Real ParMax) { |
301 | done = Standard_True; |
302 | SeqPnt.Clear(); |
303 | // Modified by skv - Wed Sep 3 16:14:10 2003 OCC578 Begin |
304 | mySeqState.Clear(); |
305 | // Modified by skv - Wed Sep 3 16:14:11 2003 OCC578 End |
306 | nbpnt = 0; |
307 | IntCurveSurface_HInter HICS; |
308 | |
309 | //-- |
310 | Standard_Real parinf=ParMin; |
311 | Standard_Real parsup=ParMax; |
312 | |
313 | if(PtrOnPolyhedron == NULL) { |
314 | HICS.Perform(HCu,Hsurface); |
315 | } |
316 | else { |
317 | parinf = IntCurveSurface_TheHCurveTool::FirstParameter(HCu); |
318 | parsup = IntCurveSurface_TheHCurveTool::LastParameter(HCu); |
319 | if(parinf<ParMin) parinf = ParMin; |
320 | if(parsup>ParMax) parsup = ParMax; |
321 | if(parinf>(parsup-1e-9)) return; |
322 | Standard_Integer nbs; |
323 | nbs = IntCurveSurface_TheHCurveTool::NbSamples(HCu,parinf,parsup); |
324 | |
325 | IntCurveSurface_ThePolygonOfHInter polygon(HCu, |
326 | parinf, |
327 | parsup, |
328 | nbs); |
329 | #if OPTIMISATION |
330 | if(PtrOnBndBounding==NULL) { |
331 | PtrOnBndBounding = (Bnd_BoundSortBox *) new Bnd_BoundSortBox(); |
332 | IntCurveSurface_ThePolyhedronOfHInter *thePolyh=(IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron; |
333 | ((Bnd_BoundSortBox *)(PtrOnBndBounding))->Initialize(IntCurveSurface_ThePolyhedronToolOfHInter::Bounding(*thePolyh), |
334 | IntCurveSurface_ThePolyhedronToolOfHInter::ComponentsBounding(*thePolyh)); |
335 | } |
336 | HICS.Perform(HCu, |
337 | polygon, |
338 | Hsurface, |
339 | *((IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron), |
340 | *((Bnd_BoundSortBox *)PtrOnBndBounding)); |
341 | #else |
342 | HICS.Perform(HCu, |
343 | polygon, |
344 | Hsurface, |
345 | *((IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron)); |
346 | #endif |
347 | } |
348 | InternalCall(HICS,parinf,parsup); |
349 | } |
350 | |
351 | //============================================================================ |
352 | Bnd_Box IntCurvesFace_Intersector::Bounding() const { |
353 | if(PtrOnPolyhedron !=NULL) { |
354 | return(((IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron)->Bounding()); |
355 | } |
356 | else { |
357 | Bnd_Box B; |
358 | return(B); |
359 | } |
360 | } |
361 | TopAbs_State IntCurvesFace_Intersector::ClassifyUVPoint(const gp_Pnt2d& Puv) const { |
362 | TopAbs_State state = myTopolTool->Classify(Puv,1e-7); |
363 | return(state); |
364 | } |
365 | //============================================================================ |
366 | void IntCurvesFace_Intersector::Destroy() { |
367 | if(PtrOnPolyhedron !=NULL) { |
368 | delete (IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron; |
369 | PtrOnPolyhedron = NULL; |
370 | } |
371 | if(PtrOnBndBounding !=NULL) { |
372 | delete (Bnd_BoundSortBox *)PtrOnBndBounding; |
373 | PtrOnBndBounding=NULL; |
374 | } |
375 | } |
376 | |
377 | |
378 | |