b311480e |
1 | // Created on: 1994-03-18 |
2 | // Created by: Bruno DUMORTIER |
3 | // Copyright (c) 1994-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 | |
7fd59977 |
17 | |
42cf5bc1 |
18 | #include <Extrema_ExtCS.hxx> |
7fd59977 |
19 | #include <Extrema_POnCurv.hxx> |
20 | #include <Extrema_POnSurf.hxx> |
42cf5bc1 |
21 | #include <Geom_Curve.hxx> |
22 | #include <Geom_Surface.hxx> |
23 | #include <GeomAdaptor_Curve.hxx> |
24 | #include <GeomAdaptor_Surface.hxx> |
25 | #include <GeomAPI_ExtremaCurveSurface.hxx> |
26 | #include <gp_Pnt.hxx> |
7fd59977 |
27 | #include <Precision.hxx> |
42cf5bc1 |
28 | #include <Standard_OutOfRange.hxx> |
29 | #include <StdFail_NotDone.hxx> |
7fd59977 |
30 | |
31 | //======================================================================= |
32 | //function : GeomAPI_ExtremaCurveSurface |
33 | //purpose : |
34 | //======================================================================= |
7fd59977 |
35 | GeomAPI_ExtremaCurveSurface::GeomAPI_ExtremaCurveSurface() |
d533dafb |
36 | : myIsDone(Standard_False), |
37 | myIndex(0) |
7fd59977 |
38 | { |
7fd59977 |
39 | } |
40 | |
41 | |
42 | //======================================================================= |
43 | //function : GeomAPI_ExtremaCurveSurface |
44 | //purpose : |
45 | //======================================================================= |
46 | |
47 | GeomAPI_ExtremaCurveSurface::GeomAPI_ExtremaCurveSurface |
48 | (const Handle(Geom_Curve)& Curve, |
49 | const Handle(Geom_Surface)& Surface) |
50 | { |
51 | Init(Curve,Surface); |
52 | } |
53 | |
54 | |
55 | //======================================================================= |
56 | //function : GeomAPI_ExtremaCurveSurface |
57 | //purpose : |
58 | //======================================================================= |
59 | |
60 | GeomAPI_ExtremaCurveSurface::GeomAPI_ExtremaCurveSurface |
61 | (const Handle(Geom_Curve)& Curve, |
62 | const Handle(Geom_Surface)& Surface, |
63 | const Standard_Real Wmin, |
64 | const Standard_Real Wmax, |
65 | const Standard_Real Umin, |
66 | const Standard_Real Umax, |
67 | const Standard_Real Vmin, |
68 | const Standard_Real Vmax) |
69 | { |
70 | Init(Curve,Surface,Wmin,Wmax,Umin,Umax,Vmin,Vmax); |
71 | } |
72 | |
73 | |
74 | //======================================================================= |
75 | //function : Init |
76 | //purpose : |
77 | //======================================================================= |
78 | |
79 | void GeomAPI_ExtremaCurveSurface::Init |
80 | (const Handle(Geom_Curve)& Curve, |
81 | const Handle(Geom_Surface)& Surface) |
82 | { |
83 | GeomAdaptor_Curve TheCurve (Curve); |
84 | GeomAdaptor_Surface TheSurface (Surface); |
85 | |
86 | Standard_Real Tol = Precision::PConfusion(); |
87 | Extrema_ExtCS theExtCS(TheCurve,TheSurface,Tol,Tol); |
88 | myExtCS = theExtCS; |
89 | |
03cca6f7 |
90 | myIsDone = myExtCS.IsDone() && (myExtCS.IsParallel() || myExtCS.NbExt() > 0); |
7fd59977 |
91 | |
92 | if ( myIsDone) { |
93 | |
94 | // evaluate the lower distance and its index; |
95 | |
96 | Standard_Real Dist2, Dist2Min = myExtCS.SquareDistance(1); |
97 | myIndex = 1; |
98 | |
99 | for ( Standard_Integer i = 2; i <= myExtCS.NbExt(); i++) { |
100 | Dist2 = myExtCS.SquareDistance(i); |
101 | if ( Dist2 < Dist2Min) { |
102 | Dist2Min = Dist2; |
103 | myIndex = i; |
104 | } |
105 | } |
106 | } |
107 | } |
108 | |
109 | |
110 | //======================================================================= |
111 | //function : Init |
112 | //purpose : |
113 | //======================================================================= |
114 | |
115 | void GeomAPI_ExtremaCurveSurface::Init |
116 | (const Handle(Geom_Curve)& Curve, |
117 | const Handle(Geom_Surface)& Surface, |
118 | const Standard_Real Wmin, |
119 | const Standard_Real Wmax, |
120 | const Standard_Real Umin, |
121 | const Standard_Real Umax, |
122 | const Standard_Real Vmin, |
123 | const Standard_Real Vmax) |
124 | { |
125 | GeomAdaptor_Curve TheCurve (Curve, Wmin, Wmax); |
126 | GeomAdaptor_Surface TheSurface (Surface, Umin, Umax, Vmin, Vmax); |
127 | |
128 | Standard_Real Tol = Precision::PConfusion(); |
129 | Extrema_ExtCS theExtCS(TheCurve,TheSurface, |
130 | Wmin,Wmax,Umin,Umax,Vmin,Vmax,Tol,Tol); |
131 | myExtCS = theExtCS; |
132 | |
03cca6f7 |
133 | myIsDone = myExtCS.IsDone() && (myExtCS.IsParallel() || myExtCS.NbExt() > 0); |
7fd59977 |
134 | |
135 | if ( myIsDone) { |
136 | |
137 | // evaluate the lower distance and its index; |
138 | |
139 | Standard_Real Dist2, Dist2Min = myExtCS.SquareDistance(1); |
140 | myIndex = 1; |
141 | |
142 | for ( Standard_Integer i = 2; i <= myExtCS.NbExt(); i++) { |
143 | Dist2 = myExtCS.SquareDistance(i); |
144 | if ( Dist2 < Dist2Min) { |
145 | Dist2Min = Dist2; |
146 | myIndex = i; |
147 | } |
148 | } |
149 | } |
150 | } |
151 | |
152 | |
153 | //======================================================================= |
154 | //function : NbExtrema |
155 | //purpose : |
156 | //======================================================================= |
157 | |
158 | Standard_Integer GeomAPI_ExtremaCurveSurface::NbExtrema() const |
159 | { |
160 | if ( myIsDone) |
161 | return myExtCS.NbExt(); |
162 | else |
163 | return 0; |
164 | } |
165 | |
166 | |
167 | //======================================================================= |
168 | //function : Points |
169 | //purpose : |
170 | //======================================================================= |
171 | |
172 | void GeomAPI_ExtremaCurveSurface::Points |
173 | (const Standard_Integer Index, |
174 | gp_Pnt& P1, |
175 | gp_Pnt& P2) const |
176 | { |
177 | Standard_OutOfRange_Raise_if( Index < 1 || Index > NbExtrema(), |
178 | "GeomAPI_ExtremaCurveCurve::Points"); |
179 | |
180 | Extrema_POnCurv PC; |
181 | Extrema_POnSurf PS; |
182 | myExtCS.Points(Index,PC,PS); |
183 | |
184 | P1 = PC.Value(); |
185 | P2 = PS.Value(); |
186 | } |
187 | |
188 | |
189 | //======================================================================= |
190 | //function : Parameters |
191 | //purpose : |
192 | //======================================================================= |
193 | |
194 | void GeomAPI_ExtremaCurveSurface::Parameters |
195 | (const Standard_Integer Index, |
196 | Standard_Real& W, |
197 | Standard_Real& U, |
198 | Standard_Real& V) const |
199 | { |
200 | Standard_OutOfRange_Raise_if( Index < 1 || Index > NbExtrema(), |
201 | "GeomAPI_ExtremaCurveCurve::Parameters"); |
202 | |
203 | Extrema_POnCurv PC; |
204 | Extrema_POnSurf PS; |
205 | myExtCS.Points(Index,PC,PS); |
206 | |
207 | W = PC.Parameter(); |
208 | PS.Parameter(U,V); |
209 | } |
210 | |
211 | |
212 | //======================================================================= |
213 | //function : Distance |
214 | //purpose : |
215 | //======================================================================= |
216 | |
217 | Standard_Real GeomAPI_ExtremaCurveSurface::Distance |
218 | (const Standard_Integer Index) const |
219 | { |
220 | Standard_OutOfRange_Raise_if( Index < 1 || Index > NbExtrema(), |
221 | "GeomAPI_ExtremaCurveCurve::Distance"); |
222 | |
223 | return sqrt (myExtCS.SquareDistance(Index)); |
224 | } |
225 | |
226 | |
227 | //======================================================================= |
228 | //function : NearestPoints |
229 | //purpose : |
230 | //======================================================================= |
231 | |
232 | void GeomAPI_ExtremaCurveSurface::NearestPoints(gp_Pnt& PC, gp_Pnt& PS) const |
233 | { |
234 | StdFail_NotDone_Raise_if |
235 | (!myIsDone, "GeomAPI_ExtremaCurveSurface::NearestPoints"); |
236 | |
237 | Points(myIndex,PC,PS); |
238 | } |
239 | |
240 | |
241 | //======================================================================= |
242 | //function : LowerDistanceParameters |
243 | //purpose : |
244 | //======================================================================= |
245 | |
246 | void GeomAPI_ExtremaCurveSurface::LowerDistanceParameters |
247 | (Standard_Real& W, |
248 | Standard_Real& U, |
249 | Standard_Real& V) const |
250 | { |
251 | StdFail_NotDone_Raise_if |
252 | (!myIsDone, "GeomAPI_ExtremaCurveSurface::LowerDistanceParameters"); |
253 | |
254 | Parameters(myIndex,W,U,V); |
255 | } |
256 | |
257 | |
258 | //======================================================================= |
259 | //function : LowerDistance |
260 | //purpose : |
261 | //======================================================================= |
262 | |
263 | Standard_Real GeomAPI_ExtremaCurveSurface::LowerDistance() const |
264 | { |
265 | StdFail_NotDone_Raise_if |
266 | (!myIsDone, "GeomAPI_ExtremaCurveSurface::LowerDistance"); |
267 | |
268 | return sqrt (myExtCS.SquareDistance(myIndex)); |
269 | } |
270 | |
271 | |
272 | //======================================================================= |
273 | //function : Standard_Integer |
274 | //purpose : |
275 | //======================================================================= |
276 | |
277 | GeomAPI_ExtremaCurveSurface::operator Standard_Integer() const |
278 | { |
279 | return NbExtrema(); |
280 | } |
281 | |
282 | |
283 | //======================================================================= |
284 | //function : Standard_Real |
285 | //purpose : |
286 | //======================================================================= |
287 | |
288 | GeomAPI_ExtremaCurveSurface::operator Standard_Real() const |
289 | { |
290 | return LowerDistance(); |
291 | } |
292 | |
293 | |