|
|
|||
File indexing completed on 2026-08-09 09:09:15
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 // G4ExtrudedSolid 0027 // 0028 // Class description: 0029 // 0030 // G4ExtrudedSolid is a solid which represents the extrusion of an arbitrary 0031 // polygon with fixed outline in the defined Z sections. 0032 // The z-sides of the solid are the scaled versions of the same polygon. 0033 // The solid is implemented as a specification of G4TessellatedSolid. 0034 // 0035 // Parameters in the constructor: 0036 // const G4String& pName - solid name 0037 // std::vector<G4TwoVector> polygon - the vertices of the outlined polygon 0038 // defined in clockwise or anti-clockwise order 0039 // std::vector<ZSection> - the z-sections defined by 0040 // z position, offset and scale 0041 // in increasing z-position order 0042 // 0043 // Parameters in the special constructor (for solid with 2 z-sections: 0044 // G4double halfZ - the solid half length in Z 0045 // G4TwoVector off1 - offset of the side in -halfZ 0046 // G4double scale1 - scale of the side in -halfZ 0047 // G4TwoVector off2 - offset of the side in +halfZ 0048 // G4double scale2 - scale of the side in +halfZ 0049 0050 // Author: Ivana Hrivnacova (IPN, Orsay), 09.02.2007 - First implementation 0051 // -------------------------------------------------------------------- 0052 #ifndef G4EXTRUDEDSOLID_HH 0053 #define G4EXTRUDEDSOLID_HH 0054 0055 #include "G4GeomTypes.hh" 0056 0057 #if defined(G4GEOM_USE_USOLIDS) 0058 #define G4GEOM_USE_UEXTRUDEDSOLID 1 0059 #endif 0060 0061 #if defined(G4GEOM_USE_UEXTRUDEDSOLID) 0062 #define G4UExtrudedSolid G4ExtrudedSolid 0063 #include "G4UExtrudedSolid.hh" 0064 #else 0065 0066 #include <vector> 0067 0068 #include "G4TwoVector.hh" 0069 #include "G4TessellatedSolid.hh" 0070 0071 /** 0072 * @brief G4ExtrudedSolid is a is a solid which represents the extrusion 0073 * of an arbitrary polygon with fixed outline in the defined Z sections. 0074 * The z-sides of the solid are the scaled versions of the same polygon. 0075 * The solid is implemented as a specification of a G4TessellatedSolid. 0076 */ 0077 0078 class G4ExtrudedSolid : public G4TessellatedSolid 0079 { 0080 public: 0081 0082 /** 0083 * Structure defining a Z section composing the solid. 0084 */ 0085 struct ZSection 0086 { 0087 ZSection() : fZ(0.), fOffset(0.,0.), fScale(1.) {} 0088 ZSection(G4double z, const G4TwoVector& offset, G4double scale) 0089 : fZ(z), fOffset(offset), fScale(scale) {} 0090 0091 G4double fZ; 0092 G4TwoVector fOffset; 0093 G4double fScale; 0094 }; 0095 0096 /** 0097 * General constructor for an extruded polygon, through contour and polyline. 0098 * @param[in] pName The solid name. 0099 * @param[in] polygon The 2D polygonal contour, i.e. the vertices of the 0100 * outlined polygon defined in clock-wise order. 0101 * @param[in] zsections The 3D polyline with scale factors, i.e. the 0102 * Z-sections defined by Z position in increasing order. 0103 */ 0104 G4ExtrudedSolid( const G4String& pName, 0105 const std::vector<G4TwoVector>& polygon, 0106 const std::vector<ZSection>& zsections); 0107 0108 /** 0109 * Special constructor for an extruded polygon with 2 Z-sections. 0110 * @param[in] pName The solid name. 0111 * @param[in] polygon The 2D polygonal contour, i.e. the vertices of the 0112 * outlined polygon defined in clock-wise order. 0113 * @param[in] halfZ Half length in Z, i.e. the distance from the origin 0114 * to the sections. 0115 * @param[in] off1 (X, Y) position of the first polygon in -halfZ. 0116 * @param[in] scale1 Scale factor at -halfZ. 0117 * @param[in] off2 (X, Y) position of the second polygon in +halfZ. 0118 * @param[in] scale2 Scale factor at +halfZ. 0119 */ 0120 G4ExtrudedSolid( const G4String& pName, 0121 const std::vector<G4TwoVector>& polygon, 0122 G4double halfZ, 0123 const G4TwoVector& off1 = G4TwoVector(0.,0.), 0124 G4double scale1 = 1., 0125 const G4TwoVector& off2 = G4TwoVector(0.,0.), 0126 G4double scale2 = 1. ); 0127 0128 /** 0129 * Default Destructor. 0130 */ 0131 ~G4ExtrudedSolid() override = default; 0132 0133 /** 0134 * Accessors. 0135 */ 0136 inline G4int GetNofVertices() const; 0137 inline G4TwoVector GetVertex(G4int index) const; 0138 inline std::vector<G4TwoVector> GetPolygon() const; 0139 inline G4int GetNofZSections() const; 0140 inline ZSection GetZSection(G4int index) const; 0141 inline std::vector<ZSection> GetZSections() const; 0142 0143 /** 0144 * Concrete implementations of the expected query interfaces for 0145 * solids, as defined in the base class G4VSolid. 0146 */ 0147 EInside Inside(const G4ThreeVector& p) const override; 0148 G4ThreeVector SurfaceNormal(const G4ThreeVector& p) const override; 0149 G4double DistanceToIn(const G4ThreeVector& p, 0150 const G4ThreeVector& v) const override; 0151 G4double DistanceToIn(const G4ThreeVector& p ) const override; 0152 G4double DistanceToOut(const G4ThreeVector& p, 0153 const G4ThreeVector& v, 0154 const G4bool calcNorm = false, 0155 G4bool* validNorm = nullptr, 0156 G4ThreeVector* n = nullptr) const override; 0157 G4double DistanceToOut(const G4ThreeVector& p) const override; 0158 0159 /** 0160 * Computes the bounding limits of the solid. 0161 * @param[out] pMin The minimum bounding limit point. 0162 * @param[out] pMax The maximum bounding limit point. 0163 */ 0164 void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const override; 0165 0166 /** 0167 * Calculates the minimum and maximum extent of the solid, when under the 0168 * specified transform, and within the specified limits. 0169 * @param[in] pAxis The axis along which compute the extent. 0170 * @param[in] pVoxelLimit The limiting space dictated by voxels. 0171 * @param[in] pTransform The internal transformation applied to the solid. 0172 * @param[out] pMin The minimum extent value. 0173 * @param[out] pMax The maximum extent value. 0174 * @returns True if the solid is intersected by the extent region. 0175 */ 0176 G4bool CalculateExtent(const EAxis pAxis, 0177 const G4VoxelLimits& pVoxelLimit, 0178 const G4AffineTransform& pTransform, 0179 G4double& pMin, G4double& pMax) const override; 0180 0181 /** 0182 * Returns the type ID, "G4ExtrudedSolid" of the solid. 0183 */ 0184 G4GeometryType GetEntityType () const override; 0185 0186 /** 0187 * Returns true as the solid has only planar faces. 0188 */ 0189 G4bool IsFaceted () const override; 0190 0191 /** 0192 * Makes a clone of the object for use in multi-treading. 0193 * @returns A pointer to the new cloned allocated solid. 0194 */ 0195 G4VSolid* Clone() const override; 0196 0197 /** 0198 * Streams the object contents to an output stream. 0199 */ 0200 std::ostream& StreamInfo(std::ostream& os) const override; 0201 0202 /** 0203 * Fake default constructor for usage restricted to direct object 0204 * persistency for clients requiring preallocation of memory for 0205 * persistifiable objects. 0206 */ 0207 G4ExtrudedSolid(__void__&); 0208 0209 /** 0210 * Copy constructor and assignment operator. 0211 */ 0212 G4ExtrudedSolid(const G4ExtrudedSolid& rhs) = default; 0213 G4ExtrudedSolid& operator=(const G4ExtrudedSolid& rhs); 0214 0215 private: 0216 0217 /** 0218 * Algorithm for SurfaceNormal() following the original 0219 * specification for points not on the surface. 0220 */ 0221 G4ThreeVector ApproxSurfaceNormal(const G4ThreeVector& p) const; 0222 0223 /** 0224 * Computes parameters for point projections p(z) 0225 * to the polygon scale & offset. 0226 */ 0227 void ComputeProjectionParameters(); 0228 0229 /** 0230 * Computes the lateral planes: a*x + b*y + c*z + d = 0. 0231 */ 0232 void ComputeLateralPlanes(); 0233 0234 /** 0235 * Returns if point 'p' is within the polygon. 0236 */ 0237 inline G4bool PointInPolygon(const G4ThreeVector& p) const; 0238 0239 /** 0240 * Returns the square distance of point 'p' from the polygon. 0241 */ 0242 inline G4double DistanceToPolygonSqr(const G4ThreeVector& p) const; 0243 0244 /** 0245 * Returns the vertex coordinates, given the indeces for the 0246 * polygons and Z sections. 0247 * @param[in] iz Index for the Z section. 0248 * @param[in] ind Index for the polygon. 0249 * @returns The shifted and scaled coordinates of the vertex. 0250 */ 0251 G4ThreeVector GetVertex(G4int iz, G4int ind) const; 0252 0253 /** 0254 * Returns the projected point of 'p' in the polygon scale. 0255 */ 0256 G4TwoVector ProjectPoint(const G4ThreeVector& point) const; 0257 0258 /** 0259 * Returns true if 'p' is on the line through 'l1', 'l2'. 0260 */ 0261 G4bool IsSameLine(const G4TwoVector& p, 0262 const G4TwoVector& l1, 0263 const G4TwoVector& l2) const; 0264 /** 0265 * Returns true if 'p' is on the line through 'l1', 'l2' 0266 * and lies between 'l1' and 'l2'. 0267 */ 0268 G4bool IsSameLineSegment(const G4TwoVector& p, 0269 const G4TwoVector& l1, 0270 const G4TwoVector& l2) const; 0271 /** 0272 * Returns true if 'p1' and 'p2' are on the same side of the line 0273 * through 'l1', 'l2'. 0274 */ 0275 G4bool IsSameSide(const G4TwoVector& p1, 0276 const G4TwoVector& p2, 0277 const G4TwoVector& l1, 0278 const G4TwoVector& l2) const; 0279 /** 0280 * Returns true if 'p' is inside of triangle abc or on its edges. 0281 */ 0282 G4bool IsPointInside(const G4TwoVector& a, 0283 const G4TwoVector& b, 0284 const G4TwoVector& c, 0285 const G4TwoVector& p) const; 0286 /** 0287 * Returns the angle of the vertex in 'p0'. 0288 */ 0289 G4double GetAngle(const G4TwoVector& p0, 0290 const G4TwoVector& pa, 0291 const G4TwoVector& pb) const; 0292 0293 /** 0294 * Returns a pointer to a triangular facet from the polygon points 0295 * given by indices forming the down side ( the normal goes in -z). 0296 */ 0297 G4VFacet* MakeDownFacet(G4int ind1, G4int ind2, G4int ind3) const; 0298 0299 /** 0300 * Returns a pointer to a triangular facet from the polygon points 0301 * given by indices forming the upper side ( z>0 ). 0302 */ 0303 G4VFacet* MakeUpFacet(G4int ind1, G4int ind2, G4int ind3) const; 0304 0305 /** 0306 * Decomposes polygonal sides in triangular facets. 0307 * @returns false if failing to define a facet. 0308 */ 0309 G4bool AddGeneralPolygonFacets(); 0310 0311 /** 0312 * Generates the tessellated structure of the solid creating the 0313 * triangular or quadrangular facets from the vertices. 0314 * @returns false if failing to define a facet. 0315 */ 0316 G4bool MakeFacets(); 0317 0318 private: 0319 0320 std::size_t fNv; 0321 std::size_t fNz; 0322 std::vector<G4TwoVector> fPolygon; 0323 std::vector<ZSection> fZSections; 0324 std::vector< std::vector<G4int> > fTriangles; 0325 G4bool fIsConvex = false; 0326 G4GeometryType fGeometryType; 0327 0328 G4int fSolidType = 0; 0329 struct plane { G4double a,b,c,d; }; // a*x + b*y + c*z + d = 0 0330 std::vector<plane> fPlanes; 0331 struct line { G4double k,m; }; // x = k*y + m; 0332 std::vector<line> fLines; 0333 std::vector<G4double> fLengths; // edge lengths 0334 0335 std::vector<G4double> fKScales; 0336 std::vector<G4double> fScale0s; 0337 std::vector<G4TwoVector> fKOffsets; 0338 std::vector<G4TwoVector> fOffset0s; 0339 }; 0340 0341 #include "G4ExtrudedSolid.icc" 0342 0343 #endif 0344 0345 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|