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 #include <DynObject.h>
15 #include <DynMovingObject.h>
16 #include <DynSequentiableMovingObject.h>
17 
18 class AABB;
19 class Vertex;
20 
24 class Primitive {
25 private:
26  // *** SERIALIZATION *** //
27  // *********************** //
28  friend class boost::serialization::access;
35  template<class Archive>
36  void serialize(Archive &ar, const unsigned int version) {
37  // Register ScenePart derived classes
38  ar.template register_type<DynMovingObject>();
39  ar.template register_type<DynSequentiableMovingObject>();
40 
41  // Debugging purposes ---
42  /*std::string partId = "#NULLID#";
43  if(part!=nullptr) partId = part->getId();*/
44  // --- Debugging purposes
45 
46  ar & part;
47  ar & material;
48  }
49 
50 public:
51  // *** ATTRIBUTES *** //
52  // ******************** //
57  std::shared_ptr<ScenePart> part = nullptr;
63  std::shared_ptr<Material> material = nullptr;
64 
65  // *** CONSTRUCTION / DESTRUCTION *** //
66  // ************************************ //
67  virtual ~Primitive(){}
68  virtual Primitive* clone() = 0;
69  virtual void _clone(Primitive *p);
70 
71  // *** M E T H O D S *** //
72  // *********************** //
77  virtual AABB* getAABB() = 0;
82  virtual glm::dvec3 getCentroid() = 0;
90  virtual double getIncidenceAngle_rad(
91  const glm::dvec3& rayOrigin,
92  const glm::dvec3& rayDir,
93  const glm::dvec3& intersectionPoint
94  ) = 0;
101  virtual std::vector<double> getRayIntersection(
102  const glm::dvec3& rayOrigin, const glm::dvec3& rayDir) = 0;
111  const glm::dvec3& rayOrigin, const glm::dvec3& rayDir) = 0;
123  virtual void onFinishLoading(NoiseSource<double> &uniformNoiseSource) {}
124 
131  inline virtual size_t getNumVertices() {return 0;}
137  virtual Vertex* getVertices() = 0;
138 
145  inline virtual size_t getNumFullVertices() {return getNumVertices();};
158  virtual Vertex* getFullVertices() {return getVertices();};
159 
187  inline virtual double getGroundZOffset() {return 0;}
188 
193  virtual void update() = 0;
194 
195  // *** RAY INTERSECTION HANDLING *** //
196  // *********************************** //
208  virtual inline bool canHandleIntersections(){return false;}
230  NoiseSource<double> &uniformNoiseSource,
231  glm::dvec3 &rayDirection,
232  glm::dvec3 const &insideIntersectionPoint,
233  glm::dvec3 const &outsideIntersectionPoint,
234  double rayIntensity
235  );
236 
237  // *** TRANSFORMATIONS *** //
238  // ************************* //
243  virtual void rotate(Rotation &r);
248  virtual void scale(double const factor);
253  virtual void translate(glm::dvec3 const &shift);
254 
255  // *** S I G M A *** //
256  // ******************* //
263  virtual bool canComputeSigmaWithLadLut() {return false;}
275  virtual double computeSigmaWithLadLut(glm::dvec3 const &direction)
276  {throw HeliosException("Primitive cannot compute sigma with LadLut");}
277 
278  // *** STREAM OPERATORS *** //
279  // ************************** //
283  friend std::ostream& operator<< (std::ostream& out, Primitive &p);
284 };
Class representing an Axis Aligned Bounding Box (AABB)
Definition: AABB.h:10
Base class for Helios exceptions.
Definition: HeliosException.h:12
Output class for intersection handling methods.
Definition: IntersectionHandlingResult.h:14
Abstract class defining the common behavior for all primitives.
Definition: Primitive.h:24
virtual void update()=0
Necessary primitive updates after modification.
virtual bool canComputeSigmaWithLadLut()
Check if primitive can compute sigma using LadLut or not.
Definition: Primitive.h:263
virtual glm::dvec3 getCentroid()=0
Obtain the primitive centroid.
virtual void translate(glm::dvec3 const &shift)
Translate primitive by given shift.
Definition: Primitive.cpp:59
virtual double getIncidenceAngle_rad(const glm::dvec3 &rayOrigin, const glm::dvec3 &rayDir, const glm::dvec3 &intersectionPoint)=0
Obtain the incidence angle in radians.
std::shared_ptr< ScenePart > part
Shared pointer to the scene part the primitive belongs to.
Definition: Primitive.h:57
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 onFinishLoading(NoiseSource< double > &uniformNoiseSource)
Method to be triggered once all Primitives have been loaded.
Definition: Primitive.h:123
virtual double getGroundZOffset()
Offset for ground point z coordinate.
Definition: Primitive.h:187
virtual AABB * getAABB()=0
Obtain the axis aligned bounding box containing the primitive.
virtual double computeSigmaWithLadLut(glm::dvec3 const &direction)
Compute sigma using LadLut.
Definition: Primitive.h:275
virtual void scale(double const factor)
Scale primitive by given factor.
Definition: Primitive.cpp:50
virtual size_t getNumFullVertices()
Obtain the number of vertices returned by the getFullVertices function.
Definition: Primitive.h:145
virtual bool canHandleIntersections()
Specify if the primitive can handle intersections or not.
Definition: Primitive.h:208
std::shared_ptr< Material > material
Shared pointer to the material defining certain properties such as reflectance, specularity,...
Definition: Primitive.h:63
virtual void rotate(Rotation &r)
Performs rotation over primitive.
Definition: Primitive.cpp:44
void serialize(Archive &ar, const unsigned int version)
Serialize a Primitive to a stream of bytes.
Definition: Primitive.h:36
virtual Vertex * getVertices()=0
Obtain basic vertices for the primitive.
friend std::ostream & operator<<(std::ostream &out, Primitive &p)
Output stream operator << overloading.
Definition: Primitive.cpp:24
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 double getRayIntersectionDistance(const glm::dvec3 &rayOrigin, const glm::dvec3 &rayDir)=0
Obtain the intersection distance between primitive and given ray.
virtual Vertex * getFullVertices()
Obtain full vertices for the primitive.
Definition: Primitive.h:158
virtual size_t getNumVertices()
Obtain the number of vertices returned by the getVertices function.
Definition: Primitive.h:131
Definition: Rotation.h:80
Class representing a vertex.
Definition: Vertex.h:14