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