source: trunk/source/geometry/solids/specific/include/G4VTwistSurface.hh @ 1236

Last change on this file since 1236 was 1228, checked in by garnier, 15 years ago

update geant4.9.3 tag

File size: 15.0 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: G4VTwistSurface.hh,v 1.6 2007/05/11 13:54:28 gcosmo Exp $
28// GEANT4 tag $Name: geant4-09-03 $
29//
30//
31// --------------------------------------------------------------------
32// GEANT 4 class header file
33//
34//
35// G4VTwistSurface
36//
37// Class description:
38//
39//  Abstract base class for boundary surface of G4VSolid.
40
41// Author:
42//   01-Aug-2002 - Kotoyo Hoshina (hoshina@hepburn.s.chiba-u.ac.jp)
43//
44// History:
45//   13-Nov-2003 - O.Link (Oliver.Link@cern.ch), Integration in Geant4
46//                 from original version in Jupiter-2.5.02 application.
47// --------------------------------------------------------------------
48#ifndef __G4VTWISTSURFACE__
49#define __G4VTWISTSURFACE__
50
51#include "G4VSolid.hh"
52#include "geomdefs.hh"
53
54#include "G4RotationMatrix.hh"
55
56#define G4VSURFACENXX 10
57
58class G4VTwistSurface
59{
60 public:  // without description
61
62   enum EValidate      {kDontValidate = 0, kValidateWithTol = 1, 
63                        kValidateWithoutTol = 2, kUninitialized = 3};
64
65 public:  // with description
66
67   G4VTwistSurface (const G4String &name);
68   G4VTwistSurface (const G4String &name,
69               const G4RotationMatrix &rot,
70               const G4ThreeVector    &tlate,
71                     G4int             handedness,
72               const EAxis             axis1,
73               const EAxis             axis2,
74                     G4double          axis0min = -kInfinity,
75                     G4double          axis1min = -kInfinity,
76                     G4double          axis0max = kInfinity,
77                     G4double          axis1max = kInfinity);
78
79   virtual ~G4VTwistSurface();
80
81   virtual G4int     AmIOnLeftSide(const G4ThreeVector &me, 
82                                   const G4ThreeVector &vec, 
83                                         G4bool withTol = true);
84
85   virtual G4double  DistanceToBoundary(      G4int areacode,
86                                              G4ThreeVector &xx,
87                                        const G4ThreeVector &p) ;
88
89
90   virtual G4double  DistanceToIn(const G4ThreeVector &gp,
91                                  const G4ThreeVector &gv,
92                                        G4ThreeVector &gxxbest);
93   virtual G4double  DistanceToOut(const G4ThreeVector &gp,
94                                   const G4ThreeVector &gv,
95                                         G4ThreeVector &gxxbest);
96   virtual G4double  DistanceTo(const G4ThreeVector &gp,
97                                      G4ThreeVector &gxx);
98     
99   virtual G4int     DistanceToSurface(const G4ThreeVector &gp,
100                                       const G4ThreeVector &gv,
101                                             G4ThreeVector gxx[],
102                                             G4double      distance[],
103                                             G4int         areacode[],
104                                             G4bool        isvalid[],
105                                       EValidate validate=kValidateWithTol) = 0;
106
107   virtual G4int     DistanceToSurface(const G4ThreeVector &gp,
108                                             G4ThreeVector gxx[],
109                                             G4double      distance[],
110                                             G4int         areacode[]) = 0;
111                                             
112   void              DebugPrint() const;
113
114   // get methods
115
116   virtual G4ThreeVector GetNormal(const G4ThreeVector &xx,G4bool isGlobal) = 0;
117   
118   virtual G4String      GetName() const { return fName; }
119   virtual void          GetBoundaryParameters(const G4int   &areacode,
120                                               G4ThreeVector &d,
121                                               G4ThreeVector &x0,
122                                               G4int &boundarytype) const;
123   virtual G4ThreeVector GetBoundaryAtPZ(G4int areacode,
124                                         const G4ThreeVector &p) const;
125
126   inline  G4double      DistanceToPlaneWithV(const G4ThreeVector &p,
127                                              const G4ThreeVector &v,
128                                              const G4ThreeVector &x0,
129                                              const G4ThreeVector &n0,
130                                                    G4ThreeVector &xx);
131
132   inline  G4double      DistanceToPlane(const G4ThreeVector &p,
133                                         const G4ThreeVector &x0,
134                                         const G4ThreeVector &n0,
135                                               G4ThreeVector &xx);
136   
137   inline  G4double      DistanceToPlane(const G4ThreeVector &p,
138                                         const G4ThreeVector &x0,
139                                         const G4ThreeVector &t1,
140                                         const G4ThreeVector &t2,
141                                               G4ThreeVector &xx,
142                                               G4ThreeVector &n);
143
144   inline  G4double      DistanceToLine (const G4ThreeVector &p,
145                                         const G4ThreeVector &x0,
146                                         const G4ThreeVector &d,
147                                               G4ThreeVector &xx);
148                                               
149   inline  G4bool IsAxis0    (G4int areacode) const;
150   inline  G4bool IsAxis1    (G4int areacode) const;
151   inline  G4bool IsOutside  (G4int areacode) const;
152   inline  G4bool IsInside   (G4int areacode, G4bool testbitmode = false) const;
153   inline  G4bool IsBoundary (G4int areacode, G4bool testbitmode = false) const;
154   inline  G4bool IsCorner   (G4int areacode, G4bool testbitmode = false) const;
155   inline  G4bool IsValidNorm() const { return fIsValidNorm; }
156           G4bool IsSameBoundary (G4VTwistSurface *surface1, G4int areacode1,
157                                  G4VTwistSurface *surface2, G4int areacode2 ) const;
158   inline  G4int  GetAxisType(G4int areacode, G4int whichaxis) const;
159
160   inline  G4ThreeVector ComputeGlobalPoint     (const G4ThreeVector &lp) const;
161   inline  G4ThreeVector ComputeLocalPoint      (const G4ThreeVector &gp) const;
162   inline  G4ThreeVector ComputeGlobalDirection (const G4ThreeVector &lp) const;
163   inline  G4ThreeVector ComputeLocalDirection  (const G4ThreeVector &gp) const;
164 
165   // set methods
166
167   inline void SetAxis(G4int i, const EAxis axis)  { fAxis[i] = axis; }
168   inline void SetNeighbours(G4VTwistSurface* axis0min, G4VTwistSurface* axis1min, 
169                             G4VTwistSurface* axis0max, G4VTwistSurface* axis1max);
170
171   virtual G4ThreeVector SurfacePoint(G4double , G4double,
172                                      G4bool isGlobal = false ) = 0 ;
173   virtual G4double GetBoundaryMin(G4double) = 0 ;
174   virtual G4double GetBoundaryMax(G4double) = 0 ;
175   virtual G4double GetSurfaceArea() = 0 ;
176   virtual void GetFacets(G4int m, G4int n, G4double xyz[][3],
177                          G4int faces[][4], G4int iside) = 0 ;
178   G4int GetNode( G4int i, G4int j, G4int m, G4int n, G4int iside )  ;
179   G4int GetFace( G4int i, G4int j, G4int m, G4int n, G4int iside )  ;
180   G4int GetEdgeVisibility( G4int i, G4int j, G4int m, G4int n, G4int number, G4int orientation) ;
181
182
183 public:  // without description
184
185   G4VTwistSurface(__void__&);
186     // Fake default constructor for usage restricted to direct object
187     // persistency for clients requiring preallocation of memory for
188     // persistifiable objects.
189
190 protected:  // with description
191 
192   // get methods
193
194   inline  G4VTwistSurface**  GetNeighbours() { return fNeighbours; } 
195   inline  G4int GetNeighbours(G4int areacode, G4VTwistSurface* surfaces[]);
196   inline  G4ThreeVector GetCorner(G4int areacode) const;
197           void GetBoundaryAxis(G4int areacode, EAxis axis[]) const;
198           void GetBoundaryLimit(G4int areacode, G4double limit[]) const;
199   virtual G4int GetAreaCode(const G4ThreeVector &xx, G4bool withtol=true) = 0;
200     
201   // set methods
202
203   virtual void SetBoundary(const G4int         &axiscode, 
204                            const G4ThreeVector &direction,
205                            const G4ThreeVector &x0, 
206                            const G4int         &boundarytype);
207     // areacode must be one of them:
208     // sAxis0 & sAxisMin, sAxis0 & sAxisMax,
209     // sAxis1 & sAxisMin, sAxis1 & sAxisMax.
210     // boundarytype represents the shape of locus
211     // from the start point to end point of boundary.
212     // ex.
213     // sAxisRho = linear line which start point is fixed at origin.
214     // sAxisPhi = part of circle which center placed at the origin.
215                           
216   void SetCorner(G4int areacode, G4double x, G4double y, G4double z);
217
218 private:
219
220   virtual void SetBoundaries() = 0;
221   virtual void SetCorners()    = 0;
222   
223 // data members ---------------------------------------------------------
224
225 public:
226
227   static const G4int sOutside ;
228   static const G4int sInside  ;
229   static const G4int sBoundary;
230   static const G4int sCorner;
231   static const G4int sC0Min1Min;
232   static const G4int sC0Max1Min;
233   static const G4int sC0Max1Max;
234   static const G4int sC0Min1Max;
235   static const G4int sAxisMin;
236   static const G4int sAxisMax;
237   static const G4int sAxisX;
238   static const G4int sAxisY;
239   static const G4int sAxisZ;
240   static const G4int sAxisRho;
241   static const G4int sAxisPhi;
242   static const G4int sAxis0;
243   static const G4int sAxis1;
244   static const G4int sSizeMask;
245   static const G4int sAxisMask;
246   static const G4int sAreaMask;
247
248 protected:
249 
250   class CurrentStatus 
251   {
252    public:
253
254      CurrentStatus();
255      virtual ~CurrentStatus();
256     
257      inline G4ThreeVector GetXX(G4int i)       const { return fXX[i];       }
258      inline G4double      GetDistance(G4int i) const { return fDistance[i]; }
259      inline G4int         GetAreacode(G4int i) const { return fAreacode[i]; }
260      inline G4int         GetNXX()             const { return fNXX;         }
261      inline G4bool        IsDone()             const { return fDone;        }
262      inline G4bool        IsValid(G4int i)     const { return fIsValid[i];  }
263
264      void SetCurrentStatus(G4int                i, 
265                            G4ThreeVector       &xx, 
266                            G4double            &dist, 
267                            G4int               &areacode, 
268                            G4bool              &isvalid,
269                            G4int                nxx,
270                            EValidate            validate,
271                      const G4ThreeVector *p, 
272                      const G4ThreeVector *v = 0);
273
274      void ResetfDone(EValidate            validate,
275                const G4ThreeVector *p, 
276                const G4ThreeVector *v = 0);
277
278
279      void DebugPrint() const;
280
281    private:
282
283      G4double             fDistance[G4VSURFACENXX];
284      G4ThreeVector        fXX[G4VSURFACENXX];
285      G4int                fAreacode[G4VSURFACENXX];
286      G4bool               fIsValid[G4VSURFACENXX];
287      G4int                fNXX;
288      G4ThreeVector        fLastp;
289      G4ThreeVector        fLastv;
290      EValidate            fLastValidate;
291      G4bool               fDone;
292   };
293     
294   class Boundary 
295   {
296    public:
297      Boundary();
298      virtual ~Boundary();
299     
300      void SetFields(const G4int         &areacode, 
301                     const G4ThreeVector &d, 
302                     const G4ThreeVector &x0, 
303                     const G4int         &boundarytype);
304     
305      G4bool IsEmpty() const;
306     
307      G4bool GetBoundaryParameters(const G4int         &areacode, 
308                                         G4ThreeVector &d,
309                                         G4ThreeVector &x0, 
310                                         G4int         &boundarytype) const;
311
312    private:
313      G4int          fBoundaryAcode;
314      G4ThreeVector  fBoundaryDirection;
315      G4ThreeVector  fBoundaryX0;
316      G4int          fBoundaryType;
317   };
318
319   EAxis               fAxis[2];
320   G4double            fAxisMin[2];
321   G4double            fAxisMax[2];
322   CurrentStatus       fCurStatWithV;
323   CurrentStatus       fCurStat;
324   G4RotationMatrix    fRot;
325   G4ThreeVector       fTrans;
326   G4int               fHandedness;
327   class G4SurfCurNormal
328   {
329     public:
330       G4ThreeVector p;
331       G4ThreeVector normal;
332   };
333   G4SurfCurNormal     fCurrentNormal;
334   G4bool              fIsValidNorm;
335   G4double            kCarTolerance;
336                       
337 private:
338                     
339   G4VTwistSurface    *fNeighbours[4]; // {0,1,2,3} = sAxis0min, sAxis1min,
340                                  //             sAxis0max, sAxis1max
341   G4ThreeVector fCorners[4];     // corners of the surface in local coordinate
342   Boundary      fBoundaries[4];  // boundaries of the surface.
343   G4String      fName;
344   
345   class G4SurfSideQuery
346   {
347     public:
348       G4ThreeVector me;
349       G4ThreeVector vec;
350       G4bool        withTol;
351       G4int         amIOnLeftSide;
352   };
353   G4SurfSideQuery fAmIOnLeftSide;
354};
355
356//========================================================
357// inline functions
358//========================================================
359
360struct Intersection
361{   
362  G4double phi ;  // parameter phi
363  G4double u ;    // parameter u
364  G4ThreeVector xx ;   // intersection point in cartesian
365  G4double distance ;  // distance to intersection
366  G4int areacode;      // the areacode of the intersection
367  G4bool isvalid ;     // valid intersection ??
368
369};
370
371inline
372G4bool DistanceSort( const Intersection &a, const Intersection &b) 
373{
374  return a.distance < b.distance ;
375}
376
377inline
378G4bool EqualIntersection( const Intersection &a, const Intersection &b)
379{
380  return ( ( a.xx - b.xx ).mag() < 1E-9*mm ) ;
381}
382
383#include "G4VTwistSurface.icc"
384
385#endif
Note: See TracBrowser for help on using the repository browser.