Code_TYMPAN  4.4.0
Industrial site acoustic simulation
GridAccelerator.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012> <EDF-R&D> <FRANCE>
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for more details.
11  * You should have received a copy of the GNU General Public License along
12  * with this program; if not, write to the Free Software Foundation, Inc.,
13  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
14  */
15 
16 #ifndef GRIDACCELERATOR_H
17 #define GRIDACCELERATOR_H
18 
19 #include "Geometry/BBox.h"
20 #include <vector>
21 #include "Geometry/Shape.h"
22 #include "Accelerator.h"
23 #include <stdint.h>
24 
25 // GridAccel Forward Declarations
26 struct Voxel;
27 
28 // Voxel Declarations
29 struct Voxel
30 {
32  size_t size() const
33  {
34  return primitives.size();
35  }
38  {
39  allCanIntersect = true;
40  }
42  Voxel(Shape* op)
43  {
44  allCanIntersect = true;
45  primitives.push_back(op);
46  }
47  void AddPrimitive(Shape* prim)
48  {
49  primitives.push_back(prim);
50  }
51  bool Intersect(Ray* ray, std::list<Intersection>& result, decimal& intermin,
53 
54 private:
55  std::vector<Shape*> primitives;
57 };
58 
63 {
64 
65 public:
67  GridAccelerator(std::vector<Shape*>* _initialMesh = NULL, BBox _globalBox = BBox());
69  virtual ~GridAccelerator()
70  {
71  for (int i = 0; i < nVoxels[0] * nVoxels[1] * nVoxels[2]; ++i)
72  if (voxels[i])
73  {
74  voxels[i]->~Voxel();
75  }
76  delete[] voxels;
77  }
78 
79  virtual bool build();
80 
81  virtual decimal traverse(Ray* r, std::list<Intersection>& result) const;
83  void setMaxProfondeur(int _maxProfondeur)
84  {
85  maxProfondeur = _maxProfondeur;
86  }
89  {
90  return maxProfondeur;
91  }
93  void setMaxPrimPerLeaf(int _maxPrimPerLeaf)
94  {
95  maxPrimPerLeaf = _maxPrimPerLeaf;
96  }
99  {
100  return maxPrimPerLeaf;
101  }
103  void print();
104  /* Uncommented cause not used:
105  bool alreadyFail;
106  unsigned int nbFail;
107  Ray r;
108  bool trace;
109  */
110 protected:
111  std::vector<Shape*>
114 
117 
119  /* Uncommented cause unused:
120  float isectCost;
121  float emptyBonus;
122  float traversalCost;
123  */
124 private:
125  // GridAccel Private Methods
126  int posToVoxel(const vec3& P, int axis) const
127  {
128  int v = (int)((P[axis] - bounds.pMin[axis]) * invWidth[axis]);
129  return Clamp(v, 0, nVoxels[axis] - 1);
130  }
131  float voxelToPos(int p, int axis) const
132  {
133  return bounds.pMin[axis] + p * width[axis];
134  }
135  inline int offset(int x, int y, int z) const
136  {
137  return z * nVoxels[0] * nVoxels[1] + y * nVoxels[0] + x;
138  }
139 
140  // GridAccel Private Data
141  int nVoxels[3];
145 };
146 
147 #endif
Base class for accelerators.
Definition: Accelerator.h:27
Definition of a bounding box which is aligned along the axis (BBox AABB).
Definition: BBox.h:32
vec3 pMin
Lower point of the BBox.
Definition: BBox.h:35
Regular grid Accelerator.
int maxProfondeur
Maximal depth.
GridAccelerator(std::vector< Shape * > *_initialMesh=NULL, BBox _globalBox=BBox())
Constructor.
int offset(int x, int y, int z) const
int getMaxPrimPerLeaf()
Get maximal primitives per leaf.
void print()
Print (not implemented)
int realMaxProfondeur
Real maximal depth.
virtual decimal traverse(Ray *r, std::list< Intersection > &result) const
Run this accelerator.
std::vector< Shape * > primitives
Pointer to all the shapes (different from initialMesh) as it is reordered.
void setMaxPrimPerLeaf(int _maxPrimPerLeaf)
Set maximal primitives per leaf.
int posToVoxel(const vec3 &P, int axis) const
int maxPrimPerLeaf
Maximal primitives per leaf.
BBox globalBox
Root bounding box.
virtual bool build()
Build this accelerator.
float voxelToPos(int p, int axis) const
int getMaxProfondeur()
Get maximal depth.
virtual ~GridAccelerator()
Destructor.
void setMaxProfondeur(int _maxProfondeur)
Set maximal depth.
: Describes a ray by a pair of unsigned int. The first one gives the source number (in the range 0-40...
Definition: Ray.h:38
base class for shapes (Cylindre, Mesh, Sphere, Triangle,...)
Definition: Shape.h:57
float decimal
Definition: mathlib.h:45
float Clamp(float val, float low, float high)
Definition: mathlib.h:1367
base_vec3< decimal > vec3
Definition: mathlib.h:381
std::vector< Shape * > primitives
Vector containing the primitives.
Voxel()
Default constructor.
void AddPrimitive(Shape *prim)
Voxel(Shape *op)
Constructor.
bool allCanIntersect
Flag not used.
bool Intersect(Ray *ray, std::list< Intersection > &result, decimal &intermin, leafTreatment::treatment choice)
size_t size() const
Get size.