Code_TYMPAN  4.4.0
Industrial site acoustic simulation
Latitude2DSampler.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 <math.h>
23 #include "Sampler.h"
24 #include "Tools/UnitConverter.h"
25 
26 #ifndef LATITUDE_2D_SAMPLER
27  #define LATITUDE_2D_SAMPLER
28 
32 class Latitude2DSampler : public Sampler
33 {
34 
35 public:
37  Latitude2DSampler(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)), _deltaPhi(0.f), _i(nbRays)
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 Latitude2DSampler(this);
66  return sampler;
67  }
69  virtual ~Latitude2DSampler() {}
70 
71  virtual vec3 getSample()
72  {
73  decimal Phi = _startPhi + _i * _deltaPhi;
74  _i++;
75 
76  vec3 result;
78  return result;
79  }
80 
81  virtual bool isAcceptableSample(vec3 v)
82  {
83  return true;
84  }
85  virtual void init()
86  {
87  int decalage = 1;
88  if (abs(_endPhi - M_2PI - _startPhi) < EPSILON_6) // Diffusion a 360�
89  {
90  decalage = 0;
91  }
92 
93  _deltaPhi = (_endPhi - _startPhi) / static_cast<decimal>(_nb_rays - decalage);
94 
95  _i = 0;
96  }
98  void setStartTheta(const decimal& startTheta)
99  {
100  _startTheta = startTheta * M_PIDIV180;
101  init();
102  }
105  {
106  return _startTheta * M_180DIVPI;
107  }
109  void setEndTheta(const decimal& endTheta)
110  {
111  _endTheta = endTheta * M_PIDIV180;
112  init();
113  }
116  {
117  return _endTheta * M_180DIVPI;
118  }
120  void setStartPhi(const decimal& startPhi)
121  {
122  _startPhi = startPhi * M_PIDIV180;
123  init();
124  }
127  {
128  return _startPhi * M_180DIVPI;
129  }
131  void setEndPhi(const decimal& endPhi)
132  {
133  _endPhi = endPhi * M_PIDIV180;
134  init();
135  }
138  {
139  return _endPhi * M_180DIVPI;
140  }
141 
142 private:
148  unsigned int _i;
149 };
150 
151 #endif // LATITUDE_2D_SAMPLER
#define EPSILON_6
Definition: 3d.h:39
#define M_2PI
2Pi.
Definition: 3d.h:55
A Sampler class for latitude sampling.
virtual bool isAcceptableSample(vec3 v)
Return true for an acceptable sample.
void setEndTheta(const decimal &endTheta)
Set ending angle theta.
decimal getEndTheta() const
Get ending angle theta.
virtual Sampler * Clone()
Clone a sample.
decimal getEndPhi() const
Get ending angle phi.
decimal getStartTheta() const
Get starting angle theta.
Latitude2DSampler(const unsigned int &nbRays=0, const decimal &Theta=(decimal) M_PIDIV2, const decimal &Phi=(decimal) M_2PI)
Constructors.
virtual ~Latitude2DSampler()
Destructor.
void setStartPhi(const decimal &startPhi)
Set starting angle phi.
Latitude2DSampler(Latitude2DSampler *sampler)
virtual vec3 getSample()
Return the sample.
Latitude2DSampler(const Latitude2DSampler &other)
decimal getStartPhi() const
Get starting angle phi.
void setEndPhi(const decimal &endPhi)
Set ending angle phi.
virtual void init()
Initialize the sample.
void setStartTheta(const decimal &startTheta)
Set starting angle theta.
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