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 private:
16  // *** SERIALIZATION *** //
17  // *********************** //
18  friend class boost::serialization::access;
25  template <typename Archive>
26  void serialize(Archive& ar, const unsigned int version) {
27  ar & pos;
28  ar & normal;
29  ar & texcoords;
30  ar & color;
31  }
32 
33 public:
34  // *** ATTRIBUTES *** //
35  // ******************** //
39  glm::dvec3 pos;
43  glm::dvec3 normal = glm::dvec3(0, 0, 0);
47  glm::dvec2 texcoords;
53 
54  // *** CONSTRUCTION / DESTRUCTION *** //
55  // ************************************ //
59  Vertex() = default;
66  Vertex(double const x, double const y, double const z) : pos(x, y, z) {};
67  Vertex(const Vertex &v);
68 
69  // *** M E T H O D S *** //
70  // *********************** //
75  inline Vertex copy() const {return Vertex(*this);}
82  static double* matxvec(double** mat, double* vec);
89  static Vertex rotateVertex(Vertex v, double** rotationMatrix);
90 
91  // *** GETTERS and SETTERS *** //
92  // ***************************** //
98  inline double getX() const {
99  return this->pos.x;
100  }
101 
107  inline double getY() const {
108  return this->pos.y;
109  }
110 
116  inline double getZ() const {
117  return this->pos.z;
118  }
119 
130  inline bool operator ==(const Vertex & v) const{
131  return
132  this->pos.x == v.pos.x &&
133  this->pos.y == v.pos.y &&
134  this->pos.z == v.pos.z;
135  }
136 
137  friend std::ostream& operator << (std::ostream& out, Vertex * v);
138 };
139 
147  bool operator() (Vertex * const & a, Vertex * & b) const{
148  return a->getX() == b->getX() &&
149  a->getY() == b->getY() &&
150  a->getZ() == b->getZ();
151  }
152 };
153 
162  size_t operator() (Vertex * const &v) const{
163  std::hash<double> doubleHasher;
164  const size_t prime = 31;
165  size_t hash = 1;
166  hash = prime * hash + doubleHasher(v->getX());
167  hash = prime * hash + doubleHasher(v->getY());
168  hash = prime * hash + doubleHasher(v->getZ());
169  return hash;
170  }
171 };
172 
Class representing a color with 4 float components: RGBA.
Definition: Color4f.h:10
Class representing a vertex.
Definition: Vertex.h:14
glm::dvec2 texcoords
Vertex texture coordinates.
Definition: Vertex.h:47
Color4f color
Vertex color (RGBA)
Definition: Vertex.h:52
Vertex(double const x, double const y, double const z)
Build a vertex with given position coordinates.
Definition: Vertex.h:66
glm::dvec3 pos
Vertex 3D position.
Definition: Vertex.h:39
Vertex copy() const
Copy the vertex.
Definition: Vertex.h:75
double getX() const
Get the X coordinate of vertex position.
Definition: Vertex.h:98
double getZ() const
Get the Z coordinate of vertex position.
Definition: Vertex.h:116
glm::dvec3 normal
Vertex normal vector.
Definition: Vertex.h:43
static Vertex rotateVertex(Vertex v, double **rotationMatrix)
Build a vertes result of rotating another vertex (v)
Definition: Vertex.cpp:29
static double * matxvec(double **mat, double *vec)
Matrix x Vector multiplication.
Definition: Vertex.cpp:15
Vertex()=default
Default vertex constructor.
bool operator==(const Vertex &v) const
Compare if two vertex are equal.
Definition: Vertex.h:130
double getY() const
Get the Y coordinate of vertex position.
Definition: Vertex.h:107
void serialize(Archive &ar, const unsigned int version)
Serialize a Vertex to a stream of bytes.
Definition: Vertex.h:26
Struct to compare vertex when using unordered set.
Definition: Vertex.h:146
Struct to obtain vertex hash when using unordered set.
Definition: Vertex.h:161