b311480e |
1 | // Created on: 1994-02-09 |
2 | // Created by: Jean Yves LEBEY |
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 | |
7fd59977 |
21 | |
22 | #include <TopOpeBRepTool_ShapeTool.ixx> |
23 | |
24 | #include <BRep_Tool.hxx> |
25 | #include <TopoDS.hxx> |
26 | #include <TopAbs.hxx> |
27 | #include <ElCLib.hxx> |
28 | #include <Geom_Surface.hxx> |
29 | #include <TopLoc_Location.hxx> |
30 | #include <Precision.hxx> |
31 | #include <Standard_ProgramError.hxx> |
32 | #include <Geom2d_Curve.hxx> |
33 | #include <Geom_Curve.hxx> |
34 | #include <TopoDS_Edge.hxx> |
35 | #include <TopoDS_Face.hxx> |
36 | #include <TopoDS.hxx> |
37 | #include <gp_Dir2d.hxx> |
38 | #include <Geom2d_Line.hxx> |
39 | #include <BRepTools.hxx> |
40 | #include <TopExp_Explorer.hxx> |
41 | #include <BRepLProp_CLProps.hxx> |
42 | #include <GeomAdaptor_Surface.hxx> |
43 | #include <TopOpeBRepTool_EXPORT.hxx> |
44 | #include <TopOpeBRepTool_2d.hxx> |
45 | |
46 | //======================================================================= |
47 | //function : Tolerance |
48 | //purpose : |
49 | //======================================================================= |
50 | |
51 | Standard_Real TopOpeBRepTool_ShapeTool::Tolerance(const TopoDS_Shape& S) |
52 | { |
53 | if ( S.IsNull() ) return 0. ; |
54 | Standard_Real tol=0; |
55 | switch (S.ShapeType()) { |
56 | case TopAbs_FACE : tol = BRep_Tool::Tolerance(TopoDS::Face(S)); break; |
57 | case TopAbs_EDGE : tol = BRep_Tool::Tolerance(TopoDS::Edge(S)); break; |
58 | case TopAbs_VERTEX : tol = BRep_Tool::Tolerance(TopoDS::Vertex(S)); break; |
59 | default : Standard_ProgramError::Raise |
60 | ("TopOpeBRepTool_ShapeTool : Shape has no tolerance"); break; |
61 | } |
62 | return tol; |
63 | } |
64 | |
65 | |
66 | //======================================================================= |
67 | //function : Pnt |
68 | //purpose : |
69 | //======================================================================= |
70 | |
71 | gp_Pnt TopOpeBRepTool_ShapeTool::Pnt(const TopoDS_Shape& S) |
72 | { |
73 | if ( S.ShapeType() != TopAbs_VERTEX ) { |
74 | Standard_ProgramError::Raise("TopOpeBRepTool_ShapeTool::Pnt"); |
75 | return gp_Pnt(); |
76 | } |
77 | return BRep_Tool::Pnt(TopoDS::Vertex(S)); |
78 | } |
79 | |
80 | |
81 | #include <Geom_OffsetCurve.hxx> |
82 | #include <Geom_TrimmedCurve.hxx> |
83 | |
84 | //======================================================================= |
85 | //function : BASISCURVE |
86 | //purpose : |
87 | //======================================================================= |
88 | Handle(Geom_Curve) TopOpeBRepTool_ShapeTool::BASISCURVE(const Handle(Geom_Curve)& C) |
89 | { |
90 | Handle(Standard_Type) T = C->DynamicType(); |
91 | if ( T == STANDARD_TYPE(Geom_OffsetCurve) ) |
92 | return BASISCURVE(Handle(Geom_OffsetCurve)::DownCast(C)->BasisCurve()); |
93 | else if ( T == STANDARD_TYPE(Geom_TrimmedCurve) ) |
94 | return BASISCURVE(Handle(Geom_TrimmedCurve)::DownCast(C)->BasisCurve()); |
95 | else return C; |
96 | } |
97 | |
98 | Handle(Geom_Curve) TopOpeBRepTool_ShapeTool::BASISCURVE(const TopoDS_Edge& E) |
99 | { |
100 | Standard_Real f, l; |
101 | Handle(Geom_Curve) C = BRep_Tool::Curve(E, f, l); |
102 | if ( C.IsNull() ) return C; |
103 | return BASISCURVE(C); |
104 | } |
105 | |
106 | #include <Geom_OffsetSurface.hxx> |
107 | #include <Geom_RectangularTrimmedSurface.hxx> |
108 | #include <Geom_SurfaceOfRevolution.hxx> |
109 | #include <Geom_SurfaceOfLinearExtrusion.hxx> |
110 | |
111 | |
112 | //======================================================================= |
113 | //function : BASISSURFACE |
114 | //purpose : |
115 | //======================================================================= |
116 | Handle(Geom_Surface) TopOpeBRepTool_ShapeTool::BASISSURFACE(const Handle(Geom_Surface)& S) |
117 | { |
118 | Handle(Standard_Type) T = S->DynamicType(); |
119 | if ( T == STANDARD_TYPE(Geom_OffsetSurface) ) |
120 | return BASISSURFACE(Handle(Geom_OffsetSurface)::DownCast(S)->BasisSurface()); |
121 | else if ( T == STANDARD_TYPE(Geom_RectangularTrimmedSurface) ) |
122 | return BASISSURFACE(Handle(Geom_RectangularTrimmedSurface)::DownCast(S)->BasisSurface()); |
123 | else return S; |
124 | } |
125 | |
126 | Handle(Geom_Surface) TopOpeBRepTool_ShapeTool::BASISSURFACE(const TopoDS_Face& F) |
127 | { |
128 | TopLoc_Location L;Handle(Geom_Surface) S = BRep_Tool::Surface(F,L); |
129 | return BASISSURFACE(S); |
130 | } |
131 | |
132 | //======================================================================= |
133 | //function : UVBOUNDS |
134 | //purpose : |
135 | //======================================================================= |
136 | void TopOpeBRepTool_ShapeTool::UVBOUNDS |
137 | (const Handle(Geom_Surface)& S, |
138 | Standard_Boolean& UPeriodic, |
139 | Standard_Boolean& VPeriodic, |
140 | Standard_Real& Umin, Standard_Real& Umax, |
141 | Standard_Real& Vmin, Standard_Real& Vmax) |
142 | { |
143 | const Handle(Geom_Surface) BS = BASISSURFACE(S); |
144 | Handle(Standard_Type) T = BS->DynamicType(); |
145 | |
146 | if ( T == STANDARD_TYPE(Geom_SurfaceOfRevolution) ) { |
147 | Handle(Geom_SurfaceOfRevolution) |
148 | SR = Handle(Geom_SurfaceOfRevolution)::DownCast(BS); |
149 | Handle(Geom_Curve) C = BASISCURVE(SR->BasisCurve()); |
150 | if (C->IsPeriodic()) { |
151 | UPeriodic = Standard_False; |
152 | VPeriodic = Standard_True; |
153 | Vmin = C->FirstParameter(); Vmax = C->LastParameter(); |
154 | } |
155 | } |
156 | else if ( T == STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion) ) { |
157 | Handle(Geom_SurfaceOfLinearExtrusion) |
158 | SE = Handle(Geom_SurfaceOfLinearExtrusion)::DownCast(BS); |
159 | Handle(Geom_Curve) C = BASISCURVE(SE->BasisCurve()); |
160 | if (C->IsPeriodic()) { |
161 | UPeriodic = Standard_True; |
162 | Umin = C->FirstParameter(); Umax = C->LastParameter(); |
163 | VPeriodic = Standard_False; |
164 | } |
165 | } |
166 | else { |
167 | UPeriodic = BS->IsUPeriodic(); |
168 | VPeriodic = BS->IsVPeriodic(); |
169 | BS->Bounds(Umin,Umax,Vmin,Vmax); |
170 | } |
171 | } |
172 | |
173 | void TopOpeBRepTool_ShapeTool::UVBOUNDS |
174 | (const TopoDS_Face& F, |
175 | Standard_Boolean& UPeriodic, Standard_Boolean& VPeriodic, |
176 | Standard_Real& Umin, Standard_Real& Umax, |
177 | Standard_Real& Vmin, Standard_Real& Vmax) |
178 | { |
179 | TopLoc_Location L;Handle(Geom_Surface) S = BRep_Tool::Surface(F,L); |
180 | UVBOUNDS(S, UPeriodic, VPeriodic, Umin, Umax, Vmin, Vmax); |
181 | } |
182 | |
183 | //======================================================================= |
184 | //function : AdjustOnPeriodic |
185 | //purpose : |
186 | //======================================================================= |
187 | |
188 | void TopOpeBRepTool_ShapeTool::AdjustOnPeriodic(const TopoDS_Shape& F, |
189 | Standard_Real& u, |
190 | Standard_Real& v) |
191 | { |
192 | TopoDS_Face FF = TopoDS::Face(F); |
193 | TopLoc_Location Loc; |
194 | const Handle(Geom_Surface) Surf = BRep_Tool::Surface(FF,Loc); |
195 | |
196 | // Standard_Real Ufirst,Ulast,Vfirst,Vlast; |
197 | Standard_Boolean isUperio,isVperio; |
198 | isUperio = Surf->IsUPeriodic(); |
199 | isVperio = Surf->IsVPeriodic(); |
200 | |
201 | // exit if surface supporting F is not periodic on U or V |
202 | if (!isUperio && !isVperio) return; |
203 | |
204 | Standard_Real UFfirst,UFlast,VFfirst,VFlast; |
205 | BRepTools::UVBounds(FF,UFfirst,UFlast,VFfirst,VFlast); |
206 | |
207 | Standard_Real tol = Precision::PConfusion(); |
208 | |
209 | if (isUperio) { |
210 | Standard_Real Uperiod = Surf->UPeriod(); |
6e6cd5d9 |
211 | |
212 | // Standard_Real ubid = UFfirst; |
213 | |
7fd59977 |
214 | // ElCLib::AdjustPeriodic(UFfirst,UFfirst + Uperiod,tol,ubid,u); |
215 | if (Abs(u - UFfirst-Uperiod) > tol) |
216 | u = ElCLib::InPeriod(u,UFfirst,UFfirst + Uperiod); |
217 | } |
218 | if (isVperio) { |
219 | Standard_Real Vperiod = Surf->VPeriod(); |
6e6cd5d9 |
220 | |
221 | // Standard_Real vbid = VFfirst; |
222 | |
7fd59977 |
223 | // ElCLib::AdjustPeriodic(VFfirst,VFfirst + Vperiod,tol,vbid,v); |
224 | if (Abs(v - VFfirst-Vperiod) > tol) |
225 | v = ElCLib::InPeriod(v,VFfirst,VFfirst + Vperiod); |
226 | } |
227 | } |
228 | |
229 | |
230 | //======================================================================= |
231 | //function : Closed |
232 | //purpose : |
233 | //======================================================================= |
234 | |
235 | Standard_Boolean TopOpeBRepTool_ShapeTool::Closed(const TopoDS_Shape& S1, |
236 | const TopoDS_Shape& S2) |
237 | { |
238 | const TopoDS_Edge& E = TopoDS::Edge(S1); |
239 | const TopoDS_Face& F = TopoDS::Face(S2); |
240 | Standard_Boolean brepclosed = BRep_Tool::IsClosed(E,F); |
241 | if ( brepclosed ) { |
242 | Standard_Integer n = 0; |
243 | for ( TopExp_Explorer x(F,TopAbs_EDGE); x.More(); x.Next() ) |
244 | if ( x.Current().IsSame(E) ) n++; |
245 | if ( n < 2 ) return Standard_False; |
246 | else return Standard_True; |
247 | } |
248 | return Standard_False; |
249 | } |
250 | |
251 | |
252 | #ifdef DEB |
1d0a9d4d |
253 | extern Standard_Boolean TopOpeBRepTool_GettraceVC(); |
254 | extern Standard_Boolean TopOpeBRepTool_GettraceNYI(); |
7fd59977 |
255 | #endif |
256 | |
257 | |
258 | inline Standard_Boolean PARINBOUNDS(const Standard_Real par, |
259 | const Standard_Real first, |
260 | const Standard_Real last, |
261 | const Standard_Real tol) |
262 | { |
263 | Standard_Boolean b = ( ((first+tol) <= par) && (par <= (last-tol)) ); |
264 | return b; |
265 | } |
266 | |
267 | inline Standard_Boolean PARONBOUND(const Standard_Real par, |
268 | const Standard_Real bound, |
269 | const Standard_Real tol) |
270 | { |
271 | Standard_Boolean b = ( ((bound-tol) <= par) && (par <= (bound+tol)) ); |
272 | return b; |
273 | } |
274 | |
275 | |
276 | Standard_Real ADJUST(const Standard_Real par, |
277 | const Standard_Real first, |
278 | const Standard_Real last, |
279 | const Standard_Real tol) |
280 | { |
281 | Standard_Real period = last - first, periopar = par; |
282 | |
283 | if (PARINBOUNDS(par,first,last,tol)) { |
284 | periopar = par + period; |
285 | } |
286 | else if (PARONBOUND(par,first,tol)) { |
287 | periopar = par + period; |
288 | } |
289 | else if (PARONBOUND(par,last,tol)) { |
290 | periopar = par - period; |
291 | } |
292 | return periopar; |
293 | } |
294 | |
295 | |
296 | //======================================================================= |
297 | //function : PeriodizeParameter |
298 | //purpose : |
299 | //======================================================================= |
300 | |
301 | Standard_Real TopOpeBRepTool_ShapeTool::PeriodizeParameter |
302 | (const Standard_Real par, |
303 | const TopoDS_Shape& EE, |
304 | const TopoDS_Shape& FF) |
305 | { |
306 | Standard_Real periopar = par; |
307 | if ( ! TopOpeBRepTool_ShapeTool::Closed(EE,FF) ) return periopar; |
308 | |
309 | TopoDS_Edge E = TopoDS::Edge(EE); |
310 | TopoDS_Face F = TopoDS::Face(FF); |
311 | |
312 | TopLoc_Location Loc; |
313 | const Handle(Geom_Surface) Surf = BRep_Tool::Surface(F,Loc); |
314 | Standard_Boolean isUperio = Surf->IsUPeriodic(); |
315 | Standard_Boolean isVperio = Surf->IsVPeriodic(); |
316 | if (!isUperio && !isVperio) return periopar; |
317 | |
318 | Standard_Real Ufirst,Ulast,Vfirst,Vlast; |
319 | Surf->Bounds(Ufirst,Ulast,Vfirst,Vlast); |
320 | Standard_Real Uperiod = 0., Vperiod = 0.; |
321 | if (isUperio) Uperiod = Ulast - Ufirst; |
322 | if (isVperio) Vperiod = Vlast - Vfirst; |
323 | |
324 | Standard_Real first,last,tolpc; |
325 | const Handle(Geom2d_Curve) PC = FC2D_CurveOnSurface(E,F,first,last,tolpc); |
326 | if (PC.IsNull()) Standard_ProgramError::Raise("ShapeTool::PeriodizeParameter : no 2d curve"); |
327 | |
328 | Handle(Standard_Type) TheType = PC->DynamicType(); |
329 | if (TheType == STANDARD_TYPE(Geom2d_Line)) { |
330 | |
331 | const Handle(Geom2d_Line)& HL = *((Handle(Geom2d_Line)*)&PC); |
332 | const gp_Dir2d& D = HL->Direction(); |
333 | |
334 | Standard_Real tol = Precision::Angular(); |
335 | Standard_Boolean isoU = Standard_False, isoV = Standard_False; |
336 | if (D.IsParallel(gp_Dir2d(0.,1.),tol)) isoU = Standard_True; |
337 | else if (D.IsParallel(gp_Dir2d(1.,0.),tol)) isoV = Standard_True; |
338 | if (isoU) { |
339 | periopar = ADJUST(par,Ufirst,Ulast,tol); |
340 | } |
341 | else if (isoV) { |
342 | periopar = ADJUST(par,Vfirst,Vlast,tol); |
343 | } |
344 | |
345 | #ifdef DEB |
346 | if (TopOpeBRepTool_GettraceVC()) { |
347 | cout<<"TopOpeBRepTool_ShapeTool PC on edge is "; |
348 | if (isoU) cout<<"isoU f,l "<<Ufirst<<" "<<Ulast<<endl; |
349 | else if (isoV) cout<<"isoV f,l "<<Vfirst<<" "<<Vlast<<endl; |
350 | else cout<<"not isoU, not isoV"<<endl; |
351 | cout<<"par = "<<par<<" --> "<<periopar<<endl; |
352 | } |
353 | #endif |
354 | |
355 | } |
356 | // NYI : BSpline ... |
357 | |
358 | return periopar; |
359 | } |
360 | |
361 | |
362 | //======================================================================= |
363 | //function : ShapesSameOriented |
364 | //purpose : |
365 | //======================================================================= |
366 | |
367 | Standard_Boolean TopOpeBRepTool_ShapeTool::ShapesSameOriented |
368 | (const TopoDS_Shape& S1, const TopoDS_Shape& S2) |
369 | { |
370 | Standard_Boolean so = Standard_True; |
371 | |
372 | Standard_Boolean sam = S1.IsSame(S2); |
373 | if (sam) { |
374 | const TopAbs_Orientation o1 = S1.Orientation(); |
375 | const TopAbs_Orientation o2 = S2.Orientation(); |
376 | if ((o1 == TopAbs_FORWARD || o1 == TopAbs_REVERSED) && |
377 | (o2 == TopAbs_FORWARD || o2 == TopAbs_REVERSED)) { |
378 | so = (o1 == o2); |
379 | return so; |
380 | } |
381 | } |
382 | |
383 | TopAbs_ShapeEnum t1 = S1.ShapeType(), t2 = S2.ShapeType(); |
384 | if ( (t1 == TopAbs_SOLID) && (t2 == TopAbs_SOLID) ) { |
385 | so = Standard_True; |
386 | } |
387 | else if ( (t1 == TopAbs_FACE) && (t2 == TopAbs_FACE) ) { |
388 | so = FacesSameOriented(S1,S2); |
389 | } |
390 | else if ( (t1 == TopAbs_EDGE) && (t2 == TopAbs_EDGE) ) { |
391 | so = EdgesSameOriented(S1,S2); |
392 | } |
393 | else if ( (t1 == TopAbs_VERTEX) && (t2 == TopAbs_VERTEX) ) { |
394 | TopAbs_Orientation o1 = S1.Orientation(); |
395 | TopAbs_Orientation o2 = S2.Orientation(); |
396 | if (o1==TopAbs_EXTERNAL||o1==TopAbs_INTERNAL||o2==TopAbs_EXTERNAL||o2==TopAbs_INTERNAL) |
397 | so = Standard_True; |
398 | else |
399 | so = ( o1 == o2 ); |
400 | } |
401 | |
402 | return so; |
403 | } |
404 | |
405 | //======================================================================= |
406 | //function : SurfacesSameOriented |
407 | //purpose : |
408 | //======================================================================= |
409 | |
410 | Standard_Boolean TopOpeBRepTool_ShapeTool::SurfacesSameOriented |
411 | (const BRepAdaptor_Surface& S1,const BRepAdaptor_Surface& Sref) |
412 | { |
413 | const BRepAdaptor_Surface& S2 = Sref; |
414 | GeomAbs_SurfaceType ST1 = S1.GetType(); |
415 | GeomAbs_SurfaceType ST2 = S2.GetType(); |
416 | |
417 | Standard_Boolean so = Standard_True; |
418 | |
419 | if (ST1 == GeomAbs_Plane && ST2 == GeomAbs_Plane) { |
420 | |
421 | Standard_Real u1 = S1.FirstUParameter(); |
422 | Standard_Real v1 = S1.FirstVParameter(); |
423 | gp_Pnt p1; gp_Vec d1u,d1v; S1.D1(u1,v1,p1,d1u,d1v); |
424 | gp_Vec n1 = d1u.Crossed(d1v); |
425 | |
426 | Standard_Real u2 = S2.FirstUParameter(); |
427 | Standard_Real v2 = S2.FirstVParameter(); |
428 | gp_Pnt p2; gp_Vec d2u,d2v; S2.D1(u2,v2,p2,d2u,d2v); |
429 | gp_Vec n2 = d2u.Crossed(d2v); |
430 | |
431 | Standard_Real d = n1.Dot(n2); |
432 | so = (d > 0.); |
433 | } |
434 | else if (ST1 == GeomAbs_Cylinder && ST2 == GeomAbs_Cylinder) { |
435 | |
436 | // On peut projeter n'importe quel point. |
437 | // prenons donc l'origine |
438 | Standard_Real u1 = 0.; |
439 | Standard_Real v1 = 0.; |
440 | gp_Pnt p1; gp_Vec d1u,d1v; S1.D1(u1,v1,p1,d1u,d1v); |
441 | gp_Vec n1 = d1u.Crossed(d1v); |
442 | |
443 | Handle(Geom_Surface) HS2 = S2.Surface().Surface(); |
444 | HS2 = Handle(Geom_Surface)::DownCast(HS2->Transformed(S2.Trsf())); |
445 | gp_Pnt2d p22d; Standard_Real dp2; |
446 | Standard_Boolean ok = FUN_tool_projPonS(p1,HS2,p22d,dp2); |
447 | if ( !ok ) return so; // NYI : raise |
448 | |
449 | Standard_Real u2 = p22d.X(); |
450 | Standard_Real v2 = p22d.Y(); |
451 | gp_Pnt p2; gp_Vec d2u,d2v; S2.D1(u2,v2,p2,d2u,d2v); |
452 | gp_Vec n2 = d2u.Crossed(d2v); |
453 | |
454 | Standard_Real d = n1.Dot(n2); |
455 | so = (d > 0.); |
456 | } |
457 | else { |
458 | // prendre u1,v1 et projeter sur 2 pour calcul des normales |
459 | // au meme point 3d. |
460 | #ifdef DEB |
461 | if (TopOpeBRepTool_GettraceNYI()) { |
462 | cout<<"TopOpeBRepTool_ShapeTool::SurfacesSameOriented surfaces non traitees : NYI"; |
463 | cout<<endl; |
464 | } |
465 | #endif |
466 | } |
467 | |
468 | return so; |
469 | } |
470 | |
471 | |
472 | //======================================================================= |
473 | //function : FacesSameOriented |
474 | //purpose : |
475 | //======================================================================= |
476 | |
477 | Standard_Boolean TopOpeBRepTool_ShapeTool::FacesSameOriented |
478 | (const TopoDS_Shape& S1, const TopoDS_Shape& Sref) |
479 | { |
480 | const TopoDS_Shape& S2 = Sref; |
481 | const TopoDS_Face& F1 = TopoDS::Face(S1); |
482 | const TopoDS_Face& F2 = TopoDS::Face(S2); |
483 | TopAbs_Orientation o1 = F1.Orientation(); |
484 | TopAbs_Orientation o2 = F2.Orientation(); |
485 | if ( o1 == TopAbs_EXTERNAL || o1 == TopAbs_INTERNAL || |
486 | o2 == TopAbs_EXTERNAL || o2 == TopAbs_INTERNAL ) { |
487 | return Standard_True; |
488 | } |
489 | |
490 | Standard_Boolean computerestriction = Standard_False; |
491 | BRepAdaptor_Surface BAS1(F1,computerestriction); |
492 | BRepAdaptor_Surface BAS2(F2,computerestriction); |
493 | Standard_Boolean so = F1.IsSame(F2) || SurfacesSameOriented(BAS1,BAS2); |
494 | Standard_Boolean b = so; |
495 | if ( o1 != o2 ) b = !so; |
496 | return b; |
497 | } |
498 | |
499 | |
500 | //======================================================================= |
501 | //function : CurvesSameOriented |
502 | //purpose : |
503 | //======================================================================= |
504 | |
505 | Standard_Boolean TopOpeBRepTool_ShapeTool::CurvesSameOriented |
506 | (const BRepAdaptor_Curve& C1, const BRepAdaptor_Curve& Cref) |
507 | { |
508 | const BRepAdaptor_Curve& C2 = Cref; |
509 | GeomAbs_CurveType CT1 = C1.GetType(); |
510 | GeomAbs_CurveType CT2 = C2.GetType(); |
511 | Standard_Boolean so = Standard_True; |
512 | |
513 | if (CT1 == GeomAbs_Line && CT2 == GeomAbs_Line) { |
514 | Standard_Real p1 = C1.FirstParameter(); |
515 | gp_Dir t1,n1; Standard_Real c1; EdgeData(C1,p1,t1,n1,c1); |
516 | Standard_Real p2 = C2.FirstParameter(); |
517 | gp_Dir t2,n2; Standard_Real c2; EdgeData(C2,p2,t2,n2,c2); |
518 | Standard_Real d = t1.Dot(t2); |
519 | so = (d > 0.); |
520 | } |
521 | else { |
522 | // prendre p1 et projeter sur 2 pour calcul des normales |
523 | // au meme point 3d. |
524 | #ifdef DEB |
525 | if (TopOpeBRepTool_GettraceNYI()) { |
526 | cout<<"TopOpeBRepTool_ShapeTool::CurvesSameOriented non lineaires : NYI"; |
527 | cout<<endl; |
528 | } |
529 | #endif |
530 | } |
531 | |
532 | return so; |
533 | } |
534 | |
535 | //======================================================================= |
536 | //function : EdgesSameOriented |
537 | //purpose : |
538 | //======================================================================= |
539 | |
540 | Standard_Boolean TopOpeBRepTool_ShapeTool::EdgesSameOriented |
541 | (const TopoDS_Shape& S1, const TopoDS_Shape& Sref) |
542 | { |
543 | const TopoDS_Shape& S2 = Sref; |
544 | const TopoDS_Edge& E1 = TopoDS::Edge(S1); |
545 | const TopoDS_Edge& E2 = TopoDS::Edge(S2); |
546 | TopAbs_Orientation o1 = E1.Orientation(); |
547 | TopAbs_Orientation o2 = E2.Orientation(); |
548 | if ( o1 == TopAbs_EXTERNAL || o1 == TopAbs_INTERNAL || |
549 | o2 == TopAbs_EXTERNAL || o2 == TopAbs_INTERNAL ) { |
550 | return Standard_True; |
551 | } |
552 | BRepAdaptor_Curve BAC1(E1); |
553 | BRepAdaptor_Curve BAC2(E2); |
554 | Standard_Boolean so = CurvesSameOriented(BAC1,BAC2); |
555 | Standard_Boolean b = so; |
556 | if ( o1 != o2 ) b = !so; |
557 | return b; |
558 | } |
559 | |
560 | |
561 | //======================================================================= |
562 | //function : EdgeData |
563 | //purpose : |
564 | //======================================================================= |
565 | |
566 | Standard_Real TopOpeBRepTool_ShapeTool::EdgeData |
567 | (const BRepAdaptor_Curve& BAC, const Standard_Real P, |
568 | gp_Dir& T, gp_Dir& N, Standard_Real& C) |
569 | |
570 | { |
571 | Standard_Real tol = Precision::Angular(); |
572 | |
573 | BRepLProp_CLProps BL(BAC,P,2,tol); |
574 | BL.Tangent(T); |
575 | C = BL.Curvature(); |
576 | |
577 | // xpu150399 cto900R4 |
578 | Standard_Real tol1 = Epsilon(0.), tol2 = RealLast(); |
579 | Standard_Real tolm = Max(tol,Max(tol1,tol2)); |
580 | |
581 | if ( Abs(C) > tolm ) BL.Normal(N); |
582 | return tol; |
583 | } |
584 | |
585 | |
586 | //======================================================================= |
587 | //function : EdgeData |
588 | //purpose : |
589 | //======================================================================= |
590 | |
591 | Standard_Real TopOpeBRepTool_ShapeTool::EdgeData |
592 | (const TopoDS_Shape& E, const Standard_Real P, |
593 | gp_Dir& T, gp_Dir& N, Standard_Real& C) |
594 | { |
595 | BRepAdaptor_Curve BAC(TopoDS::Edge(E)); |
596 | Standard_Real d = EdgeData(BAC,P,T,N,C); |
597 | return d; |
598 | } |
599 | |
600 | |
601 | //======================================================================= |
602 | //function : Resolution3dU |
603 | //purpose : |
604 | //======================================================================= |
605 | |
606 | Standard_Real TopOpeBRepTool_ShapeTool::Resolution3dU(const Handle(Geom_Surface)& SU, |
607 | const Standard_Real Tol2d) |
608 | { |
609 | GeomAdaptor_Surface GAS(SU); |
610 | Standard_Real r3dunit = 0.00001; // petite valeur (1.0 -> RangeError sur un tore) |
611 | Standard_Real ru = GAS.UResolution(r3dunit); |
612 | Standard_Real r3du = r3dunit*(Tol2d/ru); |
613 | return r3du; |
614 | } |
615 | |
616 | |
617 | //======================================================================= |
618 | //function : Resolution3dV |
619 | //purpose : |
620 | //======================================================================= |
621 | |
622 | Standard_Real TopOpeBRepTool_ShapeTool::Resolution3dV(const Handle(Geom_Surface)& SU, |
623 | const Standard_Real Tol2d) |
624 | { |
625 | GeomAdaptor_Surface GAS(SU); |
626 | Standard_Real r3dunit = 0.00001; // petite valeur (1.0 -> RangeError sur un tore) |
627 | Standard_Real rv = GAS.VResolution(r3dunit); |
628 | Standard_Real r3dv = r3dunit*(Tol2d/rv); |
629 | return r3dv; |
630 | } |
631 | |
632 | |
633 | //======================================================================= |
634 | //function : Resolution3d |
635 | //purpose : |
636 | //======================================================================= |
637 | |
638 | Standard_Real TopOpeBRepTool_ShapeTool::Resolution3d(const Handle(Geom_Surface)& SU, |
639 | const Standard_Real Tol2d) |
640 | { |
641 | Standard_Real ru = Resolution3dU(SU,Tol2d); |
642 | Standard_Real rv = Resolution3dV(SU,Tol2d); |
643 | Standard_Real r = Max(ru,rv); |
644 | return r; |
645 | } |
646 | |
647 | |
648 | //======================================================================= |
649 | //function : Resolution3d |
650 | //purpose : |
651 | //======================================================================= |
652 | |
653 | Standard_Real TopOpeBRepTool_ShapeTool::Resolution3d(const TopoDS_Face& F, |
654 | const Standard_Real Tol2d) |
655 | { |
656 | TopLoc_Location L; const Handle(Geom_Surface)& SU = BRep_Tool::Surface(F,L); |
657 | Standard_Real r = Resolution3d(SU,Tol2d); |
658 | return r; |
659 | } |