Code_TYMPAN  4.4.0
Industrial site acoustic simulation
UniformCircularSampler.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012-2024> <EDF-DTG> <FRANCE>
3  * This file is part of Code_TYMPAN (R).
4  * Code_TYMPAN (R) is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * Code_TYMPAN (R) is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License along
13  * with Code_TYMPAN (R). If not, see <https://www.gnu.org/licenses/>.
14  */
15 
16 #include "UniformCircularSampler.h"
17 
19  const vec3& normal /* = vec3{0., 0., 1.} */)
20  : Sampler(nbRays), _normal(normal)
21 {
22  init();
23 }
24 
26 {
27  _u = sampler._u;
28  _v = sampler._v;
29  _normal = sampler._normal;
30  _i = sampler._i;
31  _dTheta = sampler._dTheta;
32 }
33 
35 {
36  _u = pSampler->_u;
37  _v = pSampler->_v;
38  _normal = pSampler->_normal;
39  _i = pSampler->_i;
40  _dTheta = pSampler->_dTheta;
41 }
42 
44 {
45  Sampler* sampler = new UniformCircularSampler(this);
46  return sampler;
47 }
48 
50 {
51  // build an orthonormal basis of a plane orthogonal to _normal
52  if (abs(_normal.x) < EPSILON_13 && abs(_normal.y) < EPSILON_13)
53  {
54  // _normal is colinear to (0, 0, 1)
55  // in this case, we get directly an orthonormal basis using e1 and e2
56  _u = vec3{1., 0., 0.};
57  _v = vec3{0., 1., 0.};
58  }
59  else
60  {
61  // _normal is not colinear to (0, 0, 1)
62  // in this case, we have to build an orthonormal basis:
63  // - define a candidate u_prime, non-colinear with _normal
64  // - build u, orthogonal to _normal using the Gram-Schmidt process
65  // - build v using cross product
66  // - normalize u and v
67  const vec3 u_prime{0., 0., 1.};
68  _u = vec3{u_prime - _normal * (u_prime * _normal) / (_normal * _normal)};
69  _v = vec3{_u ^ _normal};
70  _u.normalize();
71  _v.normalize();
72  }
73 
74  _i = 0;
76 }
77 
79 {
80  const decimal theta{_i * _dTheta};
81  vec3 v{_u * std::cos(theta) + _v * std::sin(theta)};
82  _i++;
83  return v;
84 }
85 
87 {
88  return std::abs(v * _normal) < EPSILON_6;
89 }
#define EPSILON_6
Definition: 3d.h:39
#define M_2PI
2Pi.
Definition: 3d.h:55
#define EPSILON_13
Definition: 3d.h:41
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
Sampler providing directions uniformly distributed on a circle. This circle is in the plane defined b...
UniformCircularSampler(unsigned int nbRays=1, const vec3 &normal=vec3{0., 0., 1.})
void init() override
Initialize the sample.
vec3 getSample() override
Return the sample.
Sampler * Clone() override
Clone a sample.
bool isAcceptableSample(vec3 v) override
Return true for an acceptable sample.
float decimal
Definition: mathlib.h:45
base_vec3< decimal > vec3
Definition: mathlib.h:387