0024624: Lost word in license statement in source files
[occt.git] / src / BRepClass3d / BRepClass3d_SolidExplorer.cxx
CommitLineData
b311480e 1// Created on: 1994-03-10
2// Created by: Laurent BUCHARD
3// Copyright (c) 1994-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
b311480e 16
0d969553 17// Modifed: Porting NT 7-5-97 DPF (stdio.h)
7fd59977 18// Apr 16 2002 eap, classification against infinite solid (occ299)
19
20
21// Modified by skv - Thu Sep 4 12:29:30 2003 OCC578
22
0d969553 23//-- Process the case of a hole!!
7fd59977 24#define REJECTION 1
25
0d969553 26//-- To printf on NT
7fd59977 27#include <stdio.h>
28
29#include <BRepClass3d_SolidExplorer.ixx>
30#include <gp.hxx>
31#include <TopoDS.hxx>
32#include <BRepAdaptor_Curve2d.hxx>
33#include <BRepTools.hxx>
34#include <Geom2d_Curve.hxx>
35#include <gp_Vec2d.hxx>
36#include <GeomAbs_Shape.hxx>
37#include <BRepAdaptor_Surface.hxx>
38#include <BRepClass_FacePassiveClassifier.hxx>
39#include <TopAbs_Orientation.hxx>
40#include <TopExp_Explorer.hxx>
41#include <BRepClass_Edge.hxx>
42
43#include <Bnd_Box.hxx>
44#include <BRepBndLib.hxx>
45
46#include <BRepAdaptor_HSurface.hxx>
47
48#include <ElCLib.hxx>
49
50#include <BRepClass3d_DataMapIteratorOfMapOfInter.hxx>
51#include <Precision.hxx>
52//OCC454(apo)->
53#include <Extrema_ExtPS.hxx>
54#include <BRep_Tool.hxx>
55#include <BRepClass_FaceClassifier.hxx>
56//<-OCC454(apo)
be7c077a 57#include <BRepTopAdaptor_FClass2d.hxx>
58
7fd59977 59
60//=======================================================================
61//function : FindAPointInTheFace
0d969553 62//purpose : Compute a point P in the face F. Param is a Real in
7fd59977 63// ]0,1[ and is used to initialise the algorithm. For
64// different values , different points are returned.
65//=======================================================================
66
67Standard_Boolean BRepClass3d_SolidExplorer::FindAPointInTheFace
68(const TopoDS_Face& _face,
69 gp_Pnt& APoint_,
41194117
K
70 Standard_Real& param_)
71{
7fd59977 72 Standard_Real u,v;
73 Standard_Boolean r = FindAPointInTheFace(_face,APoint_,u,v,param_);
74 return r;
75}
76
77//=======================================================================
78//function : FindAPointInTheFace
79//purpose :
80//=======================================================================
81
82Standard_Boolean BRepClass3d_SolidExplorer::FindAPointInTheFace
83(const TopoDS_Face& _face,
84 gp_Pnt& APoint_,
85 Standard_Real& u_, Standard_Real& v_,
41194117
K
86 Standard_Real& param_)
87{
88 gp_Vec aVecD1U, aVecD1V;
89 return FindAPointInTheFace (_face, APoint_, u_, v_, param_, aVecD1U, aVecD1V);
90}
91
92//=======================================================================
93//function : FindAPointInTheFace
94//purpose :
95//=======================================================================
96
97Standard_Boolean BRepClass3d_SolidExplorer::FindAPointInTheFace
98(const TopoDS_Face& _face,
99 gp_Pnt& APoint_,
100 Standard_Real& u_, Standard_Real& v_,
101 Standard_Real& param_,
102 gp_Vec& theVecD1U,
103 gp_Vec& theVecD1V)
104{
105 TopoDS_Face face = _face;
106 face.Orientation (TopAbs_FORWARD);
107
108 TopExp_Explorer faceexplorer;
7fd59977 109 BRepAdaptor_Curve2d c;
110 gp_Vec2d T;
111 gp_Pnt2d P;
41194117 112
7fd59977 113 for (faceexplorer.Init(face,TopAbs_EDGE);
114 faceexplorer.More();
41194117
K
115 faceexplorer.Next())
116 {
117 TopoDS_Edge Edge = TopoDS::Edge (faceexplorer.Current());
118 c.Initialize (Edge, face);
41194117
K
119 c.D1((c.LastParameter() - c.FirstParameter()) * param_ + c.FirstParameter(),P,T);
120
121 Standard_Real x = T.X();
122 Standard_Real y = T.Y();
123 if (Edge.Orientation() == TopAbs_FORWARD)
124 {
125 T.SetCoord (-y, x);
126 }
127 else
128 {
129 T.SetCoord ( y, -x);
130 }
131 Standard_Real ParamInit = RealLast();
132 Standard_Real TolInit = 0.00001;
133 Standard_Boolean APointExist = Standard_False;
134
135 BRepClass_FacePassiveClassifier FClassifier;
136
137 T.Normalize();
138 P.SetCoord (P.X() + TolInit * T.X(), P.Y() + TolInit * T.Y());
139 FClassifier.Reset (gp_Lin2d (P, T), ParamInit, RealEpsilon()); //-- Length and Tolerance #######
140
141 TopExp_Explorer otherfaceexplorer;
142 Standard_Integer aNbEdges = 0;
143 for (otherfaceexplorer.Init (face, TopAbs_EDGE);
144 otherfaceexplorer.More();
145 otherfaceexplorer.Next(), ++aNbEdges)
146 {
147 TopoDS_Edge OtherEdge = TopoDS::Edge (otherfaceexplorer.Current());
148 if (OtherEdge.Orientation() != TopAbs_EXTERNAL && OtherEdge != Edge)
149 {
150 BRepClass_Edge AEdge (OtherEdge, face);
151 FClassifier.Compare (AEdge, OtherEdge.Orientation());
152 if (FClassifier.ClosestIntersection())
153 {
154 if(ParamInit > FClassifier.Parameter())
155 {
156 ParamInit = FClassifier.Parameter();
157 APointExist = Standard_True;
158 }
159 }
7fd59977 160 }
41194117
K
161 }
162
163 if (aNbEdges == 1)
164 {
165 BRepClass_Edge AEdge (Edge, face);
166 FClassifier.Compare (AEdge, Edge.Orientation());
167 if (FClassifier.ClosestIntersection())
168 {
169 if (ParamInit > FClassifier.Parameter())
170 {
171 ParamInit = FClassifier.Parameter();
172 APointExist = Standard_True;
173 }
7fd59977 174 }
175 }
41194117
K
176
177 if (APointExist)
178 {
179 ParamInit *= 0.41234;
180 u_ = P.X() + ParamInit* T.X();
181 v_ = P.Y() + ParamInit* T.Y();
be7c077a 182
183 //Additional check
184 BRepTopAdaptor_FClass2d Classifier(face, Precision::Confusion());
185 gp_Pnt2d aPnt2d(u_, v_);
186 TopAbs_State StateOfResultingPoint = Classifier.Perform(aPnt2d);
187 if (StateOfResultingPoint != TopAbs_IN)
188 return Standard_False;
189
41194117
K
190 BRepAdaptor_Surface s;
191 s.Initialize (face, Standard_False);
192 s.D1 (u_, v_, APoint_, theVecD1U, theVecD1V);
193 return Standard_True;
194 }
7fd59977 195 }
41194117
K
196 return Standard_False;
197}
198
199//=======================================================================
200//function : PointInTheFace
201//purpose :
202//=======================================================================
203
204Standard_Boolean BRepClass3d_SolidExplorer::PointInTheFace
205(const TopoDS_Face& Face,
206 gp_Pnt& APoint_,
207 Standard_Real& u_, Standard_Real& v_,
208 Standard_Real& param_,
209 Standard_Integer& IndexPoint,
210 const Handle(BRepAdaptor_HSurface)& surf,
211 const Standard_Real U1,
212 const Standard_Real V1,
213 const Standard_Real U2,
214 const Standard_Real V2) const
215{
216 gp_Vec aVecD1U, aVecD1V;
217 return PointInTheFace (Face, APoint_, u_, v_, param_, IndexPoint, surf,
218 U1, V1, U2, V2, aVecD1U, aVecD1V);
7fd59977 219}
220
221//=======================================================================
222//function : PointInTheFace
223//purpose :
224//=======================================================================
225
226Standard_Boolean BRepClass3d_SolidExplorer::PointInTheFace
227(const TopoDS_Face& Face,
228 gp_Pnt& APoint_,
229 Standard_Real& u_, Standard_Real& v_,
230 Standard_Real& param_,
231 Standard_Integer& IndexPoint,
232 const Handle(BRepAdaptor_HSurface)& surf,
233 const Standard_Real U1,
234 const Standard_Real V1,
235 const Standard_Real U2,
41194117
K
236 const Standard_Real V2,
237 gp_Vec& theVecD1U,
238 gp_Vec& theVecD1V) const
239{
7fd59977 240 Standard_Real u,du = (U2-U1)/6.0;
241 Standard_Real v,dv = (V2-V1)/6.0;
242 if(du<1e-12) du=1e-12;
243 if(dv<1e-12) dv=1e-12;
244 Standard_Integer NbPntCalc=0;
245 if(myMapOfInter.IsBound(Face)) {
246 void *ptr = (void*)(myMapOfInter.Find(Face));
247 if(ptr) {
248 const IntCurvesFace_Intersector& TheIntersector = (*((IntCurvesFace_Intersector *)ptr));
0d969553 249 //-- Take 4 points in each Quarter of surface
7fd59977 250 //-- -> Index : 1 -> 16
251 //--
252 //--
0d969553 253 //-- Then take a matrix of points on a tight grid
7fd59977 254 //--
0d969553
Y
255 for(u=du+(U1+U2)*0.5; u<U2; u+=du) { //-- 0 X u increases
256 for(v=dv+(V1+V2)*0.5; v<V2; v+=dv) { //-- 0 0 v increases
7fd59977 257 if(++NbPntCalc>=IndexPoint) {
258 if(TheIntersector.ClassifyUVPoint(gp_Pnt2d(u,v))==TopAbs_IN) {
259 u_=u; v_=v;
41194117
K
260 surf->D1 (u, v, APoint_, theVecD1U, theVecD1V);
261 IndexPoint = NbPntCalc;
7fd59977 262 return(Standard_True);
263 }
264 }
265 }
266 }
267
0d969553
Y
268 for(u=-du+(U1+U2)*0.5; u>U1; u-=du) { //-- 0 0 u decreases
269 for(v=-dv+(V1+V2)*0.5; v>V1; v-=dv) { //-- X 0 v decreases
7fd59977 270 if(++NbPntCalc>=IndexPoint) {
271 if(TheIntersector.ClassifyUVPoint(gp_Pnt2d(u,v))==TopAbs_IN) {
272 u_=u; v_=v;
41194117 273 surf->D1 (u, v, APoint_, theVecD1U, theVecD1V);
7fd59977 274 IndexPoint = NbPntCalc;
275 return(Standard_True);
276 }
277 }
278 }
279 }
0d969553
Y
280 for(u=-du+(U1+U2)*0.5; u>U1; u-=du) { //-- X 0 u decreases
281 for(v=dv+(V1+V2)*0.5; v<V2; v+=dv) { //-- 0 0 v increases
7fd59977 282 if(++NbPntCalc>=IndexPoint) {
283 if(TheIntersector.ClassifyUVPoint(gp_Pnt2d(u,v))==TopAbs_IN) {
284 u_=u; v_=v;
41194117 285 surf->D1 (u, v, APoint_, theVecD1U, theVecD1V);
7fd59977 286 IndexPoint = NbPntCalc;
287 return(Standard_True);
288 }
289 }
290 }
291 }
0d969553
Y
292 for(u=du+(U1+U2)*0.5; u<U2; u+=du) { //-- 0 0 u increases
293 for(v=-dv+(V1+V2)*0.5; v>V1; v-=dv) { //-- 0 X v decreases
7fd59977 294 if(++NbPntCalc>=IndexPoint) {
295 if(TheIntersector.ClassifyUVPoint(gp_Pnt2d(u,v))==TopAbs_IN) {
296 u_=u; v_=v;
41194117 297 surf->D1 (u, v, APoint_, theVecD1U, theVecD1V);
7fd59977 298 IndexPoint = NbPntCalc;
299 return(Standard_True);
300 }
301 }
302 }
303 }
0d969553 304 //-- the remainder
7fd59977 305 du = (U2-U1)/37.0;
306 dv = (V2-V1)/37.0;
307 if(du<1e-12) du=1e-12;
308 if(dv<1e-12) dv=1e-12;
309
310 for(u=du+U1; u<U2; u+=du) {
311 for(v=dv+V1; v<V2; v+=dv) {
312 if(++NbPntCalc>=IndexPoint) {
313 if(TheIntersector.ClassifyUVPoint(gp_Pnt2d(u,v))==TopAbs_IN) {
314 u_=u; v_=v;
41194117 315 surf->D1 (u, v, APoint_, theVecD1U, theVecD1V);
7fd59977 316 IndexPoint = NbPntCalc;
317 return(Standard_True);
318 }
319 }
320 }
321 }
322 u=(U1+U2)*0.5;
323 v=(V1+V2)*0.5;
324 if(++NbPntCalc>=IndexPoint) {
325 if(TheIntersector.ClassifyUVPoint(gp_Pnt2d(u,v))==TopAbs_IN) {
326 u_=u; v_=v;
41194117 327 surf->D1 (u, v, APoint_, theVecD1U, theVecD1V);
7fd59977 328 IndexPoint = NbPntCalc;
329 return(Standard_True);
330 }
331 }
332 }
333 IndexPoint = NbPntCalc;
334 }
335 else {
0d969553 336 //printf("BRepClass3d_SolidExplorer Face not found ds the map \n");
7fd59977 337 }
41194117
K
338
339 return BRepClass3d_SolidExplorer
340 ::FindAPointInTheFace (Face,APoint_, u_, v_, param_, theVecD1U, theVecD1V);
7fd59977 341}
342
343//=======================================================================
344//function : LimitInfiniteUV
345//purpose : Limit infinite parameters
346//=======================================================================
7fd59977 347static void LimitInfiniteUV (Standard_Real& U1,
348 Standard_Real& V1,
349 Standard_Real& U2,
350 Standard_Real& V2)
351{
352 Standard_Boolean
353 infU1 = Precision::IsNegativeInfinite(U1),
354 infV1 = Precision::IsNegativeInfinite(V1),
355 infU2 = Precision::IsPositiveInfinite(U2),
356 infV2 = Precision::IsPositiveInfinite(V2);
357
358 if (infU1) U1 = -1e10;
359 if (infV1) V1 = -1e10;
360 if (infU2) U2 = 1e10;
361 if (infV2) V2 = 1e10;
362}
88cc4cb8 363//=======================================================================
364//function : IsInfiniteUV
365//purpose :
366//=======================================================================
367static Standard_Integer IsInfiniteUV (Standard_Real& U1,
368 Standard_Real& V1,
369 Standard_Real& U2,
370 Standard_Real& V2)
371{
7fd59977 372 Standard_Integer aVal = 0;
373
374 if (Precision::IsInfinite(U1))
375 aVal |= 1;
376
377 if (Precision::IsInfinite(V1))
378 aVal |= 2;
379
380 if (Precision::IsInfinite(U2))
381 aVal |= 4;
382
383 if (Precision::IsInfinite(V2))
384 aVal |= 8;
385
386 return aVal;
387}
388//<-OCC454
389// Modified by skv - Tue Sep 16 13:50:39 2003 OCC578 End
390//=======================================================================
391//function : OtherSegment
392//purpose : Returns in <L>, <Par> a segment having at least
393// one intersection with the shape boundary to
394// compute intersections.
395// The First Call to this method returns a line which
396// point to a point of the first face of the shape.
397// The Second Call provide a line to the second face
398// and so on.
399//=======================================================================
88cc4cb8 400Standard_Integer BRepClass3d_SolidExplorer::OtherSegment(const gp_Pnt& P,
401 gp_Lin& L,
402 Standard_Real& _Par)
7fd59977 403{
41194117
K
404 const Standard_Real TolU = Precision::PConfusion();
405 const Standard_Real TolV = TolU;
406
7fd59977 407 TopoDS_Face face;
408 TopExp_Explorer faceexplorer;
7fd59977 409 gp_Pnt APoint;
41194117 410 gp_Vec aVecD1U, aVecD1V;
7fd59977 411 Standard_Real maxscal=0;
412 Standard_Boolean ptfound=Standard_False;
413 Standard_Real Par;
7fd59977 414 Standard_Real _u,_v;
415 Standard_Integer IndexPoint=0;
416 Standard_Integer NbPointsOK=0;
417 Standard_Integer NbFacesInSolid=0;
418
302f96fb 419 for(;;) {
7fd59977 420 myFirstFace++;
421 faceexplorer.Init(myShape,TopAbs_FACE);
422 // look for point on face starting from myFirstFace
423// Modified by skv - Thu Sep 4 14:31:12 2003 OCC578 Begin
424// while (faceexplorer.More()) {
425 for (; faceexplorer.More(); faceexplorer.Next()) {
426// Modified by skv - Thu Sep 4 14:31:12 2003 OCC578 End
427 NbFacesInSolid++;
428 if (myFirstFace > NbFacesInSolid) continue;
429 face = TopoDS::Face(faceexplorer.Current());
430
431 Handle(BRepAdaptor_HSurface) surf = new BRepAdaptor_HSurface();
432 surf->ChangeSurface().Initialize(face);
433 Standard_Real U1,V1,U2,V2;
434 U1 = surf->FirstUParameter();
435 V1 = surf->FirstVParameter();
436 U2 = surf->LastUParameter();
437 V2 = surf->LastVParameter();
438 face.Orientation(TopAbs_FORWARD);
439 //
440 //avoid process faces from uncorrected shells
441 if( Abs (U2 - U1) < 1.e-12 || Abs(V2 - V1) < 1.e-12) {
7fd59977 442 return 2;
7fd59977 443 }
444 //
445 Standard_Real svmyparam=myParamOnEdge;
446 //
7fd59977 447 // Check if the point is on the face or the face is infinite.
448 Standard_Integer anInfFlag = IsInfiniteUV(U1,V1,U2,V2);
449
7fd59977 450 GeomAdaptor_Surface GA(BRep_Tool::Surface(face));
88cc4cb8 451 Extrema_ExtPS Ext(P, GA, TolU, TolV);
452 //
7fd59977 453 if (Ext.IsDone() && Ext.NbExt() > 0) {
88cc4cb8 454 Standard_Integer i, iNear, iEnd;
455 Standard_Real aUx, aVx, Dist2, Dist2Min;
456 Extrema_POnSurf aPx;
457 //
458 iNear = 1;
459 Dist2Min = Ext.SquareDistance(1);
460 iEnd = Ext.NbExt();
7fd59977 461 for (i = 2; i <= iEnd; i++) {
88cc4cb8 462 aPx=Ext.Point(i);
463 aPx.Parameter(aUx, aVx);
464 if (aUx>=U1 && aUx<=U2 && aVx>=V1 && aVx<=V2) {
465 Dist2 = Ext.SquareDistance(i);
466 if (Dist2 < Dist2Min) {
467 Dist2Min = Dist2;
468 iNear = i;
469 }
7fd59977 470 }
471 }
88cc4cb8 472 //
7fd59977 473 Standard_Real aDist2Tresh=1.e-24;
88cc4cb8 474 //
7fd59977 475 if (Dist2Min<aDist2Tresh) {
476 if (anInfFlag) {
477 return 1;
88cc4cb8 478 }
479 else {
7fd59977 480 BRepClass_FaceClassifier classifier2d;
481 Standard_Real aU;
482 Standard_Real aV;
483
484 (Ext.Point(iNear)).Parameter(aU, aV);
485
486 gp_Pnt2d aPuv(aU, aV);
487
488 classifier2d.Perform(face,aPuv,Precision::PConfusion());
489
490 TopAbs_State aState = classifier2d.State();
491
88cc4cb8 492 if (aState == TopAbs_IN || aState == TopAbs_ON) {
7fd59977 493 return 1;
88cc4cb8 494 }
495 else {
7fd59977 496 return 3; // skv - the point is on surface but outside face.
88cc4cb8 497 }
7fd59977 498 }
499 }
7fd59977 500 if (anInfFlag) {
501 APoint = (Ext.Point(iNear)).Value();
502 gp_Vec V(P,APoint);
503 _Par = V.Magnitude();
504 L = gp_Lin(P,V);
505 ptfound=Standard_True;
7fd59977 506 return 0;
7fd59977 507 }
7fd59977 508 }
509 //The point is not ON the face or surface. The face is restricted.
510 // find point in a face not too far from a projection of P on face
41194117
K
511 do {
512 if (PointInTheFace (face, APoint, _u, _v, myParamOnEdge, ++IndexPoint, surf,
513 U1, V1, U2, V2,
514 aVecD1U, aVecD1V))
515 {
516 ++NbPointsOK;
517 gp_Vec V (P, APoint);
518 Par = V.Magnitude();
519 if (Par > gp::Resolution())
520 {
521 gp_Vec Norm = aVecD1U.Crossed (aVecD1V);
522 Standard_Real tt = Norm.Magnitude();
523 tt = Abs (Norm.Dot (V)) / (tt * Par);
524 if (tt > maxscal)
525 {
526 maxscal = tt;
527 L = gp_Lin (P, V);
528 _Par = Par;
529 ptfound = Standard_True;
530 if (maxscal>0.2)
531 {
532 myParamOnEdge=svmyparam;
533 return 0;
534 }
535 }
536 }
537 }
7fd59977 538 }
539 while(IndexPoint<200 && NbPointsOK<16);
540
541 myParamOnEdge=svmyparam;
7fd59977 542 if(maxscal>0.2) {
7fd59977 543 return 0;
7fd59977 544 }
545
546
547 // Modified by skv - Thu Sep 4 14:32:14 2003 OCC578 Begin
548 // Next is done in the main for(..) loop.
549 // faceexplorer.Next();
550 // Modified by skv - Thu Sep 4 14:32:14 2003 OCC578 End
551 IndexPoint = 0;
552
553 Standard_Boolean encoreuneface = faceexplorer.More();
554 if(ptfound==Standard_False && encoreuneface==Standard_False) {
555 if(myParamOnEdge < 0.0001) {
0d969553
Y
556 //-- This case takes place when the point is on the solid
557 //-- and this solid is reduced to a face
7fd59977 558 gp_Pnt PBidon(P.X()+1.0,P.Y(),P.Z());
559 gp_Vec V(P,PBidon);
560 Par= 1.0;
561 _Par=Par;
562 L = gp_Lin(P,V);
7fd59977 563 return 0;
7fd59977 564 }
565 }
566 } //-- Exploration of the faces
567
568 if(NbFacesInSolid==0) {
569 _Par=0.0;
570 myReject=Standard_True;
571#if DEB
0d969553 572 cout<<"\nWARNING : BRepClass3d_SolidExplorer.cxx (Solid without face)"<<endl;
7fd59977 573#endif
7fd59977 574 return 0;
7fd59977 575 }
576
577 if(ptfound) {
7fd59977 578 return 0;
7fd59977 579 }
580 myFirstFace = 0;
581 if(myParamOnEdge==0.512345) myParamOnEdge = 0.4;
582 else if(myParamOnEdge==0.4) myParamOnEdge = 0.6;
583 else if(myParamOnEdge==0.6) myParamOnEdge = 0.3;
584 else if(myParamOnEdge==0.3) myParamOnEdge = 0.7;
585 else if(myParamOnEdge==0.7) myParamOnEdge = 0.2;
586 else if(myParamOnEdge==0.2) myParamOnEdge = 0.8;
587 else if(myParamOnEdge==0.8) myParamOnEdge = 0.1;
588 else if(myParamOnEdge==0.1) myParamOnEdge = 0.9;
1da5279e 589 //
590 else {
591 myParamOnEdge*=0.5;
592 if(myParamOnEdge < 0.0001) {
593 gp_Pnt PBidon(P.X()+1.0,P.Y(),P.Z());
594 gp_Vec V(P,PBidon);
595 Par= 1.0;
596 _Par=Par;
597 L = gp_Lin(P,V);
598 return 0;
599 }
600 }
302f96fb 601 } //-- for(;;) { ... }
7fd59977 602}
603
604// Modified by skv - Thu Sep 4 12:30:14 2003 OCC578 Begin
605//=======================================================================
606//function : GetFaceSegmentIndex
607//purpose : Returns the index of face for which last segment is calculated.
608//=======================================================================
609
610Standard_Integer BRepClass3d_SolidExplorer::GetFaceSegmentIndex() const
611{
612 return myFirstFace;
613}
614// Modified by skv - Thu Sep 4 12:30:14 2003 OCC578 End
615
616//=======================================================================
617//function : PointInTheFace
618//purpose :
619//=======================================================================
620
621Standard_Boolean BRepClass3d_SolidExplorer::PointInTheFace
622(const TopoDS_Face& _face,
623 gp_Pnt& APoint_,
624 Standard_Real& u_, Standard_Real& v_,
625 Standard_Real& param_,
626 Standard_Integer& IndexPoint) const
627{
628 TopoDS_Face Face = _face;
629 Face.Orientation(TopAbs_FORWARD);
630 Handle(BRepAdaptor_HSurface) surf = new BRepAdaptor_HSurface();
631 surf->ChangeSurface().Initialize(Face);
632 Standard_Real U1,V1,U2,V2;//,u,v;
633 U1 = surf->FirstUParameter();
634 V1 = surf->FirstVParameter();
635 U2 = surf->LastUParameter();
636 V2 = surf->LastVParameter();
637 LimitInfiniteUV (U1,V1,U2,V2);
638 return(PointInTheFace(Face,APoint_,u_,v_,param_,IndexPoint,surf,U1,V1,U2,V2));
639}
640
641//=======================================================================
642//function : FindAPointInTheFace
643//purpose :
644//=======================================================================
645
646Standard_Boolean BRepClass3d_SolidExplorer::FindAPointInTheFace
647(const TopoDS_Face& _face,
648 gp_Pnt& APoint_,
649 Standard_Real& u_,Standard_Real& v_)
650{
651 Standard_Real param = 0.1;
652 Standard_Boolean r = FindAPointInTheFace(_face,APoint_,u_,v_,param);
653 return r;
654}
655
656//=======================================================================
657//function : FindAPointInTheFace
658//purpose :
659//=======================================================================
660
661Standard_Boolean BRepClass3d_SolidExplorer::FindAPointInTheFace
662(const TopoDS_Face& _face,
663 gp_Pnt& APoint_)
664{ Standard_Real u,v;
665 Standard_Boolean r = FindAPointInTheFace(_face,APoint_,u,v);
666 return r;
667}
668
669//=======================================================================
670//function : FindAPointInTheFace
671//purpose :
672//=======================================================================
673
674Standard_Boolean BRepClass3d_SolidExplorer::FindAPointInTheFace
675(const TopoDS_Face& _face,
676 Standard_Real& u_,Standard_Real& v_)
677{ gp_Pnt APoint;
678 Standard_Boolean r = FindAPointInTheFace(_face,APoint,u_,v_);
679 return r;
680}
681
682//=======================================================================
683//function : BRepClass3d_SolidExplorer
684//purpose :
685//=======================================================================
686
687BRepClass3d_SolidExplorer::BRepClass3d_SolidExplorer()
688{
689}
690#include <Standard_ConstructionError.hxx>
691
692//=======================================================================
693//function : BRepClass3d_SolidExplorer
694//purpose : Raise if called.
695//=======================================================================
696
697//BRepClass3d_SolidExplorer::BRepClass3d_SolidExplorer(const BRepClass3d_SolidExplorer& Oth)
698BRepClass3d_SolidExplorer::BRepClass3d_SolidExplorer(const BRepClass3d_SolidExplorer& )
699{
700 Standard_ConstructionError::Raise("Magic constructor not allowed");
701}
702
703//=======================================================================
704//function : BRepClass3d_SolidExplorer
705//purpose :
706//=======================================================================
707
708BRepClass3d_SolidExplorer::BRepClass3d_SolidExplorer(const TopoDS_Shape& S)
709{
710 InitShape(S);
711}
712
713//=======================================================================
714//function : Delete
715//purpose :
716//=======================================================================
717
718void BRepClass3d_SolidExplorer::Delete()
719{
720 Destroy() ;
721}
722
723//=======================================================================
724//function : Destroy
725//purpose : C++: alias ~
726//=======================================================================
727
728void BRepClass3d_SolidExplorer::Destroy() {
729 BRepClass3d_DataMapIteratorOfMapOfInter iter(myMapOfInter);
730 for(;iter.More();iter.Next()) {
731 void *ptr=iter.Value();
732 if(ptr) {
733 delete (IntCurvesFace_Intersector *)ptr;
734 myMapOfInter.ChangeFind(iter.Key()) = NULL;
735 }
736 }
737 myMapOfInter.Clear();
738}
739
740//=======================================================================
741//function : InitShape
742//purpose :
743//=======================================================================
744
745void BRepClass3d_SolidExplorer::InitShape(const TopoDS_Shape& S)
746{
747 myShape = S;
748 myFirstFace = 0;
749 myParamOnEdge = 0.512345;
0d969553 750 //-- Exploring of the Map and removal of allocated objects
7fd59977 751
752
753 BRepClass3d_DataMapIteratorOfMapOfInter iter(myMapOfInter);
754 for(;iter.More();iter.Next()) {
755 void *ptr=iter.Value();
756 if(ptr) {
757 delete (IntCurvesFace_Intersector *)ptr;
758 myMapOfInter.ChangeFind(iter.Key()) = NULL;
759 }
760 }
761
762 myMapOfInter.Clear();
763
0d969553 764 myReject = Standard_True; //-- case of infinite solid (without any face)
7fd59977 765
766 TopExp_Explorer Expl;
767 for(Expl.Init(S,TopAbs_FACE);
768 Expl.More();
769 Expl.Next()) {
770 const TopoDS_Face Face = TopoDS::Face(Expl.Current());
771 void *ptr = (void *)(new IntCurvesFace_Intersector(Face,Precision::Confusion()));
772 myMapOfInter.Bind(Face,ptr);
0d969553 773 myReject=Standard_False; //-- at least one face in the solid
7fd59977 774 }
775
776#if DEB
777 if(myReject) {
0d969553 778 cout<<"\nWARNING : BRepClass3d_SolidExplorer.cxx (Solid without face)"<<endl;
7fd59977 779 }
780#endif
781
782#if REJECTION
783 BRepBndLib::Add(myShape,myBox);
784#endif
785}
786
787//=======================================================================
788//function : Reject
789//purpose : Should return True if P outside of bounding vol. of the shape
790//=======================================================================
791
792//Standard_Boolean BRepClass3d_SolidExplorer::Reject(const gp_Pnt& P) const
793Standard_Boolean BRepClass3d_SolidExplorer::Reject(const gp_Pnt& ) const
794{
0d969553 795 return(myReject); // case of solid without face
7fd59977 796}
797
798//=======================================================================
799//function : InitShell
800//purpose : Starts an exploration of the shells.
801//=======================================================================
802
803void BRepClass3d_SolidExplorer::InitShell()
804{
805 myShellExplorer.Init(myShape,TopAbs_SHELL);
806}
807
808//=======================================================================
809//function : MoreShell
810//purpose : Returns True if there is a current shell.
811//=======================================================================
812
813Standard_Boolean BRepClass3d_SolidExplorer::MoreShell() const
814{
815 return(myShellExplorer.More());
816}
817
818//=======================================================================
819//function : NextShell
820//purpose : Sets the explorer to the next shell.
821//=======================================================================
822
823void BRepClass3d_SolidExplorer::NextShell()
824{
825 myShellExplorer.Next();
826}
827
828//=======================================================================
829//function : CurrentShell
830//purpose : Returns the current shell.
831//=======================================================================
832
833TopoDS_Shell BRepClass3d_SolidExplorer::CurrentShell() const
834{
835 return(TopoDS::Shell(myShellExplorer.Current()));
836}
837
838//=======================================================================
839//function : RejectShell
840//purpose : Returns True if the Shell is rejected.
841//=======================================================================
842
843Standard_Boolean BRepClass3d_SolidExplorer::RejectShell(const gp_Lin& ) const
844{
845 return(Standard_False);
846}
847
848//=======================================================================
849//function : InitFace
850//purpose : Starts an exploration of the faces of the current shell.
851//=======================================================================
852
853void BRepClass3d_SolidExplorer::InitFace()
854{
855 myFaceExplorer.Init(TopoDS::Shell(myShellExplorer.Current()),TopAbs_FACE);
856}
857
858//=======================================================================
859//function : MoreFace
860//purpose : Returns True if current face in current shell.
861//=======================================================================
862
863Standard_Boolean BRepClass3d_SolidExplorer::MoreFace() const
864{
865 return(myFaceExplorer.More());
866}
867
868//=======================================================================
869//function : NextFace
870//purpose : Sets the explorer to the next Face of the current shell.
871//=======================================================================
872
873void BRepClass3d_SolidExplorer::NextFace()
874{
875 myFaceExplorer.Next();
876}
877
878//=======================================================================
879//function : CurrentFace
880//purpose : Returns the current face.
881//=======================================================================
882
883TopoDS_Face BRepClass3d_SolidExplorer::CurrentFace() const
884{
885 return(TopoDS::Face(myFaceExplorer.Current()));
886}
887
888//=======================================================================
889//function : RejectFace
890//purpose : returns True if the face is rejected.
891//=======================================================================
892
893Standard_Boolean BRepClass3d_SolidExplorer::RejectFace(const gp_Lin& ) const
894{
895 return(Standard_False);
896}
897
898#ifdef DEB
899#include <TopAbs_State.hxx>
900#endif
901
902//=======================================================================
903//function : Segment
904//purpose : Returns in <L>, <Par> a segment having at least
905// one intersection with the shape boundary to
906// compute intersections.
907//=======================================================================
88cc4cb8 908Standard_Integer BRepClass3d_SolidExplorer::Segment(const gp_Pnt& P,
909 gp_Lin& L,
910 Standard_Real& Par)
7fd59977 911{
912 Standard_Integer bRetFlag;
913 myFirstFace = 0;
914 bRetFlag=OtherSegment(P,L,Par);
915 return bRetFlag;
916}
7fd59977 917
918//=======================================================================
919//function : Intersector
920//purpose :
921//=======================================================================
922
923IntCurvesFace_Intersector& BRepClass3d_SolidExplorer::Intersector(const TopoDS_Face& F) const {
924 void *ptr = (void*)(myMapOfInter.Find(F));
7fd59977 925 IntCurvesFace_Intersector& curr = (*((IntCurvesFace_Intersector *)ptr));
926 return curr;
7fd59977 927}
928
929//=======================================================================
930//function : Box
931//purpose :
932//=======================================================================
933
934const Bnd_Box& BRepClass3d_SolidExplorer::Box() const {
935 return(myBox);
936}
937
938//=======================================================================
939//function : DumpSegment
940//purpose :
941//=======================================================================
942
943void BRepClass3d_SolidExplorer::DumpSegment(const gp_Pnt&,
944 const gp_Lin&,
945 const Standard_Real,
946 const TopAbs_State) const
947{
948#ifdef DEB
0d969553 949
7fd59977 950#endif
951}