Geant4_10
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: G4SurfaceVoxelizer.hh 72335 2013-07-16 09:01:49Z gcosmo $
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 
55 struct G4VoxelBox
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() const;
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 
165  static G4int GetDefaultVoxelsCount();
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 G4ThreadLocal G4int fDefaultVoxelsCount;
189 
190  void BuildEmpty ();
191 
192  G4String GetCandidatesAsString(const G4SurfBits &bits) const;
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
G4bool Contains(const G4ThreeVector &point) const
void DisplayListNodes() const
G4int GetCandidatesVoxelArray(const G4ThreeVector &point, std::vector< G4int > &list, G4SurfBits *crossed=0) const
void Voxelize(std::vector< G4VFacet * > &facets)
friend class G4VoxelCandidatesIterator
Int_t index
Definition: macro.C:9
Definition: G4Box.hh:63
G4int GetCandidates(std::vector< G4int > &curVoxel, std::vector< G4int > *&candidates, std::vector< G4int > &space) const
const char * p
Definition: xmltok.h:285
G4double DistanceToFirst(const G4ThreeVector &point, const G4ThreeVector &direction) const
G4double DistanceToBoundingBox(const G4ThreeVector &point) const
G4int GetVoxelsIndex(G4int x, G4int y, G4int z) const
tuple x
Definition: test.py:50
static G4double MinDistanceToBox(const G4ThreeVector &aPoint, const G4ThreeVector &f)
#define G4ThreadLocal
Definition: tls.hh:52
G4bool UpdateCurrentVoxel(const G4ThreeVector &point, const G4ThreeVector &direction, std::vector< G4int > &curVoxel) const
int G4int
Definition: G4Types.hh:78
G4int GetBitsPerSlice() const
TFile f
Definition: plotHisto.C:6
G4int GetPointIndex(const G4ThreeVector &p) const
G4bool IsEmpty(G4int index) const
Double_t y
Definition: plot.C:279
static G4int BinarySearch(const std::vector< T > &vec, T value)
void GetVoxel(std::vector< G4int > &curVoxel, const G4ThreeVector &point) const
bool G4bool
Definition: G4Types.hh:79
G4double DistanceToNext(const G4ThreeVector &point, const G4ThreeVector &direction, const std::vector< G4int > &curVoxel) const
void SetMaxVoxels(G4int max)
const std::vector< G4VoxelBox > & GetBoxes() const
static G4int SetDefaultVoxelsCount(G4int count)
jump r
Definition: plot.C:36
G4ThreeVector pos
T max(const T t1, const T t2)
brief Return the largest of the two arguments
tuple z
Definition: test.py:28
void GetCandidatesVoxel(std::vector< G4int > &voxels)
long long GetCountOfVoxels() const
const XML_Char int const XML_Char * value
Definition: expat.h:331
const std::vector< G4double > & GetBoundary(G4int index) const
const G4SurfBits & Empty() const
G4int GetMaxVoxels(G4ThreeVector &ratioOfReduction)
const std::vector< G4int > & GetVoxelBoxCandidates(G4int i) const
double G4double
Definition: G4Types.hh:76
G4int GetVoxelBoxesSize() const
G4ThreeVector hlen
long long CountVoxels(std::vector< G4double > boundaries[]) const
const G4VoxelBox & GetVoxelBox(G4int i) const
static G4int GetDefaultVoxelsCount()