0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[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 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.
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 <BRep_Tool.hxx>
23 #include <BRepTools.hxx>
24 #include <BRepClass_FaceClassifier.hxx>
25 #include <gp_Pnt2d.hxx>
26 #include <Precision.hxx>
27 #include <BRepAdaptor_Surface.hxx>
28
29 //=======================================================================
30 //function : BRepExtrema_ExtFF
31 //purpose  : 
32 //=======================================================================
33
34 BRepExtrema_ExtFF::BRepExtrema_ExtFF(const TopoDS_Face& F1, const TopoDS_Face& F2)
35 {
36  Initialize(F2);
37  Perform(F1,F2);
38 }
39
40 //=======================================================================
41 //function : Initialize
42 //purpose  : 
43 //=======================================================================
44
45 void BRepExtrema_ExtFF::Initialize(const TopoDS_Face& F2)
46 {
47   BRepAdaptor_Surface Surf(F2);
48   if (Surf.GetType() == GeomAbs_OtherSurface)
49     return; // protect against non-geometric type (e.g. triangulation)
50
51   myHS = new BRepAdaptor_Surface(Surf);
52   Standard_Real Tol = Min(BRep_Tool::Tolerance(F2), Precision::Confusion());
53   Tol = Min(Surf.UResolution(Tol), Surf.VResolution(Tol));
54   Tol = Max(Tol, Precision::PConfusion());
55   Standard_Real U1, U2, V1, V2;
56   BRepTools::UVBounds(F2, U1, U2, V1, V2);
57   myExtSS.Initialize (*myHS, 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   if (myHS.IsNull() || Surf1.GetType() == GeomAbs_OtherSurface)
73     return; // protect against non-geometric type (e.g. triangulation)
74
75   Handle(BRepAdaptor_Surface) HS1 = new BRepAdaptor_Surface(Surf1);
76   Standard_Real Tol1 = Min(BRep_Tool::Tolerance(F1), Precision::Confusion());
77   Tol1 = Min(Surf1.UResolution(Tol1), Surf1.VResolution(Tol1));
78   Tol1 = Max(Tol1, Precision::PConfusion());
79   Standard_Real U1, U2, V1, V2;
80   BRepTools::UVBounds(F1, U1, U2, V1, V2);
81   myExtSS.Perform (*HS1, U1, U2, V1, V2, Tol1);
82
83   if (!myExtSS.IsDone())
84     return;
85
86   if (myExtSS.IsParallel())
87     mySqDist.Append(myExtSS.SquareDistance(1));
88   else
89   {
90     // Exploration of points and classification
91     BRepClass_FaceClassifier classifier;
92     const Standard_Real Tol2 = BRep_Tool::Tolerance(F2);
93     Extrema_POnSurf P1, P2;
94
95     Standard_Integer i;
96     for (i = 1; i <= myExtSS.NbExt(); i++)
97     {
98       myExtSS.Points(i, P1, P2);
99       P1.Parameter(U1, U2);
100       const gp_Pnt2d Puv1(U1, U2);
101       classifier.Perform(F1, Puv1, Tol1);
102       const TopAbs_State state1 = classifier.State();
103       if (state1 == TopAbs_ON || state1 == TopAbs_IN)
104       {
105         P2.Parameter(U1, U2);
106         const gp_Pnt2d Puv2(U1, U2);
107         classifier.Perform(F2, Puv2, Tol2);
108         const TopAbs_State state2 = classifier.State();
109         if (state2 == TopAbs_ON || state2 == TopAbs_IN)
110         {
111           mySqDist.Append(myExtSS.SquareDistance(i));
112           myPointsOnS1.Append(P1);
113           myPointsOnS2.Append(P2);
114         }
115       }
116     }
117   }
118 }