|
|
|||
File indexing completed on 2026-07-26 09:10:29
0001 // 0002 // ******************************************************************** 0003 // * License and Disclaimer * 0004 // * * 0005 // * The Geant4 software is copyright of the Copyright Holders of * 0006 // * the Geant4 Collaboration. It is provided under the terms and * 0007 // * conditions of the Geant4 Software License, included in the file * 0008 // * LICENSE and available at http://cern.ch/geant4/license . These * 0009 // * include a list of copyright holders. * 0010 // * * 0011 // * Neither the authors of this software system, nor their employing * 0012 // * institutes,nor the agencies providing financial support for this * 0013 // * work make any representation or warranty, express or implied, * 0014 // * regarding this software system or assume any liability for its * 0015 // * use. Please see the license in the file LICENSE and URL above * 0016 // * for the full disclaimer and the limitation of liability. * 0017 // * * 0018 // * This code implementation is the result of the scientific and * 0019 // * technical work of the GEANT4 collaboration. * 0020 // * By using, copying, modifying or distributing the software (or * 0021 // * any work based on the software) you agree to acknowledge its * 0022 // * use in resulting scientific publications, and indicate your * 0023 // * acceptance of all terms of the Geant4 Software license. * 0024 // ******************************************************************** 0025 // 0026 // G4ReduciblePolygon 0027 // 0028 // Class description: 0029 // 0030 // Utility class used to specify, test, reduce, and/or otherwise 0031 // manipulate a 2D polygon. 0032 // 0033 // For this class, a polygon consists of n > 2 points in 2D 0034 // space (a,b). The polygon is always closed by connecting the 0035 // last point to the first. A G4ReduciblePolygon is guaranteed 0036 // to fulfill this definition in all instances. 0037 // 0038 // Illegal manipulations (such that a valid polygon would be 0039 // produced) result in an error return if possible and 0040 // otherwise a G4Exception. 0041 // 0042 // The set of manipulations is limited currently to what 0043 // is needed for G4Polycone and G4Polyhedra. 0044 0045 // Author: David C. Williams (UCSC), 1998 0046 // -------------------------------------------------------------------- 0047 #ifndef G4REDUCIBLEPOLYGON_HH 0048 #define G4REDUCIBLEPOLYGON_HH 0049 0050 #include "G4Types.hh" 0051 0052 /** 0053 * @brief G4ReduciblePolygon is a utility class used to specify, test, reduce, 0054 * and/or otherwise manipulate a 2D polygon. 0055 */ 0056 0057 class G4ReduciblePolygon 0058 { 0059 friend class G4ReduciblePolygonIterator; 0060 0061 public: 0062 0063 /** 0064 * Constructor of G4ReduciblePolygon via simple a/b arrays. 0065 * @param[in] a First array of points. 0066 * @param[in] b Second array of points. 0067 * @param[in] n The number of vertices of the polygon (has to be >=3). 0068 */ 0069 G4ReduciblePolygon( const G4double a[], const G4double b[], G4int n ); 0070 0071 /** 0072 * Special constructor version for G4Polyhedra and G4Polycone, that takes 0073 * two a points at planes of b (where a==r and b==z). 0074 * @param[in] rmin Array of r-min coordinates of corners. 0075 * @param[in] rmax Array of r-max coordinates of corners. 0076 * @param[in] z Array of Z coordinates of corners. 0077 * @param[in] n The number of vertices of the polygon. 0078 */ 0079 G4ReduciblePolygon( const G4double rmin[], const G4double rmax[], 0080 const G4double z[], G4int n ); 0081 0082 /** 0083 * Copy constructor and assignment operator not allowed. 0084 */ 0085 G4ReduciblePolygon(const G4ReduciblePolygon&) = delete; 0086 G4ReduciblePolygon& operator=(const G4ReduciblePolygon&) = delete; 0087 0088 /** 0089 * Destructor, taking care to clear allocated lists. 0090 */ 0091 ~G4ReduciblePolygon(); 0092 0093 /** 0094 * Accessors. 0095 */ 0096 inline G4int NumVertices() const { return numVertices; } 0097 inline G4double Amin() const { return aMin; } 0098 inline G4double Amax() const { return aMax; } 0099 inline G4double Bmin() const { return bMin; } 0100 inline G4double Bmax() const { return bMax; } 0101 0102 /** 0103 * Copies contents of provided arrays into simple linear arrays. 0104 */ 0105 void CopyVertices( G4double a[], G4double b[] ) const; 0106 0107 /** 0108 * Methods to multiply all a or b values by a common scale. 0109 */ 0110 void ScaleA( G4double scale ); 0111 void ScaleB( G4double scale ); 0112 0113 /** 0114 * Removes adjacent vertices that are equal. 0115 * @param[in] tolerance Provided tolerance for adjacent vertices. 0116 * @returns false, if there is a problem (too few vertices remaining). 0117 */ 0118 G4bool RemoveDuplicateVertices( G4double tolerance ); 0119 0120 /** 0121 * Removes any unneeded vertices, i.e. those vertices which are on the 0122 * line connecting the previous and next vertices. 0123 * @param[in] tolerance Provided tolerance for parallel line segments. 0124 * @returns false, if there is a problem (too few vertices remaining). 0125 */ 0126 G4bool RemoveRedundantVertices( G4double tolerance ); 0127 0128 /** 0129 * Reverses the order of the vertices. 0130 */ 0131 void ReverseOrder(); 0132 0133 /** 0134 * Method is used for G4GenericPolycone; starting always with Zmin=bMin. 0135 */ 0136 void StartWithZMin(); 0137 0138 // Methods for tests 0139 0140 /** 0141 * Calculates signed polygon area, where polygons specified in a 0142 * clockwise manner have negative area. 0143 */ 0144 G4double Area(); 0145 0146 /** 0147 * Returns "true" if the polygon crosses itself. 0148 */ 0149 G4bool CrossesItself( G4double tolerance ); 0150 0151 /** 0152 * Decides if a line through two points crosses the polygon, 0153 * within tolerance. 0154 */ 0155 G4bool BisectedBy( G4double a1, G4double b1, 0156 G4double a2, G4double b2, G4double tolerance ); 0157 0158 /** 0159 * Print function for debugging. 0160 */ 0161 void Print(); 0162 0163 /** 0164 * Fake default constructor for usage restricted to direct object 0165 * persistency for clients requiring preallocation of memory for 0166 * persistifiable objects. 0167 */ 0168 G4ReduciblePolygon(__void__&); 0169 0170 private: 0171 0172 /** 0173 * Create the polygon; used in constructors. 0174 */ 0175 void Create( const G4double a[], const G4double b[], G4int n ); 0176 0177 /** 0178 * Re-calculates global values. To be called when the vertices are changed. 0179 */ 0180 void CalculateMaxMin(); 0181 0182 private: 0183 0184 // Below are member values that are *always* kept up to date 0185 // 0186 G4double aMin, aMax, bMin, bMax; 0187 G4int numVertices = 0; 0188 0189 0190 /** 0191 * A subclass which holds the vertices in a single-linked list. 0192 */ 0193 struct ABVertex; // Secret recipe for allowing 0194 friend struct ABVertex; // protected nested structures 0195 struct ABVertex 0196 { 0197 ABVertex() = default; 0198 G4double a{0.}, b{0.}; 0199 ABVertex *next{nullptr}; 0200 }; 0201 0202 ABVertex* vertexHead = nullptr; 0203 }; 0204 0205 // A companion class for iterating over the vertices of our polygon. 0206 // It is simple enough that all routines are declared inline here. 0207 // 0208 0209 /** 0210 * @brief G4ReduciblePolygonIterator is companion class for iterating over 0211 * the vertices of a polygon. 0212 */ 0213 0214 class G4ReduciblePolygonIterator 0215 { 0216 public: 0217 0218 inline G4ReduciblePolygonIterator( const G4ReduciblePolygon* theSubject ) 0219 { 0220 subject = theSubject; current = nullptr; 0221 } 0222 0223 inline void Begin() { current = subject->vertexHead; } 0224 0225 inline G4bool Next() 0226 { 0227 if (current != nullptr) { current=current->next; } 0228 return Valid(); 0229 } 0230 0231 inline G4bool Valid() const { return current != nullptr; } 0232 0233 inline G4double GetA() const { return current->a; } 0234 inline G4double GetB() const { return current->b; } 0235 0236 private: 0237 0238 const G4ReduciblePolygon* subject = nullptr; // Who are we iterating over 0239 G4ReduciblePolygon::ABVertex* current = nullptr; // Current vertex 0240 }; 0241 0242 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|