Code_TYMPAN  4.4.0
Industrial site acoustic simulation
Scene.h
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 #ifndef SCENE_H
17 #define SCENE_H
18 
19 #include <vector>
21 #include "Shape.h"
22 
27 struct compVec
28 {
29  bool operator()(const vec3& _v1, const vec3& _v2) const
30  {
31  if (fabs(_v1.x - _v2.x) > 0.001)
32  {
33  return _v1.x < _v2.x;
34  }
35  if (fabs(_v1.y - _v2.y) > 0.001)
36  {
37  return _v1.y < _v2.y;
38  }
39  if (fabs(_v1.z - _v2.z) > 0.001)
40  {
41  return _v1.z < _v2.z;
42  }
43  return false;
44  }
45 };
46 
50 class Scene : public Base
51 {
52 
53 public:
55  Scene() : Base(), accelerator(NULL)
56  {
57  name = "unknown scene";
59  compteurFace = 0;
60  }
62  Scene(const Scene& other) : Base(other) {}
64  virtual ~Scene() {}
66  void clean();
68  void addShape(Shape* shape)
69  {
70  shapes.push_back(shape);
71  globalBox = globalBox.Union(shape->getBBox());
72 
75  }
78  {
79  return globalBox;
80  }
83  {
84  return accelerator;
85  }
86 
88  std::vector<Shape*>* getShapes()
89  {
90  return &shapes;
91  }
92  const std::vector<Shape*>* getShapes() const
93  {
94  return &shapes;
95  }
97  std::vector<vec3>* getVertices()
98  {
99  return &vertices;
100  }
101  const std::vector<vec3>* getVertices() const
102  {
103  return &vertices;
104  }
106  std::vector<Shape*> getShapes(int shape_type);
107 
114  bool finish(int accelerator_id = 1, leafTreatment::treatment _intersectionChoice = leafTreatment::FIRST);
115 
122  bool getIndex(vec3& search, unsigned int& result);
129  bool getVertex(unsigned int& search, vec3& result);
136  bool addVertex(const vec3& newVertex, unsigned int& index);
137 
147  Shape* addTriangle(unsigned int i1, unsigned int i2, unsigned int i3, Material* m,
148  const bool& isSol = false);
149 
156  void addBuilding(vec3 origine, vec3 dimension, Material* m);
158  void export_to_ply(std::string fileName);
160  void import_from_ply(std::string fileName);
161 
162 protected:
163  std::vector<Shape*> shapes;
166 
167  std::vector<vec3> vertices;
168  std::map<vec3, unsigned int, compVec>
170 
171  unsigned int compteurPrimitive;
172  unsigned int compteurFace;
173 };
174 
175 #endif
Base class for accelerators.
Definition: Accelerator.h:27
Definition of a bounding box which is aligned along the axis (BBox AABB).
Definition: BBox.h:32
BBox Union(const BBox &b, const vec3 &p)
Union of a point and a BBox. A new BBox is created.
Definition: BBox.h:110
Base class of Event, Material, PostFilter, Ray, Repere, Scene, Shape, Simulation, Source.
Definition: Base.h:25
std::string name
Each instantiated object may be named.
Definition: Base.h:52
This class mainly define a mesh (list of Shape) used by the Simulation object.
Definition: Scene.h:51
Scene(const Scene &other)
Copy constructor.
Definition: Scene.h:62
void import_from_ply(std::string fileName)
Import a Scene from a PLY format file named fileName.
Definition: Scene.cpp:237
void clean()
Clear all arrays.
Definition: Scene.cpp:33
std::vector< Shape * > shapes
Array of pointers to the shapes.
Definition: Scene.h:163
std::vector< Shape * > * getShapes()
Return all the shapes.
Definition: Scene.h:88
bool getIndex(vec3 &search, unsigned int &result)
Get the index of a vertex in the vertices array.
Definition: Scene.cpp:87
void export_to_ply(std::string fileName)
Export the Scene to a PLY format file named fileName.
Definition: Scene.cpp:178
unsigned int compteurFace
Faces counter.
Definition: Scene.h:172
Accelerator * accelerator
Pointer to the accelerator.
Definition: Scene.h:165
void addShape(Shape *shape)
Add a shape to the list.
Definition: Scene.h:68
const std::vector< Shape * > * getShapes() const
Definition: Scene.h:92
Shape * addTriangle(unsigned int i1, unsigned int i2, unsigned int i3, Material *m, const bool &isSol=false)
Add a triangle to the scene built with the vertices array.
Definition: Scene.cpp:127
BBox globalBox
Bounding box of the Scene.
Definition: Scene.h:164
unsigned int compteurPrimitive
Primitives counter.
Definition: Scene.h:171
void addBuilding(vec3 origine, vec3 dimension, Material *m)
Add a building to the scene.
Definition: Scene.cpp:135
bool addVertex(const vec3 &newVertex, unsigned int &index)
Add a vertex to the vertices array.
Definition: Scene.cpp:110
virtual ~Scene()
Destructor.
Definition: Scene.h:64
Accelerator * getAccelerator() const
Get the accelerator.
Definition: Scene.h:82
BBox getGlobalBox()
Return global bounding box.
Definition: Scene.h:77
const std::vector< vec3 > * getVertices() const
Definition: Scene.h:101
bool getVertex(unsigned int &search, vec3 &result)
Get a vertex from the vertices array with its index.
Definition: Scene.cpp:99
Scene()
Constructor.
Definition: Scene.h:55
std::vector< vec3 > vertices
All the vertices used by the different shapes.
Definition: Scene.h:167
std::vector< vec3 > * getVertices()
Return all the vertices.
Definition: Scene.h:97
std::map< vec3, unsigned int, compVec > registeredVertices
Association between a vertex and his index in vertices.
Definition: Scene.h:169
bool finish(int accelerator_id=1, leafTreatment::treatment _intersectionChoice=leafTreatment::FIRST)
Build the selected accelerator on the scene.
Definition: Scene.cpp:51
base class for shapes (Cylindre, Mesh, Sphere, Triangle,...)
Definition: Shape.h:57
void setPrimitiveId(int id)
Set/Get the primitive id.
Definition: Shape.h:151
BBox getBBox()
Return the bounding box.
Definition: Shape.h:117
base_vec3< decimal > vec3
Definition: mathlib.h:381
Use to compare vectors.
Definition: Scene.h:28
bool operator()(const vec3 &_v1, const vec3 &_v2) const
Definition: Scene.h:29