00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00099 #ifndef G4TessellatedSolid_hh
00100 #define G4TessellatedSolid_hh 1
00101
00102 #include <iostream>
00103 #include <vector>
00104 #include <set>
00105 #include <map>
00106
00107 #include "G4VSolid.hh"
00108 #include "G4Types.hh"
00109 #include "G4SurfaceVoxelizer.hh"
00110
00111 struct G4VertexInfo
00112 {
00113 G4int id;
00114 G4double mag2;
00115 };
00116
00117 class G4VFacet;
00118
00119 class G4VertexComparator
00120 {
00121 public:
00122 G4bool operator() (const G4VertexInfo &l, const G4VertexInfo &r) const
00123 {
00124 return l.mag2 == r.mag2 ? l.id < r.id : l.mag2 < r.mag2;
00125 }
00126 };
00127
00128 class G4TessellatedSolid : public G4VSolid
00129 {
00130 public:
00131
00132 G4TessellatedSolid ();
00133 virtual ~G4TessellatedSolid ();
00134
00135 G4TessellatedSolid (const G4String &name);
00136
00137 G4TessellatedSolid(__void__&);
00138
00139
00140
00141
00142 G4TessellatedSolid (const G4TessellatedSolid &ts);
00143 G4TessellatedSolid &operator= (const G4TessellatedSolid &right);
00144 G4TessellatedSolid &operator+= (const G4TessellatedSolid &right);
00145
00146 G4bool AddFacet (G4VFacet *aFacet);
00147 inline G4VFacet *GetFacet (G4int i) const;
00148
00149 G4int GetNumberOfFacets () const;
00150
00151 virtual EInside Inside (const G4ThreeVector &p) const;
00152 virtual G4ThreeVector SurfaceNormal(const G4ThreeVector& p) const;
00153 virtual G4double DistanceToIn(const G4ThreeVector& p,
00154 const G4ThreeVector& v)const;
00155 virtual G4double DistanceToIn(const G4ThreeVector& p) const;
00156 virtual G4double DistanceToOut(const G4ThreeVector& p) const;
00157 virtual G4double DistanceToOut(const G4ThreeVector& p,
00158 const G4ThreeVector& v,
00159 const G4bool calcNorm,
00160 G4bool *validNorm,
00161 G4ThreeVector *norm) const;
00162
00163 virtual G4bool Normal (const G4ThreeVector &p, G4ThreeVector &n) const;
00164 virtual G4double SafetyFromOutside(const G4ThreeVector &p,
00165 G4bool aAccurate=false) const;
00166 virtual G4double SafetyFromInside (const G4ThreeVector &p,
00167 G4bool aAccurate=false) const;
00168
00169 virtual G4GeometryType GetEntityType () const;
00170 virtual std::ostream &StreamInfo(std::ostream &os) const;
00171
00172 virtual G4VSolid* Clone() const;
00173
00174 virtual G4ThreeVector GetPointOnSurface() const;
00175 virtual G4double GetSurfaceArea();
00176 virtual G4double GetCubicVolume ();
00177
00178 void SetSolidClosed (const G4bool t);
00179 G4bool GetSolidClosed () const;
00180
00181 inline void SetMaxVoxels(G4int max);
00182
00183 inline G4SurfaceVoxelizer &GetVoxels();
00184
00185 virtual G4bool CalculateExtent(const EAxis pAxis,
00186 const G4VoxelLimits& pVoxelLimit,
00187 const G4AffineTransform& pTransform,
00188 G4double& pMin, G4double& pMax) const;
00189
00190 G4double GetMinXExtent () const;
00191 G4double GetMaxXExtent () const;
00192 G4double GetMinYExtent () const;
00193 G4double GetMaxYExtent () const;
00194 G4double GetMinZExtent () const;
00195 G4double GetMaxZExtent () const;
00196
00197 G4ThreeVectorList* CreateRotatedVertices(const G4AffineTransform& pT) const;
00198
00199
00200
00201 virtual G4Polyhedron* CreatePolyhedron () const;
00202 virtual G4Polyhedron* GetPolyhedron () const;
00203 virtual G4NURBS* CreateNURBS () const;
00204 virtual void DescribeYourselfTo (G4VGraphicsScene& scene) const;
00205 virtual G4VisExtent GetExtent () const;
00206
00207 G4int AllocatedMemoryWithoutVoxels();
00208 G4int AllocatedMemory();
00209 void DisplayAllocatedMemory();
00210
00211 private:
00212
00213 void Initialize();
00214
00215 G4double DistanceToOutNoVoxels(const G4ThreeVector &p,
00216 const G4ThreeVector &v,
00217 G4ThreeVector &aNormalVector,
00218 G4bool &aConvex,
00219 G4double aPstep = kInfinity) const;
00220 G4double DistanceToInCandidates(const std::vector<G4int> &candidates,
00221 const G4ThreeVector &aPoint,
00222 const G4ThreeVector &aDirection) const;
00223 void DistanceToOutCandidates(const std::vector<G4int> &candidates,
00224 const G4ThreeVector &aPoint,
00225 const G4ThreeVector &direction,
00226 G4double &minDist,
00227 G4ThreeVector &minNormal,
00228 G4int &minCandidate) const;
00229 G4double DistanceToInNoVoxels(const G4ThreeVector &p,
00230 const G4ThreeVector &v,
00231 G4double aPstep = kInfinity) const;
00232 void SetExtremeFacets();
00233
00234 EInside InsideNoVoxels (const G4ThreeVector &p) const;
00235 EInside InsideVoxels(const G4ThreeVector &aPoint) const;
00236
00237 void Voxelize();
00238
00239 void CreateVertexList();
00240
00241 void PrecalculateInsides();
00242
00243 void SetRandomVectors();
00244
00245 G4double DistanceToInCore(const G4ThreeVector &p, const G4ThreeVector &v,
00246 G4double aPstep = kInfinity) const;
00247 G4double DistanceToOutCore(const G4ThreeVector &p, const G4ThreeVector &v,
00248 G4ThreeVector &aNormalVector,
00249 G4bool &aConvex,
00250 G4double aPstep = kInfinity) const;
00251
00252 G4int SetAllUsingStack(const std::vector<G4int> &voxel,
00253 const std::vector<G4int> &max,
00254 G4bool status, G4SurfBits &checked);
00255
00256 void DeleteObjects ();
00257 void CopyObjects (const G4TessellatedSolid &s);
00258
00259 static G4bool CompareSortedVoxel(const std::pair<G4int, G4double> &l,
00260 const std::pair<G4int, G4double> &r);
00261
00262 G4double MinDistanceFacet(const G4ThreeVector &p, G4bool simple,
00263 G4VFacet * &facet) const;
00264
00265 inline G4bool OutsideOfExtent(const G4ThreeVector &p,
00266 G4double tolerance=0) const;
00267
00268 private:
00269
00270 mutable G4Polyhedron* fpPolyhedron;
00271
00272 std::vector<G4VFacet *> fFacets;
00273 std::set<G4VFacet *> fExtremeFacets;
00274
00275
00276 G4GeometryType fGeometryType;
00277 G4double fCubicVolume;
00278 G4double fSurfaceArea;
00279
00280 std::vector<G4ThreeVector> fVertexList;
00281
00282 std::set<G4VertexInfo,G4VertexComparator> fFacetList;
00283
00284 G4ThreeVector fMinExtent, fMaxExtent;
00285
00286 G4bool fSolidClosed;
00287
00288 std::vector<G4ThreeVector> fRandir;
00289
00290 G4double kCarToleranceHalf;
00291
00292 G4int fMaxTries;
00293
00294 G4SurfaceVoxelizer fVoxels;
00295
00296 G4SurfBits fInsides;
00297 };
00298
00300
00302
00303 inline G4VFacet *G4TessellatedSolid::GetFacet (G4int i) const
00304 {
00305 return fFacets[i];
00306 }
00307
00308 inline void G4TessellatedSolid::SetMaxVoxels(G4int max)
00309 {
00310 fVoxels.SetMaxVoxels(max);
00311 }
00312
00313 inline G4SurfaceVoxelizer &G4TessellatedSolid::GetVoxels()
00314 {
00315 return fVoxels;
00316 }
00317
00318 inline G4bool G4TessellatedSolid::OutsideOfExtent(const G4ThreeVector &p,
00319 G4double tolerance) const
00320 {
00321 return ( p.x() < fMinExtent.x() - tolerance
00322 || p.x() > fMaxExtent.x() + tolerance
00323 || p.y() < fMinExtent.y() - tolerance
00324 || p.y() > fMaxExtent.y() + tolerance
00325 || p.z() < fMinExtent.z() - tolerance
00326 || p.z() > fMaxExtent.z() + tolerance);
00327 }
00328
00329 #endif