Code_TYMPAN  4.4.0
Industrial site acoustic simulation
Shape.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 SHAPE_H
17 #define SHAPE_H
18 
19 #include <string>
20 #include <vector>
21 
22 #include "Geometry/mathlib.h"
23 #include "Base.h"
24 #include "Ray/Ray.h"
25 #include "Acoustic/Material.h"
26 #include "Geometry/BBox.h"
27 
28 class Shape;
29 
34 enum FORM
35 {
36  TRIANGLE = 0,
38  SPHERE
39 };
40 
45 typedef struct _Intersection
46 {
49  Shape* p;
52 
56 class Shape : public Base
57 {
58 
59 public:
61  Shape() : Base(), material(NULL)
62  {
63  name = "unknown shape";
64  }
66  Shape(const std::string _name) : Base(), material(NULL)
67  {
68  name = _name;
69  }
71  Shape(Shape* other)
72  {
73  name = std::string(other->name);
74  primitiveId = other->primitiveId;
75  faceId = other->faceId;
76  buildingId = other->buildingId;
77  etageId = other->etageId;
78  _isSol = other->_isSol;
79  }
81  virtual ~Shape() {}
83  Shape(const Shape& other) : Base(other)
84  {
85  name = std::string(other.name);
86  primitiveId = other.primitiveId;
87  faceId = other.faceId;
88  buildingId = other.buildingId;
89  etageId = other.etageId;
90  _isSol = other._isSol;
91  }
93  virtual Shape* Clone()
94  {
95  Shape* newShape = new Shape(this);
96  return newShape;
97  }
100  {
101  return material;
102  }
105  {
106  material = m;
107  }
109  virtual bool getIntersection(Ray& ray, Intersection& inter)
110  {
111  cerr << "ERROR : Intersection with a non-type shape." << std::endl;
112  return false;
113  }
115  virtual void updateBBox(){};
118  {
119  return box;
120  }
121 
123  void setVertices(std::vector<vec3>* _vertices)
124  {
125  vertices = _vertices;
126  }
127  vector<vec3>* getVertices()
128  {
129  return vertices;
130  }
131 
133  vector<unsigned int>* getLocalVertices()
134  {
135  return &localVertices;
136  }
137 
139  virtual bool isVisible()
140  {
141  return true;
142  }
143 
145  virtual vec3 getNormal(const vec3 pos = vec3())
146  {
147  return vec3();
148  }
149 
151  void setPrimitiveId(int id)
152  {
153  primitiveId = id;
154  }
155  int getPrimitiveId() const
156  {
157  return primitiveId;
158  }
159 
161  void setFaceId(int id)
162  {
163  faceId = id;
164  }
165  int getFaceId() const
166  {
167  return faceId;
168  }
170  void setEtageId(int id)
171  {
172  etageId = id;
173  }
175  {
176  return etageId;
177  }
179  void setBuildingId(int id)
180  {
181  buildingId = id;
182  }
184  {
185  return buildingId;
186  }
188  virtual bool sample(decimal density, std::vector<vec3>& samples)
189  {
190  return false;
191  }
192 
194  bool isSol() const
195  {
196  return _isSol;
197  }
198  void setIsSol(const bool& isSol)
199  {
200  _isSol = isSol;
201  }
202 
204  virtual int form()
205  {
206  return -1;
207  }
208 
209 protected:
212  std::vector<vec3>* vertices;
213  std::vector<unsigned int> localVertices;
215  int faceId;
217  int etageId;
218  bool _isSol;
219 };
220 
221 #endif
struct _Intersection Intersection
FORM
Primitives supported by the ray tracing method.
Definition: Shape.h:35
@ TRIANGLE
Definition: Shape.h:36
@ SPHERE
Definition: Shape.h:38
@ CYLINDRE
Definition: Shape.h:37
int id
Definition of a bounding box which is aligned along the axis (BBox AABB).
Definition: BBox.h:32
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
: 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
base class for shapes (Cylindre, Mesh, Sphere, Triangle,...)
Definition: Shape.h:57
Shape(const std::string _name)
Constructor by giving a name to the Shape.
Definition: Shape.h:66
BBox box
Bounding box of the shape.
Definition: Shape.h:210
vector< vec3 > * getVertices()
Definition: Shape.h:127
int getPrimitiveId() const
Definition: Shape.h:155
int getFaceId() const
Definition: Shape.h:165
virtual int form()
Return type of the shape.
Definition: Shape.h:204
int etageId
Index of the floor (etage) supporting the primitive (-1 if none)
Definition: Shape.h:217
std::vector< vec3 > * vertices
GlobalVertices of the scene.
Definition: Shape.h:212
virtual Shape * Clone()
Clone and return a pointer to a Shape.
Definition: Shape.h:93
Material * material
Pointer to material.
Definition: Shape.h:211
int faceId
Index of the face supporting the primitive.
Definition: Shape.h:215
void setFaceId(int id)
Set/Get the face id.
Definition: Shape.h:161
Material * getMaterial()
Return the pointed material.
Definition: Shape.h:99
void setIsSol(const bool &isSol)
Definition: Shape.h:198
int getEtageId()
Definition: Shape.h:174
vector< unsigned int > * getLocalVertices()
Get local vertices.
Definition: Shape.h:133
bool isSol() const
Get/Set the flag _isSol (ground or not)
Definition: Shape.h:194
void setPrimitiveId(int id)
Set/Get the primitive id.
Definition: Shape.h:151
void setVertices(std::vector< vec3 > *_vertices)
Set/Get global vertices.
Definition: Shape.h:123
virtual bool getIntersection(Ray &ray, Intersection &inter)
Get the Intersection between a ray and this shape.
Definition: Shape.h:109
int getBuildingId()
Definition: Shape.h:183
void setBuildingId(int id)
Set/Get the building id.
Definition: Shape.h:179
Shape()
Default constructor.
Definition: Shape.h:61
virtual void updateBBox()
Update the bounding box:
Definition: Shape.h:115
virtual bool isVisible()
Return visibility.
Definition: Shape.h:139
int buildingId
Index of the building supporting the primitive (-1 if none)
Definition: Shape.h:216
int primitiveId
Index of the primitive (given by the scene)
Definition: Shape.h:214
virtual vec3 getNormal(const vec3 pos=vec3())
Get normal.
Definition: Shape.h:145
void setEtageId(int id)
Set/Get the floor id.
Definition: Shape.h:170
virtual ~Shape()
Destructor.
Definition: Shape.h:81
BBox getBBox()
Return the bounding box.
Definition: Shape.h:117
void setMaterial(Material *m)
Set the material.
Definition: Shape.h:104
bool _isSol
Triangle type (false = non natural, true = ground)
Definition: Shape.h:218
std::vector< unsigned int > localVertices
Index of the vertices used for this shape.
Definition: Shape.h:213
virtual bool sample(decimal density, std::vector< vec3 > &samples)
Uncommented cause not used:
Definition: Shape.h:188
Shape(Shape *other)
Copy constructor.
Definition: Shape.h:71
Shape(const Shape &other)
Copy constructor.
Definition: Shape.h:83
float decimal
Definition: mathlib.h:45
base_vec3< decimal > vec3
Definition: mathlib.h:381
Intersection struct.
Definition: Shape.h:46
decimal t
Definition: Shape.h:48
FORM forme
Definition: Shape.h:50
Shape * p
Definition: Shape.h:49
vec3 normal
Definition: Shape.h:47