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