source: trunk/source/geometry/solids/test/testPointOnSurface.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: 18.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// $Id: testPointOnSurface.cc,v 1.5 2007/02/12 11:29:23 gcosmo Exp $
28// GEANT4 tag $Name: geant4-09-04-beta-cand-01 $
29//
30//
31// --------------------------------------------------------------
32//
33// Test for GetPointOnSurface() method of various solids.
34// Returns 0 if generated random points are located on surface.
35//
36// Author: Dionysios Anninos
37//
38// --------------------------------------------------------------
39#include <assert.h>
40#include <cmath>
41
42#include "globals.hh"
43#include "geomdefs.hh"
44
45#include "G4TwoVector.hh"
46#include "G4ThreeVector.hh"
47
48#include "G4Tubs.hh"
49#include "G4Ellipsoid.hh"
50#include "G4EllipticalTube.hh"
51#include "G4Hype.hh"
52#include "G4Orb.hh"
53#include "G4Sphere.hh"
54#include "G4Box.hh"
55#include "G4Torus.hh"
56#include "G4Trap.hh"
57#include "G4Cons.hh"
58#include "G4Para.hh"
59#include "G4Trd.hh"
60#include "G4Polycone.hh"
61#include "G4Tet.hh"
62#include "G4Polyhedra.hh"
63#include "G4EllipticalCone.hh"
64#include "G4ExtrudedSolid.hh"
65
66#include "G4Timer.hh"
67#include "Randomize.hh"
68
69#include "G4RotationMatrix.hh"
70#include "G4AffineTransform.hh"
71#include "G4VoxelLimits.hh"
72
73G4bool checkBox(G4int N)
74{
75 
76  G4cout<<"**************************************"<<G4endl;
77  G4cout<<"************* G4BOX ******************"<<G4endl;
78  G4cout<<"**************************************"<<G4endl<<G4endl;
79
80  G4ThreeVector point;
81  G4bool what = true; 
82  G4int i=0,n=0;
83  EInside surf;
84 
85  G4Timer time;
86 
87  G4Box  t1("Solid Box #1", 
88            20*cm,
89            20*cm,
90            20*cm);
91 
92  time.Start();
93 
94  for(i=0; i<N; i++)
95  {
96    point = t1.GetPointOnSurface();
97    surf  = t1.Inside(point);
98    if(surf != kSurface){ n++; what = false; } 
99  }
100 
101  time.Stop();
102 
103  G4cout <<" Check Box had "<<n<<" inconsistencies..."<< G4endl; 
104  G4cout <<" Time taken was: "<<time.GetRealElapsed()<<" seconds."<<G4endl<<G4endl;
105  return what;
106}
107
108G4bool checkEllipsoid(G4int N)
109{
110  G4cout<<"**************************************"<<G4endl;
111  G4cout<<"************* G4ELLIPSOID ************"<<G4endl;
112  G4cout<<"**************************************"<<G4endl<<G4endl;
113 
114  G4ThreeVector point;
115  G4bool what = true; 
116  G4int i=0,n=0;
117  EInside surf;
118 
119  G4Timer time;
120 
121  G4Ellipsoid t1("Solid Ellipsoid #1", 
122                 20*cm,
123                 15*cm,
124                 35*cm,
125                 -10*cm,
126                  10*cm);
127  time.Start();
128 
129  for(i=0; i<N; i++)
130  {
131    point = t1.GetPointOnSurface();
132    surf  = t1.Inside(point);
133    if(surf != kSurface){ n++; what = false; } 
134  }
135 
136  time.Stop();
137 
138  G4cout <<" Check Ellipsoid had "<<n<<" inconsistencies..."<< G4endl;
139  G4cout <<" Time taken was: "<<time.GetRealElapsed()<<" seconds."<<G4endl<<G4endl;
140  return what;
141}
142
143G4bool checkHype(G4int N)
144{
145  G4cout<<"**************************************"<<G4endl;
146  G4cout<<"************* G4HYPE *****************"<<G4endl;
147  G4cout<<"**************************************"<<G4endl<<G4endl;
148 
149G4ThreeVector point;
150  G4bool what = true; 
151  G4int i=0,n=0;
152  EInside surf;
153 
154  G4Timer time;
155 
156  G4Hype t1("Solid Hype #1", 
157            10*cm,
158            20*cm,
159            75*deg,
160            75*deg,
161            10*cm);
162 
163  time.Start();
164 
165  for(i=0; i<N; i++)
166  {
167    point = t1.GetPointOnSurface();
168    surf  = t1.Inside(point);
169    if(surf != kSurface){ n++; what = false; } 
170  }
171 
172  time.Stop();
173 
174  G4cout <<" Check Hype had "<<n<<" inconsistencies"<< G4endl; 
175  G4cout <<" Time taken was: "<<time.GetRealElapsed()<<" seconds."<<G4endl<<G4endl;
176  return what;
177}
178
179G4bool checkEllipticalTube(G4int N)
180{
181  G4cout<<"**************************************"<<G4endl;
182  G4cout<<"************* G4ELLIPTICALTUBE *******"<<G4endl;
183  G4cout<<"**************************************"<<G4endl<<G4endl;
184 
185  G4ThreeVector point;
186  G4bool what = true; 
187  G4int i=0,n=0;
188  EInside surf;
189 
190  G4Timer time;
191 
192  G4EllipticalTube t1("Solid Ell Tube #1", 
193                      10*cm,
194                      20*cm,
195                      15*cm);
196 
197  time.Start();
198
199  for(i=0; i<N; i++)
200  {
201    point = t1.GetPointOnSurface();
202    surf  = t1.Inside(point);
203    if(surf != kSurface){ n++; what = false; } 
204  }
205 
206  time.Stop();
207 
208  G4cout <<" Check EllTube had "<<n<<" inconsistencies"<< G4endl; 
209  G4cout <<" Time taken was: "<<time.GetRealElapsed()<<" seconds."<<G4endl<<G4endl;
210  return what;
211}
212
213G4bool checkOrb(G4int N)
214{
215  G4cout<<"**************************************"<<G4endl;
216  G4cout<<"************* G4ORB ******************"<<G4endl;
217  G4cout<<"**************************************"<<G4endl<<G4endl;
218 
219  G4ThreeVector point;
220  G4bool what = true; 
221  G4int i=0,n=0;
222  EInside surf;
223 
224  G4Timer time;
225
226  G4Orb t1("Solid Orb #1", 
227           10*cm);
228
229  time.Start();
230
231  for(i=0; i<N; i++)
232  {
233    point = t1.GetPointOnSurface();
234    surf  = t1.Inside(point);
235    if(surf != kSurface){ n++; what = false; } 
236  }
237 
238  time.Stop();
239
240  G4cout <<" Check Orb had "<<n<<" inconsistencies"<< G4endl; 
241  G4cout <<" Time taken was: "<<time.GetRealElapsed()<<" seconds."<<G4endl<<G4endl;
242  return what;
243}
244
245G4bool checkTorus(G4int N)
246{
247  G4cout<<"**************************************"<<G4endl;
248  G4cout<<"************* G4TORUS ****************"<<G4endl;
249  G4cout<<"**************************************"<<G4endl<<G4endl;
250 
251  G4ThreeVector point;
252  G4bool what = true;       
253  G4int i=0,n=0;
254  EInside surf;
255 
256  G4Timer time;
257 
258  G4Torus t1("Torus  #1",   
259             5*cm,
260             8*cm,
261             20*cm,
262             33*deg,
263             270*deg);
264 
265  time.Start();
266 
267  for(i=0; i<N; i++)
268  {
269    point = t1.GetPointOnSurface();
270    surf  = t1.Inside(point);
271    if(surf != kSurface){ n++; what = false; } 
272  }
273   
274  time.Stop();
275 
276  G4cout <<" Check Torus had "<<n<<" inconsistencies"<< G4endl; 
277  G4cout <<" Time taken was: "<<time.GetRealElapsed()<<" seconds."<<G4endl<<G4endl;
278  return what;
279}
280
281G4bool checkTubs(G4int N)
282{
283  G4cout<<"**************************************"<<G4endl;
284  G4cout<<"************* G4TUBS *****************"<<G4endl;
285  G4cout<<"**************************************"<<G4endl<<G4endl;
286 
287  G4ThreeVector point;
288  G4bool what = true; 
289  G4int i=0,n=0;
290  EInside surf;
291
292  G4Timer time;
293 
294  G4Tubs t1("Tubs #1", 
295             5*cm,
296             8*cm,
297             11*cm,
298             42*deg,
299             120*deg);
300 
301  time.Start();
302 
303  for(i=0; i<N; i++)
304  {
305    point = t1.GetPointOnSurface();
306    surf  = t1.Inside(point);
307    if(surf != kSurface){ n++; what = false; } 
308  }
309 
310  time.Stop();
311 
312  G4cout <<" Check Tubs had "<<n<<" inconsistencies"<< G4endl; 
313  G4cout <<" Time taken was: "<<time.GetRealElapsed()<<" seconds."<<G4endl<<G4endl;
314  return what;
315}
316
317G4bool checkCons(G4int N)
318{ 
319  G4cout<<"**************************************"<<G4endl;
320  G4cout<<"************* G4CONS *****************"<<G4endl;
321  G4cout<<"**************************************"<<G4endl<<G4endl;
322 
323  G4ThreeVector point;
324  G4bool what = true;   
325  G4int i=0,n=0; 
326  EInside surf;
327 
328  G4Timer time;
329   
330  G4Cons t1("Cons #1", 
331            6*cm, 10*cm,   
332            8*cm, 9*cm, 
333            10*cm,   
334            43*deg,  221*deg);
335 
336  time.Start();
337 
338  for(i=0; i<N; i++)
339  {
340    point = t1.GetPointOnSurface();
341    surf  = t1.Inside(point);
342    if(surf != kSurface){ n++; what = false; } 
343  }
344
345  time.Stop();
346 
347  G4cout <<" Check Cons had "<<n<<" inconsistencies"<< G4endl; 
348  G4cout <<" Time taken was: "<<time.GetRealElapsed()<<" seconds."<<G4endl<<G4endl;
349  return what;
350}
351
352G4bool checkTrap(G4int N)
353{
354  G4cout<<"**************************************"<<G4endl;
355  G4cout<<"************* G4TRAP *****************"<<G4endl;
356  G4cout<<"**************************************"<<G4endl<<G4endl;
357 
358  G4ThreeVector point;
359  G4bool what = true; 
360  G4int i=0,n=0;
361  EInside surf;
362 
363  G4Timer time;
364   
365  G4Trap t1("Trap #1", 
366            20*mm,  10*deg, 5*deg, 
367            5*mm,   5*mm,   10*mm,   
368            20*deg, 4*mm,   7*mm, 11*mm, 20*deg);
369 
370  time.Start();
371 
372  for(i=0; i<N; i++)
373  {
374    point = t1.GetPointOnSurface();
375    surf  = t1.Inside(point);
376    if(surf != kSurface){ n++; what = false; } 
377  }
378 
379  time.Stop();
380 
381  G4cout <<" Check Trap had "<<n<<" inconsistencies"<< G4endl; 
382  G4cout <<" Time taken was: "<<time.GetRealElapsed()<<" seconds."<<G4endl<<G4endl;
383  return what;
384}
385
386G4bool checkPara(G4int N)
387{
388  G4cout<<"**************************************"<<G4endl;
389  G4cout<<"************* G4PARA *****************"<<G4endl;
390  G4cout<<"**************************************"<<G4endl<<G4endl;
391 
392  G4ThreeVector point;
393  G4bool what = true; 
394  G4int i=0,n=0;
395  EInside surf;
396   
397  G4Timer time;
398
399  G4Para t1("Para #1", 
400            5*mm,   10*mm,  20*mm, 
401            15*deg, 20*deg, 70*deg);
402
403  time.Start();
404 
405  for(i=0; i<N; i++)
406  {
407    point = t1.GetPointOnSurface();
408    surf  = t1.Inside(point);
409    if(surf != kSurface){ n++; what = false; } 
410  }
411 
412  time.Stop();
413
414  G4cout <<" Check Para had "<<n<<" inconsistencies"<< G4endl;
415  G4cout <<" Time taken was: "<<time.GetRealElapsed()<<" seconds."<<G4endl<<G4endl;
416  return what;
417}
418
419G4bool checkTrd(G4int N)
420{
421  G4cout<<"**************************************"<<G4endl;
422  G4cout<<"************* G4TRD ******************"<<G4endl;
423  G4cout<<"**************************************"<<G4endl<<G4endl;
424   
425  G4ThreeVector point;
426  G4bool what = true; 
427  G4int i=0,n=0;
428  EInside surf;
429   
430  G4Timer time;
431
432  G4Trd t1("Trd #1", 
433            10*mm,  6*mm,  12*mm, 
434            8*mm,  15*mm);
435 
436  time.Start();
437
438  for(i=0; i<N; i++)
439  {
440    point = t1.GetPointOnSurface();
441    surf  = t1.Inside(point);
442    if(surf != kSurface){ n++; what = false; } 
443  }
444 
445  time.Stop();
446
447  G4cout <<" Check Trd had "<<n<<" inconsistencies"<< G4endl; 
448  G4cout <<" Time taken was: "<<time.GetRealElapsed()<<" seconds."<<G4endl<<G4endl;
449  return what;
450}
451
452G4bool checkSphere(G4int N)
453{
454  G4cout<<"**************************************"<<G4endl;
455  G4cout<<"************* G4SPHERE ***************"<<G4endl;
456  G4cout<<"**************************************"<<G4endl<<G4endl;
457 
458  G4ThreeVector point;
459  G4bool what = true; 
460  G4int i=0,n=0;
461  EInside surf;
462
463  G4Timer time;
464   
465  G4Sphere t1("Sphere", 
466              8*mm,  12*mm,     
467              43*deg,350*deg, 
468              21*deg,50*deg); 
469 
470  time.Start();
471   
472  for(i=0; i<N; i++)
473  {
474    point = t1.GetPointOnSurface();
475    surf  = t1.Inside(point);
476    if(surf != kSurface){ n++; what = false; } 
477  }
478
479  time.Stop();
480 
481  G4cout <<" Check Sphere had "<<n<<" inconsistencies"<< G4endl; 
482  G4cout <<" Time taken was: "<<time.GetRealElapsed()<<" seconds."<<G4endl<<G4endl;
483  return what;
484} 
485
486G4bool checkPolycone(G4int N)
487{
488  G4cout<<"**************************************"<<G4endl;
489  G4cout<<"************* G4POLYCONE *************"<<G4endl;
490  G4cout<<"**************************************"<<G4endl<<G4endl;
491 
492  G4ThreeVector point;
493  G4bool what = true; 
494  G4int i=0,n=0;
495  EInside surf;
496       
497  G4double zPlanes[5] = {0., 1., 3.,  5., 10.};
498  G4double rInner[5]  = {6., 7., 2.,  2., 10.};
499  G4double rOuter[5]  = {8., 8., 10.,10., 15.};     
500 
501  G4Polycone t1("aPcone", 
502                269*deg, 342*deg,       
503                5,zPlanes,rInner,rOuter); 
504 
505  G4Timer time;
506  time.Start();
507   
508  for(i=0; i<N; i++)
509  {
510    point = t1.GetPointOnSurface();
511    surf  = t1.Inside(point);
512    if(surf != kSurface){ n++; what = false; } 
513  }
514 
515  time.Stop();
516 
517  G4cout <<" Check PolyCone had "<<n<<" inconsistencies"<< G4endl; 
518  G4cout <<" Time taken was: "<<time.GetRealElapsed()<<" seconds."<<G4endl<<G4endl;
519  return what;
520} 
521
522G4bool checkTet(G4int N)
523{
524  G4cout<<"**************************************"<<G4endl;
525  G4cout<<"************* G4TET ******************"<<G4endl;
526  G4cout<<"**************************************"<<G4endl<<G4endl;
527 
528  G4ThreeVector point;
529  G4bool what = true; 
530  G4int i=0,n=0;
531  EInside surf;
532   
533  G4Tet t1("aTet", 
534           G4ThreeVector(2.*cm,0.,10.*cm),
535           G4ThreeVector(0.,3.*cm,0.*cm),
536           G4ThreeVector(10.,10.*cm,5.*cm),
537           G4ThreeVector(0.*cm,5.*cm,5.*cm)); 
538 
539  G4Timer time;
540  time.Start();
541 
542  for(i=0; i<N; i++)
543  {
544    point = t1.GetPointOnSurface();
545    surf  = t1.Inside(point);
546    if(surf != kSurface){ n++; what = false; } 
547  }
548
549  time.Stop();
550 
551  G4cout <<" Check Tet had "<<n<<" inconsistencies"<< G4endl; 
552  G4cout <<" Time taken was: "<<time.GetRealElapsed()<<" seconds."<<G4endl<<G4endl;
553  return what;
554}
555
556G4bool checkPolyhedra(G4int N)
557{
558  G4cout<<"**************************************"<<G4endl;
559  G4cout<<"************* G4POLYHEDRA ************"<<G4endl;
560  G4cout<<"**************************************"<<G4endl<<G4endl;
561 
562  G4ThreeVector point;
563  G4bool what = true;   
564  G4int i=0,n=0;
565  EInside surf;
566       
567  G4double zPlanes[5] = {-1., 10., 15., 25., 30.};
568  G4double rInner[5]  = {0., 5., 0.,  7., 1.};
569  G4double rOuter[5]  = {21., 6., 15., 15., 38.}; 
570   
571//   G4double z[10] = {30.,25.,15.,10.,-1.,-1.,10.,15.,25.,30.};
572//   G4double r[10] = {1.,7.,0.,5.,0.,21.,6.,15.,15.,38.};
573   
574  G4Polyhedra t1("aPhedra", 
575                53.*deg, 163.*deg,         
576                8,5,zPlanes,rInner,rOuter); 
577     
578//   G4Polyhedra t1("aPhedra", 
579//               53.*deg, 163.*deg,         
580//               8, 10, r, z);
581 
582  G4Timer time;
583  time.Start();
584 
585  for(i=0; i<N; i++)
586  {
587    point = t1.GetPointOnSurface(); 
588    surf  = t1.Inside(point);
589    if(surf != kSurface)
590    { 
591      n++; what = false;
592      G4cout <<" x "<<point.x()<<" y "<<point.y()<<" z "<<point.z()<<G4endl;
593    } 
594  }
595 
596  time.Stop();
597
598  G4cout <<" Check Polyhedra had "<<n<<" inconsistencies"<< G4endl; 
599  G4cout <<" Time taken was: "<<time.GetRealElapsed()<<" seconds."<<G4endl<<G4endl;
600  return what;
601}   
602
603G4bool checkEllipticalCone(G4int N)
604{
605  G4cout<<"**************************************"<<G4endl;
606  G4cout<<"************* G4ELLIPTICALCONE *******"<<G4endl;
607  G4cout<<"**************************************"<<G4endl<<G4endl;
608 
609  G4ThreeVector point;
610  G4bool what = true;   
611  G4int i=0,n=0;
612  EInside surf;
613       
614  G4EllipticalCone t1("aElliCone", 
615                      20*cm,25*cm,20*cm, 10*cm); 
616   
617  G4Timer time;
618  time.Start();
619 
620  for(i=0; i<N; i++)
621  {
622    point = t1.GetPointOnSurface(); 
623    surf  = t1.Inside(point);
624    if(surf != kSurface){ n++; what = false; } 
625  }
626
627  time.Stop();
628 
629  G4cout <<" Check EllipticalCone had "<<n<<" inconsistencies"<< G4endl; 
630  G4cout <<" Time taken was: "<<time.GetRealElapsed()<<" seconds."<<G4endl<<G4endl;
631  return what;
632}   
633
634G4bool checkExtrudedSolid(G4int N)
635{
636  G4cout<<"**************************************"<<G4endl;
637  G4cout<<"************* G4EXTRUDEDSOLID ********"<<G4endl;
638  G4cout<<"**************************************"<<G4endl<<G4endl;
639 
640  G4ThreeVector point;
641  G4bool what = true;   
642  G4int i=0,n=0;
643  EInside surf;
644       
645  std::vector<G4TwoVector> polygon;
646  polygon.push_back(G4TwoVector(-30.*cm, -30.*cm));
647  polygon.push_back(G4TwoVector(-30.*cm,  30.*cm));
648  polygon.push_back(G4TwoVector( 30.*cm,  30.*cm));
649  polygon.push_back(G4TwoVector( 30.*cm, -30.*cm));
650  polygon.push_back(G4TwoVector( 15.*cm, -30.*cm));
651  polygon.push_back(G4TwoVector( 15.*cm,  15.*cm));
652  polygon.push_back(G4TwoVector(-15.*cm,  15.*cm));
653  polygon.push_back(G4TwoVector(-15.*cm, -30.*cm));
654
655  G4ExtrudedSolid t1("Concave_XTRU", polygon, 25.*cm,
656                     G4TwoVector(-20.*cm, 10.*cm), 1.5, G4TwoVector(), 0.5);
657
658  G4Timer time;
659  time.Start();
660 
661  for(i=0; i<N; i++)
662  {
663    point = t1.GetPointOnSurface(); 
664    surf  = t1.Inside(point);
665    if(surf != kSurface){ n++; what = false; } 
666  }
667
668  time.Stop();
669 
670  G4cout <<" Check ExtrudedSolid had "<<n<<" inconsistencies"<< G4endl; 
671  G4cout <<" Time taken was: "<<time.GetRealElapsed()<<" seconds."<<G4endl<<G4endl;
672  return what;
673}   
674
675int main() 
676{ 
677  G4bool what;   
678  G4int N = 1000000;
679 
680  G4cout <<G4endl;
681  G4cout <<"********************************************************************************"<<G4endl;
682  G4cout <<"**************** TEST GET POINT ON SURFACE METHOD ******************************"<<G4endl;
683  G4cout <<"******************** FOR "<<N<<" RANDOM POINTS *********************************"<<G4endl;
684  G4cout <<"********************************************************************************"<<G4endl;
685   
686  G4cout <<G4endl<<G4endl;
687
688  what = checkBox(1000000); 
689  what = checkEllipsoid(1000000);   
690  what = checkHype(1000000);       
691  what = checkEllipticalTube(1000000);           
692  what = checkOrb(1000000);   
693  what = checkTorus(1000000);   
694  what = checkTubs(1000000);     
695  what = checkCons(1000000);               
696  what = checkTrap(1000000);         
697  what = checkPara(1000000);       
698  what = checkTrd(1000000);   
699  what = checkSphere(1000000); 
700  what = checkPolycone(1000000);           
701  what = checkTet(1000000);           
702  what = checkPolyhedra(1000000);     
703  what = checkEllipticalCone(1000000);
704  what = checkExtrudedSolid(1000000);
705 
706  G4cout <<G4endl;
707   
708  G4cout <<"********************************************************************************"<<G4endl;
709  G4cout <<"********************** END OF POINT-ON-SURFACE TEST ****************************"<<G4endl;
710  G4cout <<"********************************************************************************"<<G4endl; 
711  G4cout <<G4endl;
712
713  return 0;     
714}
715       
716   
717 
Note: See TracBrowser for help on using the repository browser.