1 // Created on: 1993-12-15
2 // Created by: Christophe MARION
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <BRepExtrema_ExtCF.hxx>
19 #include <BRep_Tool.hxx>
20 #include <BRepTools.hxx>
21 #include <Geom_Curve.hxx>
22 #include <BRepTopAdaptor_FClass2d.hxx>
23 #include <gp_Pnt2d.hxx>
24 #include <BRepAdaptor_Surface.hxx>
25 #include <BRepAdaptor_HSurface.hxx>
26 #include <BRepAdaptor_Curve.hxx>
27 #include <BRepAdaptor_HCurve.hxx>
29 //=======================================================================
30 //function : BRepExtrema_ExtCF
32 //=======================================================================
34 BRepExtrema_ExtCF::BRepExtrema_ExtCF(const TopoDS_Edge& E, const TopoDS_Face& F)
40 //=======================================================================
41 //function : Initialize
43 //=======================================================================
45 void BRepExtrema_ExtCF::Initialize(const TopoDS_Edge& E, const TopoDS_Face& F)
47 BRepAdaptor_Surface Surf(F);
48 if (Surf.GetType() == GeomAbs_OtherSurface ||
49 !BRep_Tool::IsGeometric(E))
50 return; // protect against non-geometric type (e.g. triangulation)
51 BRepAdaptor_Curve aC(E);
52 myHS = new BRepAdaptor_HSurface(Surf);
53 Standard_Real aTolC, aTolS;
55 aTolS = Min(BRep_Tool::Tolerance(F), Precision::Confusion());
56 aTolS = Min(Surf.UResolution(aTolS), Surf.VResolution(aTolS));
57 aTolS = Max(aTolS, Precision::PConfusion());
59 aTolC = Min(BRep_Tool::Tolerance(E), Precision::Confusion());
60 aTolC = aC.Resolution(aTolC);
61 aTolC = Max(aTolC, Precision::PConfusion());
63 Standard_Real U1, U2, V1, V2;
64 BRepTools::UVBounds(F, U1, U2, V1, V2);
65 myExtCS.Initialize(myHS->Surface(), U1, U2, V1, V2, aTolC, aTolS);
68 //=======================================================================
71 //=======================================================================
73 void BRepExtrema_ExtCF::Perform(const TopoDS_Edge& E, const TopoDS_Face& F2)
80 return; // protect against non-geometric type (e.g. triangulation)
83 BRep_Tool::Range(E, U1, U2);
85 BRepAdaptor_Curve Curv(E);
86 Handle(BRepAdaptor_HCurve) HC = new BRepAdaptor_HCurve(Curv);
87 myExtCS.Perform(HC->Curve(), U1, U2);
92 if (myExtCS.IsParallel())
93 mySqDist.Append(myExtCS.SquareDistance(1));
96 // Exploration of points and classification
97 const Standard_Real Tol = BRep_Tool::Tolerance (F2);
98 BRepTopAdaptor_FClass2d classifier (F2, Tol);
100 // If the underlying surface of the face is periodic
101 // Extrema should return the point within the period,
102 // so there is no point to adjust it in classifier.
103 Standard_Boolean isAdjustPeriodic = Standard_False;
108 for (Standard_Integer i = 1; i <= myExtCS.NbExt(); i++)
110 myExtCS.Points(i, P1, P2);
111 P2.Parameter(U1, U2);
112 const gp_Pnt2d Puv(U1, U2);
113 const TopAbs_State state = classifier.Perform (Puv, isAdjustPeriodic);
114 if (state == TopAbs_ON || state == TopAbs_IN)
116 mySqDist.Append(myExtCS.SquareDistance(i));
117 myPointsOnC.Append(P1);
118 myPointsOnS.Append(P2);