Code_TYMPAN  4.4.0
Industrial site acoustic simulation
Longitude2DSampler.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 // Rajout de libraires pour creation fichier externe de sortie
17 #include <iostream>
18 #include <fstream>
19 #include <sstream>
20 #include <vector>
21 #include <string>
22 #include <cmath>
23 #include "Sampler.h"
24 #include "Tools/UnitConverter.h"
25 
26 #ifndef LONGITUDE_2D_SAMPLER
27  #define LONGITUDE_2D_SAMPLER
28 
33 {
34 
35 public:
37  Longitude2DSampler(const unsigned int& nbRays = 0, const decimal& Theta = (decimal)M_PIDIV2,
38  const decimal& Phi = (decimal)M_2PI)
39  : Sampler(nbRays, Theta, Phi), _startTheta(0.f), _endTheta(static_cast<float>(M_PI)), _startPhi(0.f),
40  _endPhi(static_cast<float>(M_PI)), _deltaTheta(0.), _nMin(vec3(0., 0., 0.)), _i(0)
41  {
42  init();
43  }
44 
46  {
47  _startTheta = other._startTheta;
48  _endTheta = other._endTheta;
49  _startPhi = other._startPhi;
50  _endPhi = other._endPhi;
51  init();
52  }
53 
55  {
56  _startTheta = sampler->_startTheta;
57  _endTheta = sampler->_endTheta;
58  _startPhi = sampler->_startPhi;
59  _endPhi = sampler->_endPhi;
60  init();
61  }
62 
63  virtual Sampler* Clone()
64  {
65  Sampler* sampler = new Longitude2DSampler(this);
66  return sampler;
67  }
69  virtual ~Longitude2DSampler() {}
70 
71  virtual vec3 getSample()
72  {
73  // angle entre l'axe des y et nMin
74  decimal Theta = std::asin(_nMin * vec3(0, 0, 1)) + _deltaTheta * _i;
75  _i++;
76 
77  vec3 result;
79 
80  return result;
81  }
82 
83  virtual bool isAcceptableSample(vec3 v)
84  {
85  return true;
86  }
87  virtual void init()
88  {
89  _nMin = vec3(cos(_startTheta), 0, sin(_startTheta));
90  vec3 nMax(cos(_endTheta), 0, sin(_endTheta));
91 
92  // angle de variation des rayons
93  _deltaTheta = std::acos(_nMin * nMax) / (_nb_rays - 1);
94 
95  _i = 0;
96  }
98  void setStartTheta(const decimal& startTheta)
99  {
100  _startTheta = startTheta * M_PIDIV180;
101  init();
102  }
104  {
105  return _startTheta * M_180DIVPI;
106  }
108  void setEndTheta(const decimal& endTheta)
109  {
110  _endTheta = endTheta * M_PIDIV180;
111  init();
112  }
114  {
115  return _endTheta * M_180DIVPI;
116  }
118  void setStartPhi(const decimal& startPhi)
119  {
120  _startPhi = startPhi * M_PIDIV180;
121  init();
122  }
124  {
125  return _startPhi * M_180DIVPI;
126  }
128  void setEndPhi(const decimal& endPhi)
129  {
130  _endPhi = endPhi * M_PIDIV180;
131  init();
132  }
134  {
135  return _endPhi * M_180DIVPI;
136  }
137 
138 private:
145  unsigned int _i;
146 };
147 
148 #endif // LONGITUDE_2D_SAMPLER
#define M_2PI
2Pi.
Definition: 3d.h:55
A Sampler class for longitudinal sampling.
decimal getEndPhi() const
Longitude2DSampler(Longitude2DSampler *sampler)
void setStartTheta(const decimal &startTheta)
Set/Get starting angle theta.
void setStartPhi(const decimal &startPhi)
Set/Get starting angle phi.
void setEndPhi(const decimal &endPhi)
Set/Get ending angle phi.
virtual bool isAcceptableSample(vec3 v)
Return true for an acceptable sample.
Longitude2DSampler(const Longitude2DSampler &other)
void setEndTheta(const decimal &endTheta)
Set/Get ending angle theta.
decimal getEndTheta() const
decimal getStartPhi() const
virtual vec3 getSample()
Return the sample.
Longitude2DSampler(const unsigned int &nbRays=0, const decimal &Theta=(decimal) M_PIDIV2, const decimal &Phi=(decimal) M_2PI)
Constructors.
virtual ~Longitude2DSampler()
Destructor.
virtual Sampler * Clone()
Clone a sample.
virtual void init()
Initialize the sample.
decimal getStartTheta() const
Sampler class and its sub-classes describe ray generators used in AcousticRayTracer....
Definition: Sampler.h:30
unsigned int _nb_rays
Number of rays to launch.
Definition: Sampler.h:116
#define M_PI
Pi.
Definition: color.cpp:25
#define M_180DIVPI
Definition: mathlib.h:80
#define M_PIDIV180
Definition: mathlib.h:79
#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