source: trunk/source/geometry/solids/Boolean/test/testG4DisplacedSolid.cc @ 1316

Last change on this file since 1316 was 1316, checked in by garnier, 14 years ago

update geant4-09-04-beta-cand-01 interfaces-V09-03-09 vis-V09-03-08

File size: 14.1 KB
Line 
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//
28// Test for G4DisplacedSolid class
29//
30// 22.11.98 V.Grichine
31// 14.11.99 V.Grichine, modifications for CalculateExtent(...) method
32//
33
34
35
36
37#include <assert.h>
38#include <cmath>
39
40#include "globals.hh"
41#include "geomdefs.hh"
42
43#include "ApproxEqual.hh"
44
45#include "G4ThreeVector.hh"
46#include "G4RotationMatrix.hh"
47#include "G4AffineTransform.hh"
48#include "G4Transform3D.hh"
49#include "G4VoxelLimits.hh"
50
51#include "G4Box.hh"
52#include "G4Cons.hh"
53#include "G4Para.hh"
54#include "G4Sphere.hh"
55#include "G4Torus.hh"
56#include "G4Trap.hh"
57#include "G4Trd.hh"
58#include "G4Tubs.hh"
59
60#include "G4IntersectionSolid.hh"
61#include "G4SubtractionSolid.hh"
62#include "G4UnionSolid.hh"
63
64#include "G4DisplacedSolid.hh"
65
66
67int main()
68{
69    G4ThreeVector pzero(0,0,0), p;
70    G4ThreeVector ponxside(20,0,0),ponyside(0,30,0),ponzside(0,0,40),
71                   ponb2x(10,0,0),ponb2y(0,10,0),ponb2z(0,0,10),
72                   ponb2mx(-10,0,0),ponb2my(0,-10,0),ponb2mz(0,0,-10);
73    G4ThreeVector ponmxside(-20,0,0),ponmyside(0,-30,0),ponmzside(0,0,-40);
74    G4ThreeVector ponzsidey(0,25,40),ponmzsidey(0,25,-40),
75                  ponb2zy(0,5,10),ponb2mzy(0,5,-10) ;
76
77    G4ThreeVector pbigx(100,0,0),pbigy(0,100,0),pbigz(0,0,100);
78    G4ThreeVector pbigmx(-100,0,0),pbigmy(0,-100,0),pbigmz(0,0,-100);
79
80    G4ThreeVector vx(1,0,0),vy(0,1,0),vz(0,0,1);
81    G4ThreeVector vmx(-1,0,0),vmy(0,-1,0),vmz(0,0,-1);
82    G4ThreeVector vxy(1/std::sqrt(2.0),1/std::sqrt(2.0),0);
83    G4ThreeVector vmxy(-1/std::sqrt(2.0),1/std::sqrt(2.0),0);
84    G4ThreeVector vmxmy(-1/std::sqrt(2.0),-1/std::sqrt(2.0),0);
85    G4ThreeVector vxmy(1/std::sqrt(2.0),-1/std::sqrt(2.0),0);
86    G4ThreeVector vxmz(1/std::sqrt(2.0),0,-1/std::sqrt(2.0));
87
88    G4double dist;
89    G4int i;
90    G4ThreeVector *pNorm,norm;
91    G4bool *pgoodNorm,goodNorm,calcNorm=true;
92
93    pNorm=&norm;
94    pgoodNorm=&goodNorm;
95   
96    G4RotationMatrix identity, xRot ;
97   
98// NOTE: xRot = rotation such that x axis->y axis & y axis->-x axis
99
100    xRot.rotateZ(-pi*0.5) ;
101
102    G4Transform3D transform(xRot,pzero) ;
103
104    G4Box b1("Test Box #1",20,30,40);
105    G4Box b2("Test Box #2",10,10,10);
106    G4Box b3("Test Box #3",10,50,10);
107
108    G4Tubs t1("Solid Tube #1",0,50,50,0,360);
109    G4Tubs t2("Hole Tube #2",45,50,50,0,360);
110    G4Tubs t3("Solid cutted Tube #3",0,50,50,0,pi/2.0);
111
112    G4Cons c1("Hollow Full Tube",50,100,50,100,50,0,2*pi),
113           c2("Full Cone",0,50,0,100,50,0,2*pi) ;
114
115    G4IntersectionSolid b1Ib2("b1Intersectionb2",&b1,&b2),
116                        t1Ib2("t1Intersectionb2",&t1,&b2),
117                        c2Ib2("c2Intersectionb2",&c2,&b2) ;
118
119    // passRotT3 should be in 2 octant, while actiRotT3 in 4 one
120
121    G4DisplacedSolid passRotT3("passRotT3",&t3,&xRot,ponb2mx) ;
122    G4DisplacedSolid actiRotT3("actiRotT3",&t3,transform) ;
123    G4DisplacedSolid actiRotB1("actiRotB3",&b1,transform) ;
124    G4DisplacedSolid passRotB2("passRotT3",&b2,&xRot,ponb2mx) ;
125
126    G4ThreeVector pRmaxPlus(50,1,0) ;
127   
128    dist = passRotT3.DistanceToIn(pRmaxPlus,vmx) ;
129    G4cout<<"passRotT3.DistanceToIn(pRmaxPlus,vmx) = "<<dist<<G4endl ;
130
131    dist = actiRotT3.DistanceToIn(pRmaxPlus,vmx) ;
132    G4cout<<"actiRotT3.DistanceToIn(pRmaxPlus,vmx) = "<<dist<<G4endl ;
133
134// Check Inside
135
136    assert(passRotT3.Inside(pzero)==kOutside);
137    assert(passRotT3.Inside(pbigz)==kOutside);
138    assert(passRotT3.Inside(ponb2x)==kOutside);
139    assert(passRotT3.Inside(ponb2y)==kOutside);
140    assert(passRotT3.Inside(ponb2z)==kOutside);
141
142    //    assert(t3.Inside(pzero)==kSurface);
143    //    assert(actiRotT3.Inside(pzero)==kSurface);
144
145    assert(actiRotT3.Inside(pbigz)==kOutside);
146    assert(actiRotT3.Inside(ponb2x)==kSurface);
147    assert(actiRotT3.Inside(ponb2y)==kOutside);
148
149    //    assert(actiRotT3.Inside(ponb2z)==kSurface);
150
151
152// Check Surface Normal
153
154    G4ThreeVector normal;
155
156    normal=actiRotT3.SurfaceNormal(G4ThreeVector(20,0,0));
157    assert(ApproxEqual(normal,G4ThreeVector(0,1,0)));
158
159    normal=passRotT3.SurfaceNormal(G4ThreeVector(-15,0,0));
160    assert(ApproxEqual(normal,G4ThreeVector(0,-1,0)));
161
162    normal=passRotT3.SurfaceNormal(G4ThreeVector(-10,10,0));
163    assert(ApproxEqual(normal,G4ThreeVector(1,0,0)));
164
165    // (0,-1,0) is transformed to (0,1,0) ??
166    //    normal=actiRotT3.SurfaceNormal(ponb2my);
167    //    assert(ApproxEqual(normal,G4ThreeVector(-1,0,0)));
168
169    normal=actiRotT3.SurfaceNormal(G4ThreeVector(1,-1,50));
170    assert(ApproxEqual(normal,G4ThreeVector(0,0,1)));
171
172    normal=actiRotT3.SurfaceNormal(G4ThreeVector(1,-1,-50));
173    assert(ApproxEqual(normal,G4ThreeVector(0,0,-1)));
174
175    normal=passRotT3.SurfaceNormal(G4ThreeVector(-15,1,50));
176    assert(ApproxEqual(normal,G4ThreeVector(0,0,1)));
177
178    normal=passRotT3.SurfaceNormal(G4ThreeVector(-15,1,-50));
179    assert(ApproxEqual(normal,G4ThreeVector(0,0,-1)));
180
181
182// DistanceToOut(P)
183
184    dist=actiRotT3.DistanceToOut(pzero);
185    assert(ApproxEqual(dist,0));
186
187    dist=actiRotT3.DistanceToOut(vx);
188    assert(ApproxEqual(dist,0));
189
190    dist=actiRotT3.DistanceToOut(G4ThreeVector(1,-1,0));
191    assert(ApproxEqual(dist,1));
192
193    dist=passRotT3.DistanceToOut(G4ThreeVector(-20,20,45));
194    assert(ApproxEqual(dist,5));
195
196// DistanceToOut(P,V)
197
198    dist=actiRotT3.DistanceToOut(G4ThreeVector(1,-1,0),vy,
199                                 calcNorm,pgoodNorm,pNorm);
200    assert(ApproxEqual(dist,1)&&ApproxEqual(*pNorm,vy)&&*pgoodNorm);
201
202    dist=actiRotT3.DistanceToOut(G4ThreeVector(1,-1,0),vxmy,
203                                 calcNorm,pgoodNorm,pNorm);
204    assert(ApproxEqual(dist,50-std::sqrt(2.0))&&ApproxEqual(norm,vxmy)&&*pgoodNorm);
205
206    dist=passRotT3.DistanceToOut(G4ThreeVector(-20,10,0),vx,
207                                 calcNorm,pgoodNorm,pNorm);
208    assert(ApproxEqual(dist,10)&&ApproxEqual(norm,vx)&&*pgoodNorm);
209
210    dist=passRotT3.DistanceToOut(G4ThreeVector(-20,10,0),vmy,
211                                 calcNorm,pgoodNorm,pNorm);
212    assert(ApproxEqual(dist,10)&&ApproxEqual(norm,vmy)&&*pgoodNorm);
213
214    dist=passRotT3.DistanceToOut(G4ThreeVector(-20,10,0),vz,
215                                 calcNorm,pgoodNorm,pNorm);
216    assert(ApproxEqual(dist,50)&&ApproxEqual(norm,vz)&&*pgoodNorm);
217
218    dist=passRotT3.DistanceToOut(G4ThreeVector(-20,10,0),vmz,
219                                 calcNorm,pgoodNorm,pNorm);
220    assert(ApproxEqual(dist,50)&&ApproxEqual(norm,vmz)&&*pgoodNorm);
221
222//  G4cout<<"b1.DistanceToOut(ponxside,vy) = "<<dist<<G4endl;
223//  assert(ApproxEqual(dist,0)&&ApproxEqual(*pNorm,vy)&&*pgoodNorm);
224
225
226//DistanceToIn(P)
227
228    dist=actiRotT3.DistanceToIn(G4ThreeVector(10,1,0));
229    assert(ApproxEqual(dist,1));
230
231    dist=actiRotT3.DistanceToIn(ponb2x);
232    assert(ApproxEqual(dist,0));
233
234    dist=passRotT3.DistanceToIn(G4ThreeVector(0,10,0));
235    assert(ApproxEqual(dist,10));
236
237
238
239    // DistanceToIn(P,V)
240
241    dist=passRotT3.DistanceToIn(G4ThreeVector(100,10,0),vmx);
242    assert(ApproxEqual(dist,110));
243
244    dist=actiRotT3.DistanceToIn(G4ThreeVector(-100,-10,0),vx);
245    assert(ApproxEqual(dist,100));
246
247    dist=actiRotT3.DistanceToIn(G4ThreeVector(10,100,0),vmy);
248    assert(ApproxEqual(dist,100));
249
250    dist=passRotT3.DistanceToIn(G4ThreeVector(-20,-100,0),vy);
251    assert(ApproxEqual(dist,100));
252
253    dist=passRotT3.DistanceToIn(pbigz,vmz);
254    assert(ApproxEqual(dist,kInfinity));
255
256    dist=passRotT3.DistanceToIn(pbigmz,vz);
257    assert(ApproxEqual(dist,kInfinity));
258
259    dist=passRotT3.DistanceToIn(pbigx,vxy);
260    assert(ApproxEqual(dist,kInfinity));
261
262    dist=actiRotT3.DistanceToIn(pbigmx,vxy);
263    assert(ApproxEqual(dist,kInfinity));
264
265    dist=passRotB2.DistanceToIn(ponb2x,vmx);
266    assert(ApproxEqual(dist,10.));
267
268
269    // Point on surface
270    G4cout<<G4endl;
271    G4cout<<"Point on surface of 10x10x10 box shifted -10 along x-axis:"<<G4endl<<G4endl;
272    for(i=0;i<10;i++)
273    {
274      p = passRotB2.GetPointOnSurface();
275      G4cout<<p.x()<<"\t\t"<<p.y()<<"\t\t"<<p.z()<<G4endl;
276    }
277    G4cout<<G4endl;
278
279
280
281    // CalculateExtent
282
283    G4VoxelLimits limit ;               // Unlimited
284    G4RotationMatrix noRot ;
285    G4AffineTransform origin ;
286    G4double min,max;
287
288    assert(b1.CalculateExtent(kXAxis,limit,origin,min,max));
289    assert(ApproxEqual(min,-20)&&ApproxEqual(max,20));
290
291    assert(b1.CalculateExtent(kYAxis,limit,origin,min,max));
292    assert(ApproxEqual(min,-30)&&ApproxEqual(max,30));
293
294    assert(b1.CalculateExtent(kZAxis,limit,origin,min,max));
295    assert(ApproxEqual(min,-40)&&ApproxEqual(max,40));
296
297    assert(actiRotT3.CalculateExtent(kXAxis,limit,origin,min,max));
298    G4cout<<"min of actiRotT3.CalculateExtent(kXAxis,limit,origin,min,max) = "
299          <<min<<G4endl ;
300    G4cout<<"max of actiRotT3.CalculateExtent(kXAxis,limit,origin,min,max) = "
301          <<max<<G4endl ;
302    //  assert(ApproxEqual(min,0)&&ApproxEqual(max,50));
303
304    assert(actiRotB1.CalculateExtent(kXAxis,limit,origin,min,max));
305    assert(ApproxEqual(min,-30)&&ApproxEqual(max,30));
306
307
308
309
310    G4ThreeVector pmxmymz(-100,-110,-120);
311    G4AffineTransform tPosOnly(pmxmymz);
312
313    assert(actiRotT3.CalculateExtent(kXAxis,limit,tPosOnly,min,max));
314    G4cout<<"min of actiRotT3.CalculateExtent(kXAxis,limit,tPosOnly,min,max) = "
315          <<min<<G4endl ;
316    G4cout<<"max of actiRotT3.CalculateExtent(kXAxis,limit,tPosOnly,min,max) = "
317          <<max<<G4endl ;
318    //  assert(ApproxEqual(min,-100)&&ApproxEqual(max,-50));
319
320    assert(actiRotB1.CalculateExtent(kXAxis,limit,tPosOnly,min,max));
321    assert(ApproxEqual(min,-130)&&ApproxEqual(max,-70));
322
323    assert(b1.CalculateExtent(kXAxis,limit,tPosOnly,min,max));
324    assert(ApproxEqual(min,-120)&&ApproxEqual(max,-80));
325
326    assert(b1.CalculateExtent(kYAxis,limit,tPosOnly,min,max));
327    assert(ApproxEqual(min,-140)&&ApproxEqual(max,-80));
328
329    assert(b1.CalculateExtent(kZAxis,limit,tPosOnly,min,max));
330    assert(ApproxEqual(min,-160)&&ApproxEqual(max,-80));
331
332    G4RotationMatrix r90Z;
333    r90Z.rotateZ(pi/2);
334    G4AffineTransform tRotZ(r90Z,pzero);
335
336    assert(b1.CalculateExtent(kXAxis,limit,tRotZ,min,max));
337    assert(ApproxEqual(min,-30)&&ApproxEqual(max,30));
338
339    assert(b1.CalculateExtent(kYAxis,limit,tRotZ,min,max));
340    assert(ApproxEqual(min,-20)&&ApproxEqual(max,20));
341
342    assert(b1.CalculateExtent(kZAxis,limit,tRotZ,min,max));
343    assert(ApproxEqual(min,-40)&&ApproxEqual(max,40));
344
345    assert(actiRotB1.CalculateExtent(kXAxis,limit,tRotZ,min,max));
346    assert(ApproxEqual(min,-20)&&ApproxEqual(max,20));
347
348// Check that clipped away
349
350    G4VoxelLimits xClip;
351    xClip.AddLimit(kXAxis,-100,-50);
352    assert(!b1.CalculateExtent(kXAxis,xClip,origin,min,max));
353
354// Assert clipped to volume
355
356    G4VoxelLimits allClip;
357    allClip.AddLimit(kXAxis,-5,+5);
358    allClip.AddLimit(kYAxis,-5,+5);
359    allClip.AddLimit(kZAxis,-5,+5);
360    G4RotationMatrix genRot;
361    genRot.rotateX(pi/6);
362    genRot.rotateY(pi/6);
363    genRot.rotateZ(pi/6);
364    G4AffineTransform tGen(genRot,vx);
365
366    assert(b1.CalculateExtent(kXAxis,allClip,tGen,min,max));
367    assert(ApproxEqual(min,-5)&&ApproxEqual(max,5));
368
369    assert(b1.CalculateExtent(kYAxis,allClip,tGen,min,max));
370    assert(ApproxEqual(min,-5)&&ApproxEqual(max,5));
371
372    assert(b1.CalculateExtent(kZAxis,allClip,tGen,min,max));
373    assert(ApproxEqual(min,-5)&&ApproxEqual(max,5));
374
375    G4VoxelLimits buggyClip2;
376    buggyClip2.AddLimit(kXAxis,5,15);
377
378    assert(b1.CalculateExtent(kXAxis,buggyClip2,origin,min,max));
379    assert(ApproxEqual(min,5)&&ApproxEqual(max,15));
380
381    assert(b1.CalculateExtent(kYAxis,buggyClip2,origin,min,max));
382    assert(ApproxEqual(min,-30)&&ApproxEqual(max,30));
383
384    assert(b1.CalculateExtent(kZAxis,buggyClip2,origin,min,max));
385    assert(ApproxEqual(min,-40)&&ApproxEqual(max,40));
386
387    buggyClip2.AddLimit(kYAxis,5,15);
388
389    assert(b1.CalculateExtent(kXAxis,buggyClip2,origin,min,max));
390    assert(ApproxEqual(min,5)&&ApproxEqual(max,15));
391
392    assert(b1.CalculateExtent(kYAxis,buggyClip2,origin,min,max));
393    assert(ApproxEqual(min,5)&&ApproxEqual(max,15));
394
395    assert(b1.CalculateExtent(kZAxis,buggyClip2,origin,min,max));
396    assert(ApproxEqual(min,-40)&&ApproxEqual(max,40));
397
398    G4VoxelLimits buggyClip1;
399    buggyClip1.AddLimit(kXAxis,-5,+5);
400
401    assert(b1.CalculateExtent(kXAxis,buggyClip1,origin,min,max));
402    assert(ApproxEqual(min,-5)&&ApproxEqual(max,5));
403
404    assert(b1.CalculateExtent(kYAxis,buggyClip1,origin,min,max));
405    assert(ApproxEqual(min,-30)&&ApproxEqual(max,30));
406
407    assert(b1.CalculateExtent(kZAxis,buggyClip1,origin,min,max));
408    assert(ApproxEqual(min,-40)&&ApproxEqual(max,40));
409
410    buggyClip1.AddLimit(kYAxis,-5,+5);
411
412    assert(b1.CalculateExtent(kXAxis,buggyClip1,origin,min,max));
413    assert(ApproxEqual(min,-5)&&ApproxEqual(max,5));
414
415    assert(b1.CalculateExtent(kYAxis,buggyClip1,origin,min,max));
416    assert(ApproxEqual(min,-5)&&ApproxEqual(max,5));
417
418    assert(b1.CalculateExtent(kZAxis,buggyClip1,origin,min,max));
419    assert(ApproxEqual(min,-40)&&ApproxEqual(max,40));
420
421
422  return 0 ;
423}
Note: See TracBrowser for help on using the repository browser.