0022682: Draw options -v and -f do not influent to AISInitViewer command
[occt.git] / src / Extrema / Extrema_ExtElCS.cxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
2// Copyright (c) 1999-2012 OPEN CASCADE SAS
3//
4// The content of this file is subject to the Open CASCADE Technology Public
5// License Version 6.5 (the "License"). You may not use the content of this file
6// except in compliance with the License. Please obtain a copy of the License
7// at http://www.opencascade.org and read it completely before using this file.
8//
9// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11//
12// The Original Code and all software distributed under the License is
13// distributed on an "AS IS" basis, without warranty of any kind, and the
14// Initial Developer hereby disclaims all such warranties, including without
15// limitation, any warranties of merchantability, fitness for a particular
16// purpose or non-infringement. Please see the License for the specific terms
17// and conditions governing the rights and limitations under the License.
18
7fd59977 19
20// Modified by skv - Thu Jul 7 14:37:05 2005 OCC9134
21
22#include <Extrema_ExtElCS.ixx>
23#include <Extrema_ExtPElS.hxx>
24#include <Extrema_ExtPElC.hxx>
25#include <Extrema_ExtElC.hxx>
26#include <Extrema_POnCurv.hxx>
27#include <Standard_NotImplemented.hxx>
28#include <StdFail_InfiniteSolutions.hxx>
29#include <Precision.hxx>
30#include <ElSLib.hxx>
31#include <ElCLib.hxx>
32#include <gp_Vec.hxx>
33
34
35Extrema_ExtElCS::Extrema_ExtElCS()
36{
37 myDone = Standard_False;
38 myIsPar = Standard_False;
39}
40
41
42Extrema_ExtElCS::Extrema_ExtElCS(const gp_Lin& C,
43 const gp_Pln& S)
44{
45 Perform(C, S);
46}
47
48
49
50void Extrema_ExtElCS::Perform(const gp_Lin& C,
51 const gp_Pln& S)
52{
53 myDone = Standard_True;
54 myIsPar = Standard_False;
55
56 if (C.Direction().IsNormal(S.Axis().Direction(),
57 Precision::Angular())) {
58 mySqDist = new TColStd_HArray1OfReal(1, 1);
59 mySqDist->SetValue(1, S.SquareDistance(C));
60 myIsPar = Standard_True;
61 }
62 else {
63 myNbExt = 0;
64 }
65
66}
67
68
69Extrema_ExtElCS::Extrema_ExtElCS(const gp_Lin& C,
70 const gp_Cylinder& S)
71{
72 Perform(C, S);
73}
74
75
76
77void Extrema_ExtElCS::Perform(const gp_Lin& C,
78 const gp_Cylinder& S)
79{
80 myDone = Standard_False;
81 myNbExt = 0;
82 myIsPar = Standard_False;
83
84 gp_Ax3 Pos = S.Position();
85#ifdef DEB
86 gp_Pnt O = Pos.Location();
87#else
88 Pos.Location();
89#endif
90 Standard_Real radius = S.Radius();
91 Extrema_ExtElC Extrem(gp_Lin(Pos.Axis()), C, Precision::Angular());
92 if (Extrem.IsParallel()) {
93 mySqDist = new TColStd_HArray1OfReal(1, 1);
94 Standard_Real aDist = sqrt (Extrem.SquareDistance(1)) - radius;
95 mySqDist->SetValue(1, aDist * aDist);
96 myDone = Standard_True;
97 myIsPar = Standard_True;
98 }
99 else {
100 Standard_Integer i;
101 if (Extrem.IsDone()) {
102 Extrema_POnCurv myPOnC1, myPOnC2;
103 Extrem.Points(1, myPOnC1, myPOnC2);
104 gp_Pnt PC = myPOnC2.Value();
105
106 if ((gp_Lin(Pos.Axis())).Contains(PC, Precision::Confusion())) {
107 gp_Dir D = C.Direction();
108 gp_Vec Dp(-D.Dot(Pos.YDirection()), D.Dot(Pos.XDirection()), 0.0);
109 Standard_Real U, V;
110 gp_Pnt P1(PC.Translated(radius*Dp));
111 gp_Pnt P2(PC.Translated(-radius*Dp));
112
113 myNbExt = 2;
114 mySqDist = new TColStd_HArray1OfReal(1, myNbExt);
115 myPoint1 = new Extrema_HArray1OfPOnCurv(1, myNbExt);
116 myPoint2 = new Extrema_HArray1OfPOnSurf(1, myNbExt);
117 ElSLib::CylinderParameters(Pos, radius, P1, U, V);
118 Extrema_POnSurf P1S(U, V, P1);
119 ElSLib::CylinderParameters(Pos, radius, P2, U, V);
120 Extrema_POnSurf P2S(U, V, P2);
121 mySqDist->SetValue(1, PC.SquareDistance(P1));
122 mySqDist->SetValue(2, PC.SquareDistance(P2));
123 myPoint1->SetValue(1, myPOnC2);
124 myPoint1->SetValue(2, myPOnC2);
125 myPoint2->SetValue(1, P1S);
126 myPoint2->SetValue(2, P2S);
127 }
128 else {
129 Extrema_ExtPElS ExPS(myPOnC2.Value(), S, Precision::Confusion());
130 if (ExPS.IsDone()) {
131 myNbExt = ExPS.NbExt();
132 mySqDist = new TColStd_HArray1OfReal(1, myNbExt);
133 myPoint1 = new Extrema_HArray1OfPOnCurv(1, myNbExt);
134 myPoint2 = new Extrema_HArray1OfPOnSurf(1, myNbExt);
135 for (i = 1; i <= myNbExt; i++) {
136 myPoint1->SetValue(i, myPOnC2);
137 myPoint2->SetValue(i, ExPS.Point(i));
138 mySqDist->SetValue(i,(myPOnC2.Value()).SquareDistance(ExPS.Point(i).Value()));
139 }
140 }
141 }
142 myDone = Standard_True;
143 }
144 }
145
146}
147
148
149
150Extrema_ExtElCS::Extrema_ExtElCS(const gp_Lin& C,
151 const gp_Cone& S)
152{
153 Perform(C, S);
154}
155
156
157
158//void Extrema_ExtElCS::Perform(const gp_Lin& C,
159// const gp_Cone& S)
160void Extrema_ExtElCS::Perform(const gp_Lin& ,
161 const gp_Cone& )
162{
163 Standard_NotImplemented::Raise();
164
165}
166
167
168
169Extrema_ExtElCS::Extrema_ExtElCS(const gp_Lin& C,
170 const gp_Sphere& S)
171{
172 Perform(C, S);
173}
174
175
176
177void Extrema_ExtElCS::Perform(const gp_Lin& C,
178 const gp_Sphere& S)
179{
180 myDone = Standard_False;
181 myNbExt = 0;
182 myIsPar = Standard_False;
183
184 gp_Pnt O = S.Location();
185
186 Extrema_ExtPElC Extrem(O, C, Precision::Angular(), RealFirst(), RealLast());
187
188 Standard_Integer i;
189 if (Extrem.IsDone()) {
190 Extrema_POnCurv myPOnC1 = Extrem.Point(1);
191 Extrema_ExtPElS ExPS(myPOnC1.Value(), S, Precision::Confusion());
192 if (ExPS.IsDone()) {
193 myNbExt = ExPS.NbExt();
194 mySqDist = new TColStd_HArray1OfReal(1, myNbExt);
195 myPoint1 = new Extrema_HArray1OfPOnCurv(1, myNbExt);
196 myPoint2 = new Extrema_HArray1OfPOnSurf(1, myNbExt);
197 for (i = 1; i <= myNbExt; i++) {
198 myPoint1->SetValue(i, myPOnC1);
199 myPoint2->SetValue(i, ExPS.Point(i));
200 mySqDist->SetValue(i,(myPOnC1.Value()).SquareDistance(ExPS.Point(i).Value()));
201 myDone = Standard_True;
202 }
203 }
204 }
205}
206
207
208Extrema_ExtElCS::Extrema_ExtElCS(const gp_Lin& C,
209 const gp_Torus& S)
210{
211 Perform(C, S);
212}
213
214
215
216//void Extrema_ExtElCS::Perform(const gp_Lin& C,
217// const gp_Torus& S)
218void Extrema_ExtElCS::Perform(const gp_Lin& ,
219 const gp_Torus& )
220{
221 Standard_NotImplemented::Raise();
222
223}
224
225
226// Circle-?
227
228Extrema_ExtElCS::Extrema_ExtElCS(const gp_Circ& C,
229 const gp_Pln& S)
230{
231 Perform(C, S);
232}
233
234
235
236//void Extrema_ExtElCS::Perform(const gp_Circ& C,
237// const gp_Pln& S)
238void Extrema_ExtElCS::Perform(const gp_Circ& ,
239 const gp_Pln& )
240{
241 Standard_NotImplemented::Raise();
242
243}
244
245
246
247Extrema_ExtElCS::Extrema_ExtElCS(const gp_Circ& C,
248 const gp_Cylinder& S)
249{
250 Perform(C, S);
251}
252
253
254
255// Modified by skv - Thu Jul 7 14:37:05 2005 OCC9134 Begin
256// Implementation of the method.
257void Extrema_ExtElCS::Perform(const gp_Circ& C,
258 const gp_Cylinder& S)
259{
260 myDone = Standard_False;
261 myIsPar = Standard_False;
262 myNbExt = 0;
263
264 // Get an axis line of the cylinder.
265 gp_Lin anAxis(S.Axis());
266
267 // Compute extrema between the circle and the line.
268 Extrema_ExtElC anExtC(anAxis, C, 0.);
269
270 if (anExtC.IsDone()) {
271 if (anExtC.IsParallel()) {
272 myIsPar = Standard_True;
273 mySqDist = new TColStd_HArray1OfReal(1, 1);
274 Standard_Real aDist = sqrt (anExtC.SquareDistance(1)) - S.Radius();
275 mySqDist->SetValue(1, aDist * aDist);
276 } else {
277 Standard_Integer aNbExt = anExtC.NbExt();
278 gp_Pnt aCenter = C.Location();
279 Standard_Integer i;
280 Standard_Integer aCurI = 1;
281 Standard_Real aTolConf = Precision::Confusion();
282 Standard_Real aCylRad = S.Radius();
283
284 // Compute the extremas.
285 myNbExt = 2*aNbExt;
286 mySqDist = new TColStd_HArray1OfReal(1, myNbExt);
287 myPoint1 = new Extrema_HArray1OfPOnCurv(1, myNbExt);
288 myPoint2 = new Extrema_HArray1OfPOnSurf(1, myNbExt);
289
290 for (i = 1; i <= aNbExt; i++) {
291 Extrema_POnCurv aPOnAxis;
292 Extrema_POnCurv aPOnCirc;
293 Standard_Real aSqDist = anExtC.SquareDistance(i);
294 Standard_Real aDist = sqrt (aSqDist);
295
296 anExtC.Points(i, aPOnAxis, aPOnCirc);
297
298 if (aSqDist <= (aTolConf * aTolConf) || aCenter.IsEqual(aPOnAxis.Value(), aTolConf)) {
299 myNbExt -= 2;
300 continue;
301 }
302
303 gp_Dir aDir(aPOnAxis.Value().XYZ().
304 Subtracted(aPOnCirc.Value().XYZ()));
305 Standard_Real aShift[2] = { aDist + aCylRad, aDist - aCylRad };
306 Standard_Integer j;
307
308 for (j = 0; j < 2; j++) {
309 gp_Vec aVec(aDir);
310 gp_Pnt aPntOnCyl;
311
312 aVec.Multiply(aShift[j]);
313 aPntOnCyl = aPOnCirc.Value().Translated(aVec);
314
315 Standard_Real aU;
316 Standard_Real aV;
317
318 ElSLib::Parameters(S, aPntOnCyl, aU, aV);
319
320 Extrema_POnSurf aPOnSurf(aU, aV, aPntOnCyl);
321
322 myPoint1->SetValue(aCurI, aPOnCirc);
323 myPoint2->SetValue(aCurI, aPOnSurf);
324 mySqDist->SetValue(aCurI++, aShift[j] * aShift[j]);
325 }
326 }
327 }
328
329 myDone = Standard_True;
330 }
331}
332// Modified by skv - Thu Jul 7 14:37:05 2005 OCC9134 End
333
334
335
336Extrema_ExtElCS::Extrema_ExtElCS(const gp_Circ& C,
337 const gp_Cone& S)
338{
339 Perform(C, S);
340}
341
342
343
344//void Extrema_ExtElCS::Perform(const gp_Circ& C,
345// const gp_Cone& S)
346void Extrema_ExtElCS::Perform(const gp_Circ& ,
347 const gp_Cone& )
348{
349 Standard_NotImplemented::Raise();
350
351}
352
353
354
355Extrema_ExtElCS::Extrema_ExtElCS(const gp_Circ& C,
356 const gp_Sphere& S)
357{
358 Perform(C, S);
359}
360
361
362
363//void Extrema_ExtElCS::Perform(const gp_Circ& C,
364// const gp_Sphere& S)
365void Extrema_ExtElCS::Perform(const gp_Circ& ,
366 const gp_Sphere& )
367{
368 Standard_NotImplemented::Raise();
369
370}
371
372Extrema_ExtElCS::Extrema_ExtElCS(const gp_Circ& C,
373 const gp_Torus& S)
374{
375 Perform(C, S);
376}
377
378
379
380//void Extrema_ExtElCS::Perform(const gp_Circ& C,
381// const gp_Torus& S)
382void Extrema_ExtElCS::Perform(const gp_Circ& ,
383 const gp_Torus& )
384{
385 Standard_NotImplemented::Raise();
386
387}
388
389Extrema_ExtElCS::Extrema_ExtElCS(const gp_Hypr& C,
390 const gp_Pln& S)
391{
392 Perform(C, S);
393}
394
395
396
397void Extrema_ExtElCS::Perform(const gp_Hypr& C,
398 const gp_Pln& S)
399{
400 myDone = Standard_True;
401 myIsPar = Standard_False;
402
403 gp_Ax2 Pos = C.Position();
404 gp_Dir NHypr = Pos.Direction();
405 gp_Dir NPln = S.Axis().Direction();
406
407 if (NHypr.IsParallel(NPln, Precision::Angular())) {
408
409 mySqDist = new TColStd_HArray1OfReal(1, 1);
410 mySqDist->SetValue(1, S.SquareDistance(C.Location()));
411 myIsPar = Standard_True;
412
413 }
414 else {
415
416 gp_Dir XDir = Pos.XDirection();
417 gp_Dir YDir = Pos.YDirection();
418
419 Standard_Real A = C.MinorRadius()*(NPln.Dot(YDir));
420 Standard_Real B = C.MajorRadius()*(NPln.Dot(XDir));
421
422 if(Abs(B) > Abs(A)) {
423 Standard_Real T = -0.5 * Log((A+B)/(B-A));
424 gp_Pnt Ph = ElCLib::HyperbolaValue(T, Pos, C.MajorRadius(), C.MinorRadius());
425 Extrema_POnCurv PC(T, Ph);
426 myPoint1 = new Extrema_HArray1OfPOnCurv(1,1);
427 myPoint1->SetValue(1, PC);
428
429 mySqDist = new TColStd_HArray1OfReal(1, 1);
430 mySqDist->SetValue(1, S.SquareDistance(Ph));
431
432 Standard_Real U, V;
433 ElSLib::PlaneParameters(S.Position(), Ph, U, V);
434 gp_Pnt Pp = ElSLib::PlaneValue(U, V, S.Position());
435 Extrema_POnSurf PS(U, V, Pp);
436 myPoint2 = new Extrema_HArray1OfPOnSurf(1,1);
437 myPoint2->SetValue(1, PS);
438
439 myNbExt = 1;
440 }
441 else {
442 myNbExt = 0;
443 }
444
445 }
446
447}
448
449
450Standard_Boolean Extrema_ExtElCS::IsDone() const
451{
452 return myDone;
453}
454
455
456Standard_Integer Extrema_ExtElCS::NbExt() const
457{
458 if (myIsPar) StdFail_InfiniteSolutions::Raise();
459 return myNbExt;
460}
461
462Standard_Real Extrema_ExtElCS::SquareDistance(const Standard_Integer N) const
463{
464 if (myIsPar && N != 1) StdFail_InfiniteSolutions::Raise();
465 return mySqDist->Value(N);
466}
467
468
469void Extrema_ExtElCS::Points(const Standard_Integer N,
470 Extrema_POnCurv& P1,
471 Extrema_POnSurf& P2) const
472{
473 if (myIsPar) StdFail_InfiniteSolutions::Raise();
474 P1 = myPoint1->Value(N);
475 P2 = myPoint2->Value(N);
476}
477
478
479Standard_Boolean Extrema_ExtElCS::IsParallel() const
480{
481 return myIsPar;
482}