Geant4  10.02.p01
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 91755 2015-08-05 08:17:56Z 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 struct G4VoxelBox
54 {
55  G4ThreeVector hlen; // half length of the box
56  G4ThreeVector pos; // position of the box
57 };
58 
60 {
64 };
65 
67 {
68  public:
69 
70  template <typename T>
71  static inline G4int BinarySearch(const std::vector<T> &vec, T value);
72 
73  void Voxelize(std::vector<G4VFacet *> &facets);
74 
75  void DisplayVoxelLimits();
76  void DisplayBoundaries();
77  void DisplayListNodes() const;
78 
81 
82  void GetCandidatesVoxel(std::vector<G4int> &voxels);
83  // Method displaying the nodes located in a voxel characterized
84  // by its three indexes.
85 
87  std::vector<G4int> &list,
88  G4SurfBits *crossed=0) const;
89  // Method returning in a vector container the nodes located in a voxel
90  // characterized by its three indexes.
91  G4int GetCandidatesVoxelArray(const std::vector<G4int> &voxels,
92  const G4SurfBits bitmasks[],
93  std::vector<G4int> &list,
94  G4SurfBits *crossed=0) const;
95  G4int GetCandidatesVoxelArray(const std::vector<G4int> &voxels,
96  std::vector<G4int> &list,
97  G4SurfBits *crossed=0)const;
98 
99  inline const std::vector<G4VoxelBox> &GetBoxes() const;
100  // Method returning the pointer to the array containing the
101  // characteristics of each box.
102 
103  inline const std::vector<G4double> &GetBoundary(G4int index) const;
104 
106  const G4ThreeVector &direction,
107  std::vector<G4int> &curVoxel) const;
108 
109  inline void GetVoxel(std::vector<G4int> &curVoxel,
110  const G4ThreeVector &point) const;
111 
112  inline G4int GetBitsPerSlice () const;
113 
114  G4bool Contains(const G4ThreeVector &point) const;
115 
117  const G4ThreeVector &direction,
118  const std::vector<G4int> &curVoxel) const;
119 
121  const G4ThreeVector &direction) const;
122 
123  G4double DistanceToBoundingBox(const G4ThreeVector &point) const;
124 
125  inline G4int GetVoxelsIndex(G4int x, G4int y, G4int z) const;
126  inline G4int GetVoxelsIndex(const std::vector<G4int> &voxels) const;
127 
128  inline G4int GetPointIndex(const G4ThreeVector &p) const;
129 
130  inline const G4SurfBits &Empty() const;
131  inline G4bool IsEmpty(G4int index) const;
132 
133  void SetMaxVoxels(G4int max);
134  void SetMaxVoxels(const G4ThreeVector &reductionRatio);
135 
136  inline G4int GetMaxVoxels(G4ThreeVector &ratioOfReduction);
137 
139 
140  inline long long GetCountOfVoxels() const;
141 
142  inline long long CountVoxels(std::vector<G4double> boundaries[]) const;
143 
144  inline const std::vector<G4int> &
145  GetCandidates(std::vector<G4int> &curVoxel) const;
146 
147  inline G4int GetVoxelBoxesSize() const;
148 
149  inline const G4VoxelBox &GetVoxelBox(G4int i) const;
150 
151  inline const std::vector<G4int> &GetVoxelBoxCandidates(G4int i) const;
152 
153  inline G4int GetTotalCandidates() const;
154 
155  static G4double MinDistanceToBox (const G4ThreeVector &aPoint,
156  const G4ThreeVector &f);
157 
158  static G4int SetDefaultVoxelsCount(G4int count);
159 
160  static G4int GetDefaultVoxelsCount();
161 
162  private:
163 
165  {
166  public:
167 
168  std::vector<G4VoxelInfo> &fVoxels;
169 
170  G4VoxelComparator(std::vector<G4VoxelInfo> &voxels) : fVoxels(voxels) {}
171 
172  G4bool operator()(const G4int& l, const G4int& r) const
173  {
174  G4VoxelInfo &lv = fVoxels[l], &rv = fVoxels[r];
175  G4int left = lv.count + fVoxels[lv.next].count;
176  G4int right = rv.count + fVoxels[rv.next].count;
177  return (left == right) ? l < r : left < right;
178  }
179  };
180 
181  private:
182 
184 
185  void BuildEmpty ();
186 
187  G4String GetCandidatesAsString(const G4SurfBits &bits) const;
188 
189  void CreateSortedBoundary(std::vector<G4double> &boundaryRaw, G4int axis);
190 
191  void BuildBoundaries();
192 
193  void BuildReduceVoxels(std::vector<G4double> fBoundaries[],
194  G4ThreeVector reductionRatio);
195  void BuildReduceVoxels2(std::vector<G4double> fBoundaries[],
196  G4ThreeVector reductionRatio);
197 
198  void BuildVoxelLimits(std::vector<G4VFacet *> &facets);
199 
200  void DisplayBoundaries(std::vector<G4double> &fBoundaries);
201 
202  void BuildBitmasks(std::vector<G4double> fBoundaries[],
203  G4SurfBits bitmasks[], G4bool countsOnly=false);
204 
205  void BuildBoundingBox();
206 
207  void SetReductionRatio(G4int maxVoxels, G4ThreeVector &reductionRatio);
208 
209  void CreateMiniVoxels(std::vector<G4double> fBoundaries[],
210  G4SurfBits bitmasks[]);
211  static void FindComponentsFastest(unsigned int mask,
212  std::vector<G4int> &list, G4int i);
213 
214  private:
215 
216  std::vector<G4VoxelBox> fVoxelBoxes;
217  std::vector<std::vector<G4int> > fVoxelBoxesCandidates;
218  mutable std::map<G4int, std::vector<G4int> > fCandidates;
219 
220  const std::vector<G4int> fNoCandidates;
221 
222  long long fCountOfVoxels;
223 
225 
226  std::vector<G4VoxelBox> fBoxes;
227  // Array of box limits on the 3 cartesian axis
228 
229  std::vector<G4double> fBoundaries[3];
230  // Sorted and if need skimmed fBoundaries along X,Y,Z axis
231 
232  std::vector<G4int> fCandidatesCounts[3];
233 
235 
237 
239 
241 
243 
245 
247 
249 
251 };
252 
253 #include "G4SurfaceVoxelizer.icc"
254 
255 #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
G4ThreeVector fBoundingBoxCenter
static ush mask[]
Definition: csz_inflate.cc:317
G4double z
Definition: TRTMaterials.hh:39
Definition: G4Box.hh:64
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:89
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]
const std::vector< G4int > & GetCandidates(std::vector< G4int > &curVoxel) const
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
const G4double x[NPOINTSGL]
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
G4int GetTotalCandidates() 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()