Intersection.hpp
Go to the documentation of this file.
1 #ifndef LVR2_RAYCASTING_INTERSECTION_HPP
2 #define LVR2_RAYCASTING_INTERSECTION_HPP
3 
4 #include <string>
5 #include <sstream>
6 #include <tuple>
7 #include <type_traits>
8 #include <iostream>
10 
11 namespace lvr2 {
12 
13 // Intersect flags
14 // weird intersection construction
15 
16 namespace intelem {
17 
22 struct Point {
24 };
25 
30 struct Distance {
31  float dist;
32 };
33 
39 struct Normal {
41 };
42 
47 struct Face {
48  unsigned int face_id;
49 };
50 
65 struct Barycentrics {
67 };
68 
73 struct Mesh {
74  unsigned int mesh_id;
75 };
76 
77 } // namespace intelem
78 
102 template<typename ...Tp>
103 struct Intersection : public Tp...
104 {
105 public:
106  static constexpr std::size_t N = sizeof...(Tp);
107  using elems = std::tuple<Tp...>;
108 
109 private:
110  template <typename T, typename Tuple>
111  struct has_type;
112 
113  template <typename T>
114  struct has_type<T, std::tuple<>> : std::false_type {};
115 
116  template <typename T, typename U, typename... Ts>
117  struct has_type<T, std::tuple<U, Ts...>> : has_type<T, std::tuple<Ts...>> {};
118 
119 
120  template <typename T, typename... Ts>
121  struct has_type<T, std::tuple<T, Ts...>> : std::true_type {};
122 
123  template<typename F>
124  struct has_elem {
125  static constexpr bool value = has_type<F, elems>::type::value;
126  };
127 
128 public:
136  template<typename F>
137  static constexpr bool has() {
138  return has_elem<F>::value;
139  }
140 };
141 
142 // Common types
147 using AllInt = Intersection<
154 
155 } // namespace lvr2
156 
157 
158 template<typename ...T>
159 std::ostream& operator<<(std::ostream& os, const lvr2::Intersection<T...>& intersection)
160 {
161  using IntT = lvr2::Intersection<T...>;
162  os << "Raycaster Intersection: \n";
163 
164  if constexpr(IntT::template has<lvr2::intelem::Point>())
165  {
166  os << "-- point: " << intersection.point.transpose() << "\n";
167  }
168 
169  if constexpr(IntT::template has<lvr2::intelem::Distance>())
170  {
171  os << "-- dist: " << intersection.dist << "\n";
172  }
173 
174  if constexpr(IntT::template has<lvr2::intelem::Normal>())
175  {
176  os << "-- normal: " << intersection.normal.transpose() << "\n";
177  }
178 
179  if constexpr(IntT::template has<lvr2::intelem::Face>())
180  {
181  os << "-- face: " << intersection.face_id << "\n";
182  }
183 
184  if constexpr(IntT::template has<lvr2::intelem::Barycentrics>())
185  {
186  os << "-- barycentrics: " << intersection.b_uv.transpose() << "\n";
187  }
188 
189  if constexpr(IntT::template has<lvr2::intelem::Mesh>())
190  {
191  os << "-- mesh: " << intersection.mesh_id << "\n";
192  }
193 
194  return os;
195 }
196 
197 #endif // LVR2_RAYCASTING_INTERSECTION_HPP
std::ostream & operator<<(std::ostream &os, const BaseVector< T > &v)
Definition: BaseVector.hpp:227
Barycentric coordinates of the intersection point.
Raycaster should compute the normal of the intersected face flipped towards the ray.
CRTP Container for User defined intersection elements.
Intersection distance(float)
Intersection point (x,y,z)
unsigned int mesh_id
Eigen::Vector3f Vector3f
Eigen 3D vector, single precision.
std::tuple< Tp... > elems
unsigned int face_id
static constexpr bool has()
Check if Intersection container has a specific intelem (lvr2::intelem).
Eigen::Vector2f Vector2f
Eigen 2D vector, single precision.
Receive the intersected Mesh. TODO.
Intersection face as uint id.


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Mon Feb 28 2022 22:46:06