Helios++
Helios software for LiDAR simulations
Primitive.h
1 #pragma once
2 
3 #include <vector>
4 #include <boost/serialization/base_object.hpp>
5 #include <boost/serialization/shared_ptr.hpp>
6 #include <glm/glm.hpp>
7 
8 #include "Material.h"
9 #include "ScenePart.h"
10 #include <NoiseSource.h>
11 #include <IntersectionHandlingResult.h>
12 #include <util/HeliosException.h>
13 
14 class AABB;
15 class Vertex;
16 
20 class Primitive {
21  // *** SERIALIZATION *** //
22  // *********************** //
23  friend class boost::serialization::access;
24  template<class Archive>
25  void serialize(Archive &ar, const unsigned int version) {
26  ar & part;
27  ar & material;
28  }
29 
30 public:
31  // *** ATTRIBUTES *** //
32  // ******************** //
37  std::shared_ptr<ScenePart> part = nullptr;
43  std::shared_ptr<Material> material = nullptr;
44 
45  // *** CONSTRUCTION / DESTRUCTION *** //
46  // ************************************ //
47  virtual ~Primitive(){}
48  virtual Primitive* clone() = 0;
49  virtual void _clone(Primitive *p);
50 
51  // *** M E T H O D S *** //
52  // *********************** //
57  virtual AABB* getAABB() = 0;
62  virtual glm::dvec3 getCentroid() = 0;
70  virtual double getIncidenceAngle_rad(
71  const glm::dvec3& rayOrigin,
72  const glm::dvec3& rayDir,
73  const glm::dvec3& intersectionPoint
74  ) = 0;
81  virtual std::vector<double> getRayIntersection(
82  const glm::dvec3& rayOrigin, const glm::dvec3& rayDir) = 0;
90  virtual double getRayIntersectionDistance(
91  const glm::dvec3& rayOrigin, const glm::dvec3& rayDir) = 0;
103  virtual void onFinishLoading(NoiseSource<double> &uniformNoiseSource) {}
104 
111  inline virtual size_t getNumVertices() {return 0;}
117  virtual Vertex* getVertices() = 0;
118 
125  inline virtual size_t getNumFullVertices() {return getNumVertices();};
138  virtual Vertex* getFullVertices() {return getVertices();};
139 
167  inline virtual double getGroundZOffset() {return 0;}
168 
173  virtual void update() = 0;
174 
175  // *** RAY INTERSECTION HANDLING *** //
176  // *********************************** //
188  virtual inline bool canHandleIntersections(){return false;}
210  NoiseSource<double> &uniformNoiseSource,
211  glm::dvec3 &rayDirection,
212  glm::dvec3 const &insideIntersectionPoint,
213  glm::dvec3 const &outsideIntersectionPoint,
214  double rayIntensity
215  );
216 
217  // *** TRANSFORMATIONS *** //
218  // ************************* //
223  virtual void rotate(Rotation &r);
228  virtual void scale(double const factor);
233  virtual void translate(glm::dvec3 const &shift);
234 
235  // *** S I G M A *** //
236  // ******************* //
243  virtual bool canComputeSigmaWithLadLut() {return false;}
255  virtual double computeSigmaWithLadLut(glm::dvec3 const &direction)
256  {throw HeliosException("Primitive cannot compute sigma with LadLut");}
257 
258  // *** STREAM OPERATORS *** //
259  // ************************** //
263  friend std::ostream& operator<< (std::ostream& out, Primitive &p);
264 };
virtual double computeSigmaWithLadLut(glm::dvec3 const &direction)
Compute sigma using LadLut.
Definition: Primitive.h:255
friend std::ostream & operator<<(std::ostream &out, Primitive &p)
Output stream operator << overloading.
Definition: Primitive.cpp:24
Definition: Rotation.h:80
virtual AABB * getAABB()=0
Obtain the axis aligned bounding box containing the primitive.
std::shared_ptr< Material > material
Shared pointer to the material defining certain properties such as reflectance, specularity, ...
Definition: Primitive.h:43
Base class for Helios exceptions.
Definition: HeliosException.h:12
virtual glm::dvec3 getCentroid()=0
Obtain the primitive centroid.
virtual bool canHandleIntersections()
Specify if the primitive can handle intersections or not.
Definition: Primitive.h:188
Output class for intersection handling methods.
Definition: IntersectionHandlingResult.h:13
virtual void update()=0
Necessary primitive updates after modification.
virtual void translate(glm::dvec3 const &shift)
Translate primitive by given shift.
Definition: Primitive.cpp:59
virtual size_t getNumVertices()
Obtain the number of vertices returned by the getVertices function.
Definition: Primitive.h:111
virtual Vertex * getFullVertices()
Obtain full vertices for the primitive.
Definition: Primitive.h:138
Class representing an Axis Aligned Bounding Box (AABB)
Definition: AABB.h:10
virtual std::vector< double > getRayIntersection(const glm::dvec3 &rayOrigin, const glm::dvec3 &rayDir)=0
Obtain the intersection point between primitive and given ray.
virtual void scale(double const factor)
Scale primitive by given factor.
Definition: Primitive.cpp:50
virtual IntersectionHandlingResult onRayIntersection(NoiseSource< double > &uniformNoiseSource, glm::dvec3 &rayDirection, glm::dvec3 const &insideIntersectionPoint, glm::dvec3 const &outsideIntersectionPoint, double rayIntensity)
Handle ray intersections.
Definition: Primitive.cpp:12
virtual Vertex * getVertices()=0
Obtain basic vertices for the primitive.
std::shared_ptr< ScenePart > part
Shared pointer to the scene part the primitive belongs to.
Definition: Primitive.h:37
virtual void rotate(Rotation &r)
Performs rotation over primitive.
Definition: Primitive.cpp:44
virtual size_t getNumFullVertices()
Obtain the number of vertices returned by the getNumFullVertices function.
Definition: Primitive.h:125
Abstract class defining the common behavior for all primitives.
Definition: Primitive.h:20
virtual void onFinishLoading(NoiseSource< double > &uniformNoiseSource)
Method to be triggered once all Primitives have been loaded.
Definition: Primitive.h:103
virtual double getGroundZOffset()
Offset for ground point z coordinate.
Definition: Primitive.h:167
virtual bool canComputeSigmaWithLadLut()
Check if primitive can compute sigma using LadLut or not.
Definition: Primitive.h:243
virtual double getIncidenceAngle_rad(const glm::dvec3 &rayOrigin, const glm::dvec3 &rayDir, const glm::dvec3 &intersectionPoint)=0
Obtain the incidence angle in radians.
virtual double getRayIntersectionDistance(const glm::dvec3 &rayOrigin, const glm::dvec3 &rayDir)=0
Obtain the intersection distance between primitive and given ray.
Class representing a vertex.
Definition: Vertex.h:14