0024428: Implementation of LGPL license
[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-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and / or modify it
9 // under the terms of the GNU Lesser General Public 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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 // modified by mps (juillet 96 ): on utilise BRepAdaptor a la place de 
18 // GeomAdaptor dans Initialize et Perform.
19
20 #include <BRepExtrema_ExtFF.hxx>
21
22 #include <BRepExtrema_ExtCF.hxx>
23 #include <BRep_Tool.hxx>
24 #include <BRepTools.hxx>
25 #include <BRepClass_FaceClassifier.hxx>
26 #include <gp_Pnt2d.hxx>
27 #include <Precision.hxx>
28 #include <BRepAdaptor_HSurface.hxx>
29
30 //=======================================================================
31 //function : BRepExtrema_ExtFF
32 //purpose  : 
33 //=======================================================================
34
35 BRepExtrema_ExtFF::BRepExtrema_ExtFF(const TopoDS_Face& F1, const TopoDS_Face& F2)
36 {
37  Initialize(F2);
38  Perform(F1,F2);
39 }
40
41 //=======================================================================
42 //function : Initialize
43 //purpose  : 
44 //=======================================================================
45
46 void BRepExtrema_ExtFF::Initialize(const TopoDS_Face& F2)
47 {
48   BRepAdaptor_Surface Surf(F2);
49   myHS = new BRepAdaptor_HSurface(Surf);
50   const Standard_Real Tol = BRep_Tool::Tolerance(F2);
51   Standard_Real U1, U2, V1, V2;
52   BRepTools::UVBounds(F2, U1, U2, V1, V2);
53   myExtSS.Initialize(myHS->Surface(), U1, U2, V1, V2, Tol);
54 }
55
56 //=======================================================================
57 //function : Perform
58 //purpose  : 
59 //=======================================================================
60
61 void BRepExtrema_ExtFF::Perform(const TopoDS_Face& F1, const TopoDS_Face& F2)
62
63   mySqDist.Clear();
64   myPointsOnS1.Clear();
65   myPointsOnS2.Clear();
66
67   BRepAdaptor_Surface Surf1(F1);
68   Handle(BRepAdaptor_HSurface) HS1 = new BRepAdaptor_HSurface(Surf1);
69   const Standard_Real Tol1 = BRep_Tool::Tolerance(F1);
70   Standard_Real U1, U2, V1, V2;
71   BRepTools::UVBounds(F1, U1, U2, V1, V2);
72   myExtSS.Perform(HS1->Surface(), U1, U2, V1, V2, Tol1);
73
74   if (!myExtSS.IsDone())
75     return;
76
77   if (myExtSS.IsParallel())
78     mySqDist.Append(myExtSS.SquareDistance(1));
79   else
80   {
81     // Exploration of points and classification
82     BRepClass_FaceClassifier classifier;
83     const Standard_Real Tol2 = BRep_Tool::Tolerance(F2);
84     Extrema_POnSurf P1, P2;
85
86     Standard_Integer i;
87     for (i = 1; i <= myExtSS.NbExt(); i++)
88     {
89       myExtSS.Points(i, P1, P2);
90       P1.Parameter(U1, U2);
91       const gp_Pnt2d Puv1(U1, U2);
92       classifier.Perform(F1, Puv1, Tol1);
93       const TopAbs_State state1 = classifier.State();
94       if (state1 == TopAbs_ON || state1 == TopAbs_IN)
95       {
96         P2.Parameter(U1, U2);
97         const gp_Pnt2d Puv2(U1, U2);
98         classifier.Perform(F2, Puv2, Tol2);
99         const TopAbs_State state2 = classifier.State();
100         if (state2 == TopAbs_ON || state2 == TopAbs_IN)
101         {
102           mySqDist.Append(myExtSS.SquareDistance(i));
103           myPointsOnS1.Append(P1);
104           myPointsOnS2.Append(P2);
105         }
106       }
107     }
108   }
109 }