Warnings on vc14 were eliminated
[occt.git] / src / BRepExtrema / BRepExtrema_ExtPF.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 (june 96) : on utilise BRepClass_FaceClassifier seulement 
18 //  si IsDone de Extrema est vrai  
19
20 #include <BRepExtrema_ExtPF.hxx>
21
22 #include <BRep_Tool.hxx>
23 #include <BRepTools.hxx>
24 #include <BRepClass_FaceClassifier.hxx>
25 #include <gp_Pnt2d.hxx>
26 #include <BRepAdaptor_Surface.hxx>
27 #include <Precision.hxx>
28
29 //=======================================================================
30 //function : BRepExtrema_ExtPF
31 //purpose  : 
32 //=======================================================================
33
34 BRepExtrema_ExtPF::BRepExtrema_ExtPF(const TopoDS_Vertex& TheVertex, const TopoDS_Face& TheFace,
35                                      const Extrema_ExtFlag TheFlag, const Extrema_ExtAlgo TheAlgo)
36 {
37   Initialize(TheFace,TheFlag,TheAlgo);
38   Perform(TheVertex,TheFace);
39 }
40
41 //=======================================================================
42 //function : Initialize
43 //purpose  : 
44 //=======================================================================
45
46 void BRepExtrema_ExtPF::Initialize(const TopoDS_Face& TheFace,
47                                    const Extrema_ExtFlag TheFlag, const Extrema_ExtAlgo TheAlgo)
48 {
49   // cette surface doit etre en champ. Extrema ne fait
50   // pas de copie et prend seulement un pointeur dessus.
51   mySurf.Initialize(TheFace, Standard_False); 
52
53   if (mySurf.GetType() == GeomAbs_OtherSurface)
54     return;  // protect against non-geometric type (e.g. triangulation)
55
56   Standard_Real Tol = Min(BRep_Tool::Tolerance(TheFace), Precision::Confusion());
57   Standard_Real aTolU, aTolV;
58   aTolU = Max(mySurf.UResolution(Tol), Precision::PConfusion());
59   aTolV = Max(mySurf.VResolution(Tol), Precision::PConfusion()); 
60   Standard_Real U1, U2, V1, V2;
61   BRepTools::UVBounds(TheFace, U1, U2, V1, V2);
62   myExtPS.SetFlag(TheFlag);
63   myExtPS.SetAlgo(TheAlgo);
64   myExtPS.Initialize(mySurf, U1, U2, V1, V2, aTolU, aTolV);
65 }
66
67 //=======================================================================
68 //function : Perform
69 //purpose  : 
70 //=======================================================================
71
72 void BRepExtrema_ExtPF::Perform(const TopoDS_Vertex& TheVertex, const TopoDS_Face& TheFace)
73 {
74   mySqDist.Clear();
75   myPoints.Clear();
76
77   const gp_Pnt P = BRep_Tool::Pnt(TheVertex);
78   if (mySurf.GetType() == GeomAbs_OtherSurface)
79     return;  // protect against non-geometric type (e.g. triangulation)
80   
81   myExtPS.Perform(P);
82
83   // Exploration of points and classification
84   if (myExtPS.IsDone())
85   {
86     BRepClass_FaceClassifier classifier;
87     Standard_Real U1, U2;
88     const Standard_Real Tol = BRep_Tool::Tolerance(TheFace);
89     for (Standard_Integer i = 1; i <= myExtPS.NbExt(); i++)
90     {
91       myExtPS.Point(i).Parameter(U1, U2);
92       const gp_Pnt2d Puv(U1, U2);
93       classifier.Perform(TheFace, Puv, Tol);
94       const TopAbs_State state = classifier.State();
95       if(state == TopAbs_ON || state == TopAbs_IN)
96       {
97         mySqDist.Append(myExtPS.SquareDistance(i));
98         myPoints.Append(myExtPS.Point(i));
99       }
100     }
101   }
102 }