Code_TYMPAN  4.4.0
Industrial site acoustic simulation
Triangle.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012-2024> <EDF-DTG> <FRANCE>
3  * This file is part of Code_TYMPAN (R).
4  * Code_TYMPAN (R) is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * Code_TYMPAN (R) is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License along
13  * with Code_TYMPAN (R). If not, see <https://www.gnu.org/licenses/>.
14  */
15 
16 #ifndef TRIANGLE_H
17 #define TRIANGLE_H
18 
19 #include "Shape.h"
20 
24 class Triangle : public Shape
25 {
26 
27 public:
30  {
31  name = "unknown triangle";
32  };
34  Triangle(unsigned int p1, unsigned int p2, unsigned int p3, std::vector<vec3>* _vertices, Material* _m,
35  const bool& isSol = false);
37  Triangle(const vec3& p1, const vec3& p2, const vec3& p3, Material* m, const bool& isSol = false);
39  Triangle(const Triangle& other) : Shape(other)
40  {
41  box = other.box;
42  p = other.p;
43  u = other.u;
44  v = other.v;
45  normal = other.normal;
46  planeNormal = other.planeNormal;
47  };
49  virtual ~Triangle() {}
50 
51  virtual void updateBBox();
52 
53  virtual bool getIntersection(Ray& ray, Intersection& inter);
54 
56  void setNormal(const vec3& _normal)
57  {
58  normal = _normal;
59  }
60  virtual vec3 getNormal(const vec3 pos = vec3())
61  {
62  return normal;
63  }
64 
66  virtual bool sample(decimal density, std::vector<vec3>& samples);
67 
68  virtual int form()
69  {
70  return TRIANGLE;
71  }
72 
73 protected:
74  vec3 p;
75  vec3 u;
76  vec3 v;
77 
80 };
81 
82 #endif
@ TRIANGLE
Definition: Shape.h:36
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
BBox box
Bounding box of the shape.
Definition: Shape.h:210
bool isSol() const
Get/Set the flag _isSol (ground or not)
Definition: Shape.h:194
Triangle class.
Definition: Triangle.h:25
virtual bool sample(decimal density, std::vector< vec3 > &samples)
Uncommented method cause not used.
Definition: Triangle.cpp:112
void setNormal(const vec3 &_normal)
Set/Get the normal.
Definition: Triangle.h:56
vec3 normal
Normalized normal to triangle.
Definition: Triangle.h:78
virtual bool getIntersection(Ray &ray, Intersection &inter)
Get the Intersection between a ray and this shape.
Definition: Triangle.cpp:72
Triangle(const Triangle &other)
Copy constructor.
Definition: Triangle.h:39
virtual void updateBBox()
Update the bounding box:
Definition: Triangle.cpp:63
vec3 planeNormal
Non-normalized normal, equal to u cross v.
Definition: Triangle.h:79
virtual int form()
Return type of the shape.
Definition: Triangle.h:68
virtual ~Triangle()
Destructor.
Definition: Triangle.h:49
vec3 v
Vector to reach the third vertex (vertex3=p+v)
Definition: Triangle.h:76
vec3 u
Vector to reach the second vertex (vertex2=p+u)
Definition: Triangle.h:75
Triangle()
Default constructor.
Definition: Triangle.h:29
vec3 p
First vertex (vertex1=p)
Definition: Triangle.h:74
virtual vec3 getNormal(const vec3 pos=vec3())
Get normal.
Definition: Triangle.h:60
float decimal
Definition: mathlib.h:45
base_vec3< decimal > vec3
Definition: mathlib.h:387
Intersection struct.
Definition: Shape.h:46