Code_TYMPAN  4.2.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,
22  const nodes_pool_t & nodes, float w, float h,
23  OPoint3D source, OPoint3D receptor)
24 {
25  CGAL_Point3 _source = to_cgal(source);
26  CGAL_Point3 _receptor = to_cgal(receptor);
27  deque<CGAL_Point3> vertices = build_box(w, h, _source, _receptor);
28  // we just want to apply rotation on mesh triangles and no translation --> center the box system
29  // on (0, 0, 0)
30  CGAL_Vector3 vx = normalize(CGAL_Vector3(vertices[0], vertices[1]));
31  CGAL_Vector3 vy = normalize(CGAL_Vector3(vertices[0], vertices[2]));
32  CGAL_Vector3 vz = normalize(CGAL_Vector3(vertices[0], vertices[3]));
33  CGAL_Transform3 to_box_system(vx.x(), vx.y(), vx.z(),
34  vy.x(), vy.y(), vy.z(),
35  vz.x(), vz.y(), vz.z());
36  // Move triangles from the triangle soup of the scene to the volume reference systeme and
37  // build CGAL triangles out of them
38  deque<CGAL_Point3> cgal_nodes;
39  for(nodes_pool_t::const_iterator it = nodes.begin(); it != nodes.end(); it ++)
40  {
41  cgal_nodes.push_back(CGAL_Point3(it->_x, it->_y, it->_z).transform(to_box_system));
42  }
43  CGAL_Triangles cgal_triangles;
44  for(triangle_pool_t::const_iterator it = triangle_soup.begin(); it != triangle_soup.end(); it++)
45  {
46  cgal_triangles.push_back(CGAL_Triangle(cgal_nodes[it->n[0]], cgal_nodes[it->n[1]],
47  cgal_nodes[it->n[2]]));
48  }
49  float l = (float)sqrt(CGAL_Vector3(_source, _receptor).squared_length());
50  // these 3 points delimit the bounds of the fresnel box (in other terms, the bounding
51  // box of this triangle should have the dimensions of the fresnel box). This will be checked
52  // anyway by intersected_triangles() thanks to the expected dimensions passed: l, w and h
53  std::deque<CGAL_Point3> box_triangle;
54  box_triangle.push_back(vertices[1].transform(to_box_system));
55  box_triangle.push_back(vertices[2].transform(to_box_system));
56  box_triangle.push_back(vertices[3].transform(to_box_system));
57  return intersected_triangles(cgal_triangles, box_triangle, l, w, h);
58 }
59 
60 node_idx AcousticProblemModel::make_node(const Point& p)
61 {
62  all_nodes.push_back(p);
63  return all_nodes.size() - 1;
64 }
65 
66 AcousticTriangle::AcousticTriangle(node_idx n1, node_idx n2, node_idx n3)
67 {
68  n[0] = n1;
69  n[1] = n2;
70  n[2] = n3;
71 }
72 
73 triangle_idx AcousticProblemModel::make_triangle(node_idx n1, node_idx n2, node_idx n3)
74 {
75  all_triangles.push_back(AcousticTriangle(n1, n2, n3));
76  return all_triangles.size() - 1;
77 }
78 
79 material_ptr_t AcousticProblemModel::make_material(const string& name, double resistivity, double deviation, double length)
80 {
81  material_ptr_t p_mat = tympan::static_pointer_cast<AcousticMaterialBase>(
82  tympan::make_shared<AcousticGroundMaterial>(name, resistivity, deviation, length));
83  all_materials.push_back(p_mat);
84  return p_mat;
85 }
86 
87 material_ptr_t AcousticProblemModel::make_material(const string& name, const ComplexSpectrum& spectrum)
88 {
89  material_ptr_t p_mat = tympan::static_pointer_cast<AcousticMaterialBase>(
90  tympan::make_shared<AcousticBuildingMaterial>(name, spectrum));
91  all_materials.push_back(p_mat);
92  return p_mat;
93 }
94 
95 source_idx AcousticProblemModel::make_source(
96  const Point& point,
97  const Spectrum& spectrum,
98  SourceDirectivityInterface* directivity)
99 {
100 
101  all_sources.push_back(AcousticSource(point, spectrum, directivity));
102  return all_sources.size() - 1;
103 }
104 
105 receptor_idx AcousticProblemModel::make_receptor(
106  const Point& position_)
107 {
108  all_receptors.push_back(AcousticReceptor(position_));
109  return all_receptors.size() - 1;
110 }
111 
112 std::unique_ptr<AcousticProblemModel> make_AcousticProblemModel()
113 { return std::unique_ptr<AcousticProblemModel>(new AcousticProblemModel()); }
114 
115 } // namespace tympan
CGAL::Triangle_3< CGAL_Gt > CGAL_Triangle
Definition: cgal_tools.h:51
This file provides the top-level declaration for the acoustic problem model.
shared_ptr< AcousticMaterialBase > material_ptr_t
Definition: entities.hpp:35
size_t node_idx
const char * name
size_t source_idx
Definition: entities.hpp:335
std::deque< CGAL_Triangle > CGAL_Triangles
Definition: cgal_tools.h:52
CGAL::Point_3< CGAL_Gt > CGAL_Point3
Definition: cgal_tools.h:46
CGAL_Plane to_cgal(const OPlan &oplan)
Convert a OPlan to CGAL_Plane.
Definition: cgal_tools.cpp:19
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
std::unique_ptr< AcousticProblemModel > make_AcousticProblemModel()
STL namespace.
Describing a triangle.
Definition: entities.hpp:144
size_t receptor_idx
Definition: entities.hpp:353
Utilities to ease (and wrap) use of CGAL.
CGAL_Vector3 normalize(CGAL_Vector3 v)
normalize vector v
Definition: cgal_tools.cpp:26
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 triangle_idx
Definition: entities.hpp:157
std::deque< AcousticTriangle > triangle_pool_t
Array of AcousticTriangle.
Definition: entities.hpp:156
Class to describe the acoustic problem.
Describes an acoustic receptor.
Definition: entities.hpp:341
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...
CGAL::Vector_3< CGAL_Gt > CGAL_Vector3
Definition: cgal_tools.h:48
CGAL::Aff_transformation_3< CGAL_Gt > CGAL_Transform3
Definition: cgal_tools.h:54
std::deque< Point > nodes_pool_t
Base class for material.
Definition: entities.hpp:22
Describes an acoustic source.
Definition: entities.hpp:315
The 3D point class.
Definition: 3d.h:484
Store acoustic power values for different frequencies.
Definition: spectre.h:49
Interface for source directivity classes (SphericalSourceDirectivity, CommonFaceDirectivity, ...)
Definition: entities.hpp:164