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_ */
lvr2::Normal::operator=
Normal< CoordType > & operator=(const T &other)
BaseVector.hpp
lvr2::BaseVector< CoordType >
lvr2::Normal::Normal
Normal()
Definition: Normal.hpp:62
lvr2::Normal::getY
CoordType getY() const
Definition: Normal.hpp:97
lvr2::operator<<
std::ostream & operator<<(std::ostream &os, const BaseVector< T > &v)
Definition: BaseVector.hpp:227
kfusion::device::Normal
float4 Normal
Definition: internal.hpp:13
lvr2::Normal
A vector guaranteed to be normalized (length = 1).
Definition: BaseVector.hpp:49
lvr2::Normal::operator-
Normal< CoordType > operator-() const
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::Normal::operator+
Normal< CoordType > operator+(const T &other) const
lvr2::Normal::average
static Normal< CoordType > & average(const CollectionT &normals)
Returns the average of all normals in the given collection.
lvr2::Normal::operator*
friend Normal< T > operator*(const Eigen::Matrix< S, 4, 4 > &mat, const Normal< T > &normal)
lvr2::operator*
BaseVector< CoordType > operator*(const Eigen::Matrix< Scalar, 4, 4 > &mat, const BaseVector< CoordType > &normal)
Multiplication operator to support transformation with Eigen matrices. Rotates the normal,...
Definition: BaseVector.hpp:249
lvr2::Normal::getZ
CoordType getZ() const
Definition: Normal.hpp:102
lvr2::Normal::getX
CoordType getX() const
Definition: Normal.hpp:92


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 Wed Mar 2 2022 00:37:24