Normal.hpp
Go to the documentation of this file.
1 
28 /*
29  * Normal.hpp
30  *
31  * @date 03.06.2017
32  * @author Lukas Kalbertodt <lukas.kalbertodt@gmail.com>
33  */
34 
35 #ifndef LVR2_GEOMETRY_NORMAL_H_
36 #define LVR2_GEOMETRY_NORMAL_H_
37 
38 #include <ostream>
39 
40 // Eigen sometimes produces errors when compiled with CUDA. Disables
41 // all Eigen related function for CUDA code (which is currently fine).
42 #ifndef __NVCC__
43 #include <Eigen/Dense>
44 #endif
45 
47 
48 namespace lvr2
49 {
50 
51 
59 template <typename CoordType>
60 struct Normal : public BaseVector<CoordType>
61 {
62  Normal() { this->x = 0; this->y = 1; this->z = 0;}
63 
64 
65  // ^ Private inheritance to restrict modifying access to the vector's data
66  // in order to prevent modifications that would result in a non-normalized
67  // vector.
68 
75  explicit Normal(BaseVector<CoordType> base);
76 
83  Normal(
84  CoordType x,
85  CoordType y,
86  CoordType z
87  );
88 
89 
90  // Since the fields x, y and z can't be access directly anymore (else the
91  // user could invalidate this *normal*), we provide getter methods.
92  CoordType getX() const
93  {
94  return this->x;
95  }
96 
97  CoordType getY() const
98  {
99  return this->y;
100  }
101 
102  CoordType getZ() const
103  {
104  return this->z;
105  }
106 
113  template<typename CollectionT>
114  static Normal<CoordType>& average(const CollectionT& normals);
115 
118  template<typename T>
119  Normal<CoordType>& operator=(const T& other);
120 
121  template<typename T>
122  Normal<CoordType> operator+(const T& other) const;
123 
124  template<typename T>
125  Normal<CoordType> operator-(const T& other) const;
126 
128 
129 // Eigen sometimes produces errors when compiled with CUDA. Disables
130 // all Eigen related function for CUDA code (which is currently fine).
131 #ifndef __NVCC__
132  // Friend declaration for Eigen multiplication
133  template<typename T, typename S>
134  friend Normal<T> operator*(const Eigen::Matrix<S, 4, 4>& mat, const Normal<T>& normal);
135 #endif // ifndef __NVCC__
136 
137 };
138 
139 template<typename CoordType>
140 inline std::ostream& operator<<(std::ostream& os, const Normal<CoordType>& n)
141 {
142  os << "Normal[" << n.getX() << ", " << n.getY() << ", " << n.getZ() << "]";
143  return os;
144 }
145 
146 // Eigen sometimes produces errors when compiled with CUDA. Disables
147 // all Eigen related function for CUDA code (which is currently fine).
148 #ifndef __NVCC__
149 
161 template<typename CoordType, typename Scalar = CoordType>
162 inline Normal<CoordType> operator*(const Eigen::Matrix<Scalar, 4, 4>& mat, const Normal<CoordType>& normal)
163 {
164  // TODO: CHECK IF THIS IS CORRECT
165  CoordType x = mat(0, 0) * normal.x + mat(1, 0) * normal.y + mat(2, 0) * normal.z;
166  CoordType y = mat(0, 1) * normal.x + mat(1, 1) * normal.y + mat(2, 1) * normal.z;
167  CoordType z = mat(0, 2) * normal.x + mat(1, 2) * normal.y + mat(2, 2) * normal.z;
168  return Normal<CoordType>(x,y,z);
169 }
170 #endif // ifndef __NVCC__
171 
172 } // namespace lvr2
173 
174 #include "lvr2/geometry/Normal.tcc"
175 
176 #endif /* LVR2_GEOMETRY_NORMAL_H_ */
Normal< CoordType > & operator=(const T &other)
Normal< CoordType > operator-() const
static Normal< CoordType > & average(const CollectionT &normals)
Returns the average of all normals in the given collection.
Normal< CoordType > operator+(const T &other) const
A vector guaranteed to be normalized (length = 1).
Definition: BaseVector.hpp:49
CoordType getZ() const
Definition: Normal.hpp:102
friend Normal< T > operator*(const Eigen::Matrix< S, 4, 4 > &mat, const Normal< T > &normal)
CoordType getX() const
Definition: Normal.hpp:92
CoordType getY() const
Definition: Normal.hpp:97


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:08