1 #pragma once
2 
3 #include <Eigen/Core>
4 #include <Eigen/Geometry>
5 #include <Eigen/Dense>
6 #include <cstdint>
7 #include <vector>
8 
9 using Eigen::Vector2d;
10 using Eigen::Vector3d;
11 using Eigen::Vector3f;
12 using Eigen::Vector3i;
13 
14 #ifdef _MSC_VER
15   #include <Eigen/StdVector> // https://eigen.tuxfamily.org/dox/group__TopicStlContainers.html
16   #if !EIGEN_HAS_CXX11_CONTAINERS
17     #warning "Eigen has detected no support for CXX11 containers and has redefined std::vector"
18   #endif
19   typedef std::vector<Vector2d, Eigen::aligned_allocator<Vector2d> > VectorOfVector2d;
20 #else
21   typedef std::vector<Vector2d> VectorOfVector2d;
22 #endif
23 
24 typedef Eigen::AlignedBox<double, 3> BoundingBox;
25 using Eigen::Matrix3f;
26 using Eigen::Matrix3d;
27 using Eigen::Matrix4d;
28 #define Transform3d Eigen::Affine3d
29 #define Transform2d Eigen::Affine2d
30 
31 bool matrix_contains_infinity( const Transform3d &m );
32 bool matrix_contains_nan( const Transform3d &m );
33 int32_t hash_floating_point( double v );
34 
is_finite(const Eigen::MatrixBase<Derived> & x)35 template<typename Derived> bool is_finite(const Eigen::MatrixBase<Derived>& x) {
36    return ( (x - x).array() == (x - x).array()).all();
37 }
38 
is_nan(const Eigen::MatrixBase<Derived> & x)39 template<typename Derived> bool is_nan(const Eigen::MatrixBase<Derived>& x) {
40    return !((x.array() == x.array())).all();
41 }
42 
43 BoundingBox operator*(const Transform3d &m, const BoundingBox &box);
44 
45 // Vector4f is fixed-size vectorizable
46 // Use Eigen::DontAlign so we can store Color4f in STL containers
47 // https://eigen.tuxfamily.org/dox/group__DenseMatrixManipulation__Alignement.html
48 class Color4f : public Eigen::Matrix<float, 4, 1, Eigen::DontAlign>
49 {
50 public:
Color4f()51 	Color4f() { }
52 	Color4f(int r, int g, int b, int a = 255) { setRgb(r,g,b,a); }
53 	Color4f(float r, float g, float b, float a = 1.0f) : Eigen::Matrix<float, 4, 1, Eigen::DontAlign>(r, g, b, a) { }
54 
55 	void setRgb(int r, int g, int b, int a = 255) {
56 		*this << r/255.0f, g/255.0f, b/255.0f, a/255.0f;
57 	}
58 
isValid()59 	bool isValid() const { return this->minCoeff() >= 0.0f; }
60 };
61