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