0023024: Update headers of OCCT files
[occt.git] / src / BRepExtrema / BRepExtrema_ExtFF.cxx
1 // Created on: 1993-12-15
2 // Created by: Christophe MARION
3 // Copyright (c) 1993-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
21 // modified by mps (juillet 96 ): on utilise BRepAdaptor a la place de 
22 // GeomAdaptor dans Initialize et Perform.
23
24 #include <BRepExtrema_ExtFF.hxx>
25
26 #include <BRepExtrema_ExtCF.hxx>
27 #include <BRep_Tool.hxx>
28 #include <BRepTools.hxx>
29 #include <BRepClass_FaceClassifier.hxx>
30 #include <gp_Pnt2d.hxx>
31 #include <Precision.hxx>
32 #include <BRepAdaptor_HSurface.hxx>
33
34 //=======================================================================
35 //function : BRepExtrema_ExtFF
36 //purpose  : 
37 //=======================================================================
38
39 BRepExtrema_ExtFF::BRepExtrema_ExtFF(const TopoDS_Face& F1, const TopoDS_Face& F2)
40 {
41  Initialize(F2);
42  Perform(F1,F2);
43 }
44
45 //=======================================================================
46 //function : Initialize
47 //purpose  : 
48 //=======================================================================
49
50 void BRepExtrema_ExtFF::Initialize(const TopoDS_Face& F2)
51 {
52   BRepAdaptor_Surface Surf(F2);
53   myHS = new BRepAdaptor_HSurface(Surf);
54   const Standard_Real Tol = BRep_Tool::Tolerance(F2);
55   Standard_Real U1, U2, V1, V2;
56   BRepTools::UVBounds(F2, U1, U2, V1, V2);
57   myExtSS.Initialize(myHS->Surface(), U1, U2, V1, V2, Tol);
58 }
59
60 //=======================================================================
61 //function : Perform
62 //purpose  : 
63 //=======================================================================
64
65 void BRepExtrema_ExtFF::Perform(const TopoDS_Face& F1, const TopoDS_Face& F2)
66
67   mySqDist.Clear();
68   myPointsOnS1.Clear();
69   myPointsOnS2.Clear();
70
71   BRepAdaptor_Surface Surf1(F1);
72   Handle(BRepAdaptor_HSurface) HS1 = new BRepAdaptor_HSurface(Surf1);
73   const Standard_Real Tol1 = BRep_Tool::Tolerance(F1);
74   Standard_Real U1, U2, V1, V2;
75   BRepTools::UVBounds(F1, U1, U2, V1, V2);
76   myExtSS.Perform(HS1->Surface(), U1, U2, V1, V2, Tol1);
77
78   if (!myExtSS.IsDone())
79     return;
80
81   if (myExtSS.IsParallel())
82     mySqDist.Append(myExtSS.SquareDistance(1));
83   else
84   {
85     // Exploration of points and classification
86     BRepClass_FaceClassifier classifier;
87     const Standard_Real Tol2 = BRep_Tool::Tolerance(F2);
88     Extrema_POnSurf P1, P2;
89
90     Standard_Integer i;
91     for (i = 1; i <= myExtSS.NbExt(); i++)
92     {
93       myExtSS.Points(i, P1, P2);
94       P1.Parameter(U1, U2);
95       const gp_Pnt2d Puv1(U1, U2);
96       classifier.Perform(F1, Puv1, Tol1);
97       const TopAbs_State state1 = classifier.State();
98       if (state1 == TopAbs_ON || state1 == TopAbs_IN)
99       {
100         P2.Parameter(U1, U2);
101         const gp_Pnt2d Puv2(U1, U2);
102         classifier.Perform(F2, Puv2, Tol2);
103         const TopAbs_State state2 = classifier.State();
104         if (state2 == TopAbs_ON || state2 == TopAbs_IN)
105         {
106           mySqDist.Append(myExtSS.SquareDistance(i));
107           myPointsOnS1.Append(P1);
108           myPointsOnS2.Append(P2);
109         }
110       }
111     }
112   }
113 }