MobileRT  1.0
A multi platform C++ CPU progressive Ray Tracer.
Naive.hpp
Go to the documentation of this file.
1 #ifndef MOBILERT_ACCELERATORS_NAIVE_HPP
2 #define MOBILERT_ACCELERATORS_NAIVE_HPP
3 
5 #include "MobileRT/Ray.hpp"
6 #include <vector>
7 
8 namespace MobileRT {
9 
19  template<typename T>
20  class Naive final {
21  private:
22  ::std::vector<T> primitives_ {};
23 
24  private:
25  Intersection intersect(Intersection intersection);
26 
27  public:
28  explicit Naive() = default;
29 
30  explicit Naive(::std::vector<T> &&primitives);
31 
32  Naive(const Naive &naive) = delete;
33 
34  Naive(Naive &&naive) noexcept = default;
35 
36  ~Naive();
37 
38  Naive &operator=(const Naive &naive) = delete;
39 
40  Naive &operator=(Naive &&naive) noexcept = default;
41 
42  Intersection trace(Intersection intersection);
43 
45 
46  const ::std::vector<T>& getPrimitives() const;
47  };
48 
55  template<typename T>
56  Naive<T>::Naive(::std::vector<T> &&primitives) :
57  primitives_ {::std::move(primitives)} {
58  LOG_INFO("Built Native for: ", typeid(T).name());
59  }
60 
66  template<typename T>
68  this->primitives_.clear();
69  ::std::vector<T> {}.swap(this->primitives_);
70  }
71 
84  template<typename T>
86  const float lastDist {intersection.length_};
87  for (T &primitive : this->primitives_) {
88  intersection = primitive.intersect(intersection);
89  if (intersection.ray_.shadowTrace_ && intersection.length_ < lastDist) {
90  return intersection;
91  }
92  }
93  return intersection;
94  }
95 
104  template<typename T>
106  intersection = intersect(intersection);
107  return intersection;
108  }
109 
119  template<typename T>
121  intersection = intersect(intersection);
122  return intersection;
123  }
124 
131  template<typename T>
132  const ::std::vector<T>& Naive<T>::getPrimitives() const {
133  return this->primitives_;
134  }
135 
136 }//namespace MobileRT
137 
138 #endif //MOBILERT_ACCELERATORS_NAIVE_HPP
Ray ray_
Definition: Intersection.hpp:27
Naive()=default
Intersection trace(Intersection intersection)
Definition: Naive.hpp:105
#define LOG_INFO(...)
Definition: Utils.hpp:43
Intersection shadowTrace(Intersection intersection)
Definition: Naive.hpp:120
float length_
Definition: Intersection.hpp:19
Definition: Intersection.hpp:14
~Naive()
Definition: Naive.hpp:67
const ::std::vector< T > & getPrimitives() const
Definition: Naive.hpp:132
bool shadowTrace_
Definition: Ray.hpp:45
Naive & operator=(const Naive &naive)=delete
::std::vector< T > primitives_
Definition: Naive.hpp:22
Intersection intersect(Intersection intersection)
Definition: Naive.hpp:85
Definition: Naive.hpp:20
Definition: AABB.cpp:105