0028966: Coding Rules - remove Adaptor2d_HCurve2d, Adaptor3d_HCurve and Adaptor3d_HSu...
[occt.git] / src / BRepExtrema / BRepExtrema_ExtCF.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 #include <BRepExtrema_ExtCF.hxx>
18
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_Curve.hxx>
26
27 //=======================================================================
28 //function : BRepExtrema_ExtCF
29 //purpose  : 
30 //=======================================================================
31
32 BRepExtrema_ExtCF::BRepExtrema_ExtCF(const TopoDS_Edge& E, const TopoDS_Face& F)
33 {
34   Initialize(E, F);
35   Perform(E, F);
36 }
37
38 //=======================================================================
39 //function : Initialize
40 //purpose  : 
41 //=======================================================================
42
43 void BRepExtrema_ExtCF::Initialize(const TopoDS_Edge& E, const TopoDS_Face& F)
44 {
45   BRepAdaptor_Surface Surf(F);
46   if (Surf.GetType() == GeomAbs_OtherSurface ||
47       !BRep_Tool::IsGeometric(E))
48     return; // protect against non-geometric type (e.g. triangulation)
49   BRepAdaptor_Curve aC(E);
50   myHS = new BRepAdaptor_Surface(Surf);
51   Standard_Real aTolC, aTolS;
52   //
53   aTolS = Min(BRep_Tool::Tolerance(F), Precision::Confusion());
54   aTolS = Min(Surf.UResolution(aTolS), Surf.VResolution(aTolS));
55   aTolS = Max(aTolS, Precision::PConfusion());
56   //
57   aTolC = Min(BRep_Tool::Tolerance(E), Precision::Confusion());
58   aTolC = aC.Resolution(aTolC);
59   aTolC = Max(aTolC, Precision::PConfusion());
60   //
61   Standard_Real U1, U2, V1, V2;
62   BRepTools::UVBounds(F, U1, U2, V1, V2);
63   myExtCS.Initialize (*myHS, U1, U2, V1, V2, aTolC, aTolS);
64 }
65
66 //=======================================================================
67 //function : Perform
68 //purpose  : 
69 //=======================================================================
70
71 void BRepExtrema_ExtCF::Perform(const TopoDS_Edge& E, const TopoDS_Face& F2)
72 {
73   mySqDist.Clear();
74   myPointsOnS.Clear();
75   myPointsOnC.Clear();
76
77   if (myHS.IsNull())
78     return; // protect against non-geometric type (e.g. triangulation)
79
80   Standard_Real U1, U2;
81   BRep_Tool::Range(E, U1, U2);
82
83   BRepAdaptor_Curve Curv(E);
84   Handle(BRepAdaptor_Curve) HC = new BRepAdaptor_Curve(Curv);
85   myExtCS.Perform(HC->Curve(), U1, U2);
86
87   if(!myExtCS.IsDone())
88     return;
89
90   if (myExtCS.IsParallel())
91     mySqDist.Append(myExtCS.SquareDistance(1));
92   else
93   {
94     // Exploration of points and classification
95     const Standard_Real Tol = BRep_Tool::Tolerance (F2);
96     BRepTopAdaptor_FClass2d classifier (F2, Tol);
97
98     // If the underlying surface of the face is periodic
99     // Extrema should return the point within the period,
100     // so there is no point to adjust it in classifier.
101     Standard_Boolean isAdjustPeriodic = Standard_False;
102
103     Extrema_POnCurv P1;
104     Extrema_POnSurf P2;
105
106     for (Standard_Integer i = 1; i <= myExtCS.NbExt(); i++)
107     {
108       myExtCS.Points(i, P1, P2);
109       P2.Parameter(U1, U2);
110       const gp_Pnt2d Puv(U1, U2);
111       const TopAbs_State state = classifier.Perform (Puv, isAdjustPeriodic);
112       if (state == TopAbs_ON || state == TopAbs_IN)
113       {
114         mySqDist.Append(myExtCS.SquareDistance(i));
115         myPointsOnC.Append(P1);
116         myPointsOnS.Append(P2);
117       }
118     }
119   }
120 }