a30002cb87b2cbc740a6b134dea91efe2c8e0aab
[occt.git] / src / BRepExtrema / BRepExtrema_ExtPF.cxx
1 // File:        BRepExtrema_ExtPF.cxx
2 // Created:     Wed Dec 15 16:48:53 1993
3 // Author:      Christophe MARION
4 //              <cma@sdsun1>
5 // modified by MPS (june 96) : on utilise BRepClass_FaceClassifier seulement 
6 //  si IsDone de Extrema est vrai  
7 #include <BRepExtrema_ExtPF.ixx>
8 #include <BRep_Tool.hxx>
9 #include <BRepTools.hxx>
10 #include <StdFail_NotDone.hxx>
11 #include <Standard_Failure.hxx>
12 #include <BRepClass_FaceClassifier.hxx>
13 #include <gp_Pnt2d.hxx>
14 #include <BRepAdaptor_Curve.hxx>
15 #include <BRepAdaptor_HCurve.hxx>
16 #include <BRepAdaptor_Surface.hxx>
17 #include <BRepAdaptor_HSurface.hxx>
18
19 //=======================================================================
20 //function : BRepExtrema_ExtPF
21 //purpose  : 
22 //=======================================================================
23
24 BRepExtrema_ExtPF::BRepExtrema_ExtPF()
25 {
26 }
27
28 //=======================================================================
29 //function : BRepExtrema_ExtPF
30 //purpose  : 
31 //=======================================================================
32
33 BRepExtrema_ExtPF::BRepExtrema_ExtPF
34   (const TopoDS_Vertex& V,
35    const TopoDS_Face&   E)
36 {
37   Initialize(E);
38   Perform(V, E);
39 }
40
41 //=======================================================================
42 //function : Initialize
43 //purpose  : 
44 //=======================================================================
45
46 void BRepExtrema_ExtPF::Initialize(const TopoDS_Face& F)
47 {
48   // cette surface doit etre en champ. Extrema ne fait
49   // pas de copie et prend seulement un pointeur dessus.
50   mySurf.Initialize(F, Standard_False); 
51   Standard_Real Tol = BRep_Tool::Tolerance(F);
52   Standard_Real U1, U2, V1, V2;
53   BRepTools::UVBounds(F, U1, U2, V1, V2);
54   myExtrem.Initialize(mySurf, U1, U2, V1, V2, Tol, Tol);
55 }
56
57 //=======================================================================
58 //function : Perform
59 //purpose  : 
60 //=======================================================================
61
62 void BRepExtrema_ExtPF::Perform(const TopoDS_Vertex& V,
63                                 const TopoDS_Face&   E)
64 {
65   mySqDist.Clear();
66   myPoints.Clear();
67   gp_Pnt P = BRep_Tool::Pnt(V);
68   myExtrem.Perform(P);
69
70   // exploration des points et classification:
71   if (myExtrem.IsDone()) {
72   BRepClass_FaceClassifier classifier;
73   gp_Pnt2d Puv;
74   Standard_Real U1, U2;
75   TopAbs_State state;
76   Standard_Real Tol = BRep_Tool::Tolerance(E);
77   mynbext = 0;
78   for (Standard_Integer i = 1; i <= myExtrem.NbExt(); i++) {
79     myExtrem.Point(i).Parameter(U1, U2);
80     Puv.SetCoord(U1, U2);
81     classifier.Perform(E, Puv, Tol);
82     state = classifier.State();
83     if(state == TopAbs_ON || state == TopAbs_IN) {
84       mynbext++;
85       mySqDist.Append(myExtrem.SquareDistance(i));
86       myPoints.Append(myExtrem.Point(i));
87     }
88   }
89  }
90 }
91 //=======================================================================
92 //function : IsDone
93 //purpose  : 
94 //=======================================================================
95
96 Standard_Boolean BRepExtrema_ExtPF::IsDone()const
97 {
98   return myExtrem.IsDone();
99 }
100
101 //=======================================================================
102 //function : NbExt
103 //purpose  : 
104 //=======================================================================
105
106 Standard_Integer BRepExtrema_ExtPF::NbExt() const
107 {
108   if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
109   return mynbext;
110 }
111
112
113 //=======================================================================
114 //function : Value
115 //purpose  : 
116 //=======================================================================
117
118 Standard_Real BRepExtrema_ExtPF::SquareDistance
119   (const Standard_Integer N) const
120 {
121   if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
122   if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise();
123   return mySqDist.Value(N);
124 }
125
126 //=======================================================================
127 //function : Parameters
128 //purpose  : 
129 //=======================================================================
130
131
132 void BRepExtrema_ExtPF::Parameter(const Standard_Integer N,
133                                   Standard_Real& U,
134                                   Standard_Real& V) const
135 {
136   if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
137   if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise();
138   myPoints.Value(N).Parameter(U, V);
139 }
140
141 //=======================================================================
142 //function : Point
143 //purpose  : 
144 //=======================================================================
145
146 gp_Pnt BRepExtrema_ExtPF::Point
147   (const Standard_Integer N) const
148 {
149   if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
150   if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise();
151   gp_Pnt P = myPoints.Value(N).Value();
152   return P; 
153 }