source: trunk/source/geometry/solids/specific/src/G4SolidExtentList.cc@ 896

Last change on this file since 896 was 850, checked in by garnier, 17 years ago

geant4.8.2 beta

File size: 4.8 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: G4SolidExtentList.cc,v 1.5 2007/05/11 13:54:29 gcosmo Exp $
28// GEANT4 tag $Name: HEAD $
29//
30//
31// --------------------------------------------------------------------
32// GEANT 4 class source file
33//
34//
35// G4SolidExtentList.cc
36//
37// Implementation of a list of (voxel) extents along one axis
38//
39// --------------------------------------------------------------------
40
41#include "G4SolidExtentList.hh"
42#include "G4VoxelLimits.hh"
43#include "G4GeometryTolerance.hh"
44
45
46//
47// Constructor (default)
48//
49G4SolidExtentList::G4SolidExtentList()
50{
51 axis = kZAxis;
52 limited = false;
53 minLimit = -DBL_MAX;
54 maxLimit = +DBL_MAX;
55}
56
57
58//
59// Constructor (limited case)
60//
61G4SolidExtentList::G4SolidExtentList( const EAxis targetAxis,
62 const G4VoxelLimits &voxelLimits )
63{
64 axis = targetAxis;
65
66 limited = voxelLimits.IsLimited( axis );
67 if (limited)
68 {
69 minLimit = voxelLimits.GetMinExtent( axis );
70 maxLimit = voxelLimits.GetMaxExtent( axis );
71 }
72 else
73 {
74 minLimit = -DBL_MAX;
75 maxLimit = +DBL_MAX;
76 }
77}
78
79
80//
81// Destructor
82//
83G4SolidExtentList::~G4SolidExtentList()
84{
85}
86
87
88//
89// AddSurface
90//
91//
92void G4SolidExtentList::AddSurface( const G4ClippablePolygon &surface )
93{
94 //
95 // Keep track of four surfaces
96 //
97 G4double min, max;
98
99 surface.GetExtent( axis, min, max );
100
101 if (min > maxLimit)
102 {
103 //
104 // Nearest surface beyond maximum limit
105 //
106 if (surface.InFrontOf(minAbove,axis)) minAbove = surface;
107 }
108 else if (max < minLimit)
109 {
110 //
111 // Nearest surface below minimum limit
112 //
113 if (surface.BehindOf(maxBelow,axis)) maxBelow = surface;
114 }
115 else
116 {
117 //
118 // Max and min surfaces inside
119 //
120 if (surface.BehindOf(maxSurface,axis)) maxSurface = surface;
121 if (surface.InFrontOf(minSurface,axis)) minSurface = surface;
122 }
123}
124
125
126
127//
128// GetExtent
129//
130// Return extent after processing all surfaces
131//
132G4bool G4SolidExtentList::GetExtent( G4double &min, G4double &max ) const
133{
134 G4double kCarTolerance = G4GeometryTolerance::GetInstance()
135 ->GetSurfaceTolerance();
136 //
137 // Did we have any surfaces within the limits?
138 //
139 if (minSurface.Empty())
140 {
141 //
142 // Nothing! Do we have anything above?
143 //
144 if (minAbove.Empty()) return false;
145
146 //
147 // Yup. Is it facing inwards?
148 //
149 if (minAbove.GetNormal().operator()(axis) < 0) return false;
150
151 //
152 // No. We must be entirely within the solid
153 //
154 max = maxLimit + kCarTolerance;
155 min = minLimit - kCarTolerance;
156 return true;
157 }
158
159 //
160 // Check max surface
161 //
162 if (maxSurface.GetNormal().operator()(axis) < 0)
163 {
164 //
165 // Inward facing: max limit must be embedded within solid
166 //
167 max = maxLimit + kCarTolerance;
168 }
169 else
170 {
171 G4double sMin, sMax;
172 maxSurface.GetExtent( axis, sMin, sMax );
173 max = ( (sMax > maxLimit) ? maxLimit : sMax ) + kCarTolerance;
174 }
175
176 //
177 // Check min surface
178 //
179 if (minSurface.GetNormal().operator()(axis) > 0)
180 {
181 //
182 // Inward facing: max limit must be embedded within solid
183 //
184 min = minLimit - kCarTolerance;
185 }
186 else
187 {
188 G4double sMin, sMax;
189 minSurface.GetExtent( axis, sMin, sMax );
190 min = ( (sMin < minLimit) ? minLimit : sMin ) - kCarTolerance;
191 }
192
193 return true;
194}
195
Note: See TracBrowser for help on using the repository browser.