Helios++
Helios software for LiDAR simulations
Vertex.h
1 #pragma once
2 
3 #include <boost/archive/text_iarchive.hpp>
4 #include <boost/archive/text_oarchive.hpp>
5 
6 #include <glm/glm.hpp>
7 #include <glm/gtx/hash.hpp>
8 
9 #include "Color4f.h"
10 
14 class Vertex {
15  // *** SERIALIZATION *** //
16  // ******************
17  friend class boost::serialization::access;
18  template <typename Archive>
19  void serialize(Archive& ar, const unsigned int version) {
20  ar & pos;
21  ar & normal;
22  ar & color;
23  ar & texcoords;
24  }
25 
26 public:
27  // *** ATTRIBUTES *** //
28  // ******************** //
32  glm::dvec3 pos;
36  glm::dvec3 normal;
40  glm::dvec2 texcoords;
46 
47  // *** CONSTRUCTION / DESTRUCTION *** //
48  // ************************************ //
52  Vertex() = default;
53  Vertex(const Vertex &v);
54 
55  // *** M E T H O D S *** //
56  // *********************** //
61  Vertex copy();
68  static double* matxvec(double** mat, double* vec);
75  static Vertex rotateVertex(Vertex v, double** rotationMatrix);
76 
77  // *** GETTERS and SETTERS *** //
78  // ***************************** //
84  inline double getX() const {
85  return this->pos.x;
86  }
87 
93  inline double getY() const {
94  return this->pos.y;
95  }
96 
102  inline double getZ() const {
103  return this->pos.z;
104  }
105 
116  inline bool operator ==(const Vertex & v) const{
117  return
118  this->pos.x == v.pos.x &&
119  this->pos.y == v.pos.y &&
120  this->pos.z == v.pos.z;
121  }
122 
123  friend std::ostream& operator << (std::ostream& out, Vertex * v);
124 };
125 
133  bool operator() (Vertex * const & a, Vertex * & b) const{
134  return a->getX() == b->getX() &&
135  a->getY() == b->getY() &&
136  a->getZ() == b->getZ();
137  }
138 };
139 
148  size_t operator() (Vertex * const &v) const{
149  std::hash<double> doubleHasher;
150  const size_t prime = 31;
151  size_t hash = 1;
152  hash = prime * hash + doubleHasher(v->getX());
153  hash = prime * hash + doubleHasher(v->getY());
154  hash = prime * hash + doubleHasher(v->getZ());
155  return hash;
156  }
157 };
158 
glm::dvec3 normal
Vertex normal vector.
Definition: Vertex.h:36
Color4f color
Vertex color (RGBA)
Definition: Vertex.h:45
Vertex copy()
Copy the vertex.
Definition: Vertex.cpp:14
glm::dvec2 texcoords
Vertex texture coordinates.
Definition: Vertex.h:40
Class representing a color with 4 float components: RGBA.
Definition: Color4f.h:6
static double * matxvec(double **mat, double *vec)
Matrix x Vector multiplication.
Definition: Vertex.cpp:19
bool operator==(const Vertex &v) const
Compare if two vertex are equal.
Definition: Vertex.h:116
Struct to compare vertex when using unordered set.
Definition: Vertex.h:132
double getX() const
Get the X coordinate of vertex position.
Definition: Vertex.h:84
glm::dvec3 pos
Vertex 3D position.
Definition: Vertex.h:32
double getZ() const
Get the Z coordinate of vertex position.
Definition: Vertex.h:102
Vertex()=default
Default vertex constructor.
static Vertex rotateVertex(Vertex v, double **rotationMatrix)
Build a vertes result of rotating another vertex (v)
Definition: Vertex.cpp:33
Struct to obtain vertex hash when using unordered set.
Definition: Vertex.h:147
Class representing a vertex.
Definition: Vertex.h:14
double getY() const
Get the Y coordinate of vertex position.
Definition: Vertex.h:93