Geant4  10.00.p02
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 
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 
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 
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 
240 
242 
244 
246 
248 
250 
252 
254 
256 };
257 
258 #include "G4SurfaceVoxelizer.icc"
259 
260 #endif
G4bool Contains(const G4ThreeVector &point) const
G4ThreeVector fBoundingBoxSize
void BuildReduceVoxels(std::vector< G4double > fBoundaries[], G4ThreeVector reductionRatio)
void DisplayListNodes() const
std::vector< G4VoxelInfo > & fVoxels
G4int GetCandidatesVoxelArray(const G4ThreeVector &point, std::vector< G4int > &list, G4SurfBits *crossed=0) const
std::vector< G4VoxelBox > fVoxelBoxes
void Voxelize(std::vector< G4VFacet * > &facets)
CLHEP::Hep3Vector G4ThreeVector
friend class G4VoxelCandidatesIterator
G4ThreeVector fBoundingBoxCenter
G4double z
Definition: TRTMaterials.hh:39
Definition: G4Box.hh:64
G4int GetCandidates(std::vector< G4int > &curVoxel, std::vector< G4int > *&candidates, std::vector< G4int > &space) const
G4double DistanceToFirst(const G4ThreeVector &point, const G4ThreeVector &direction) const
G4double DistanceToBoundingBox(const G4ThreeVector &point) const
std::vector< G4int > fCandidatesCounts[3]
G4bool operator()(const G4int &l, const G4int &r) const
void BuildVoxelLimits(std::vector< G4VFacet * > &facets)
G4int GetVoxelsIndex(G4int x, G4int y, G4int z) const
G4String GetCandidatesAsString(const G4SurfBits &bits) const
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
static G4ThreadLocal G4int fDefaultVoxelsCount
G4int GetPointIndex(const G4ThreeVector &p) const
std::map< G4int, std::vector< G4int > > fCandidates
G4bool IsEmpty(G4int index) const
static G4int BinarySearch(const std::vector< T > &vec, T value)
void SetReductionRatio(G4int maxVoxels, G4ThreeVector &reductionRatio)
std::vector< std::vector< G4int > > fVoxelBoxesCandidates
void GetVoxel(std::vector< G4int > &curVoxel, const G4ThreeVector &point) const
bool G4bool
Definition: G4Types.hh:79
void CreateMiniVoxels(std::vector< G4double > fBoundaries[], G4SurfBits bitmasks[])
void BuildBitmasks(std::vector< G4double > fBoundaries[], G4SurfBits bitmasks[], G4bool countsOnly=false)
std::vector< G4VoxelBox > fBoxes
G4double DistanceToNext(const G4ThreeVector &point, const G4ThreeVector &direction, const std::vector< G4int > &curVoxel) const
void SetMaxVoxels(G4int max)
const std::vector< G4VoxelBox > & GetBoxes() const
std::vector< G4double > fBoundaries[3]
static G4int SetDefaultVoxelsCount(G4int count)
G4ThreeVector pos
T max(const T t1, const T t2)
brief Return the largest of the two arguments
G4ThreeVector fReductionRatio
static void FindComponentsFastest(unsigned int mask, std::vector< G4int > &list, G4int i)
void BuildReduceVoxels2(std::vector< G4double > fBoundaries[], G4ThreeVector reductionRatio)
void GetCandidatesVoxel(std::vector< G4int > &voxels)
G4VoxelComparator(std::vector< G4VoxelInfo > &voxels)
long long GetCountOfVoxels() const
const std::vector< G4double > & GetBoundary(G4int index) const
const G4SurfBits & Empty() const
G4int GetMaxVoxels(G4ThreeVector &ratioOfReduction)
void CreateSortedBoundary(std::vector< G4double > &boundaryRaw, G4int axis)
const std::vector< G4int > & GetVoxelBoxCandidates(G4int i) const
const std::vector< G4int > fNoCandidates
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()