1 | // |
---|
2 | // ******************************************************************** |
---|
3 | // * License and Disclaimer * |
---|
4 | // * * |
---|
5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
7 | // * conditions of the Geant4 Software License, included in the file * |
---|
8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
9 | // * include a list of copyright holders. * |
---|
10 | // * * |
---|
11 | // * Neither the authors of this software system, nor their employing * |
---|
12 | // * institutes,nor the agencies providing financial support for this * |
---|
13 | // * work make any representation or warranty, express or implied, * |
---|
14 | // * regarding this software system or assume any liability for its * |
---|
15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
16 | // * for the full disclaimer and the limitation of liability. * |
---|
17 | // * * |
---|
18 | // * This code implementation is the result of the scientific and * |
---|
19 | // * technical work of the GEANT4 collaboration. * |
---|
20 | // * By using, copying, modifying or distributing the software (or * |
---|
21 | // * any work based on the software) you agree to acknowledge its * |
---|
22 | // * use in resulting scientific publications, and indicate your * |
---|
23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
24 | // ******************************************************************** |
---|
25 | // |
---|
26 | // |
---|
27 | // $Id: G4NURBStubesector.cc,v 1.12 2006/06/29 19:06:55 gunter Exp $ |
---|
28 | // GEANT4 tag $Name: $ |
---|
29 | // |
---|
30 | // |
---|
31 | // Olivier Crumeyrolle 12 September 1996 |
---|
32 | |
---|
33 | // Tubesector builder implementation |
---|
34 | // OC 290896 |
---|
35 | |
---|
36 | #include "G4NURBStubesector.hh" |
---|
37 | #include <sstream> |
---|
38 | |
---|
39 | G4NURBStubesector::G4NURBStubesector(G4double r, G4double R, |
---|
40 | G4double DZ, G4double PHI1, G4double PHI2) |
---|
41 | : G4NURBS( 2, 3, // linear along U, quadratic along V |
---|
42 | 5, DecideNbrCtrlPts(PHI1, PHI2), |
---|
43 | // rectangle along U, required stuff along V |
---|
44 | // we must use a static function which |
---|
45 | // take the two angles because the |
---|
46 | // mother constructor is initialised |
---|
47 | // before everything |
---|
48 | Regular, // the knot vector along U will be generated |
---|
49 | RegularRep ) // circular like knot vector also |
---|
50 | { |
---|
51 | // check angles |
---|
52 | G4double deltaPHI = PHI2-PHI1; |
---|
53 | while (deltaPHI <= 0) { PHI2 += twopi; deltaPHI += twopi; }; |
---|
54 | |
---|
55 | G4int f = (int)floor(deltaPHI / (halfpi)); //number of pi/2 arcs |
---|
56 | |
---|
57 | const G4double mr = (r+R)/2; |
---|
58 | |
---|
59 | const G4double cp1 = std::cos(PHI1); |
---|
60 | const G4double sp1 = std::sin(PHI1); |
---|
61 | const G4double cp2 = std::cos(PHI2); |
---|
62 | const G4double sp2 = std::sin(PHI2); |
---|
63 | |
---|
64 | |
---|
65 | // define control points |
---|
66 | CP(mpCtrlPts[ 0] , cp1*mr, sp1*mr, 0, 1 ); |
---|
67 | CP(mpCtrlPts[ 1] , cp1*mr, sp1*mr, 0, 1 ); |
---|
68 | CP(mpCtrlPts[ 2] , cp1*mr, sp1*mr, 0, 1 ); |
---|
69 | CP(mpCtrlPts[ 3] , cp1*mr, sp1*mr, 0, 1 ); |
---|
70 | CP(mpCtrlPts[ 4] , cp1*mr, sp1*mr, 0, 1 ); |
---|
71 | |
---|
72 | CP(mpCtrlPts[ 5] , cp1*mr, sp1*mr, 0, 1 ); |
---|
73 | CP(mpCtrlPts[ 6] , cp1*mr, sp1*mr, 0, 1 ); |
---|
74 | CP(mpCtrlPts[ 7] , cp1*mr, sp1*mr, 0, 1 ); |
---|
75 | CP(mpCtrlPts[ 8] , cp1*mr, sp1*mr, 0, 1 ); |
---|
76 | CP(mpCtrlPts[ 9] , cp1*mr, sp1*mr, 0, 1 ); |
---|
77 | |
---|
78 | CP(mpCtrlPts[10] , cp1*r, sp1*r, DZ, 1 ); |
---|
79 | CP(mpCtrlPts[11] , cp1*R, sp1*R, DZ, 1 ); |
---|
80 | CP(mpCtrlPts[12] , cp1*R, sp1*R, -DZ, 1 ); |
---|
81 | CP(mpCtrlPts[13] , cp1*r, sp1*r, -DZ, 1 ); |
---|
82 | CP(mpCtrlPts[14] , cp1*r, sp1*r, DZ, 1 ); |
---|
83 | |
---|
84 | t_indCtrlPt i = 15; |
---|
85 | G4double srcAngle = PHI1; |
---|
86 | G4double deltaAngleo2; |
---|
87 | |
---|
88 | G4double destAngle = halfpi + PHI1; |
---|
89 | |
---|
90 | for(; f > 0; f--) |
---|
91 | { |
---|
92 | // the first arc CP is already Done |
---|
93 | |
---|
94 | deltaAngleo2 = (destAngle - srcAngle) / 2; |
---|
95 | const G4double csa = std::cos(srcAngle); |
---|
96 | const G4double ssa = std::sin(srcAngle); |
---|
97 | const G4double tdao2 = std::tan(deltaAngleo2); |
---|
98 | |
---|
99 | // to calculate the intermediate CP : |
---|
100 | // rotate by srcAngle the (1, tdao2) point |
---|
101 | const t_Coord x = csa - ssa*tdao2; |
---|
102 | const t_Coord y = ssa + csa*tdao2; |
---|
103 | |
---|
104 | // weight of the CP |
---|
105 | const G4Float weight = (std::cos(deltaAngleo2)); |
---|
106 | |
---|
107 | // initialization. postfix ++ because i initialized to 15 |
---|
108 | CP(mpCtrlPts[i++], x*r, y*r, DZ, 1, weight); |
---|
109 | CP(mpCtrlPts[i++], x*R, y*R, DZ, 1, weight); |
---|
110 | CP(mpCtrlPts[i++], x*R, y*R, -DZ, 1, weight); |
---|
111 | CP(mpCtrlPts[i++], x*r, y*r, -DZ, 1, weight); |
---|
112 | CP(mpCtrlPts[i++], x*r, y*r, DZ, 1, weight); |
---|
113 | |
---|
114 | // end CP (which is the first CP of the next arc) |
---|
115 | const G4double cda = std::cos(destAngle); |
---|
116 | const G4double sda = std::sin(destAngle); |
---|
117 | CP(mpCtrlPts[i++], cda*r, sda*r, DZ, 1); |
---|
118 | CP(mpCtrlPts[i++], cda*R, sda*R, DZ, 1); |
---|
119 | CP(mpCtrlPts[i++], cda*R, sda*R, -DZ, 1); |
---|
120 | CP(mpCtrlPts[i++], cda*r, sda*r, -DZ, 1); |
---|
121 | CP(mpCtrlPts[i++], cda*r, sda*r, DZ, 1); |
---|
122 | |
---|
123 | // prepare next arc |
---|
124 | srcAngle = destAngle; |
---|
125 | destAngle += halfpi; |
---|
126 | } |
---|
127 | |
---|
128 | // f == 0, final Arc |
---|
129 | // could be handled in the loops |
---|
130 | |
---|
131 | destAngle = PHI2; |
---|
132 | deltaAngleo2 = (destAngle - srcAngle) / 2; |
---|
133 | const G4double csa = std::cos(srcAngle); |
---|
134 | const G4double ssa = std::sin(srcAngle); |
---|
135 | const G4double tdao2 = std::tan(deltaAngleo2); |
---|
136 | |
---|
137 | // to calculate the intermediate CP : |
---|
138 | // rotate by srcAngle the (1, tdao2) point |
---|
139 | const t_Coord x = csa - ssa*tdao2; |
---|
140 | const t_Coord y = ssa + csa*tdao2; |
---|
141 | |
---|
142 | // weight of the CP |
---|
143 | const G4Float weight = (std::cos(deltaAngleo2)); |
---|
144 | |
---|
145 | // initialization. |
---|
146 | CP(mpCtrlPts[i++], x*r, y*r, DZ, 1, weight); |
---|
147 | CP(mpCtrlPts[i++], x*R, y*R, DZ, 1, weight); |
---|
148 | CP(mpCtrlPts[i++], x*R, y*R, -DZ, 1, weight); |
---|
149 | CP(mpCtrlPts[i++], x*r, y*r, -DZ, 1, weight); |
---|
150 | CP(mpCtrlPts[i++], x*r, y*r, DZ, 1, weight); |
---|
151 | |
---|
152 | // end CP |
---|
153 | const G4double cda = std::cos(destAngle); |
---|
154 | const G4double sda = std::sin(destAngle); |
---|
155 | CP(mpCtrlPts[i++], cda*r, sda*r, DZ, 1); |
---|
156 | CP(mpCtrlPts[i++], cda*R, sda*R, DZ, 1); |
---|
157 | CP(mpCtrlPts[i++], cda*R, sda*R, -DZ, 1); |
---|
158 | CP(mpCtrlPts[i++], cda*r, sda*r, -DZ, 1); |
---|
159 | CP(mpCtrlPts[i++], cda*r, sda*r, DZ, 1); |
---|
160 | |
---|
161 | if (i != (mtotnbrCtrlPts - 10) ) |
---|
162 | { |
---|
163 | G4cerr << "\nERROR: G4NURBStubesector::G4NURBStubesector: wrong index," |
---|
164 | << i << " instead of " << (mtotnbrCtrlPts - 10) |
---|
165 | << "\n\tThe tubesector won't be correct." |
---|
166 | << G4endl; |
---|
167 | } |
---|
168 | |
---|
169 | CP(mpCtrlPts[i++] , cp2*mr, sp2*mr, 0, 1); |
---|
170 | CP(mpCtrlPts[i++] , cp2*mr, sp2*mr, 0, 1); |
---|
171 | CP(mpCtrlPts[i++] , cp2*mr, sp2*mr, 0, 1); |
---|
172 | CP(mpCtrlPts[i++] , cp2*mr, sp2*mr, 0, 1); |
---|
173 | CP(mpCtrlPts[i++] , cp2*mr, sp2*mr, 0, 1); |
---|
174 | |
---|
175 | CP(mpCtrlPts[i++] , cp2*mr, sp2*mr, 0, 1); |
---|
176 | CP(mpCtrlPts[i++] , cp2*mr, sp2*mr, 0, 1); |
---|
177 | CP(mpCtrlPts[i++] , cp2*mr, sp2*mr, 0, 1); |
---|
178 | CP(mpCtrlPts[i++] , cp2*mr, sp2*mr, 0, 1); |
---|
179 | CP(mpCtrlPts[i++] , cp2*mr, sp2*mr, 0, 1); |
---|
180 | |
---|
181 | // possible to put a DZ DZ -DZ -DZ DZ column to scratch |
---|
182 | // to a line instead of a point |
---|
183 | |
---|
184 | // creating the nurbs identity |
---|
185 | std::ostringstream tmpstr; |
---|
186 | tmpstr << "Tubs" << " \tPHI1=" << PHI1 << " ; PHI2=" << PHI2; |
---|
187 | mpwhoami = new char [tmpstr.str().length() + 1]; |
---|
188 | mpwhoami = std::strcpy(mpwhoami, tmpstr.str().c_str()); |
---|
189 | } |
---|
190 | |
---|
191 | const char* G4NURBStubesector::Whoami() const |
---|
192 | { |
---|
193 | return mpwhoami; |
---|
194 | } |
---|
195 | |
---|
196 | G4NURBStubesector::~G4NURBStubesector() |
---|
197 | { |
---|
198 | if (mpwhoami) { delete [] mpwhoami; mpwhoami = 0; } |
---|
199 | } |
---|
200 | |
---|
201 | G4NURBStubesector::t_inddCtrlPt |
---|
202 | G4NURBStubesector::DecideNbrCtrlPts(G4double PHI1, G4double PHI2) |
---|
203 | { |
---|
204 | // check angles |
---|
205 | G4double deltaPHI = PHI2-PHI1; |
---|
206 | while (deltaPHI <= 0) { PHI2 += twopi; deltaPHI += twopi; } |
---|
207 | G4double k = deltaPHI / (halfpi); |
---|
208 | |
---|
209 | // G4cerr << " k " << k << G4endl; |
---|
210 | // G4cerr << " fk " << std::floor(k) << G4endl; |
---|
211 | // G4cerr << " ifk " << ((int)(std::floor(k))) << G4endl; |
---|
212 | // G4cerr << " n " << (2*((int)(std::floor(k))) + 7) << G4endl; |
---|
213 | |
---|
214 | return ( 2*((int)(std::floor(k))) + 7 ); |
---|
215 | } |
---|