Code_TYMPAN  4.4.0
Industrial site acoustic simulation
acoustic_problem_model.cpp
Go to the documentation of this file.
1 
9 #include <iostream>
10 #include <iomanip>
11 
15 
16 using namespace std;
17 
18 namespace tympan
19 {
20 
21 deque<triangle_idx> scene_volume_intersection(const triangle_pool_t& triangle_soup, const nodes_pool_t& nodes,
22  float w, float h, OPoint3D source, OPoint3D receptor)
23 {
24  CGAL_Point3 _source = to_cgal(source);
25  CGAL_Point3 _receptor = to_cgal(receptor);
26  deque<CGAL_Point3> vertices = build_box(w, h, _source, _receptor);
27  // we just want to apply rotation on mesh triangles and no translation --> center the box system
28  // on (0, 0, 0)
29  CGAL_Vector3 vx = normalize(CGAL_Vector3(vertices[0], vertices[1]));
30  CGAL_Vector3 vy = normalize(CGAL_Vector3(vertices[0], vertices[2]));
31  CGAL_Vector3 vz = normalize(CGAL_Vector3(vertices[0], vertices[3]));
32  CGAL_Transform3 to_box_system(vx.x(), vx.y(), vx.z(), vy.x(), vy.y(), vy.z(), vz.x(), vz.y(), vz.z());
33  // Move triangles from the triangle soup of the scene to the volume reference systeme and
34  // build CGAL triangles out of them
35  deque<CGAL_Point3> cgal_nodes;
36  for (nodes_pool_t::const_iterator it = nodes.begin(); it != nodes.end(); it++)
37  {
38  cgal_nodes.push_back(CGAL_Point3(it->_x, it->_y, it->_z).transform(to_box_system));
39  }
40  CGAL_Triangles cgal_triangles;
41  for (triangle_pool_t::const_iterator it = triangle_soup.begin(); it != triangle_soup.end(); it++)
42  {
43  cgal_triangles.push_back(
44  CGAL_Triangle(cgal_nodes[it->n[0]], cgal_nodes[it->n[1]], cgal_nodes[it->n[2]]));
45  }
46  float l = (float)sqrt(CGAL_Vector3(_source, _receptor).squared_length());
47  // these 3 points delimit the bounds of the fresnel box (in other terms, the bounding
48  // box of this triangle should have the dimensions of the fresnel box). This will be checked
49  // anyway by intersected_triangles() thanks to the expected dimensions passed: l, w and h
50  std::deque<CGAL_Point3> box_triangle;
51  box_triangle.push_back(vertices[1].transform(to_box_system));
52  box_triangle.push_back(vertices[2].transform(to_box_system));
53  box_triangle.push_back(vertices[3].transform(to_box_system));
54  return intersected_triangles(cgal_triangles, box_triangle, l, w, h);
55 }
56 
57 node_idx AcousticProblemModel::make_node(const Point& p)
58 {
59  all_nodes.push_back(p);
60  return all_nodes.size() - 1;
61 }
62 
63 AcousticTriangle::AcousticTriangle(node_idx n1, node_idx n2, node_idx n3)
64 {
65  n[0] = n1;
66  n[1] = n2;
67  n[2] = n3;
68 }
69 
70 triangle_idx AcousticProblemModel::make_triangle(node_idx n1, node_idx n2, node_idx n3)
71 {
72  all_triangles.push_back(AcousticTriangle(n1, n2, n3));
73  return all_triangles.size() - 1;
74 }
75 
76 material_ptr_t AcousticProblemModel::make_material(const string& name, double resistivity, double deviation,
77  double length, double factor_g)
78 {
79  material_ptr_t p_mat = nullptr;
80  shared_ptr<AcousticGroundMaterial> ptr = nullptr;
81  bool found = false;
82  // Search if an instance of AcousticGroundMaterial with same name and characteristics is already pushed
83  for (auto iter = all_materials.begin(); iter != all_materials.end(); ++iter)
84  {
85  ptr = tympan::dynamic_pointer_cast<AcousticGroundMaterial>(*iter);
86  // If it is not an AcousticGroundMaterial, continue
87  if (ptr == nullptr)
88  continue;
89  if (ptr->compare(name, resistivity, deviation, length, factor_g))
90  {
91  found = true;
92  break;
93  }
94  }
95  if (found)
96  {
97  p_mat = ptr;
98  }
99  else
100  {
101  // If no equivalent AcousticGroundMaterial is found, then create it and push it
102  p_mat = tympan::static_pointer_cast<AcousticMaterialBase>(
103  tympan::make_shared<AcousticGroundMaterial>(name, resistivity, deviation, length, factor_g));
104  all_materials.push_back(p_mat);
105  }
106  return p_mat;
107 }
108 
109 material_ptr_t AcousticProblemModel::make_material(const string& name, const ComplexSpectrum& spectrum)
110 {
111  material_ptr_t p_mat = tympan::static_pointer_cast<AcousticMaterialBase>(
112  tympan::make_shared<AcousticBuildingMaterial>(name, spectrum));
113  all_materials.push_back(p_mat);
114  return p_mat;
115 }
116 
117 source_idx AcousticProblemModel::make_source(const Point& point, const Spectrum& spectrum,
118  SourceDirectivityInterface* directivity)
119 {
120 
121  all_sources.push_back(AcousticSource(point, spectrum, directivity));
122  return all_sources.size() - 1;
123 }
124 
125 receptor_idx AcousticProblemModel::make_receptor(const Point& position_)
126 {
127  all_receptors.push_back(AcousticReceptor(position_));
128  return all_receptors.size() - 1;
129 }
130 
131 std::unique_ptr<AcousticProblemModel> make_AcousticProblemModel()
132 {
133  return std::unique_ptr<AcousticProblemModel>(new AcousticProblemModel());
134 }
135 
136 } // namespace tympan
const char * name
This file provides the top-level declaration for the acoustic problem model.
Utilities to ease (and wrap) use of CGAL.
The 3D point class.
Definition: 3d.h:487
Class to describe the acoustic problem.
Describes an acoustic receptor.
Definition: entities.hpp:388
Describes an acoustic source.
Definition: entities.hpp:366
Describing a triangle.
Definition: entities.hpp:189
Interface for source directivity classes (SphericalSourceDirectivity, CommonFaceDirectivity,...
Definition: entities.hpp:208
CGAL_Vector3 normalize(CGAL_Vector3 v)
normalize vector v
Definition: cgal_tools.cpp:26
size_t triangle_idx
Definition: entities.hpp:200
CGAL::Triangle_3< CGAL_Gt > CGAL_Triangle
Definition: cgal_tools.h:50
CGAL_Plane to_cgal(const OPlan &oplan)
Convert a OPlan to CGAL_Plane.
Definition: cgal_tools.cpp:19
size_t source_idx
Definition: entities.hpp:381
CGAL::Point_3< CGAL_Gt > CGAL_Point3
Definition: cgal_tools.h:45
CGAL::Vector_3< CGAL_Gt > CGAL_Vector3
Definition: cgal_tools.h:47
std::deque< CGAL_Triangle > CGAL_Triangles
Definition: cgal_tools.h:51
deque< triangle_idx > scene_volume_intersection(const triangle_pool_t &triangle_soup, const nodes_pool_t &nodes, float w, float h, OPoint3D source, OPoint3D receptor)
Find the intersection between some triangles (triangles, nodes) and a volume given by a width,...
std::deque< Point > nodes_pool_t
size_t receptor_idx
Definition: entities.hpp:398
std::unique_ptr< AcousticProblemModel > make_AcousticProblemModel()
std::deque< CGAL_Point3 > build_box(float w, float h, CGAL_Point3 pta, CGAL_Point3 ptb)
return 4 points defining a 3D parallelepiped
Definition: cgal_tools.cpp:31
CGAL::Aff_transformation_3< CGAL_Gt > CGAL_Transform3
Definition: cgal_tools.h:53
shared_ptr< AcousticMaterialBase > material_ptr_t
Definition: entities.hpp:40
std::deque< AcousticTriangle > triangle_pool_t
Array of AcousticTriangle.
Definition: entities.hpp:199
std::deque< size_t > intersected_triangles(CGAL_Triangles &triangle_soup, std::deque< CGAL_Point3 > query_box, float length, float width, float height)
Find the triangles from triangle_soup that are intersected by the 3D box including the points of quer...
Definition: cgal_tools.cpp:68
size_t node_idx