Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
G4SurfaceVoxelizer.hh
Go to the documentation of this file.
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// $Id:$
27// GEANT4 tag $Name: not supported by cvs2svn $
28//
29// --------------------------------------------------------------------
30// GEANT 4 class header file
31//
32// G4SurfaceVoxelizer
33//
34// Class description:
35//
36// Voxelizer for tessellated surfaces, used in G4TessellatedSolid.
37
38// History:
39// 19.10.12 Marek Gayer, created
40// --------------------------------------------------------------------
41
42#ifndef G4SurfaceVoxelizer_HH
43#define G4SurfaceVoxelizer_HH
44
45#include <vector>
46#include <string>
47#include <map>
48
49#include "G4SurfBits.hh"
50#include "G4Box.hh"
51#include "G4VFacet.hh"
52
53#include "Randomize.hh"
54
56{
57 G4ThreeVector hlen; // half length of the box
58 G4ThreeVector pos; // position of the box
59};
60
62{
66};
67
69{
71
72 public:
73
74 template <typename T>
75 static inline G4int BinarySearch(const std::vector<T> &vec, T value);
76
77 void Voxelize(std::vector<G4VFacet *> &facets);
78
79 void DisplayVoxelLimits();
80 void DisplayBoundaries();
81 void DisplayListNodes();
82
85
86 void GetCandidatesVoxel(std::vector<G4int> &voxels);
87 // Method displaying the nodes located in a voxel characterized
88 // by its three indexes.
89
91 std::vector<G4int> &list,
92 G4SurfBits *crossed=0) const;
93 // Method returning in a vector container the nodes located in a voxel
94 // characterized by its three indexes.
95 G4int GetCandidatesVoxelArray(const std::vector<G4int> &voxels,
96 const G4SurfBits bitmasks[],
97 std::vector<G4int> &list,
98 G4SurfBits *crossed=0) const;
99 G4int GetCandidatesVoxelArray(const std::vector<G4int> &voxels,
100 std::vector<G4int> &list,
101 G4SurfBits *crossed=0)const;
102
103 inline const std::vector<G4VoxelBox> &GetBoxes() const;
104 // Method returning the pointer to the array containing the
105 // characteristics of each box.
106
107 inline const std::vector<G4double> &GetBoundary(G4int index) const;
108
110 const G4ThreeVector &direction,
111 std::vector<G4int> &curVoxel) const;
112
113 inline void GetVoxel(std::vector<G4int> &curVoxel,
114 const G4ThreeVector &point) const;
115
116 inline G4int GetBitsPerSlice () const;
117
118 G4bool Contains(const G4ThreeVector &point) const;
119
121 const G4ThreeVector &direction,
122 const std::vector<G4int> &curVoxel) const;
123
125 const G4ThreeVector &direction) const;
126
127 G4double DistanceToBoundingBox(const G4ThreeVector &point) const;
128
129 inline G4int GetVoxelsIndex(G4int x, G4int y, G4int z) const;
130 inline G4int GetVoxelsIndex(const std::vector<G4int> &voxels) const;
131
132 inline G4int GetPointIndex(const G4ThreeVector &p) const;
133
134 inline const G4SurfBits &Empty() const;
135 inline G4bool IsEmpty(G4int index) const;
136
137 void SetMaxVoxels(G4int max);
138 void SetMaxVoxels(const G4ThreeVector &reductionRatio);
139
140 inline G4int GetMaxVoxels(G4ThreeVector &ratioOfReduction);
141
143
144 inline long long GetCountOfVoxels() const;
145
146 inline long long CountVoxels(std::vector<G4double> boundaries[]) const;
147
148 inline G4int GetCandidates(std::vector<G4int> &curVoxel,
149 std::vector<G4int> *&candidates,
150 std::vector<G4int> &space) const;
151 inline const std::vector<G4int> &
152 GetCandidates(std::vector<G4int> &curVoxel) const;
153
154 inline G4int GetVoxelBoxesSize() const;
155
156 inline const G4VoxelBox &GetVoxelBox(G4int i) const;
157
158 inline const std::vector<G4int> &GetVoxelBoxCandidates(G4int i) const;
159
160 static G4double MinDistanceToBox (const G4ThreeVector &aPoint,
161 const G4ThreeVector &f);
162
163 static G4int SetDefaultVoxelsCount(G4int count);
164
166
167 private:
168
169 class G4VoxelComparator
170 {
171 public:
172
173 std::vector<G4VoxelInfo> &fVoxels;
174
175 G4VoxelComparator(std::vector<G4VoxelInfo> &voxels) : fVoxels(voxels) {}
176
177 G4bool operator()(const G4int& l, const G4int& r) const
178 {
179 G4VoxelInfo &lv = fVoxels[l], &rv = fVoxels[r];
180 G4int left = lv.count + fVoxels[lv.next].count;
181 G4int right = rv.count + fVoxels[rv.next].count;
182 return (left == right) ? l < r : left < right;
183 }
184 };
185
186 private:
187
188 static int fDefaultVoxelsCount;
189
190 void BuildEmpty ();
191
192 G4String GetCandidatesAsString(const G4SurfBits &bits);
193
194 void CreateSortedBoundary(std::vector<G4double> &boundaryRaw, G4int axis);
195
196 void BuildBoundaries();
197
198 void BuildReduceVoxels(std::vector<G4double> fBoundaries[],
199 G4ThreeVector reductionRatio);
200 void BuildReduceVoxels2(std::vector<G4double> fBoundaries[],
201 G4ThreeVector reductionRatio);
202
203 void BuildVoxelLimits(std::vector<G4VFacet *> &facets);
204
205 void DisplayBoundaries(std::vector<G4double> &fBoundaries);
206
207 void BuildBitmasks(std::vector<G4double> fBoundaries[],
208 G4SurfBits bitmasks[], G4bool countsOnly=false);
209
210 void BuildBoundingBox();
211
212 void SetReductionRatio(G4int maxVoxels, G4ThreeVector &reductionRatio);
213
214 void CreateMiniVoxels(std::vector<G4double> fBoundaries[],
215 G4SurfBits bitmasks[]);
216 static void FindComponentsFastest(unsigned int mask,
217 std::vector<G4int> &list, G4int i);
218
219 private:
220
221 std::vector<G4VoxelBox> fVoxelBoxes;
222 std::vector<std::vector<G4int> > fVoxelBoxesCandidates;
223 mutable std::map<G4int, std::vector<G4int> > fCandidates;
224
225 const std::vector<G4int> fNoCandidates;
226
227 long long fCountOfVoxels;
228
229 G4int fNPerSlice;
230
231 std::vector<G4VoxelBox> fBoxes;
232 // Array of box limits on the 3 cartesian axis
233
234 std::vector<G4double> fBoundaries[3];
235 // Sorted and if need skimmed fBoundaries along X,Y,Z axis
236
237 std::vector<G4int> fCandidatesCounts[3];
238
239 G4int fTotalCandidates;
240
241 G4SurfBits fBitmasks[3];
242
243 G4ThreeVector fBoundingBoxCenter;
244
245 G4Box fBoundingBox;
246
247 G4ThreeVector fBoundingBoxSize;
248
249 G4ThreeVector fReductionRatio;
250
251 G4int fMaxVoxels;
252
253 G4double fTolerance;
254
255 G4SurfBits fEmpty;
256};
257
258#include "G4SurfaceVoxelizer.icc"
259
260#endif
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
bool G4bool
Definition: G4Types.hh:67
Definition: G4Box.hh:55
const std::vector< G4int > & GetCandidates(std::vector< G4int > &curVoxel) const
G4int GetMaxVoxels(G4ThreeVector &ratioOfReduction)
G4bool Contains(const G4ThreeVector &point) const
G4int GetVoxelsIndex(const std::vector< G4int > &voxels) const
G4int GetCandidates(std::vector< G4int > &curVoxel, std::vector< G4int > *&candidates, std::vector< G4int > &space) const
G4bool UpdateCurrentVoxel(const G4ThreeVector &point, const G4ThreeVector &direction, std::vector< G4int > &curVoxel) const
G4int GetPointIndex(const G4ThreeVector &p) const
long long GetCountOfVoxels() const
G4double DistanceToBoundingBox(const G4ThreeVector &point) const
void SetMaxVoxels(G4int max)
G4double DistanceToNext(const G4ThreeVector &point, const G4ThreeVector &direction, const std::vector< G4int > &curVoxel) const
const G4VoxelBox & GetVoxelBox(G4int i) const
G4int GetCandidatesVoxelArray(const G4ThreeVector &point, std::vector< G4int > &list, G4SurfBits *crossed=0) const
G4int GetVoxelsIndex(G4int x, G4int y, G4int z) const
static G4double MinDistanceToBox(const G4ThreeVector &aPoint, const G4ThreeVector &f)
G4double DistanceToFirst(const G4ThreeVector &point, const G4ThreeVector &direction) const
static G4int SetDefaultVoxelsCount(G4int count)
void Voxelize(std::vector< G4VFacet * > &facets)
void GetVoxel(std::vector< G4int > &curVoxel, const G4ThreeVector &point) const
G4int GetBitsPerSlice() const
const std::vector< G4VoxelBox > & GetBoxes() const
G4int GetVoxelBoxesSize() const
G4bool IsEmpty(G4int index) const
long long CountVoxels(std::vector< G4double > boundaries[]) const
const std::vector< G4double > & GetBoundary(G4int index) const
static G4int BinarySearch(const std::vector< T > &vec, T value)
const G4SurfBits & Empty() const
void GetCandidatesVoxel(std::vector< G4int > &voxels)
static G4int GetDefaultVoxelsCount()
const std::vector< G4int > & GetVoxelBoxCandidates(G4int i) const
friend class G4VoxelCandidatesIterator
G4ThreeVector hlen
G4ThreeVector pos