0024972: Problem of the influence of the includes order during compilation
[occt.git] / src / IntTools / IntTools_Context.cxx
CommitLineData
b311480e 1// Created by: Peter KURNEV
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
7fd59977 14
1e143abb 15#include <IntTools_Context.ixx>
7fd59977 16
17#include <Precision.hxx>
18
19#include <Geom_Curve.hxx>
20#include <Geom_BoundedCurve.hxx>
21#include <GeomAPI_ProjectPointOnCurve.hxx>
22#include <GeomAPI_ProjectPointOnSurf.hxx>
23#include <GeomAdaptor_Curve.hxx>
24
4e57c75e 25#include <Geom2dHatch_Intersector.hxx>
26#include <Geom2d_TrimmedCurve.hxx>
27
7fd59977 28#include <TopAbs_State.hxx>
29#include <TopoDS.hxx>
30#include <TopExp_Explorer.hxx>
31
32#include <BRep_Tool.hxx>
33#include <BRepAdaptor_Surface.hxx>
34
35#include <IntTools_Tools.hxx>
36#include <IntTools_FClass2d.hxx>
4e57c75e 37//
7fd59977 38#include <Extrema_LocateExtPC.hxx>
39
40#include <Geom2d_Curve.hxx>
4e57c75e 41#include <NCollection_IncAllocator.hxx>
42#include <IntTools_SurfaceRangeLocalizeData.hxx>
43
7fd59977 44
45//=======================================================================
46//function :
47//purpose :
48//=======================================================================
1e143abb 49IntTools_Context::IntTools_Context()
4e57c75e 50:
51 myAllocator(new NCollection_IncAllocator()),
52 myFClass2dMap(100, myAllocator),
53 myProjPSMap(100, myAllocator),
54 myProjPCMap(100, myAllocator),
55 mySClassMap(100, myAllocator),
56 myProjPTMap(100, myAllocator),
57 myHatcherMap(100, myAllocator),
58 myProjSDataMap(100, myAllocator),
59 myCreateFlag(0)
60{
61}
62//=======================================================================
63//function :
64//purpose :
65//=======================================================================
1e143abb 66IntTools_Context::IntTools_Context
67 (const Handle(NCollection_BaseAllocator)& theAllocator)
4e57c75e 68:
69 myAllocator(theAllocator),
70 myFClass2dMap(100, myAllocator),
71 myProjPSMap(100, myAllocator),
72 myProjPCMap(100, myAllocator),
73 mySClassMap(100, myAllocator),
74 myProjPTMap(100, myAllocator),
75 myHatcherMap(100, myAllocator),
76 myProjSDataMap(100, myAllocator),
77 myCreateFlag(1)
7fd59977 78{
79}
80//=======================================================================
81//function : ~
82//purpose :
83//=======================================================================
1e143abb 84IntTools_Context::~IntTools_Context()
7fd59977 85{
86 Standard_Address anAdr;
4e57c75e 87 BOPCol_DataMapIteratorOfDataMapOfShapeAddress aIt;
88 BOPCol_DataMapIteratorOfDataMapOfTransientAddress aIt1;
3f524765 89 //
7fd59977 90 IntTools_FClass2d* pFClass2d;
4e57c75e 91 //
92 aIt.Initialize(myFClass2dMap);
93 for (; aIt.More(); aIt.Next()) {
94 anAdr=aIt.Value();
7fd59977 95 pFClass2d=(IntTools_FClass2d*)anAdr;
4e57c75e 96 (*pFClass2d).~IntTools_FClass2d();
97 myAllocator->Free(anAdr);
7fd59977 98 }
99 myFClass2dMap.Clear();
100 //
101 GeomAPI_ProjectPointOnSurf* pProjPS;
4e57c75e 102 aIt.Initialize(myProjPSMap);
103 for (; aIt.More(); aIt.Next()) {
104 anAdr=aIt.Value();
7fd59977 105 pProjPS=(GeomAPI_ProjectPointOnSurf*)anAdr;
4e57c75e 106 (*pProjPS).~GeomAPI_ProjectPointOnSurf();
107 myAllocator->Free(anAdr);
7fd59977 108 }
109 myProjPSMap.Clear();
110 //
111 GeomAPI_ProjectPointOnCurve* pProjPC;
4e57c75e 112 aIt.Initialize(myProjPCMap);
113 for (; aIt.More(); aIt.Next()) {
114 anAdr=aIt.Value();
7fd59977 115 pProjPC=(GeomAPI_ProjectPointOnCurve*)anAdr;
4e57c75e 116 (*pProjPC).~GeomAPI_ProjectPointOnCurve();
117 myAllocator->Free(anAdr);
7fd59977 118 }
119 myProjPCMap.Clear();
120 //
4e57c75e 121 //
122 BRepClass3d_SolidClassifier* pSC;
123 aIt.Initialize(mySClassMap);
124 for (; aIt.More(); aIt.Next()) {
125 anAdr=aIt.Value();
126 pSC=(BRepClass3d_SolidClassifier*)anAdr;
127 (*pSC).~BRepClass3d_SolidClassifier();
128 myAllocator->Free(anAdr);
129 }
130 mySClassMap.Clear();
131 //
7fd59977 132 GeomAPI_ProjectPointOnCurve* pProjPT;
4e57c75e 133 aIt1.Initialize(myProjPTMap);
134 for (; aIt1.More(); aIt1.Next()) {
135 anAdr=aIt1.Value();
7fd59977 136 pProjPT=(GeomAPI_ProjectPointOnCurve*)anAdr;
4e57c75e 137 (*pProjPT).~GeomAPI_ProjectPointOnCurve();
138 myAllocator->Free(anAdr);
7fd59977 139 }
140 myProjPTMap.Clear();
141 //
4e57c75e 142 Geom2dHatch_Hatcher* pHatcher;
143 aIt.Initialize(myHatcherMap);
144 for (; aIt.More(); aIt.Next()) {
145 anAdr=aIt.Value();
146 pHatcher=(Geom2dHatch_Hatcher*)anAdr;
147 (*pHatcher).~Geom2dHatch_Hatcher();
148 myAllocator->Free(anAdr);
7fd59977 149 }
4e57c75e 150 myHatcherMap.Clear();
7fd59977 151 //
152 IntTools_SurfaceRangeLocalizeData* pSData = NULL;
4e57c75e 153 aIt.Initialize(myProjSDataMap);
154 for (; aIt.More(); aIt.Next()) {
155 anAdr=aIt.Value();
7fd59977 156 pSData = (IntTools_SurfaceRangeLocalizeData*)anAdr;
4e57c75e 157 (*pSData).~IntTools_SurfaceRangeLocalizeData();
158 myAllocator->Free(anAdr);
7fd59977 159 }
160 myProjSDataMap.Clear();
161}
162//=======================================================================
163//function : FClass2d
164//purpose :
165//=======================================================================
1e143abb 166IntTools_FClass2d& IntTools_Context::FClass2d(const TopoDS_Face& aF)
7fd59977 167{
168 Standard_Address anAdr;
169 IntTools_FClass2d* pFClass2d;
cf8e963a 170 //
4e57c75e 171 if (!myFClass2dMap.IsBound(aF)) {
7fd59977 172 Standard_Real aTolF;
4e57c75e 173 TopoDS_Face aFF;
174 //
175 aFF=aF;
7fd59977 176 aFF.Orientation(TopAbs_FORWARD);
177 aTolF=BRep_Tool::Tolerance(aFF);
178 //
4e57c75e 179 pFClass2d=(IntTools_FClass2d*)myAllocator->Allocate(sizeof(IntTools_FClass2d));
180 new (pFClass2d) IntTools_FClass2d(aFF, aTolF);
7fd59977 181 //
182 anAdr=(Standard_Address)pFClass2d;
4e57c75e 183 myFClass2dMap.Bind(aFF, anAdr);
7fd59977 184 }
7fd59977 185 else {
4e57c75e 186 anAdr=myFClass2dMap.Find(aF);
187 pFClass2d=(IntTools_FClass2d*)anAdr;
7fd59977 188 }
7fd59977 189 return *pFClass2d;
190}
191//=======================================================================
192//function : ProjPS
193//purpose :
194//=======================================================================
1e143abb 195GeomAPI_ProjectPointOnSurf& IntTools_Context::ProjPS(const TopoDS_Face& aF)
7fd59977 196{
197 Standard_Address anAdr;
198 GeomAPI_ProjectPointOnSurf* pProjPS;
4e57c75e 199
200 if (!myProjPSMap.IsBound(aF)) {
201 Standard_Real Umin, Usup, Vmin, Vsup, anEpsT=1.e-12 ;
7fd59977 202 BRepAdaptor_Surface aBAS;
203 //
204 const Handle(Geom_Surface)& aS=BRep_Tool::Surface(aF);
205 aBAS.Initialize (aF, Standard_True);
206 //
207 Umin=aBAS.FirstUParameter();
208 Usup=aBAS.LastUParameter ();
209 Vmin=aBAS.FirstVParameter();
210 Vsup=aBAS.LastVParameter ();
211 //
4e57c75e 212 pProjPS=(GeomAPI_ProjectPointOnSurf*)myAllocator->Allocate(sizeof(GeomAPI_ProjectPointOnSurf));
213 new (pProjPS) GeomAPI_ProjectPointOnSurf();
b4109929 214 pProjPS->Init(aS ,Umin, Usup, Vmin, Vsup, anEpsT/*, Extrema_ExtAlgo_Tree*/);
d633fd70 215 Extrema_ExtPS& anExtAlgo = const_cast<Extrema_ExtPS&>(pProjPS->Extrema());
216 anExtAlgo.SetFlag(Extrema_ExtFlag_MIN);
7fd59977 217 //
218 anAdr=(Standard_Address)pProjPS;
4e57c75e 219 myProjPSMap.Bind(aF, anAdr);
7fd59977 220 }
221
222 else {
4e57c75e 223 anAdr=myProjPSMap.Find(aF);
224 pProjPS=(GeomAPI_ProjectPointOnSurf*)anAdr;
7fd59977 225 }
226 return *pProjPS;
227}
228//=======================================================================
229//function : ProjPC
230//purpose :
231//=======================================================================
1e143abb 232GeomAPI_ProjectPointOnCurve& IntTools_Context::ProjPC(const TopoDS_Edge& aE)
7fd59977 233{
234 Standard_Address anAdr;
235 GeomAPI_ProjectPointOnCurve* pProjPC;
4e57c75e 236
237 if (!myProjPCMap.IsBound(aE)) {
7fd59977 238 Standard_Real f, l;
239 //
240 Handle(Geom_Curve)aC3D=BRep_Tool::Curve (aE, f, l);
241 //
4e57c75e 242 pProjPC=(GeomAPI_ProjectPointOnCurve*)myAllocator->Allocate(sizeof(GeomAPI_ProjectPointOnCurve));
243 new (pProjPC) GeomAPI_ProjectPointOnCurve();
7fd59977 244 pProjPC->Init(aC3D, f, l);
245 //
246 anAdr=(Standard_Address)pProjPC;
4e57c75e 247 myProjPCMap.Bind(aE, anAdr);
7fd59977 248 }
4e57c75e 249
7fd59977 250 else {
4e57c75e 251 anAdr=myProjPCMap.Find(aE);
252 pProjPC=(GeomAPI_ProjectPointOnCurve*)anAdr;
7fd59977 253 }
254 return *pProjPC;
255}
4e57c75e 256
7fd59977 257//=======================================================================
258//function : ProjPT
259//purpose :
260//=======================================================================
1e143abb 261GeomAPI_ProjectPointOnCurve& IntTools_Context::ProjPT
262 (const Handle(Geom_Curve)& aC3D)
4e57c75e 263
7fd59977 264{
265 Standard_Address anAdr;
266 GeomAPI_ProjectPointOnCurve* pProjPT;
4e57c75e 267
268 if (!myProjPTMap.IsBound(aC3D)) {
7fd59977 269 Standard_Real f, l;
270 f=aC3D->FirstParameter();
271 l=aC3D->LastParameter();
272 //
4e57c75e 273 pProjPT=(GeomAPI_ProjectPointOnCurve*)myAllocator->Allocate(sizeof(GeomAPI_ProjectPointOnCurve));
274 new (pProjPT) GeomAPI_ProjectPointOnCurve();
7fd59977 275 pProjPT->Init(aC3D, f, l);
276 //
277 anAdr=(Standard_Address)pProjPT;
4e57c75e 278 myProjPTMap.Bind(aC3D, anAdr);
7fd59977 279 }
280
281 else {
4e57c75e 282 anAdr=myProjPTMap.Find(aC3D);
283 pProjPT=(GeomAPI_ProjectPointOnCurve*)anAdr;
7fd59977 284 }
285 return *pProjPT;
286}
287//=======================================================================
4e57c75e 288//function : SolidClassifier
7fd59977 289//purpose :
290//=======================================================================
1e143abb 291BRepClass3d_SolidClassifier& IntTools_Context::SolidClassifier
292 (const TopoDS_Solid& aSolid)
7fd59977 293{
294 Standard_Address anAdr;
4e57c75e 295 BRepClass3d_SolidClassifier* pSC;
296
297 if (!mySClassMap.IsBound(aSolid)) {
7fd59977 298 //
4e57c75e 299 pSC=(BRepClass3d_SolidClassifier*)myAllocator->Allocate(sizeof(BRepClass3d_SolidClassifier));
300 new (pSC) BRepClass3d_SolidClassifier(aSolid);
7fd59977 301 //
4e57c75e 302 anAdr=(Standard_Address)pSC;
303 mySClassMap.Bind(aSolid, anAdr);
7fd59977 304 }
305
306 else {
4e57c75e 307 anAdr=mySClassMap.Find(aSolid);
308 pSC =(BRepClass3d_SolidClassifier*)anAdr;
7fd59977 309 }
4e57c75e 310 return *pSC;
7fd59977 311}
4e57c75e 312
7fd59977 313//=======================================================================
4e57c75e 314//function : Hatcher
7fd59977 315//purpose :
316//=======================================================================
1e143abb 317Geom2dHatch_Hatcher& IntTools_Context::Hatcher(const TopoDS_Face& aF)
7fd59977 318{
319 Standard_Address anAdr;
4e57c75e 320 Geom2dHatch_Hatcher* pHatcher;
cf8e963a 321 //
4e57c75e 322 if (!myHatcherMap.IsBound(aF)) {
323 Standard_Real aTolArcIntr, aTolTangfIntr, aTolHatch2D, aTolHatch3D;
324 Standard_Real aU1, aU2, aEpsT;
325 TopAbs_Orientation aOrE;
326 Handle(Geom_Surface) aS;
327 Handle(Geom2d_Curve) aC2D;
328 Handle(Geom2d_TrimmedCurve) aCT2D;
329 TopoDS_Face aFF;
330 TopExp_Explorer aExp;
7fd59977 331 //
4e57c75e 332 aTolHatch2D=1.e-8;
333 aTolHatch3D=1.e-8;
334 aTolArcIntr=1.e-10;
335 aTolTangfIntr=1.e-10;
336 aEpsT=Precision::PConfusion();
7fd59977 337 //
4e57c75e 338 Geom2dHatch_Intersector aIntr(aTolArcIntr, aTolTangfIntr);
339 pHatcher=new Geom2dHatch_Hatcher(aIntr,
340 aTolHatch2D, aTolHatch3D,
341 Standard_True, Standard_False);
342
343 //
344 aFF=aF;
345 aFF.Orientation(TopAbs_FORWARD);
346 aS=BRep_Tool::Surface(aFF);
347
348 aExp.Init (aFF, TopAbs_EDGE);
349 for (; aExp.More() ; aExp.Next()) {
350 const TopoDS_Edge& aE=*((TopoDS_Edge*)&aExp.Current());
351 aOrE=aE.Orientation();
352 //
353 aC2D=BRep_Tool::CurveOnSurface (aE, aFF, aU1, aU2);
354 if (aC2D.IsNull() ) {
355 continue;
356 }
357 if (fabs(aU1-aU2) < aEpsT) {
358 continue;
359 }
360 //
361 aCT2D=new Geom2d_TrimmedCurve(aC2D, aU1, aU2);
362 pHatcher->AddElement(aCT2D, aOrE);
363 }// for (; aExp.More() ; aExp.Next()) {
364 //
365 anAdr=(Standard_Address)pHatcher;
366 myHatcherMap.Bind(aFF, anAdr);
367 }//if (!myHatcherMap.IsBound(aF)) {
368 //
369 else {
370 anAdr=myHatcherMap.Find(aF);
371 pHatcher=(Geom2dHatch_Hatcher*)anAdr;
7fd59977 372 }
4e57c75e 373
374 return *pHatcher;
375}
376
377//=======================================================================
378//function : SurfaceData
379//purpose :
380//=======================================================================
1e143abb 381IntTools_SurfaceRangeLocalizeData& IntTools_Context::SurfaceData
382 (const TopoDS_Face& aF)
4e57c75e 383{
384 Standard_Address anAdr;
385 IntTools_SurfaceRangeLocalizeData* pSData;
386 //
387 if (!myProjSDataMap.IsBound(aF)) {
1e143abb 388 pSData=new IntTools_SurfaceRangeLocalizeData
389 (3,
390 3,
391 10. * Precision::PConfusion(),
392 10. * Precision::PConfusion());
4e57c75e 393 //
394 anAdr=(Standard_Address)pSData;
395 myProjSDataMap.Bind(aF, anAdr);
396 }
397
7fd59977 398 else {
4e57c75e 399 anAdr=myProjSDataMap.Find(aF);
400 pSData=(IntTools_SurfaceRangeLocalizeData*)anAdr;
7fd59977 401 }
4e57c75e 402 return *pSData;
403
7fd59977 404}
4e57c75e 405
7fd59977 406//=======================================================================
4e57c75e 407//function : ComputePE
7fd59977 408//purpose :
409//=======================================================================
1e143abb 410Standard_Integer IntTools_Context::ComputePE
411 (const gp_Pnt& aP1,
412 const Standard_Real aTolP1,
413 const TopoDS_Edge& aE2,
414 Standard_Real& aT)
7fd59977 415{
4e57c75e 416 if (!BRep_Tool::IsGeometric(aE2)) {
417 return -2;
418 }
419 Standard_Real aDist, aTolE2, aTolSum;
420 Standard_Integer aNbProj;
7fd59977 421 //
4e57c75e 422 GeomAPI_ProjectPointOnCurve& aProjector=ProjPC(aE2);
423 aProjector.Perform(aP1);
424
425 aNbProj=aProjector.NbPoints();
426 if (!aNbProj) {
427 return -3;
428 }
7fd59977 429 //
4e57c75e 430 aDist=aProjector.LowerDistance();
431 //
432 aTolE2=BRep_Tool::Tolerance(aE2);
433 aTolSum=aTolP1+aTolE2;
434 //
435 aT=aProjector.LowerDistanceParameter();
436 if (aDist > aTolSum) {
437 return -4;
438 }
439 return 0;
7fd59977 440}
441//=======================================================================
442//function : ComputeVE
443//purpose :
444//=======================================================================
1e143abb 445Standard_Integer IntTools_Context::ComputeVE
446 (const TopoDS_Vertex& aV1,
447 const TopoDS_Edge& aE2,
448 Standard_Real& aT)
7fd59977 449{
7fd59977 450 if (BRep_Tool::Degenerated(aE2)) {
451 return -1;
452 }
4e57c75e 453 if (!BRep_Tool::IsGeometric(aE2)) {
454 return -2;
455 }
456 Standard_Real aDist, aTolV1, aTolE2, aTolSum;
7fd59977 457 Standard_Integer aNbProj;
458 gp_Pnt aP;
459 //
460 aP=BRep_Tool::Pnt(aV1);
461 //
462 GeomAPI_ProjectPointOnCurve& aProjector=ProjPC(aE2);
463 aProjector.Perform(aP);
4e57c75e 464
7fd59977 465 aNbProj=aProjector.NbPoints();
466 if (!aNbProj) {
467 return -3;
468 }
469 //
470 aDist=aProjector.LowerDistance();
42ff8f5b 471
472 // tolerance of check for coincidence is sum of tolerances of edge and vertex
473 // extended by additional Precision::Confusion() to allow for interference where
474 // it is very close but not fit to tolerance (see #24108)
7fd59977 475 aTolV1=BRep_Tool::Tolerance(aV1);
476 aTolE2=BRep_Tool::Tolerance(aE2);
42ff8f5b 477 aTolSum = aTolV1 + aTolE2 + Precision::Confusion();
7fd59977 478 //
479 aT=aProjector.LowerDistanceParameter();
480 if (aDist > aTolSum) {
481 return -4;
482 }
7fd59977 483 return 0;
484}
7fd59977 485//=======================================================================
486//function : ComputeVS
487//purpose :
488//=======================================================================
1e143abb 489Standard_Integer IntTools_Context::ComputeVF
490 (const TopoDS_Vertex& aV1,
491 const TopoDS_Face& aF2,
492 Standard_Real& U,
493 Standard_Real& V)
7fd59977 494{
495 Standard_Real aTolV1, aTolF2, aTolSum, aDist;
496 gp_Pnt aP;
497
498 aP=BRep_Tool::Pnt(aV1);
499 //
500 // 1. Check if the point is projectable on the surface
501 GeomAPI_ProjectPointOnSurf& aProjector=ProjPS(aF2);
502 aProjector.Perform(aP);
503 //
4e57c75e 504 if (!aProjector.IsDone()) { // the point is not projectable on the surface
7fd59977 505 return -1;
506 }
507 //
508 // 2. Check the distance between the projection point and
509 // the original point
510 aDist=aProjector.LowerDistance();
511
512 aTolV1=BRep_Tool::Tolerance(aV1);
513 aTolF2=BRep_Tool::Tolerance(aF2);
514 aTolSum=aTolV1+aTolF2;
515 if (aDist > aTolSum) {
516 // the distance is too large
517 return -2;
518 }
519 aProjector.LowerDistanceParameters(U, V);
520 //
521 gp_Pnt2d aP2d(U, V);
522 Standard_Boolean pri=IsPointInFace (aF2, aP2d);
4e57c75e 523 if (!pri) {// the point lays on the surface but out of the face
7fd59977 524 return -3;
525 }
526 return 0;
527}
528//=======================================================================
529//function : StatePointFace
530//purpose :
531//=======================================================================
1e143abb 532TopAbs_State IntTools_Context::StatePointFace
533 (const TopoDS_Face& aF,
534 const gp_Pnt2d& aP2d)
7fd59977 535{
536 TopAbs_State aState;
537 IntTools_FClass2d& aClass2d=FClass2d(aF);
538 aState=aClass2d.Perform(aP2d);
539 return aState;
540}
541//=======================================================================
542//function : IsPointInFace
543//purpose :
544//=======================================================================
1e143abb 545Standard_Boolean IntTools_Context::IsPointInFace
546 (const TopoDS_Face& aF,
547 const gp_Pnt2d& aP2d)
7fd59977 548{
549 TopAbs_State aState=StatePointFace(aF, aP2d);
550 if (aState==TopAbs_OUT || aState==TopAbs_ON) {
551 return Standard_False;
552 }
553 return Standard_True;
554}
555//=======================================================================
556//function : IsPointInOnFace
557//purpose :
558//=======================================================================
1e143abb 559 Standard_Boolean IntTools_Context::IsPointInOnFace(const TopoDS_Face& aF,
4e57c75e 560 const gp_Pnt2d& aP2d)
7fd59977 561{
562 TopAbs_State aState=StatePointFace(aF, aP2d);
563 if (aState==TopAbs_OUT) {
564 return Standard_False;
565 }
566 return Standard_True;
567}
568//=======================================================================
569//function : IsValidPointForFace
570//purpose :
571//=======================================================================
1e143abb 572Standard_Boolean IntTools_Context::IsValidPointForFace
573 (const gp_Pnt& aP,
574 const TopoDS_Face& aF,
575 const Standard_Real aTol)
7fd59977 576{
577 Standard_Boolean bFlag;
96a95605 578 Standard_Real Umin, U, V;
7fd59977 579
580 GeomAPI_ProjectPointOnSurf& aProjector=ProjPS(aF);
581 aProjector.Perform(aP);
582
583 bFlag=aProjector.IsDone();
584 if (bFlag) {
585
586 Umin=aProjector.LowerDistance();
587 //if (Umin > 1.e-3) { // it was
588 if (Umin > aTol) {
589 return !bFlag;
590 }
591 //
592 aProjector.LowerDistanceParameters(U, V);
593 gp_Pnt2d aP2D(U, V);
594 bFlag=IsPointInOnFace (aF, aP2D);
595 }
596 return bFlag;
597}
598//=======================================================================
599//function : IsValidPointForFaces
600//purpose :
601//=======================================================================
1e143abb 602Standard_Boolean IntTools_Context::IsValidPointForFaces
603 (const gp_Pnt& aP,
604 const TopoDS_Face& aF1,
605 const TopoDS_Face& aF2,
606 const Standard_Real aTol)
7fd59977 607{
608 Standard_Boolean bFlag1, bFlag2;
609
610 bFlag1=IsValidPointForFace(aP, aF1, aTol);
611 if (!bFlag1) {
612 return bFlag1;
613 }
614 bFlag2=IsValidPointForFace(aP, aF2, aTol);
615 return bFlag2;
616}
617//=======================================================================
618//function : IsValidBlockForFace
619//purpose :
620//=======================================================================
1e143abb 621Standard_Boolean IntTools_Context::IsValidBlockForFace
622 (const Standard_Real aT1,
623 const Standard_Real aT2,
624 const IntTools_Curve& aC,
625 const TopoDS_Face& aF,
626 const Standard_Real aTol)
7fd59977 627{
628 Standard_Boolean bFlag;
96a95605 629 Standard_Real aTInterm;
7fd59977 630 gp_Pnt aPInterm;
631
632 aTInterm=IntTools_Tools::IntermediatePoint(aT1, aT2);
633
634 Handle(Geom_Curve) aC3D=aC.Curve();
7fd59977 635 // point 3D
636 aC3D->D0(aTInterm, aPInterm);
637 //
638 bFlag=IsValidPointForFace (aPInterm, aF, aTol);
639 return bFlag;
640}
641//=======================================================================
642//function : IsValidBlockForFaces
643//purpose :
644//=======================================================================
1e143abb 645Standard_Boolean IntTools_Context::IsValidBlockForFaces
646 (const Standard_Real aT1,
647 const Standard_Real aT2,
648 const IntTools_Curve& aC,
649 const TopoDS_Face& aF1,
650 const TopoDS_Face& aF2,
651 const Standard_Real aTol)
7fd59977 652{
653 Standard_Boolean bFlag1, bFlag2;
654 //
655 Handle(Geom2d_Curve) aPC1 = aC.FirstCurve2d();
656 Handle(Geom2d_Curve) aPC2 = aC.SecondCurve2d();
657 if( !aPC1.IsNull() && !aPC2.IsNull() ) {
658 Standard_Real aMidPar = IntTools_Tools::IntermediatePoint(aT1, aT2);
659 gp_Pnt2d aPnt2D;
660
661
662 aPC1->D0(aMidPar, aPnt2D);
663 bFlag1 = IsPointInOnFace(aF1, aPnt2D);
664
665 if( !bFlag1 )
666 return bFlag1;
667
668 aPC2->D0(aMidPar, aPnt2D);
669 bFlag2 = IsPointInOnFace(aF2, aPnt2D);
670 return bFlag2;
671 }
672 //
673
674 bFlag1=IsValidBlockForFace (aT1, aT2, aC, aF1, aTol);
675 if (!bFlag1) {
676 return bFlag1;
677 }
678 bFlag2=IsValidBlockForFace (aT1, aT2, aC, aF2, aTol);
679 return bFlag2;
680}
681//=======================================================================
682//function : IsVertexOnLine
683//purpose :
684//=======================================================================
1e143abb 685Standard_Boolean IntTools_Context::IsVertexOnLine
686 (const TopoDS_Vertex& aV,
687 const IntTools_Curve& aC,
688 const Standard_Real aTolC,
689 Standard_Real& aT)
7fd59977 690{
691 Standard_Boolean bRet;
692 Standard_Real aTolV;
693 //
694 aTolV=BRep_Tool::Tolerance(aV);
1e143abb 695 bRet=IntTools_Context::IsVertexOnLine(aV, aTolV, aC, aTolC , aT);
7fd59977 696 //
697 return bRet;
698}
699//=======================================================================
700//function : IsVertexOnLine
701//purpose :
702//=======================================================================
1e143abb 703Standard_Boolean IntTools_Context::IsVertexOnLine
704 (const TopoDS_Vertex& aV,
705 const Standard_Real aTolV,
706 const IntTools_Curve& aC,
707 const Standard_Real aTolC,
708 Standard_Real& aT)
7fd59977 709{
710 Standard_Real aFirst, aLast, aDist, aTolSum;
711 Standard_Integer aNbProj;
712 gp_Pnt aPv;
713
714 aPv=BRep_Tool::Pnt(aV);
715
716 Handle(Geom_Curve) aC3D=aC.Curve();
717
718
719 aTolSum=aTolV+aTolC;
720 //
721 GeomAdaptor_Curve aGAC(aC3D);
722 GeomAbs_CurveType aType=aGAC.GetType();
723 if (aType==GeomAbs_BSplineCurve ||
724 aType==GeomAbs_BezierCurve) {
725 aTolSum=2.*aTolSum;
726 if (aTolSum<1.e-5) {
727 aTolSum=1.e-5;
728 }
729 }
730 else {
731 aTolSum=2.*aTolSum;//xft
732 if(aTolSum < 1.e-6)
733 aTolSum = 1.e-6;
734 }
735 //
736 aFirst=aC3D->FirstParameter();
737 aLast =aC3D->LastParameter();
738 //
739 //Checking extermities first
740 if (!Precision::IsInfinite(aFirst)) {
741 gp_Pnt aPCFirst=aC3D->Value(aFirst);
742 aDist=aPv.Distance(aPCFirst);
743 if (aDist < aTolSum) {
744 aT=aFirst;
745 //
746 if(aDist > aTolV) {
4e57c75e 747 Extrema_LocateExtPC anExt(aPv, aGAC, aFirst, 1.e-10);
748
749 if(anExt.IsDone()) {
750 Extrema_POnCurv aPOncurve = anExt.Point();
751 aT = aPOncurve.Parameter();
752
753 if((aT > (aLast + aFirst) * 0.5) ||
754 (aPv.Distance(aPOncurve.Value()) > aTolSum) ||
755 (aPCFirst.Distance(aPOncurve.Value()) < Precision::Confusion()))
756 aT = aFirst;
757 }
7fd59977 758 }
759 //
760 return Standard_True;
761 }
762 }
763 //
4e57c75e 764 //if (!Precision::IsInfinite(aFirst)) {
7fd59977 765 if (!Precision::IsInfinite(aLast)) {
766 gp_Pnt aPCLast=aC3D->Value(aLast);
767 aDist=aPv.Distance(aPCLast);
768 if (aDist < aTolSum) {
769 aT=aLast;
770 //
771 if(aDist > aTolV) {
4e57c75e 772 Extrema_LocateExtPC anExt(aPv, aGAC, aLast, 1.e-10);
773
774 if(anExt.IsDone()) {
775 Extrema_POnCurv aPOncurve = anExt.Point();
776 aT = aPOncurve.Parameter();
777
778 if((aT < (aLast + aFirst) * 0.5) ||
779 (aPv.Distance(aPOncurve.Value()) > aTolSum) ||
780 (aPCLast.Distance(aPOncurve.Value()) < Precision::Confusion()))
781 aT = aLast;
782 }
7fd59977 783 }
784 //
785 return Standard_True;
786 }
787 }
788 //
789 GeomAPI_ProjectPointOnCurve& aProjector=ProjPT(aC3D);
790 aProjector.Perform(aPv);
791
792 aNbProj=aProjector.NbPoints();
793 if (!aNbProj) {
794 Handle(Geom_BoundedCurve) aBC=
795 Handle(Geom_BoundedCurve)::DownCast(aC3D);
796 if (!aBC.IsNull()) {
797 gp_Pnt aPStart=aBC->StartPoint();
798 gp_Pnt aPEnd =aBC->EndPoint();
799
800 aDist=aPv.Distance(aPStart);
801 if (aDist < aTolSum) {
4e57c75e 802 aT=aFirst;
803 return Standard_True;
7fd59977 804 }
805
806 aDist=aPv.Distance(aPEnd);
807 if (aDist < aTolSum) {
4e57c75e 808 aT=aLast;
809 return Standard_True;
7fd59977 810 }
811 }
812
813 return Standard_False;
814 }
815
816 aDist=aProjector.LowerDistance();
817
818 if (aDist > aTolSum) {
819 return Standard_False;
820 }
821
822 aT=aProjector.LowerDistanceParameter();
823
824 return Standard_True;
825}
826//=======================================================================
827//function : ProjectPointOnEdge
828//purpose :
829//=======================================================================
1e143abb 830Standard_Boolean IntTools_Context::ProjectPointOnEdge
831 (const gp_Pnt& aP,
832 const TopoDS_Edge& anEdge,
833 Standard_Real& aT)
7fd59977 834{
835 Standard_Integer aNbPoints;
836
837 GeomAPI_ProjectPointOnCurve& aProjector=ProjPC(anEdge);
838 aProjector.Perform(aP);
839
840 aNbPoints=aProjector.NbPoints();
841 if (aNbPoints) {
842 aT=aProjector.LowerDistanceParameter();
843 return Standard_True;
844 }
845 return Standard_False;
846}
847