[831] | 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: G4ReduciblePolygon.hh,v 1.9 2006/06/29 18:47:29 gunter Exp $ |
---|
[1058] | 28 | // GEANT4 tag $Name: geant4-09-02-ref-02 $ |
---|
[831] | 29 | // |
---|
| 30 | // |
---|
| 31 | // -------------------------------------------------------------------- |
---|
| 32 | // GEANT 4 class header file |
---|
| 33 | // |
---|
| 34 | // |
---|
| 35 | // G4ReduciblePolygon.hh |
---|
| 36 | // |
---|
| 37 | // Class description: |
---|
| 38 | // |
---|
| 39 | // Utility class used to specify, test, reduce, and/or otherwise |
---|
| 40 | // manipulate a 2D polygon. |
---|
| 41 | // |
---|
| 42 | // For this class, a polygon consists of n > 2 points in 2D |
---|
| 43 | // space (a,b). The polygon is always closed by connecting the |
---|
| 44 | // last point to the first. A G4ReduciblePolygon is guaranteed |
---|
| 45 | // to fulfill this definition in all instances. |
---|
| 46 | // |
---|
| 47 | // Illegal manipulations (such that a valid polygon would be |
---|
| 48 | // produced) result in an error return if possible and |
---|
| 49 | // otherwise a G4Exception. |
---|
| 50 | // |
---|
| 51 | // The set of manipulations is limited currently to what |
---|
| 52 | // is needed for G4Polycone and G4Polyhedra. |
---|
| 53 | |
---|
| 54 | // Author: |
---|
| 55 | // David C. Williams (davidw@scipp.ucsc.edu) |
---|
| 56 | // -------------------------------------------------------------------- |
---|
| 57 | #ifndef G4ReduciblePolygon_hh |
---|
| 58 | #define G4ReduciblePolygon_hh |
---|
| 59 | |
---|
| 60 | #include "G4Types.hh" |
---|
| 61 | |
---|
| 62 | class G4ReduciblePolygon |
---|
| 63 | { |
---|
| 64 | friend class G4ReduciblePolygonIterator; |
---|
| 65 | |
---|
| 66 | public: |
---|
| 67 | // |
---|
| 68 | // Creator: via simple a/b arrays |
---|
| 69 | // |
---|
| 70 | G4ReduciblePolygon( const G4double a[], const G4double b[], G4int n ); |
---|
| 71 | |
---|
| 72 | // |
---|
| 73 | // Creator: a special version for G4Polygon and G4Polycone |
---|
| 74 | // that takes two a points at planes of b |
---|
| 75 | // (where a==r and b==z for the GEANT3 classic PCON and PGON) |
---|
| 76 | // |
---|
| 77 | G4ReduciblePolygon( const G4double rmin[], const G4double rmax[], |
---|
| 78 | const G4double z[], G4int n ); |
---|
| 79 | |
---|
| 80 | virtual ~G4ReduciblePolygon(); |
---|
| 81 | |
---|
| 82 | // |
---|
| 83 | // Queries |
---|
| 84 | // |
---|
| 85 | inline G4int NumVertices() const { return numVertices; } |
---|
| 86 | |
---|
| 87 | inline G4double Amin() const { return aMin; } |
---|
| 88 | inline G4double Amax() const { return aMax; } |
---|
| 89 | inline G4double Bmin() const { return bMin; } |
---|
| 90 | inline G4double Bmax() const { return bMax; } |
---|
| 91 | |
---|
| 92 | void CopyVertices( G4double a[], G4double b[] ) const; |
---|
| 93 | |
---|
| 94 | // |
---|
| 95 | // Manipulations |
---|
| 96 | // |
---|
| 97 | void ScaleA( G4double scale ); |
---|
| 98 | void ScaleB( G4double scale ); |
---|
| 99 | |
---|
| 100 | G4bool RemoveDuplicateVertices( G4double tolerance ); |
---|
| 101 | G4bool RemoveRedundantVertices( G4double tolerance ); |
---|
| 102 | |
---|
| 103 | void ReverseOrder(); |
---|
| 104 | |
---|
| 105 | // |
---|
| 106 | // Tests |
---|
| 107 | // |
---|
| 108 | G4double Area(); |
---|
| 109 | G4bool CrossesItself( G4double tolerance ); |
---|
| 110 | G4bool BisectedBy( G4double a1, G4double b1, |
---|
| 111 | G4double a2, G4double b2, G4double tolerance ); |
---|
| 112 | |
---|
| 113 | void Print(); // Debugging only |
---|
| 114 | |
---|
| 115 | public: // without description |
---|
| 116 | |
---|
| 117 | G4ReduciblePolygon(__void__&); |
---|
| 118 | // Fake default constructor for usage restricted to direct object |
---|
| 119 | // persistency for clients requiring preallocation of memory for |
---|
| 120 | // persistifiable objects. |
---|
| 121 | |
---|
| 122 | protected: |
---|
| 123 | |
---|
| 124 | void Create( const G4double a[], const G4double b[], G4int n ); |
---|
| 125 | |
---|
| 126 | void CalculateMaxMin(); |
---|
| 127 | |
---|
| 128 | // |
---|
| 129 | // Below are member values that are *always* kept up to date (please!) |
---|
| 130 | // |
---|
| 131 | G4double aMin, aMax, bMin, bMax; |
---|
| 132 | G4int numVertices; |
---|
| 133 | |
---|
| 134 | // |
---|
| 135 | // A subclass which holds the vertices in a single-linked list |
---|
| 136 | // |
---|
| 137 | // Yeah, call me an old-fashioned c hacker, but I cannot make |
---|
| 138 | // myself use the rogue tools for this trivial list. |
---|
| 139 | // |
---|
| 140 | struct ABVertex; // Secret recipe for allowing |
---|
| 141 | friend struct ABVertex; // protected nested structures |
---|
| 142 | struct ABVertex |
---|
| 143 | { |
---|
| 144 | ABVertex() { next = 0; } |
---|
| 145 | G4double a, b; |
---|
| 146 | ABVertex *next; |
---|
| 147 | }; |
---|
| 148 | |
---|
| 149 | ABVertex *vertexHead; |
---|
| 150 | |
---|
| 151 | private: |
---|
| 152 | |
---|
| 153 | G4ReduciblePolygon(const G4ReduciblePolygon&); |
---|
| 154 | G4ReduciblePolygon& operator=(const G4ReduciblePolygon&); |
---|
| 155 | // Private copy constructor and assignment operator. |
---|
| 156 | }; |
---|
| 157 | |
---|
| 158 | |
---|
| 159 | // |
---|
| 160 | // A companion class for iterating over the vertices of our polygon. |
---|
| 161 | // It is simple enough that all routines are declared inline here. |
---|
| 162 | // |
---|
| 163 | class G4ReduciblePolygonIterator |
---|
| 164 | { |
---|
| 165 | public: |
---|
| 166 | |
---|
| 167 | G4ReduciblePolygonIterator( const G4ReduciblePolygon *theSubject ) |
---|
| 168 | { subject = theSubject; current=0; } |
---|
| 169 | |
---|
| 170 | void Begin() { current = subject->vertexHead; } |
---|
| 171 | G4bool Next() { if (current) current=current->next; return Valid(); } |
---|
| 172 | |
---|
| 173 | G4bool Valid() const { return current!=0; } |
---|
| 174 | |
---|
| 175 | G4double GetA() const { return current->a; } |
---|
| 176 | G4double GetB() const { return current->b; } |
---|
| 177 | |
---|
| 178 | protected: |
---|
| 179 | |
---|
| 180 | const G4ReduciblePolygon *subject; // Who are we iterating over |
---|
| 181 | G4ReduciblePolygon::ABVertex *current; // Current vertex |
---|
| 182 | }; |
---|
| 183 | |
---|
| 184 | #endif |
---|