b311480e |
1 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
d5f74e42 |
6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
10 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
b311480e |
14 | |
4ad142d9 |
15 | #include <Prs3d_Arrow.hxx> |
42cf5bc1 |
16 | |
62ef08df |
17 | #include <gp_Ax3.hxx> |
42cf5bc1 |
18 | #include <gp_Dir.hxx> |
19 | #include <gp_Pnt.hxx> |
62ef08df |
20 | #include <gp_Trsf.hxx> |
b8ddfc2f |
21 | #include <Graphic3d_ArrayOfPolylines.hxx> |
42cf5bc1 |
22 | #include <Graphic3d_ArrayOfSegments.hxx> |
23 | #include <Graphic3d_Group.hxx> |
42cf5bc1 |
24 | #include <Prs3d_Presentation.hxx> |
62ef08df |
25 | #include <Prs3d_ToolCylinder.hxx> |
26 | #include <Prs3d_ToolDisk.hxx> |
27 | #include <Prs3d_ToolSphere.hxx> |
7fd59977 |
28 | |
29 | //======================================================================= |
30 | //function : Draw |
31 | //purpose : |
32 | //======================================================================= |
4ad142d9 |
33 | void Prs3d_Arrow::Draw(const Handle(Graphic3d_Group)& theGroup, |
7fd59977 |
34 | const gp_Pnt& aLocation, |
b8ddfc2f |
35 | const gp_Dir& aDirection, |
7fd59977 |
36 | const Quantity_PlaneAngle anAngle, |
b8ddfc2f |
37 | const Quantity_Length aLength) |
38 | { |
7fd59977 |
39 | Quantity_Length dx,dy,dz; aDirection.Coord(dx,dy,dz); |
40 | // |
81bba717 |
41 | // Point of the arrow: |
7fd59977 |
42 | Quantity_Length xo,yo,zo; aLocation.Coord(xo,yo,zo); |
43 | |
81bba717 |
44 | // Center of the base circle of the arrow: |
7fd59977 |
45 | Quantity_Length xc = xo - dx * aLength; |
46 | Quantity_Length yc = yo - dy * aLength; |
47 | Quantity_Length zc = zo - dz * aLength; |
48 | |
81bba717 |
49 | // Construction of i,j mark for the circle: |
7fd59977 |
50 | Quantity_Length xn=0., yn=0., zn=0.; |
51 | |
52 | if ( Abs(dx) <= Abs(dy) && Abs(dx) <= Abs(dz)) xn=1.; |
53 | else if ( Abs(dy) <= Abs(dz) && Abs(dy) <= Abs(dx)) yn=1.; |
54 | else zn=1.; |
55 | Quantity_Length xi = dy * zn - dz * yn; |
56 | Quantity_Length yi = dz * xn - dx * zn; |
57 | Quantity_Length zi = dx * yn - dy * xn; |
58 | |
59 | Quantity_Length Norme = sqrt ( xi*xi + yi*yi + zi*zi ); |
60 | xi = xi / Norme; yi = yi / Norme; zi = zi/Norme; |
61 | |
b8ddfc2f |
62 | const Quantity_Length xj = dy * zi - dz * yi; |
63 | const Quantity_Length yj = dz * xi - dx * zi; |
64 | const Quantity_Length zj = dx * yi - dy * xi; |
7fd59977 |
65 | |
b8ddfc2f |
66 | const Standard_Integer NbPoints = 15; |
7fd59977 |
67 | |
b8ddfc2f |
68 | Handle(Graphic3d_ArrayOfSegments) aPrims1 = new Graphic3d_ArrayOfSegments(2*NbPoints); |
69 | Handle(Graphic3d_ArrayOfPolylines) aPrims2 = new Graphic3d_ArrayOfPolylines(NbPoints+1); |
7fd59977 |
70 | |
b8ddfc2f |
71 | gp_Pnt p1; |
72 | const Standard_Real Tg=tan(anAngle); |
7fd59977 |
73 | |
b8ddfc2f |
74 | for (Standard_Integer i = 1; i <= NbPoints ; i++) |
75 | { |
76 | const Standard_Real cosinus = cos ( 2 * M_PI / NbPoints * (i-1) ); |
77 | const Standard_Real sinus = sin ( 2 * M_PI / NbPoints * (i-1) ); |
7fd59977 |
78 | |
b8ddfc2f |
79 | const gp_Pnt pp(xc + (cosinus * xi + sinus * xj) * aLength * Tg, |
80 | yc + (cosinus * yi + sinus * yj) * aLength * Tg, |
81 | zc + (cosinus * zi + sinus * zj) * aLength * Tg); |
7fd59977 |
82 | |
b8ddfc2f |
83 | aPrims1->AddVertex(aLocation); |
84 | aPrims1->AddVertex(pp); |
85 | if(i==1) p1 = pp; |
86 | aPrims2->AddVertex(pp); |
7fd59977 |
87 | } |
b8ddfc2f |
88 | aPrims2->AddVertex(p1); |
89 | |
4ad142d9 |
90 | theGroup->AddPrimitiveArray (aPrims1); |
91 | theGroup->AddPrimitiveArray (aPrims2); |
7fd59977 |
92 | } |
62ef08df |
93 | |
94 | // ============================================================================ |
95 | // function : DrawShaded |
96 | // purpose : |
97 | // ============================================================================ |
98 | Handle(Graphic3d_ArrayOfTriangles) Prs3d_Arrow::DrawShaded (const gp_Ax1& theAxis, |
99 | const Standard_Real theTubeRadius, |
100 | const Standard_Real theAxisLength, |
101 | const Standard_Real theConeRadius, |
102 | const Standard_Real theConeLength, |
103 | const Standard_Integer theNbFacettes) |
104 | { |
105 | const Standard_Real aTubeLength = Max (0.0, theAxisLength - theConeLength); |
106 | const Standard_Integer aNbTrisTube = (theTubeRadius > 0.0 && aTubeLength > 0.0) |
107 | ? Prs3d_ToolCylinder::TrianglesNb (theNbFacettes, 1) |
108 | : 0; |
109 | const Standard_Integer aNbTrisCone = (theConeRadius > 0.0 && theConeLength > 0.0) |
110 | ? (Prs3d_ToolDisk ::TrianglesNb (theNbFacettes, 1) |
111 | + Prs3d_ToolCylinder::TrianglesNb (theNbFacettes, 1)) |
112 | : 0; |
113 | |
114 | const Standard_Integer aNbTris = aNbTrisTube + aNbTrisCone; |
115 | if (aNbTris == 0) |
116 | { |
117 | return Handle(Graphic3d_ArrayOfTriangles)(); |
118 | } |
119 | |
120 | Handle(Graphic3d_ArrayOfTriangles) anArray = new Graphic3d_ArrayOfTriangles (aNbTris * 3, 0, Standard_True); |
121 | if (aNbTrisTube != 0) |
122 | { |
123 | gp_Ax3 aSystem (theAxis.Location(), theAxis.Direction()); |
124 | gp_Trsf aTrsf; |
125 | aTrsf.SetTransformation (aSystem, gp_Ax3()); |
126 | |
127 | Prs3d_ToolCylinder aTool (theTubeRadius, theTubeRadius, aTubeLength, theNbFacettes, 1); |
128 | aTool.FillArray (anArray, aTrsf); |
129 | } |
130 | |
131 | if (aNbTrisCone != 0) |
132 | { |
133 | gp_Pnt aConeOrigin = theAxis.Location().Translated (gp_Vec (theAxis.Direction().X() * aTubeLength, |
134 | theAxis.Direction().Y() * aTubeLength, |
135 | theAxis.Direction().Z() * aTubeLength)); |
136 | gp_Ax3 aSystem (aConeOrigin, theAxis.Direction()); |
137 | gp_Trsf aTrsf; |
138 | aTrsf.SetTransformation (aSystem, gp_Ax3()); |
139 | { |
140 | Prs3d_ToolDisk aTool (0.0, theConeRadius, theNbFacettes, 1); |
141 | aTool.FillArray (anArray, aTrsf); |
142 | } |
143 | { |
144 | Prs3d_ToolCylinder aTool (theConeRadius, 0.0, theConeLength, theNbFacettes, 1); |
145 | aTool.FillArray (anArray, aTrsf); |
146 | } |
147 | } |
148 | |
149 | return anArray; |
150 | } |