Code_TYMPAN  4.2.0
Industrial site acoustic simulation
geometry_modifier.cpp
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 
17 
18 #include "geometry_modifier.h"
22 #include "Lancer.h"
23 #include "RayCourb.h"
24 
25 using namespace std;
26 
28 {
29  unsigned int nbRay = shot.nbRay;
30  pos_center = shot.sources[0];
31 
32  // 1- On creer nos triangles de Delaunay
33  ODelaunayMaker oDelaunayMaker(1e-5);
34 
35  for (unsigned int i = 0; i < nbRay; ++i) // boucle sur les rayons lances
36  {
37  for (unsigned int j = 0; j < shot.MatRes[0][i].etapes.size(); ++j) // boucle sur les points du rayon
38  {
39  // the mesh is corrected to reflect final geometry transformation
40  vec3 pos(shot.MatRes[0][i].etapes[j].pos);
41  pos.z = -(pos.z-pos_center.z);
42  oDelaunayMaker.addVertex(vec3toOPoint3D(pos));
43  }
44  }
45 
46  oDelaunayMaker.compute();
47 
48  // 2- On a notre liste de triangles
49  QList<OTriangle> Liste_triangles = oDelaunayMaker.getFaces();
50  QList<OPoint3D> Liste_vertex = oDelaunayMaker.getVertex();
52  append_triangles_to_scene(Liste_vertex, Liste_triangles);
53 }
54 
56 {
57  double h = compute_h(P);
58 
59  return vec3(P.x, P.y, P.z + h);
60 }
61 
63 {
64  double h = compute_h(P);
65 
66  return vec3(P.x, P.y, P.z - h);
67 }
68 
70 {
71  double offset = 2000.;
72  vec3 origine(P.x, P.y, (P.z + offset) );
73  Ray ray1( origine, vec3(0., 0., -1.) );
74 
75  std::list<Intersection> LI;
76  return (P.z + offset) - static_cast<double>( _scene->getAccelerator()->traverse( &ray1, LI ) );
77 }
78 
79 void geometry_modifier_z_correction::append_triangles_to_scene(QList<OPoint3D>& Liste_vertex, QList<OTriangle>& Liste_triangles)
80 {
81  vec3 pos;
82  for (int i = 0; i<Liste_triangles.size(); i++)
83  {
84  unsigned int a, b, c;
85 
86  pos = OPoint3Dtovec3( Liste_vertex.at( Liste_triangles.at(i)._p1 ) );
87  _scene->addVertex(pos, a);
88 
89  pos = OPoint3Dtovec3( Liste_vertex.at( Liste_triangles.at(i)._p2 ) );
90  _scene->addVertex(pos, b);
91 
92  pos = OPoint3Dtovec3( Liste_vertex.at( Liste_triangles.at(i)._p3 ) );
93  _scene->addVertex(pos, c);
94 
95  (Triangle*)_scene->addTriangle(a, b, c, nullptr);
96  }
97 
98  _scene->finish(1); // Use grid accelerator
99 }
virtual vec3 fonction_h(const vec3 &P)
Pure virtual function for a point transformation.
Describes analytical ray curve tracing.
Definition: Lancer.h:37
unsigned int nbRay
Launched rays number.
Definition: Lancer.h:161
STL namespace.
base_vec3< decimal > vec3
Definition: mathlib.h:269
QList< OTriangle > getFaces(void)
Return faces list.
vector< RayCourb * > MatRes
Array containing the resulting rays for each source.
Definition: Lancer.h:167
NxReal c
Definition: NxVec3.cpp:345
3D vector Vector defined with 3 float numbers
Definition: mathlib.h:107
QList< OPoint3D > getVertex(void)
Return the vertexes list.
void addVertex(OPoint3D vertex)
Add a vertex.
vector< vec3 > sources
Sources vector.
Definition: Lancer.h:146
: Describes a ray by a pair of unsigned int. The first one gives the source number (in the range 0-40...
Definition: Ray.h:38
Triangle class.
Definition: Triangle.h:24
Delaunay triangulation.
vec3 OPoint3Dtovec3(const OPoint3D &_p)
Converts a OPoint3D to vec3.
Definition: mathlib.h:313
virtual void buildNappe(const Lancer &shot)
Pure virtual function to create the triangles mesh built with rays.
OPoint3D vec3toOPoint3D(const vec3 &_v)
Converts a vec3 to OPoint3D.
Definition: mathlib.h:307
void append_triangles_to_scene(QList< OPoint3D > &Liste_vertex, QList< OTriangle > &Liste_triangles)
bool compute(void)
Compute the triangulation.
virtual vec3 fonction_h_inverse(const vec3 &P)
Pure virtual function for an inverse point transformation.