-
Notifications
You must be signed in to change notification settings - Fork 15
/
Common.h
108 lines (91 loc) · 3.42 KB
/
Common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#ifndef COMMON_H
#define COMMON_H
#include <Eigen/Dense>
#include "float.h"
#define _USE_MATH_DEFINES
#include <cmath>
#define USE_DOUBLE
#define MIN_PARALLEL_SIZE 64
#ifdef USE_DOUBLE
typedef double Real;
#define REAL_MAX DBL_MAX
#define REAL_MIN DBL_MIN
#else
typedef float Real;
#define REAL_MAX FLT_MAX
#define REAL_MIN FLT_MIN
#endif
using Vector2r = Eigen::Matrix<Real, 2, 1>;
using Vector3r = Eigen::Matrix<Real, 3, 1>;
using Vector4r = Eigen::Matrix<Real, 4, 1>;
using Vector6r = Eigen::Matrix<Real, 6, 1>;
using Vector9r = Eigen::Matrix<Real, 9, 1>;
using VectorXr = Eigen::Matrix<Real, Eigen::Dynamic, 1>;
using Matrix2r = Eigen::Matrix<Real, 2, 2>;
using Matrix3r = Eigen::Matrix<Real, 3, 3>;
using Matrix4r = Eigen::Matrix<Real, 4, 4>;
using Matrix6r = Eigen::Matrix<Real, 6, 6>;
using Matrix9r = Eigen::Matrix<Real, 9, 9>;
using MatrixXr = Eigen::Matrix<Real, Eigen::Dynamic, Eigen::Dynamic>;
using AlignedBox2r = Eigen::AlignedBox<Real, 2>;
using AlignedBox3r = Eigen::AlignedBox<Real, 3>;
using AngleAxisr = Eigen::AngleAxis<Real>;
using Quaternionr = Eigen::Quaternion<Real>;
//allocators to be used in STL collections containing Eigen structures
using Alloc_Vector2r = Eigen::aligned_allocator<Vector2r>;
using Alloc_Vector3r = Eigen::aligned_allocator<Vector3r>;
using Alloc_Vector4r = Eigen::aligned_allocator<Vector4r>;
using Alloc_Matrix2r = Eigen::aligned_allocator<Matrix2r>;
using Alloc_Matrix3r = Eigen::aligned_allocator<Matrix3r>;
using Alloc_Matrix4r = Eigen::aligned_allocator<Matrix4r>;
using Alloc_AlignedBox2r = Eigen::aligned_allocator<AlignedBox2r>;
using Alloc_AlignedBox3r = Eigen::aligned_allocator<AlignedBox3r>;
using Alloc_AngleAxisr = Eigen::aligned_allocator<AngleAxisr>;
using Alloc_Quaternionr = Eigen::aligned_allocator<Quaternionr>;
#if EIGEN_ALIGN
#define PDB_MAKE_ALIGNED_OPERATOR_NEW EIGEN_MAKE_ALIGNED_OPERATOR_NEW
#define REPORT_MEMORY_LEAKS
#if defined(WIN32) || defined(_WIN32) || defined(WIN64)
#ifdef _DEBUG
// Enable memory leak detection for Eigen new
#undef PDB_MAKE_ALIGNED_OPERATOR_NEW
#define PDB_MAKE_ALIGNED_OPERATOR_NEW EIGEN_MAKE_ALIGNED_OPERATOR_NEW \
void *operator new(size_t size, int const block_use, char const* file_name, int const line_number) { \
\
return _aligned_malloc_dbg(size, 16, file_name, line_number); \
} \
void *operator new[](size_t size, int const block_use, char const* file_name, int const line_number) { \
return operator new(size, block_use, file_name, line_number); \
}\
void operator delete(void* block, int const block_use, char const* file_name, int const line_number) { \
\
return _aligned_free_dbg(block); \
} \
void operator delete[](void* block, int const block_use, char const* file_name, int const line_number) { \
return operator delete(block, block_use, file_name, line_number); \
}
#endif
#endif
#else
#define PDB_MAKE_ALIGNED_OPERATOR_NEW
#if defined(WIN32) || defined(_WIN32) || defined(WIN64)
// Enable memory leak detection
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
#define REPORT_MEMORY_LEAKS _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#else
#define REPORT_MEMORY_LEAKS
#endif
#else
#define REPORT_MEMORY_LEAKS
#endif
#endif
#endif
#if defined(WIN32) || defined(_WIN32) || defined(WIN64)
#define FORCE_INLINE __forceinline
#else
#define FORCE_INLINE __attribute__((always_inline))
#endif