0024511: Remove obsolete Image_PixelAddress.cxx
[occt.git] / src / Primitives / Primitives_Wedge.gxx
CommitLineData
b311480e 1// Created on: 1991-09-27
2// Created by: Christophe MARION
3// Copyright (c) 1991-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//
973c2be1 8// This library is free software; you can redistribute it and / or modify it
9// under the terms of the GNU Lesser General Public 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.
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 <Precision.hxx>
18#include <gp_Vec.hxx>
19#include <gp_Pln.hxx>
20#include <gp_Lin.hxx>
21#include <ElSLib.hxx>
22#include <ElCLib.hxx>
23
24#include <Standard_DomainError.hxx>
25#include <Standard_OutOfRange.hxx>
26
27#undef Standard_True
28#undef Standard_False
29
30#define Standard_True ((Standard_Boolean) 1)
31#define Standard_False ((Standard_Boolean) 0)
32
33#define NBFACES 6
34#define NBWIRES 6
35#define NBEDGES 12
36#define NBVERTICES 8
37
38static const Standard_Integer num[6] = {0,1,2,3,4,5};
39static const Standard_Integer val[6] = {0,4,0,2,0,1};
40static const Standard_Integer tab[6][6] = {{-1,-1, 0, 1, 8, 9},
41 {-1,-1, 2, 3,10,11},
42 { 0, 2,-1,-1, 4, 5},
43 { 1, 3,-1,-1, 6, 7},
44 { 8,10, 4, 6,-1,-1},
45 { 9,11, 5, 7,-1,-1}};
46
47//=======================================================================
48//function : Primitives_Wedge_NumDir1
49//purpose : when giving a direction return the range of the face
50//=======================================================================
51
52static Standard_Integer Primitives_Wedge_NumDir1
53 (const Primitives_Direction d1) { return num[d1]; }
54
55//=======================================================================
56//function : Primitives_Wedge_NumDir2
57//purpose : when giving two directions return the range of the edge
58//=======================================================================
59
60static Standard_Integer Primitives_Wedge_NumDir2
61 (const Primitives_Direction d1,
62 const Primitives_Direction d2)
63{
64 Standard_Integer i1 = Primitives_Wedge_NumDir1(d1);
65 Standard_Integer i2 = Primitives_Wedge_NumDir1(d2);
66 if ( i1/2 == i2/2 ) Standard_DomainError::Raise();
67 return tab[i1][i2];
68}
69
70//=======================================================================
71//function : Primitives_Wedge_NumDir3
72//purpose : when giving three directions return the range of the vertex
73//=======================================================================
74
75static Standard_Integer Primitives_Wedge_NumDir3
76 (const Primitives_Direction d1,
77 const Primitives_Direction d2,
78 const Primitives_Direction d3)
79{
80 Standard_Integer i1 = Primitives_Wedge_NumDir1(d1);
81 Standard_Integer i2 = Primitives_Wedge_NumDir1(d2);
82 Standard_Integer i3 = Primitives_Wedge_NumDir1(d3);
83 if (( i1/2 == i2/2 ) ||
84 ( i2/2 == i3/2 ) ||
85 ( i3/2 == i1/2 )) Standard_DomainError::Raise();
86 return val[i1]+val[i2]+val[i3];
87}
88
89//=======================================================================
90//function : Primitives_Wedge_Check
91//purpose : raise Standard_DomainError if something was built
92//=======================================================================
93
94static void Primitives_Wedge_Check(const Standard_Boolean V[],
95 const Standard_Boolean E[],
96 const Standard_Boolean W[],
97 const Standard_Boolean F[])
98{
99 Standard_Integer i;
100 for (i = 0; i < NBVERTICES; i++)
101 if (V[i]) Standard_DomainError::Raise();
102 for (i = 0; i < NBEDGES; i++)
103 if (E[i]) Standard_DomainError::Raise();
104 for (i = 0; i < NBWIRES; i++)
105 if (W[i]) Standard_DomainError::Raise();
106 for (i = 0; i < NBFACES; i++)
107 if (F[i]) Standard_DomainError::Raise();
108}
109
110//=======================================================================
111//function : Primitives_Wedge_Init
112//purpose : Set arrays to Standard_False
113//=======================================================================
114
115static void Primitives_Wedge_Init(Standard_Boolean& S,
116 Standard_Boolean V[],
117 Standard_Boolean E[],
118 Standard_Boolean W[],
119 Standard_Boolean F[])
120{
121 Standard_Integer i;
122 S = Standard_False;
123 for (i = 0; i < NBVERTICES; i++)
124 V[i] = Standard_False;
125 for (i = 0; i < NBEDGES; i++)
126 E[i] = Standard_False;
127 for (i = 0; i < NBWIRES; i++)
128 W[i] = Standard_False;
129 for (i = 0; i < NBFACES; i++)
130 F[i] = Standard_False;
131}
132
133//=======================================================================
134//function : Primitives_Wedge
135//purpose : build a box
136//=======================================================================
137
138Primitives_Wedge::Primitives_Wedge (const TheBuilder& B,
139 const gp_Ax2& Axes,
140 const Standard_Real dx,
141 const Standard_Real dy,
142 const Standard_Real dz) :
143 myBuilder(B),
144 myAxes(Axes),
145 XMin(0),
146 XMax(dx),
147 YMin(0),
148 YMax(dy),
149 ZMin(0),
150 ZMax(dz),
151 Z2Min(0),
152 Z2Max(dz),
153 X2Min(0),
154 X2Max(dx)
155{
156 for (Standard_Integer i = 0; i < NBFACES; i++) { myInfinite[i]=Standard_False; }
157 if ( ( dx <= Precision::Confusion() ) ||
158 ( dy <= Precision::Confusion() ) ||
159 ( dz <= Precision::Confusion() ) )
160 Standard_DomainError::Raise();
161 Primitives_Wedge_Init(ShellBuilt,VerticesBuilt,EdgesBuilt,
162 WiresBuilt,FacesBuilt);
163}
164
165//=======================================================================
166//function : Primitives_Wedge
167//purpose : build a STEP wedge
168//=======================================================================
169
170Primitives_Wedge::Primitives_Wedge (const TheBuilder& B,
171 const gp_Ax2& Axes,
172 const Standard_Real dx,
173 const Standard_Real dy,
174 const Standard_Real dz,
175 const Standard_Real ltx) :
176 myBuilder(B),
177 myAxes(Axes),
178 XMin(0),
179 XMax(dx),
180 YMin(0),
181 YMax(dy),
182 ZMin(0),
183 ZMax(dz),
184 Z2Min(0),
185 Z2Max(dz),
186 X2Min(0),
187 X2Max(ltx)
188{
189 for (Standard_Integer i = 0; i < NBFACES; i++) { myInfinite[i]=Standard_False; }
190 if ( ( dx <= Precision::Confusion() ) ||
191 ( dy <= Precision::Confusion() ) ||
192 ( dz <= Precision::Confusion() ) ||
193 ( ltx < 0 ) )
194 Standard_DomainError::Raise();
195 Primitives_Wedge_Init(ShellBuilt,VerticesBuilt,EdgesBuilt,
196 WiresBuilt,FacesBuilt);
197}
198
199//=======================================================================
200//function : Primitives_Wedge
201//purpose : build a wedge by giving all the fields
202//=======================================================================
203
204Primitives_Wedge::Primitives_Wedge (const TheBuilder& B,
205 const gp_Ax2& Axes,
206 const Standard_Real xmin,
207 const Standard_Real ymin,
208 const Standard_Real zmin,
209 const Standard_Real z2min,
210 const Standard_Real x2min,
211 const Standard_Real xmax,
212 const Standard_Real ymax,
213 const Standard_Real zmax,
214 const Standard_Real z2max,
215 const Standard_Real x2max) :
216 myBuilder(B),
217 myAxes(Axes),
218 XMin(xmin),
219 XMax(xmax),
220 YMin(ymin),
221 YMax(ymax),
222 ZMin(zmin),
223 ZMax(zmax),
224 Z2Min(z2min),
225 Z2Max(z2max),
226 X2Min(x2min),
227 X2Max(x2max)
228{
229 for (Standard_Integer i = 0; i < NBFACES; i++) { myInfinite[i]=Standard_False; }
230 if ( ( XMax-XMin <= Precision::Confusion() ) ||
231 ( YMax-YMin <= Precision::Confusion() ) ||
232 ( ZMax-ZMin <= Precision::Confusion() ) ||
233 ( Z2Max-Z2Min < 0 ) ||
234 ( X2Max-X2Min < 0 ) )
235 Standard_DomainError::Raise();
236 Primitives_Wedge_Init(ShellBuilt,VerticesBuilt,EdgesBuilt,
237 WiresBuilt,FacesBuilt);
238}
239
240//=======================================================================
241//function : Axes,
242// GetXMin, GetYMin, GetZMin, GetZ2Min, GetX2Min
243// GetXMax, GetYMax, GetZMax, GetZ2Max, GetX2Max
244//purpose : trivial
245//=======================================================================
246
247gp_Ax2 Primitives_Wedge::Axes () const { return myAxes; }
248Standard_Real Primitives_Wedge::GetXMin () const { return XMin; }
249Standard_Real Primitives_Wedge::GetYMin () const { return YMin; }
250Standard_Real Primitives_Wedge::GetZMin () const { return ZMin; }
251Standard_Real Primitives_Wedge::GetZ2Min () const { return Z2Min; }
252Standard_Real Primitives_Wedge::GetX2Min () const { return X2Min; }
253Standard_Real Primitives_Wedge::GetXMax () const { return XMax; }
254Standard_Real Primitives_Wedge::GetYMax () const { return YMax; }
255Standard_Real Primitives_Wedge::GetZMax () const { return ZMax; }
256Standard_Real Primitives_Wedge::GetZ2Max () const { return Z2Max; }
257Standard_Real Primitives_Wedge::GetX2Max () const { return X2Max; }
258
259//=======================================================================
260//function : Open
261//purpose : trivial
262//=======================================================================
263
264void Primitives_Wedge::Open (const Primitives_Direction d1)
265{
266 Primitives_Wedge_Check(VerticesBuilt,EdgesBuilt,WiresBuilt,FacesBuilt);
267 myInfinite[Primitives_Wedge_NumDir1(d1)] = Standard_True;
268}
269
270//=======================================================================
271//function : Close
272//purpose : trivial
273//=======================================================================
274
275void Primitives_Wedge::Close (const Primitives_Direction d1)
276{
277 Primitives_Wedge_Check(VerticesBuilt,EdgesBuilt,WiresBuilt,FacesBuilt);
278 myInfinite[Primitives_Wedge_NumDir1(d1)] = Standard_False;
279}
280
281//=======================================================================
282//function : IsInfinite
283//purpose : true if it is open in the given direction
284//=======================================================================
285
286Standard_Boolean Primitives_Wedge::IsInfinite (const Primitives_Direction d1) const
287{ return myInfinite[Primitives_Wedge_NumDir1(d1)]; }
288
289//=======================================================================
290//function : Shell
291//purpose :
292//=======================================================================
293
294const TheShell& Primitives_Wedge::Shell() {
295 if (!ShellBuilt) {
296 myBuilder.MakeShell(myShell);
297
298 if (HasFace(Primitives_XMin))
299 myBuilder.AddShellFace(myShell,Face(Primitives_XMin));
300 if (HasFace(Primitives_XMax))
301 myBuilder.AddShellFace(myShell,Face(Primitives_XMax));
302 if (HasFace(Primitives_YMin))
303 myBuilder.AddShellFace(myShell,Face(Primitives_YMin));
304 if (HasFace(Primitives_YMax))
305 myBuilder.AddShellFace(myShell,Face(Primitives_YMax));
306 if (HasFace(Primitives_ZMin))
307 myBuilder.AddShellFace(myShell,Face(Primitives_ZMin));
308 if (HasFace(Primitives_ZMax))
309 myBuilder.AddShellFace(myShell,Face(Primitives_ZMax));
310
311 myBuilder.CompleteShell(myShell);
312 ShellBuilt = Standard_True;
313 }
314 return myShell;
315}
316
317//=======================================================================
318//function : HasFace
319//purpose : true if the face exist in one direction
320//=======================================================================
321
322Standard_Boolean Primitives_Wedge::HasFace (const Primitives_Direction d1) const
323{
324 Standard_Boolean state = !myInfinite[Primitives_Wedge_NumDir1(d1)];
325 if ( d1 == Primitives_YMax ) state = state && ( Z2Max != Z2Min )
326 && ( X2Max != X2Min );
327 return state;
328}
329
330//=======================================================================
331//function : Plane
332//purpose :
333//=======================================================================
334
335gp_Pln Primitives_Wedge::Plane(const Primitives_Direction d1)
336{
337
338 Standard_Integer i = Primitives_Wedge_NumDir1(d1);
339
340 gp_Dir D;
341 gp_Vec VX = myAxes.XDirection();
342 gp_Vec VY = myAxes.YDirection();
343 gp_Vec VZ = myAxes.Direction();
344
345 switch (i/2) {
346
347 case 0 :
348 D = myAxes.XDirection();
349 break;
350
351 case 1 :
352 D = myAxes.YDirection();
353 break;
354
355 case 2 :
356 D = myAxes.Direction();
357 break;
358
359 };
1d47d8d0 360 Standard_Real X = 0., Y = 0., Z = 0.;
7fd59977 361
362 switch (i) {
363
364 case 0 :
365 // XMin
366 X = XMin;
367 Y = YMin;
368 Z = ZMin;
369 if ( X2Min != XMin ) D = gp_Dir((YMax-YMin)*VX+(XMin-X2Min)*VY);
370 break;
371
372 case 1 :
373 // XMax
374 X = XMax;
375 Y = YMin;
376 Z = ZMin;
377 if ( X2Max != XMax ) D = gp_Dir((YMax-YMin)*VX+(XMax-X2Max)*VY);
378 break;
379
380 case 2 :
381 // YMin
382 X = XMin;
383 Y = YMin;
384 Z = ZMin;
385 break;
386
387 case 3 :
388 // YMax
389 X = XMin;
390 Y = YMax;
391 Z = ZMin;
392 break;
393
394 case 4 :
395 // ZMin
396 X = XMin;
397 Y = YMin;
398 Z = ZMin;
399 if ( Z2Min != ZMin ) D = gp_Dir((YMax-YMin)*VZ+(ZMin-Z2Min)*VY);
400 break;
401
402 case 5 :
403 // ZMax
404 X = XMin;
405 Y = YMin;
406 Z = ZMax;
407 if ( Z2Max != ZMax ) D = gp_Dir((YMax-YMin)*VZ+(ZMax-Z2Max)*VY);
408 break;
409
410 };
411
412 gp_Pnt P = myAxes.Location();
413 P.Translate(X*gp_Vec(myAxes.XDirection()));
414 P.Translate(Y*gp_Vec(myAxes.YDirection()));
415 P.Translate(Z*gp_Vec(myAxes.Direction ()));
416 gp_Pln plane(P,D);
417 return plane;
418}
419
420//=======================================================================
421//function : Face
422//purpose : the face in one direction
423//=======================================================================
424
425const TheFace& Primitives_Wedge::Face
426 (const Primitives_Direction d1)
427{
428
429 Standard_Integer i = Primitives_Wedge_NumDir1(d1);
430
431 if (!FacesBuilt[i]) {
432 gp_Pln P = Plane(d1);
433 myBuilder.MakeFace(myFaces[i],P);
434 if (HasWire(d1)) myBuilder.AddFaceWire(myFaces[i],Wire(d1));
435 if ( i%2 == 0 ) myBuilder.ReverseFace(myFaces[i]);
436
437 // pcurves
1d47d8d0 438
7fd59977 439 Primitives_Direction dd1 = Primitives_ZMin, dd2 = Primitives_YMax,
440 dd3 = Primitives_ZMax,dd4 = Primitives_YMin;
1d47d8d0 441
7fd59977 442 switch (i/2) {
443
444 case 0 :
445 // XMin XMax
446 dd1 = Primitives_ZMin;
447 dd2 = Primitives_YMax;
448 dd3 = Primitives_ZMax;
449 dd4 = Primitives_YMin;
450 break;
451
452 case 1 :
453 // YMin YMax
454 dd1 = Primitives_XMin;
455 dd2 = Primitives_ZMax;
456 dd3 = Primitives_XMax;
457 dd4 = Primitives_ZMin;
458 break;
459
460 case 2 :
461 // ZMin ZMax
462 dd1 = Primitives_YMin;
463 dd2 = Primitives_XMax;
464 dd3 = Primitives_YMax;
465 dd4 = Primitives_XMin;
466 break;
467
468 };
469
470 gp_Lin L;
471 gp_Dir DX = P.XAxis().Direction();
472 gp_Dir DY = P.YAxis().Direction();
473 Standard_Real U,V,DU,DV;
474 if (HasEdge(d1,dd4)) {
475 L = Line(d1,dd4);
476 ElSLib::Parameters(P,L.Location(),U,V);
477 DU = L.Direction() * DX;
478 DV = L.Direction() * DY;
479 myBuilder.SetPCurve(myEdges[Primitives_Wedge_NumDir2(d1,dd4)],
480 myFaces[i],
481 gp_Lin2d(gp_Pnt2d(U,V),gp_Dir2d(DU,DV)));
482 }
483 if (HasEdge(d1,dd3)) {
484 L = Line(d1,dd3);
485 ElSLib::Parameters(P,L.Location(),U,V);
486 DU = L.Direction() * DX;
487 DV = L.Direction() * DY;
488 myBuilder.SetPCurve(myEdges[Primitives_Wedge_NumDir2(d1,dd3)],
489 myFaces[i],
490 gp_Lin2d(gp_Pnt2d(U,V),gp_Dir2d(DU,DV)));
491 }
492
493 if (HasEdge(d1,dd2)) {
494 L = Line(d1,dd2);
495 ElSLib::Parameters(P,L.Location(),U,V);
496 DU = L.Direction() * DX;
497 DV = L.Direction() * DY;
498 myBuilder.SetPCurve(myEdges[Primitives_Wedge_NumDir2(d1,dd2)],
499 myFaces[i],
500 gp_Lin2d(gp_Pnt2d(U,V),gp_Dir2d(DU,DV)));
501 }
502
503 if (HasEdge(d1,dd1)) {
504 L = Line(d1,dd1);
505 ElSLib::Parameters(P,L.Location(),U,V);
506 DU = L.Direction() * DX;
507 DV = L.Direction() * DY;
508 myBuilder.SetPCurve(myEdges[Primitives_Wedge_NumDir2(d1,dd1)],
509 myFaces[i],
510 gp_Lin2d(gp_Pnt2d(U,V),gp_Dir2d(DU,DV)));
511 }
512
513
514 myBuilder.CompleteFace(myFaces[i]);
515 FacesBuilt[i] = Standard_True;
516 }
517
518 return myFaces[i];
519
520}
521
522//=======================================================================
523//function : HasWire
524//purpose : trivial
525//=======================================================================
526
527Standard_Boolean Primitives_Wedge::HasWire (const Primitives_Direction d1) const
528{
529 Standard_Integer i = Primitives_Wedge_NumDir1(d1);
530
531 if (myInfinite[i]) return Standard_False;
7fd59977 532 Primitives_Direction dd1 = Primitives_XMin,dd2 = Primitives_YMax,dd3 = Primitives_XMax ,dd4 = Primitives_ZMin;
1d47d8d0 533
7fd59977 534 switch (i/2) {
535
536 case 0 :
537 // XMin XMax
538 dd1 = Primitives_ZMin;
539 dd2 = Primitives_YMax;
540 dd3 = Primitives_ZMax;
541 dd4 = Primitives_YMin;
542 break;
543
544 case 1 :
545 // YMin YMax
546 dd1 = Primitives_XMin;
547 dd2 = Primitives_ZMax;
548 dd3 = Primitives_XMax;
549 dd4 = Primitives_ZMin;
550 break;
551
552 case 2 :
553 // ZMin ZMax
554 dd1 = Primitives_YMin;
555 dd2 = Primitives_XMax;
556 dd3 = Primitives_YMax;
557 dd4 = Primitives_XMin;
558 break;
559#ifndef DEB
560 default:
561 break;
562#endif
563 };
564
565 return HasEdge(d1,dd1)||HasEdge(d1,dd2)||HasEdge(d1,dd3)||HasEdge(d1,dd4);
566
567}
568
569//=======================================================================
570//function : Wire
571//purpose : trivial
572//=======================================================================
573
574const TheWire& Primitives_Wedge::Wire
575 (const Primitives_Direction d1)
576{
577 Standard_Integer i = Primitives_Wedge_NumDir1(d1);
578
7fd59977 579 Primitives_Direction dd1 = Primitives_XMin,dd2 = Primitives_YMax,dd3 = Primitives_XMax ,dd4 = Primitives_ZMin;
1d47d8d0 580
7fd59977 581 if (!WiresBuilt[i]) {
582
583 switch (i/2) {
584
585 case 0 :
586 // XMin XMax
587 dd1 = Primitives_ZMin;
588 dd2 = Primitives_YMax;
589 dd3 = Primitives_ZMax;
590 dd4 = Primitives_YMin;
591 break;
592
593 case 1 :
594 // YMin YMax
595 dd1 = Primitives_XMin;
596 dd2 = Primitives_ZMax;
597 dd3 = Primitives_XMax;
598 dd4 = Primitives_ZMin;
599 break;
600
601 case 2 :
602 // ZMin ZMax
603 dd1 = Primitives_YMin;
604 dd2 = Primitives_XMax;
605 dd3 = Primitives_YMax;
606 dd4 = Primitives_XMin;
607 break;
608#ifndef DEB
609 default:
610 break;
611#endif
612 };
613
614 myBuilder.MakeWire(myWires[i]);
615
616 if (HasEdge(d1,dd4))
617 myBuilder.AddWireEdge(myWires[i],Edge(d1,dd4),Standard_False);
618 if (HasEdge(d1,dd3))
619 myBuilder.AddWireEdge(myWires[i],Edge(d1,dd3),Standard_False);
620 if (HasEdge(d1,dd2))
621 myBuilder.AddWireEdge(myWires[i],Edge(d1,dd2),Standard_True );
622 if (HasEdge(d1,dd1))
623 myBuilder.AddWireEdge(myWires[i],Edge(d1,dd1),Standard_True );
624
625 myBuilder.CompleteWire(myWires[i]);
626 WiresBuilt[i] = Standard_True;
627 }
628
629 return myWires[i];
630
631}
632
633//=======================================================================
634//function : HasEdge
635//purpose : trivial
636//=======================================================================
637
638Standard_Boolean Primitives_Wedge::HasEdge (const Primitives_Direction d1,
639 const Primitives_Direction d2) const
640{
641 Standard_Boolean state = !(myInfinite[Primitives_Wedge_NumDir1(d1)] ||
642 myInfinite[Primitives_Wedge_NumDir1(d2)]);
643 Standard_Integer i = Primitives_Wedge_NumDir2(d1,d2);
644 if ( i == 6 || i == 7 ) state = state && ( X2Max != X2Min );
645 else if ( i == 1 || i == 3 ) state = state && ( Z2Max != Z2Min );
646 return state;
647}
648
649//=======================================================================
650//function : Line
651//purpose : trivial
652//=======================================================================
653
654gp_Lin Primitives_Wedge::Line
655 (const Primitives_Direction d1,
656 const Primitives_Direction d2)
657{
658 if (!HasEdge(d1,d2)) Standard_DomainError::Raise();
659
660 Standard_Integer i = Primitives_Wedge_NumDir2(d1,d2);
1d47d8d0 661
7fd59977 662 Standard_Real X =0., Y =0., Z =0.;
1d47d8d0 663
7fd59977 664 gp_Dir D;
665 gp_Vec VX = myAxes.XDirection();
666 gp_Vec VY = myAxes.YDirection();
667 gp_Vec VZ = myAxes.Direction();
668 Primitives_Direction dd1,dd2;
669
670 switch (i/4) {
671
672 case 0 :
673 D = myAxes.Direction();
674 dd1 = Primitives_ZMin;
675 dd2 = Primitives_ZMax;
676 break;
677
678 case 1 :
679 D = myAxes.XDirection();
680 dd1 = Primitives_XMin;
681 dd2 = Primitives_XMax;
682 break;
683
684 case 2 :
685 D = myAxes.YDirection();
686 dd1 = Primitives_YMin;
687 dd2 = Primitives_YMax;
688 break;
689
690 };
691
692 switch (i) {
693
694 case 0 :
695 // XMin YMin
696 X = XMin;
697 Y = YMin;
698 Z = ZMin;
699 break;
700
701 case 1 :
702 // XMin YMax
703 X = X2Min;
704 Y = YMax;
705 Z = Z2Min;
706 break;
707
708 case 2 :
709 // XMax YMin
710 X = XMax;
711 Y = YMin;
712 Z = ZMin;
713 break;
714
715 case 3 :
716 // XMax YMax
717 X = X2Max;
718 Y = YMax;
719 Z = Z2Min;
720 break;
721
722 case 4 :
723 // YMin ZMin
724 X = XMin;
725 Y = YMin;
726 Z = ZMin;
727 break;
728
729 case 5 :
730 // YMin ZMax
731 X = XMin;
732 Y = YMin;
733 Z = ZMax;
734 break;
735
736 case 6 :
737 // YMax ZMin
738 X = X2Min;
739 Y = YMax;
740 Z = Z2Min;
741 break;
742
743 case 7 :
744 // YMax ZMax
745 X = X2Min;
746 Y = YMax;
747 Z = Z2Max;
748 break;
749
750 case 8 :
751 // ZMin XMin
752 X = XMin;
753 Y = YMin;
754 Z = ZMin;
755 if ( (XMin != X2Min) || (ZMin != Z2Min) )
b70bbe58 756 D = gp_Vec( (X2Min-XMin)*VX + (YMax-YMin)*VY + (Z2Min-ZMin)*VZ);
7fd59977 757 break;
758
759 case 9 :
760 // ZMax XMin
761 X = XMin;
762 Y = YMin;
763 Z = ZMax;
764 if ( (XMin != X2Min) || (ZMax != Z2Max) )
765 D = gp_Vec( (X2Min-XMin)*VX + (YMax-YMin)*VY + (Z2Max-ZMax)*VZ);
766 break;
767
768 case 10 :
769 // ZMin XMax
770 X = XMax;
771 Y = YMin;
772 Z = ZMin;
773 if ( (XMax != X2Max) || (ZMin != Z2Min) )
774 D = gp_Vec( (X2Max-XMax)*VX + (YMax-YMin)*VY + (Z2Min-ZMin)*VZ);
775 break;
776
777 case 11 :
778 // ZMax XMax
779 X = XMax;
780 Y = YMin;
781 Z = ZMax;
782 if ( (XMax != X2Max) || (ZMax != Z2Max) )
783 D = gp_Vec(gp_Pnt(XMax,YMin,ZMax),gp_Pnt(X2Max,YMax,Z2Max));
784 D = gp_Vec( (X2Max-XMax)*VX + (YMax-YMin)*VY + (Z2Max-ZMax)*VZ);
785 break;
786
787 }
788
789 gp_Pnt P = myAxes.Location();
790 P.Translate(X*gp_Vec(myAxes.XDirection()));
791 P.Translate(Y*gp_Vec(myAxes.YDirection()));
792 P.Translate(Z*gp_Vec(myAxes.Direction ()));
793 return gp_Lin(gp_Ax1(P,D));
794
795}
796
797//=======================================================================
798//function : Edge
799//purpose : trivial
800//=======================================================================
801
802const TheEdge& Primitives_Wedge::Edge
803 (const Primitives_Direction d1,
804 const Primitives_Direction d2)
805{
806 if (!HasEdge(d1,d2)) Standard_DomainError::Raise();
807
808 Standard_Integer i = Primitives_Wedge_NumDir2(d1,d2);
809
810 if (!EdgesBuilt[i]) {
1d47d8d0 811
7fd59977 812 Primitives_Direction dd1 = Primitives_XMin ,dd2 = Primitives_XMax;
1d47d8d0 813
7fd59977 814 switch (i/4) {
815
816 case 0 :
817 dd1 = Primitives_ZMin;
818 dd2 = Primitives_ZMax;
819 break;
820
821 case 1 :
822 dd1 = Primitives_XMin;
823 dd2 = Primitives_XMax;
824 break;
825
826 case 2 :
827 dd1 = Primitives_YMin;
828 dd2 = Primitives_YMax;
829 break;
830#ifndef DEB
831 default:
832 break;
833#endif
834 };
835
836 gp_Lin L = Line(d1,d2);
837 myBuilder.MakeEdge(myEdges[i],L);
838
839 if (HasVertex(d1,d2,dd2)) {
840 myBuilder.AddEdgeVertex(myEdges[i],Vertex(d1,d2,dd2),
841 ElCLib::Parameter(L,Point(d1,d2,dd2)),
842 Standard_False);
843 }
844 if (HasVertex(d1,d2,dd1)) {
845 myBuilder.AddEdgeVertex(myEdges[i],Vertex(d1,d2,dd1),
846 ElCLib::Parameter(L,Point(d1,d2,dd1)),
847 Standard_True );
848 }
849
850 if ( Z2Max == Z2Min ) {
851 if ( i == 6 ) {
852 myEdges[7] = myEdges[6];
853 EdgesBuilt[7] = Standard_True;
854 }
855 else if ( i == 7 ) {
856 myEdges[6] = myEdges[7];
857 EdgesBuilt[6] = Standard_True;
858 }
859 }
860 if ( X2Max == X2Min ) {
861 if ( i == 1 ) {
862 myEdges[3] = myEdges[1];
863 EdgesBuilt[3] = Standard_True;
864 }
865 else if ( i == 3 ) {
866 myEdges[1] = myEdges[3];
867 EdgesBuilt[1] = Standard_True;
868 }
869 }
870
871 myBuilder.CompleteEdge(myEdges[i]);
872 EdgesBuilt[i] = Standard_True;
873 }
874
875 return myEdges[i];
876
877}
878
879//=======================================================================
880//function : HasVertex
881//purpose : trivial
882//=======================================================================
883
884Standard_Boolean Primitives_Wedge::HasVertex
885 (const Primitives_Direction d1,
886 const Primitives_Direction d2,
887 const Primitives_Direction d3) const
888{ return !(myInfinite[Primitives_Wedge_NumDir1(d1)] ||
889 myInfinite[Primitives_Wedge_NumDir1(d2)] ||
890 myInfinite[Primitives_Wedge_NumDir1(d3)]); }
891
892//=======================================================================
893//function : Point
894//purpose : trivial
895//=======================================================================
896
897gp_Pnt Primitives_Wedge::Point
898 (const Primitives_Direction d1,
899 const Primitives_Direction d2,
900 const Primitives_Direction d3)
901{
902 if (!HasVertex(d1,d2,d3)) Standard_DomainError::Raise();
903
904 Standard_Integer i = Primitives_Wedge_NumDir3(d1,d2,d3);
1d47d8d0 905
7fd59977 906 Standard_Real X =0., Y =0., Z =0.;
1d47d8d0 907
7fd59977 908 switch (i) {
909
910 case 0 :
911 X = XMin;
912 Y = YMin;
913 Z = ZMin;
914 break;
915
916 case 1 :
917 X = XMin;
918 Y = YMin;
919 Z = ZMax;
920 break;
921
922 case 2 :
923 X = X2Min;
924 Y = YMax;
925 Z = Z2Min;
926 break;
927
928 case 3 :
929 X = X2Min;
930 Y = YMax;
931 Z = Z2Max;
932 break;
933
934 case 4 :
935 X = XMax;
936 Y = YMin;
937 Z = ZMin;
938 break;
939
940 case 5 :
941 X = XMax;
942 Y = YMin;
943 Z = ZMax;
944 break;
945
946 case 6 :
947 X = X2Max;
948 Y = YMax;
949 Z = Z2Min;
950 break;
951
952 case 7 :
953 X = X2Max;
954 Y = YMax;
955 Z = Z2Max;
956 break;
957
958 };
959
960 gp_Pnt P = myAxes.Location();
961 P.Translate(X*gp_Vec(myAxes.XDirection()));
962 P.Translate(Y*gp_Vec(myAxes.YDirection()));
963 P.Translate(Z*gp_Vec(myAxes.Direction ()));
964 return P;
965}
966
967//=======================================================================
968//function : Vertex
969//purpose : trivial
970//=======================================================================
971
972const TheVertex& Primitives_Wedge::Vertex
973 (const Primitives_Direction d1,
974 const Primitives_Direction d2,
975 const Primitives_Direction d3)
976{
977 if (!HasVertex(d1,d2,d3)) Standard_DomainError::Raise();
978
979 Standard_Integer i = Primitives_Wedge_NumDir3(d1,d2,d3);
980
981 if (!VerticesBuilt[i]) {
982
983 myBuilder.MakeVertex(myVertices[i],Point(d1,d2,d3));
984
985 if ( Z2Max == Z2Min ) {
986 if ( i == 2 || i == 6 ) {
987 myVertices[3] = myVertices[2];
988 myVertices[7] = myVertices[6];
989 VerticesBuilt[3] = Standard_True;
990 VerticesBuilt[7] = Standard_True;
991 }
992 else if ( i == 3 || i == 7 ) {
993 myVertices[2] = myVertices[3];
994 myVertices[6] = myVertices[7];
995 VerticesBuilt[2] = Standard_True;
996 VerticesBuilt[6] = Standard_True;
997 }
998 }
999 if ( X2Max == X2Min ) {
1000 if ( i == 2 || i == 3 ) {
1001 myVertices[6] = myVertices[2];
1002 myVertices[7] = myVertices[3];
1003 VerticesBuilt[6] = Standard_True;
1004 VerticesBuilt[7] = Standard_True;
1005 }
1006 else if ( i == 6 || i == 7 ) {
1007 myVertices[2] = myVertices[6];
1008 myVertices[3] = myVertices[7];
1009 VerticesBuilt[2] = Standard_True;
1010 VerticesBuilt[3] = Standard_True;
1011 }
1012 }
1013
1014 VerticesBuilt[i] = Standard_True;
1015 }
1016
1017 return myVertices[i];
1018
1019}
1020