source: trunk/source/geometry/solids/specific/include/G4VCSGface.hh @ 1058

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

file release beta

File size: 12.5 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: G4VCSGface.hh,v 1.9 2008/05/15 11:41:59 gcosmo Exp $
28// GEANT4 tag $Name: geant4-09-02-ref-02 $
29//
30//
31// --------------------------------------------------------------------
32// GEANT 4 class header file
33//
34//
35// G4VCSGface
36//
37// Class description:
38//
39//   Definition of the virtual base class G4VCSGface, one side (or face)
40//   of a CSG-like solid. It should be possible to build a CSG entirely out of
41//   connecting CSG faces.
42//
43//   Each face has an inside and outside surface, the former represents
44//   the inside of the volume, the latter, the outside.
45//
46//   Virtual members:
47//
48//  -------------------------------------------------------------------
49//      Intersect( const G4ThreeVector &p, const G4ThreeVector &v,
50//                 G4bool outGoing, G4double surfTolerance,
51//                 G4double &distance, G4double &distFromSurface,
52//                 G4ThreeVector &normal, G4bool &allBehind );
53//
54//          p               - (in) position
55//          v               - (in) direction (assumed to be a unit vector)
56//          outgoing        - (in) true, to consider only inside surfaces
57//                                 false, to consider only outside surfaces
58//          distance        - (out) distance to intersection
59//          distFromSurface - (out) distance from surface (along surface normal),
60//                            < 0 if the point is in front of the surface
61//          normal          - (out) normal of surface at intersection point
62//          allBehind       - (out) true, if entire surface is behind normal
63//
64//          return value = true if there is an intersection,
65//                         false if there is no intersection
66//                               (all output arguments undefined)
67//
68//   Determine the distance along a line to the face.
69//
70//  -------------------------------------------------------------------
71//   Distance( const G4ThreeVector &p, const G4bool outgoing );
72//
73//      p         - (in) position
74//      outgoing  - (in) true, to consider only inside surfaces
75//                             false, to consider only outside surfaces
76//
77//      return value = distance to closest surface satisifying requirements
78//                         or kInfinity if no such surface exists
79//
80//   Determine the distance of a point from either the inside or outside
81//   surfaces of the face.
82//
83//  -------------------------------------------------------------------
84//       Inside( const G4ThreeVector &p, const G4double tolerance,
85//               G4double *bestDistance );
86//
87//      p            - (in) position
88//      tolerance    - (in) tolerance defining the bounds of the "kSurface",
89//                          nominally equal to kCarTolerance/2
90//      bestDistance - (out) distance to closest surface (in or out)
91//
92//      return value = kInside if the point is closest to the inside surface
93//                     kOutside if the point is closest to the outside surface
94//                     kSurface if the point is withing tolerance of the surface
95//
96//   Determine whether a point is inside, outside, or on the surface of
97//   the face.
98//
99//  -------------------------------------------------------------------
100//       Normal( const G4ThreeVector &p,  G4double *bestDistance );
101//
102//       p            - (in) position
103//       bestDistance - (out) distance to closest surface (in or out)
104//
105//       return value = the normal of the surface nearest the point
106//
107//   Return normal of surface closest to the point.
108//
109//  -------------------------------------------------------------------
110//   Extent( const G4ThreeVector axis );
111//
112//       axis    - (in) unit vector defining direction
113//
114//       return value = the largest point along the given axis of the
115//                      the face's extent.
116//
117//  -------------------------------------------------------------------
118//       CalculateExtent( const EAxis pAxis,
119//                        const G4VoxelLimit &pVoxelLimit,
120//                        const G4AffineTransform &pTransform,
121//                        G4double &min, G4double &max )
122//
123//           pAxis       - (in) The x,y, or z axis in which to check
124//                              the shapes 3D extent against
125//           pVoxelLimit - (in) Limits along x, y, and/or z axes
126//           pTransform  - (in) A coordinate transformation on which
127//                              to apply to the shape before testing
128//           min         - (out) If the face has any point on its
129//                               surface after tranformation and limits
130//                               along pAxis that is smaller than the value
131//                               of min, than it is used to replace min.
132//                               Undefined if the return value is false.
133//           max         - (out) Same as min, except for the largest
134//                               point.
135//                               Undefined if the return value is false.
136//
137//           return value = true if anything remains of the face
138//
139//   Calculate the extent of the face for the voxel navigator.
140//   In analogy with CalculateExtent for G4VCSGfaceted, this is
141//   done in the following steps:
142//
143//          1. Transform the face using pTranform, an arbitrary 3D
144//             rotation/offset/reflection
145//          2. Clip the face to those boundaries as specified in
146//             pVoxelLimit. This may include limits in any number
147//             of x, y, or z axes.
148//          3. For each part of the face that remains (there could
149//             be many separate pieces in general):
150//                4. Check to see if the piece overlaps the currently
151//                   existing limits along axis pAxis. For
152//                   pVoxelLimit.IsLimited(pAxis) = false, there are
153//                   no limits.
154//                5. For a piece that does overlap, update min/max
155//                   accordingly (within confines of pre-existing
156//                   limits) along the direction pAxis.
157//          6. If min/max were updated, return true
158//                           
159//  -------------------------------------------------------------------
160//       G3VCSGface *Clone()
161//
162//   This method is invoked by G4CSGfaceted during the copy constructor
163//   or the assignment operator. Its purpose is to return a pointer
164//   (of type G4VCSGface) to a duplicate copy of the face.
165//   The implementation is straight forward for inherited classes. Example:
166//
167//   G4VCSGface G4PolySideFace::Clone() { return new G4PolySideFace(*this); }
168//
169//   Of course, this assumes the copy constructor of G4PolySideFace is
170//   correctly implemented.
171//
172//   Implementation notes:
173//   * distance.
174//        The meaning of distance includes the boundaries of the face.
175//        For example, for a rectangular, planer face:
176//
177//               A   |  B           | C
178//                   |              |
179//              -------+--------------+-----
180//               D   |  I           | E
181//                   |              |
182//              -------+--------------+-----
183//               F   |  G           | H
184//                   |              |
185//       
186//        A, C, F, and H: closest distance is the distance to
187//        the adjacent corner.
188//
189//        B, D, E, and G: closest distance is the distance to
190//        the adjacent line.
191//
192//        I: normal distance to plane
193//
194//        For non-planer faces, one can use the normal to decide when
195//        a point falls off the edge and then act accordingly.
196//
197//
198//   Usage:
199//
200//   A CSG shape can be defined by putting together any number of generic
201//   faces, as long as the faces cover the entire surface of the shape
202//   without overlapping.
203//
204//   G4VSolid::CalculateExtent
205//
206//   Define unit vectors along the specified transform axis.
207//   Use the inverse of the specified coordinate transformation to rotate
208//   these unit vectors. Loop over each face, call face->Extent, and save
209//   the maximum value.
210//
211//   G4VSolid::Inside
212//
213//   To decide if a point is inside, outside, or on the surface of the shape,
214//   loop through all faces, and find the answer from face->Inside which gives
215//   a value of "bestDistance" smaller than any other. While looping, if any
216//   face->Inside returns kSurface, this value can be returned immediately.
217//
218//  EInside answer;
219//  G4VCSGface *face = faces;
220//  G4double best = kInfinity;
221//  do {
222//    G4double distance;
223//    EInside result = (*face)->Inside( p, kCarTolerance/2, distance );
224//    if (result == kSurface) return kSurface;
225//    if (distance < best) {
226//      best = distance;
227//      answer = result;
228//    }
229//  } while( ++face < faces + numFaces );
230//
231//  return(answer);
232//
233//   G4VSolid::SurfaceNormal
234//
235//   Loop over all faces, call face->Normal, and return the normal to the face
236//   that is closest to the point.
237//
238//   G4VSolid::DistanceToIn(p)
239//
240//   Loop over all faces, invoking face->Distance with outgoing = false,
241//   and save the answer that is smallest.
242//
243//   G4VSolid::DistanceToIn(p,v)
244//
245//   Loop over all faces, invoking face->Intersect with outgoing = false,
246//   and save the answer that is smallest.
247//
248//   G4VSolid::DistanceToOut(p)
249//
250//   Loop over all faces, invoking face->Distance with outgoing = true,
251//   and save the answer that is smallest.
252//
253//   G4VSolid::DistanceToOut(p,v)
254//
255//   Loop over all faces, invoking face->Intersect with outgoing = true,
256//   and save the answer that is smallest. If there is more than one answer,
257//   or if allBehind is false for the one answer, return validNorm as false.
258
259// Author:
260//   David C. Williams (davidw@scipp.ucsc.edu)
261// --------------------------------------------------------------------
262#ifndef G4VCSGface_hh
263#define G4VCSGface_hh
264
265#include "G4Types.hh"
266#include "G4ThreeVector.hh"
267#include "geomdefs.hh"
268#include "G4VSolid.hh"
269
270class G4VoxelLimits;
271class G4AffineTransform;
272class G4SolidExtentList;
273
274class G4VCSGface
275{
276  public:  // with description
277
278  G4VCSGface() {}
279  virtual ~G4VCSGface() {}
280 
281  virtual G4bool Intersect( const G4ThreeVector &p, const G4ThreeVector &v, 
282                            G4bool outgoing, G4double surfTolerance,
283                            G4double &distance, G4double &distFromSurface,
284                            G4ThreeVector &normal, G4bool &allBehind ) = 0;
285
286  virtual G4double Distance( const G4ThreeVector &p, G4bool outgoing ) = 0;
287 
288  virtual EInside Inside( const G4ThreeVector &p, G4double tolerance, 
289                          G4double *bestDistance ) = 0;
290   
291  virtual G4ThreeVector Normal( const G4ThreeVector &p,
292                                G4double *bestDistance ) = 0;
293
294  virtual G4double Extent( const G4ThreeVector axis ) = 0;
295 
296  virtual void CalculateExtent( const EAxis axis, 
297                                const G4VoxelLimits &voxelLimit,
298                                const G4AffineTransform &tranform,
299                                G4SolidExtentList &extentList       ) = 0;
300
301  virtual G4VCSGface* Clone() = 0;
302
303  virtual G4double SurfaceArea( ) = 0;
304  virtual G4ThreeVector GetPointOnFace() = 0;
305};
306
307#endif
Note: See TracBrowser for help on using the repository browser.