72 theta = ((
decimal)(rand())) * angleOuverture / ((
decimal)RAND_MAX);
74 if (theta > angleOuverture / 2.)
84 theta = (nbResponseLeft * delta_theta) - (angleOuverture /
decimal(2.));
90 name =
"unknown diffraction";
148 #ifdef _ALLOW_TARGETING_
158 if (!targets.empty())
160 r =
vec3(targets.back());
181 bRep = (*responseValidator)(
from,
N1,
N2, r);
192 vec3 v1 =
c->getVertices()->at(
c->getLocalVertices()->at(0));
193 vec3 v2 =
c->getVertices()->at(
c->getLocalVertices()->at(1));
204 vec3 X =
c->getFirstShape()->getNormal() +
c->getSecondShape()->getNormal();
231 unsigned int nbResponses)
233 for (
unsigned int i = 0; i < nbResponses; i++)
241 succededTest.push_back(newDir);
245 failTest.push_back(newDir);
251 #ifdef _ALLOW_TARGETING_
257 if (localResponse.z < 0.)
262 decimal phi = acos(localResponse.z);
265 if (localResponse.y >= 0.)
267 tetha = acos(localResponse.x /
268 (sqrt(localResponse.x * localResponse.x + localResponse.y * localResponse.y)));
273 2. *
M_PI - acos(localResponse.x /
274 (sqrt(localResponse.x * localResponse.x + localResponse.y * localResponse.y)));
283 if (deltaPhi <
M_PI / 18.)
293 for (
unsigned int i = 0; i < nbResponses; i++)
296 responses.push_back(newDir);
309 targets.push_back(newDir);
321 targets.push_back(newDir);
double ABS(double a)
Return the absolute value.
bool responseAngleLimiter(const vec3 &from, const vec3 &N1, const vec3 &N2, vec3 &T)
void getThetaRandom(const decimal &angleOuverture, const decimal &delta_theta, const decimal &nbResponseLeft, decimal &theta)
void getThetaRegular(const decimal &angleOuverture, const decimal &delta_theta, const decimal &nbResponseLeft, decimal &theta)
bool responseAlwaysYes(const vec3 &from, const vec3 &N1, const vec3 &N2, vec3 &T)
bool DiffractionFilterRayAtCreation
Flag to filter the created rays during diffraction.
bool DiffractionUseRandomSampler
Flag to enable random (and not regular) sampling for diffraction.
static AcousticRaytracerConfiguration * get()
Get access to the configuration.
std::string name
Each instantiated object may be named.
void computeDTheta()
Compute the angle step between two responses in function of the aperture angle and the number of resp...
Repere localRepere
Local frame.
virtual bool getResponse(vec3 &r, bool force=false)
Computes the next response of the event in function of the number of responses left.
decimal delta_theta
Angle step between two rays to send.
decimal angleArrive
Incident ray angle.
virtual bool generateTest(std::vector< vec3 > &succededTest, std::vector< vec3 > &failTest, unsigned int nbResponses)
bool(* responseValidator)(const vec3 &, const vec3 &, const vec3 &, vec3 &)
Filter generated response (or not)
void computeAngle()
Compute the angle between the incident ray and the diffraction edge.
void buildRepere()
Build local frame.
void(* getTheta)(const decimal &, const decimal &, const decimal &, decimal &)
Diffraction(const vec3 &position=vec3(0.0, 0.0, 0.0), const vec3 &incomingDirection=vec3(0.0, 0.0, 0.0), Cylindre *c=NULL)
Constructor.
decimal angleOuverture
Angle formed by the two faces of the diffraction edge.
Class describing an event (reflection, diffraction, ...)
int nbResponseLeft
Number of remaining rays to launch.
Shape * shape
The impact primitive.
vec3 from
Direction vector of the incoming ray.
vec3 pos
Location point of the event.
int initialNbResponse
Number of rays to launch after event.
typeevent type
Event type.
virtual bool generateResponse(std::vector< vec3 > &responses, unsigned int nbResponses)
virtual bool appendTarget(vec3 target, bool force=false)
virtual bool isAcceptableResponse(vec3 &test)
Return true if the ray direction vector in response of the event is acceptable.
vec3 vectorFromGlobalToLocal(const vec3 &global)
Get local coordinates of vector expressed in global coordinates.
vec3 vectorFromLocalToGlobal(const vec3 &local)
Get global coordinates of vector expressed in local coordinates.
base class for shapes (Cylindre, Mesh, Sphere, Triangle,...)
virtual vec3 getNormal(const vec3 pos=vec3())
Get normal.
base_vec3< decimal > vec3