b311480e |
1 | // Created on: 1995-07-18 |
2 | // Created by: Modelistation |
3 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
17 | #include <StdFail_NotDone.hxx> |
18 | #include <math_DirectPolynomialRoots.hxx> |
19 | #include <math_FunctionRoots.hxx> |
20 | #include <Standard_OutOfRange.hxx> |
21 | #include <Standard_NotImplemented.hxx> |
22 | |
23 | |
24 | //======================================================================= |
25 | //function : Extrema_GenExtPC |
26 | //purpose : |
27 | //======================================================================= |
28 | |
29 | Extrema_GenExtPC::Extrema_GenExtPC () { |
30 | myDone = Standard_False; |
31 | myInit = Standard_False; |
32 | } |
33 | |
34 | |
35 | |
36 | //======================================================================= |
37 | //function : Extrema_GenExtPC |
38 | //purpose : |
39 | //======================================================================= |
40 | |
41 | Extrema_GenExtPC::Extrema_GenExtPC (const Pnt& P, |
42 | const Curve& C, |
43 | const Standard_Integer NbSample, |
44 | const Standard_Real TolU, |
45 | const Standard_Real TolF) : myF (P,C) |
46 | { |
47 | Initialize(C, NbSample, TolU, TolF); |
48 | Perform(P); |
49 | } |
50 | |
51 | |
52 | //======================================================================= |
53 | //function : Extrema_GenExtPC |
54 | //purpose : |
55 | //======================================================================= |
56 | |
57 | Extrema_GenExtPC::Extrema_GenExtPC (const Pnt& P, |
58 | const Curve& C, |
59 | const Standard_Integer NbSample, |
60 | const Standard_Real Umin, |
61 | const Standard_Real Usup, |
62 | const Standard_Real TolU, |
63 | const Standard_Real TolF) : myF (P,C) |
64 | { |
65 | Initialize(C, NbSample, Umin, Usup, TolU, TolF); |
66 | Perform(P); |
67 | } |
68 | |
69 | |
70 | //======================================================================= |
71 | //function : Initialize |
72 | //purpose : |
73 | //======================================================================= |
74 | |
75 | void Extrema_GenExtPC::Initialize(const Curve& C, |
76 | const Standard_Integer NbU, |
77 | const Standard_Real TolU, |
78 | const Standard_Real TolF) |
79 | { |
80 | myInit = Standard_True; |
81 | mynbsample = NbU; |
82 | mytolu = TolU; |
83 | mytolF = TolF; |
84 | myF.Initialize(C); |
85 | myumin = Tool::FirstParameter(C); |
86 | myusup = Tool::LastParameter(C); |
87 | } |
88 | |
89 | //======================================================================= |
90 | //function : Initialize |
91 | //purpose : |
92 | //======================================================================= |
93 | |
94 | void Extrema_GenExtPC::Initialize(const Curve& C, |
95 | const Standard_Integer NbU, |
96 | const Standard_Real Umin, |
97 | const Standard_Real Usup, |
98 | const Standard_Real TolU, |
99 | const Standard_Real TolF) |
100 | { |
101 | myInit = Standard_True; |
102 | mynbsample = NbU; |
103 | mytolu = TolU; |
104 | mytolF = TolF; |
105 | myF.Initialize(C); |
106 | myumin = Umin; |
107 | myusup = Usup; |
108 | } |
109 | |
110 | |
111 | //======================================================================= |
112 | //function : Initialize |
113 | //purpose : |
114 | //======================================================================= |
115 | |
116 | void Extrema_GenExtPC::Initialize(const Standard_Integer NbU, |
117 | const Standard_Real Umin, |
118 | const Standard_Real Usup, |
119 | const Standard_Real TolU, |
120 | const Standard_Real TolF) |
121 | { |
122 | mynbsample = NbU; |
123 | mytolu = TolU; |
124 | mytolF = TolF; |
125 | myumin = Umin; |
126 | myusup = Usup; |
127 | } |
128 | |
129 | //======================================================================= |
130 | //function : Initialize |
131 | //purpose : |
132 | //======================================================================= |
133 | |
134 | void Extrema_GenExtPC::Initialize(const Curve& C) |
135 | { |
136 | myF.Initialize(C); |
137 | } |
138 | |
139 | |
140 | |
141 | //======================================================================= |
142 | //function : Perform |
143 | //purpose : |
144 | //======================================================================= |
145 | |
146 | void Extrema_GenExtPC::Perform(const Pnt& P) |
147 | /*----------------------------------------------------------------------------- |
148 | Fonction: |
149 | Recherche des valeurs de parametre u telle que dist(P,C(u)) passe |
150 | par un extremum. |
151 | |
152 | Methode: |
153 | Si U est solution, alors (C(U)-P).C'(U) = 0. |
154 | Le probleme consiste a rechercher les racines de cette fonction |
155 | dans l'intervalle de definition de la courbe. |
156 | On utilise la classe math_FunctionRoots avec les arguments de |
157 | construction suivant: |
158 | - F: Extrema_FuncExtPC cree a partir de P et C, |
159 | - Uinf: borne inferieure de l'intervalle de definition, |
160 | - Usup: borne superieure de l'intervalle de definition, |
161 | - NbSample, |
162 | - TolU, |
163 | - TolF, |
164 | - TolF. |
165 | -----------------------------------------------------------------------------*/ |
166 | { |
167 | myF.SetPoint(P); |
32ca7a51 |
168 | myF.SubIntervalInitialize(myumin,myusup); |
7fd59977 |
169 | myDone = Standard_False; |
170 | |
171 | math_FunctionRoots S (myF, myumin, myusup, mynbsample, mytolu, mytolF, mytolF); |
172 | if (!S.IsDone() || |
173 | S.IsAllNull()) { return; } |
174 | |
175 | myDone = Standard_True; |
176 | } |
177 | |
178 | |
179 | |
180 | //======================================================================= |
181 | //function : IsDone |
182 | //purpose : |
183 | //======================================================================= |
184 | |
185 | Standard_Boolean Extrema_GenExtPC::IsDone () const { |
186 | |
187 | return myDone; |
188 | } |
189 | |
190 | |
191 | //======================================================================= |
192 | //function : NbExt |
193 | //purpose : |
194 | //======================================================================= |
195 | |
196 | Standard_Integer Extrema_GenExtPC::NbExt () const { |
197 | |
9775fa61 |
198 | if (!IsDone()) { throw StdFail_NotDone(); } |
7fd59977 |
199 | return myF.NbExt(); |
200 | } |
201 | |
202 | |
203 | //======================================================================= |
204 | //function : Value |
205 | //purpose : |
206 | //======================================================================= |
207 | |
208 | Standard_Real Extrema_GenExtPC::SquareDistance (const Standard_Integer N) const { |
209 | |
9775fa61 |
210 | if (!IsDone()) { throw StdFail_NotDone(); } |
7fd59977 |
211 | return myF.SquareDistance(N); |
212 | } |
213 | |
214 | |
215 | //======================================================================= |
216 | //function : IsMin |
217 | //purpose : |
218 | //======================================================================= |
219 | |
220 | Standard_Boolean Extrema_GenExtPC::IsMin (const Standard_Integer N) const { |
221 | |
9775fa61 |
222 | if (!IsDone()) { throw StdFail_NotDone(); } |
7fd59977 |
223 | return myF.IsMin(N); |
224 | } |
225 | |
226 | |
227 | //======================================================================= |
228 | //function : Point |
229 | //purpose : |
230 | //======================================================================= |
231 | |
5d99f2c8 |
232 | const POnC & Extrema_GenExtPC::Point (const Standard_Integer N) const |
7fd59977 |
233 | { |
9775fa61 |
234 | if (!IsDone()) { throw StdFail_NotDone(); } |
7fd59977 |
235 | return myF.Point(N); |
236 | } |
237 | //============================================================================= |