Code_TYMPAN  4.4.0
Industrial site acoustic simulation
RandomSphericSampler.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 RANDOM_SPHERIC_SAMPLER
17 #define RANDOM_SPHERIC_SAMPLER
18 
19 // Rajout de libraires pour creation fichier externe de sortie
20 #include <iostream>
21 #include <fstream>
22 #include <sstream>
23 #include <vector>
24 #include <string>
25 #include <math.h>
26 
27 #include <boost/random/mersenne_twister.hpp>
28 #include <boost/random/uniform_real.hpp>
29 
30 #include "Geometry/Sampler.h"
31 #include "Tools/UnitConverter.h"
32 
37 {
38 
39 public:
41  RandomSphericSampler(const unsigned int& nbRays = 0, const decimal& Theta = (decimal)M_PIDIV2,
42  const decimal& Phi = (decimal)M_2PI)
43  : Sampler(nbRays, Theta, Phi), bounded_sampler(boost::uniform_real<>(0., 1.))
44  {
45  }
46 
48  : Sampler(other), bounded_sampler(other.bounded_sampler)
49  {
50  }
51 
53  : Sampler(sampler), bounded_sampler(sampler->bounded_sampler)
54  {
55  }
56 
57  virtual Sampler* Clone()
58  {
59  Sampler* sampler = new RandomSphericSampler(this);
60  return sampler;
61  }
63  virtual ~RandomSphericSampler() {}
64 
65  virtual vec3 getSample()
66  {
69 
70  decimal thetaCalcul = (decimal)acos(2. * U - 1.) - _theta;
71  decimal phiCalcul = _phi * (decimal)V;
72 
73  vec3 result;
74  Tools::fromRadianToCarthesien(thetaCalcul, phiCalcul, result);
75  result.normalize();
76 
77  return result;
78  }
79 
80  virtual bool isAcceptableSample(vec3 v)
81  {
82  return true;
83  }
84 
85  virtual unsigned int computeDiffractionNbr(const decimal& thetaCalcul)
86  {
87  return static_cast<unsigned int>(
88  floor(sqrt(static_cast<decimal>(_nb_rays)) * sin(M_PIDIV2 - thetaCalcul) + 0.5));
89  }
90 
91 private:
92  static boost::mt19937 random_generator;
93 
94  boost::uniform_real<> bounded_sampler;
95 };
96 
97 boost::mt19937 RandomSphericSampler::random_generator = boost::mt19937();
98 
99 #endif // RANDOM_SPHERIC_SAMPLER
#define M_2PI
2Pi.
Definition: 3d.h:55
A Sampler class for random spherical sampling.
virtual vec3 getSample()
Return the sample.
virtual unsigned int computeDiffractionNbr(const decimal &thetaCalcul)
Return the number of rays to launch after a diffraction event.
RandomSphericSampler(const RandomSphericSampler &other)
RandomSphericSampler(const unsigned int &nbRays=0, const decimal &Theta=(decimal) M_PIDIV2, const decimal &Phi=(decimal) M_2PI)
Constructors.
static boost::mt19937 random_generator
virtual Sampler * Clone()
Clone a sample.
boost::uniform_real bounded_sampler
RandomSphericSampler(RandomSphericSampler *sampler)
virtual bool isAcceptableSample(vec3 v)
Return true for an acceptable sample.
virtual ~RandomSphericSampler()
Destructor.
Sampler class and its sub-classes describe ray generators used in AcousticRayTracer....
Definition: Sampler.h:30
decimal _phi
Global equatorial angle.
Definition: Sampler.h:118
decimal _theta
Global polar angle.
Definition: Sampler.h:117
unsigned int _nb_rays
Number of rays to launch.
Definition: Sampler.h:116
#define M_PIDIV2
Definition: mathlib.h:68
void fromRadianToCarthesien(decimal theta, decimal phi, vec3 &result)
Convert spherical coordinates to cartesian coordinates In this function :
float decimal
Definition: mathlib.h:45
base_vec3< decimal > vec3
Definition: mathlib.h:381