1 // File: BRepExtrema_ExtFF.cxx
2 // Created: Wed Dec 15 16:48:53 1993
3 // Author: Christophe MARION
5 // modified by mps (juillet 96 ): on utilise BRepAdaptor a la place de
6 // GeomAdaptor dans Initialize et Perform.
7 #include <BRepExtrema_ExtFF.ixx>
8 #include <BRepExtrema_ExtCF.hxx>
9 #include <BRep_Tool.hxx>
10 #include <BRepTools.hxx>
11 #include <Geom_Curve.hxx>
12 #include <StdFail_NotDone.hxx>
13 #include <Standard_Failure.hxx>
14 #include <BRepClass_FaceClassifier.hxx>
16 #include <TopAbs_ShapeEnum.hxx>
17 #include <TopExp_Explorer.hxx>
18 #include <Geom_Surface.hxx>
19 #include <Extrema_POnSurf.hxx>
20 #include <gp_Pnt2d.hxx>
21 #include <Precision.hxx>
22 #include <BRepAdaptor_HSurface.hxx>
24 //=======================================================================
25 //function : BRepExtrema_ExtFF
27 //=======================================================================
29 BRepExtrema_ExtFF::BRepExtrema_ExtFF()
33 //=======================================================================
34 //function : BRepExtrema_ExtFF
36 //=======================================================================
38 BRepExtrema_ExtFF::BRepExtrema_ExtFF
39 (const TopoDS_Face& F1,
40 const TopoDS_Face& F2)
45 //=======================================================================
46 //function : Initialize
48 //=======================================================================
50 void BRepExtrema_ExtFF::Initialize(const TopoDS_Face& F2)
52 BRepAdaptor_Surface Surf(F2);
53 myHS = new BRepAdaptor_HSurface(Surf);
54 Standard_Real Tol = BRep_Tool::Tolerance(F2);
55 Standard_Real U1, U2, V1, V2;
56 BRepTools::UVBounds(F2, U1, U2, V1, V2);
57 myExtrem.Initialize(myHS->Surface(), U1, U2, V1, V2, Tol);
61 //=======================================================================
64 //=======================================================================
66 void BRepExtrema_ExtFF::Perform(const TopoDS_Face& F1,
67 const TopoDS_Face& F2)
69 Standard_Real U1, U2, V1, V2;
74 BRepAdaptor_Surface Surf1(F1);
75 Handle(BRepAdaptor_HSurface) HS1 = new BRepAdaptor_HSurface(Surf1);
76 Standard_Real Tol1 = BRep_Tool::Tolerance(F1);
77 BRepTools::UVBounds(F1, U1, U2, V1, V2);
78 myExtrem.Perform(HS1->Surface(), U1, U2, V1, V2, Tol1);
81 // exploration des points et classification:
82 BRepClass_FaceClassifier classifier;
84 TopAbs_State state1, state2;
85 Standard_Real Tol2 = BRep_Tool::Tolerance(F2);
86 Extrema_POnSurf P1, P2;
89 if (myExtrem.IsParallel()) {
90 mySqDist.Append(myExtrem.SquareDistance(1));
94 for (i = 1; i <= myExtrem.NbExt(); i++) {
95 myExtrem.Points(i, P1, P2);
98 classifier.Perform(F1, Puv, Tol1);
99 state1 = classifier.State();
100 P2.Parameter(U1, U2);
101 Puv.SetCoord(U1, U2);
102 classifier.Perform(F2, Puv, Tol2);
103 state2 = classifier.State();
104 if((state1 == TopAbs_ON || state1 == TopAbs_IN) &&
105 (state2 == TopAbs_ON || state2 == TopAbs_IN)) {
107 mySqDist.Append(myExtrem.SquareDistance(i));
108 myPointsOnS1.Append(P1);
109 myPointsOnS2.Append(P2);
115 //=======================================================================
118 //=======================================================================
120 Standard_Boolean BRepExtrema_ExtFF::IsDone()const
122 return myExtrem.IsDone();
125 //=======================================================================
126 //function : IsParallel
128 //=======================================================================
130 Standard_Boolean BRepExtrema_ExtFF::IsParallel()const
132 return myExtrem.IsParallel();
136 //=======================================================================
139 //=======================================================================
141 Standard_Integer BRepExtrema_ExtFF::NbExt() const
143 if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
148 //=======================================================================
149 //function : SquareDistance
151 //=======================================================================
153 Standard_Real BRepExtrema_ExtFF::SquareDistance
154 (const Standard_Integer N) const
156 if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
157 if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise();
158 return mySqDist.Value(N);
161 //=======================================================================
162 //function : ParameterOnFace1
164 //=======================================================================
166 void BRepExtrema_ExtFF::ParameterOnFace1(const Standard_Integer N,
168 Standard_Real& V) const
170 if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
171 if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise();
172 myPointsOnS1.Value(N).Parameter(U, V);
175 //=======================================================================
176 //function : PointOnFace1
178 //=======================================================================
180 gp_Pnt BRepExtrema_ExtFF::PointOnFace1
181 (const Standard_Integer N) const
183 if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
184 if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise();
185 gp_Pnt P = myPointsOnS1.Value(N).Value();
190 //=======================================================================
191 //function : ParameterOnFace2
193 //=======================================================================
195 void BRepExtrema_ExtFF::ParameterOnFace2(const Standard_Integer N,
197 Standard_Real& V) const
199 if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
200 if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise();
201 myPointsOnS2.Value(N).Parameter(U, V);
204 //=======================================================================
205 //function : PointOnFace1
207 //=======================================================================
209 gp_Pnt BRepExtrema_ExtFF::PointOnFace2
210 (const Standard_Integer N) const
212 if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
213 if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise();
214 gp_Pnt P = myPointsOnS2.Value(N).Value();