source: trunk/source/geometry/solids/BREPS/test/CurveTestFunction.hh @ 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: 7.6 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: CurveTestFunction.hh,v 1.9 2007/05/18 10:31:11 gcosmo Exp $
28// GEANT4 tag $Name: geant4-09-04-beta-cand-01 $
29//////////////////////////////////////////////////////////////////////////
30//
31//
32// L. Broglia
33// October 26, 1998
34//
35// Functions wich tested the basic functionnality of the different curves :
36//   - line
37//   - circular curve
38//   - ellipse
39//   - parabola
40//   - hyperbola
41//
42// Test the functionality of Axis2Placement3D and Project
43//
44// These functions are utilized into CurveTest.cc
45//
46
47
48#include "G4Axis2Placement3D.hh"
49#include "G4Curve.hh"
50#include "G4Line.hh"
51#include "G4CircularCurve.hh"
52#include "G4Ellipse.hh"
53#include "G4Parabola.hh"
54#include "G4Hyperbola.hh"
55#include "G4Transform3D.hh"
56#include "CLHEP/Random/RandFlat.h"
57
58
59
60// Printing debug info
61std::ostream& operator<<(std::ostream& os, const G4Axis2Placement3D& p)
62{
63  os << "(" << p.GetLocation()
64     << ", " << p.GetAxis()
65     << ", " << p.GetRefDirection() << ")";
66  return os;
67}
68
69
70std::ostream& operator<<(std::ostream& os, const G4BoundingBox3D& b)
71{
72  os << "(" << b.GetBoxMin()
73     << ", " << b.GetBoxMax() << ")";
74  return os;
75}
76
77
78// Get a random parametric point
79G4double GetRandomP(G4Curve* c)
80{
81  G4double pMax = c->GetPMax();
82  G4double min  = c->GetPStart();
83  G4double max  = c->GetPEnd();
84
85  if ( max<=min && pMax>0) 
86    max+= pMax;
87 
88  G4double r= CLHEP::RandFlat::shoot(min, max);
89 
90  if (pMax>0 && r>=pMax) 
91    r-= pMax;
92 
93  return r;
94}
95
96
97// Test basic functionality common to curves
98void TestCurve(G4Curve* c)
99{
100  // bounds
101  G4cout << "  GetStartPoint  : " << c->GetStart()  << G4endl;
102  G4cout << "  GetEndPoint    : " << c->GetEnd()    << G4endl;
103  G4cout << "  GetPStartPoint : " << c->GetPStart() << G4endl;
104  G4cout << "  GetPEndPoint   : " << c->GetPEnd()   << G4endl;
105  G4cout << "  GetPMax        : " << c->GetPMax()   << G4endl;
106  G4cout << "  u -> GetPoint() -> p -> GetPPoint() -> u2" << G4endl;
107
108  G4int i;
109  for (i=0; i<1000; i++) 
110  {
111    G4double  u    = GetRandomP(c);
112    G4Point3D p    = c->GetPoint(u);
113    G4double  u2   = c->GetPPoint(p);
114    G4double  pMax = c->GetPMax();
115
116    if (pMax>0) 
117      u2-= std::floor((u2-u)/pMax+0.5)*pMax;
118   
119    G4bool error= std::abs(u-u2) > 0.0001;
120   
121    if (i<5 || error) 
122    {
123      G4cout << " u : " << u << " p: " << p
124             << " u2: " << u2 << G4endl;
125     
126      if (error) 
127      {
128        G4cout << "    Error: u != u2 !" << G4endl;
129        exit(EXIT_FAILURE);
130      }
131    }
132
133    if (!c->IsPOn(u)) 
134    {
135      G4cout << "    Error: u is not on the curve!" << G4endl;
136      exit(EXIT_FAILURE);
137    }
138  }
139
140  const G4BoundingBox3D& bBox= *(c->BBox());
141  G4cout << "  BBox: " << bBox << G4endl;
142  G4BoundingBox3D bBox2(c->GetStart(), c->GetEnd());
143 
144  for (i=0; i<1000; i++) 
145    bBox2.Extend(c->GetPoint(GetRandomP(c)));
146 
147  G4cout << "  BBox from random points: " << bBox2 << G4endl;
148  G4cout << "  empty space around it when put in BBox:" << G4endl;
149 
150  G4Vector3D max= bBox.GetBoxMax()-bBox2.GetBoxMax();
151  G4Vector3D min= bBox2.GetBoxMin()-bBox.GetBoxMin();
152 
153  G4cout << " min x: " << min.x() << " max x: " << max.x()
154         << "\n min y: " << min.y() << " max y: " << max.y()
155         << "\n min z: " << min.z() << " max z: " << max.z() << G4endl;
156}
157
158
159// Test G4Axis2Placement3D
160void TestPlacement(G4Axis2Placement3D* p)
161{
162  G4cout << "G4Axis2Placement3D " << p->GetLocation() << " " << p->GetAxis()
163         << " " << p->GetRefDirection() << G4endl;
164
165  G4cout << "  coordinate vectors:" << G4endl;
166
167  G4cout << " p[1]: " << p->GetPX() 
168         << "\n p[2]: " << p->GetPY()
169         << "\n p[3]: " << p->GetPZ() << G4endl;
170
171  G4cout << " p[1].p[2]: " << p->GetPX()*p->GetPY()
172         << "\n p[3]-(p[1]xp[2]): "<< p->GetPZ()-(p->GetPX().cross(p->GetPY()))
173         << G4endl;
174
175  G4cout << "  coordinate vectors computed from the transformation:" << G4endl;
176
177  G4cout << " p[1]: " << p->GetFromPlacementCoordinates()*G4Point3D(1, 0, 0)
178         << "\n p[2]: " << p->GetFromPlacementCoordinates()*G4Point3D(0, 1, 0)
179         << "\n p[3]: " << p->GetFromPlacementCoordinates()*G4Point3D(0, 0, 1)
180         << G4endl;
181 
182  G4cout << "  coordinate vectors in placement coordinate system:";
183
184  G4cout << "\n   " << p->GetToPlacementCoordinates()*p->GetPX()
185         << "\n   " << p->GetToPlacementCoordinates()*p->GetPY()
186         << "\n   " << p->GetToPlacementCoordinates()*p->GetPZ() << G4endl;
187}
188
189
190// Test the project function
191void TestProject(G4Curve* c, const G4Transform3D& tr)
192{
193  G4int i;
194  G4Curve*   projC = c->Project(tr);
195
196  for (i=0; i<1000; i++) 
197  {
198    G4double  u  = GetRandomP(c);
199    G4Point3D p1 = tr*c->GetPoint(u);
200    p1.setZ(0);
201
202    G4Point3D p2 = projC->GetPoint(u);
203    G4bool error = false;
204 
205    if (std::abs(p2.z())>0.0001) 
206    {
207      error= true;
208      G4cout << "Error: the projection is not in the xy plane!" << G4endl;
209    }
210
211    if ((p1-p2).mag()>0.001) 
212    {
213      error= true;
214      G4cout << "Error: the two projected points should be the same!" << G4endl;
215    }
216
217    if (error) 
218    {
219      G4cout << "u: " << u << G4endl;
220     
221      G4cout << "point on original curve:\n" << c->GetPoint(u)
222             << "\n projected: " << tr*c->GetPoint(u) << G4endl;
223     
224      G4cout << "point on projected curve: " << projC->GetPoint(u) << G4endl;
225     
226      u= -u;
227      G4cout << "u: " << u << G4endl;
228     
229      G4cout << "point on original curve:\n" << c->GetPoint(u)
230             << "\n projected: " << tr*c->GetPoint(u) << G4endl;
231     
232      G4cout << "point on projected curve:\n" << projC->GetPoint(u) << G4endl;
233     
234      u= -u; u+= pi;
235      G4cout << "u: " << u << G4endl;
236     
237      G4cout << "point on original curve:\n" << c->GetPoint(u)
238             << "\n projected: " << tr*c->GetPoint(u) << G4endl;
239     
240      G4cout << "\npoint on projected curve: " << projC->GetPoint(u) << G4endl;
241     
242      u= -u;
243      G4cout << "u: " << u << G4endl;
244     
245      G4cout << "point on original curve:\n" << c->GetPoint(u)
246             << "\n projected: " << tr*c->GetPoint(u) << G4endl;
247     
248      G4cout << "point on projected curve: " << projC->GetPoint(u) << G4endl;
249     
250      exit(EXIT_FAILURE);
251    }
252  }
253}
Note: See TracBrowser for help on using the repository browser.