Line data Source code
1 : #pragma once 2 : 3 : #include "DisableWarnings.h" 4 : 5 : #include <complex> 6 : #include <cstddef> 7 : #include <type_traits> 8 : 9 : #include <Eigen/Core> 10 : #include <Eigen/Geometry> 11 : 12 : #ifdef ELSA_CUDA_VECTOR 13 : #include <thrust/complex.h> 14 : #endif 15 : 16 : #include "Complex.h" 17 : 18 : namespace elsa 19 : { 20 : using real_t = float; ///< global type for real numbers 21 : using complex_t = complex<real_t>; ///< global type for complex numbers 22 : using index_t = std::ptrdiff_t; ///< global type for indices 23 : 24 : /// global type for vectors of real numbers 25 : using RealVector_t = Eigen::Matrix<real_t, Eigen::Dynamic, 1>; 26 : 27 : /// global type for vectors of complex numbers 28 : using ComplexVector_t = Eigen::Matrix<complex_t, Eigen::Dynamic, 1>; 29 : 30 : /// global type for vectors of indices 31 : using IndexVector_t = Eigen::Matrix<index_t, Eigen::Dynamic, 1>; 32 : 33 : /// global type for vectors of booleans 34 : using BooleanVector_t = Eigen::Matrix<bool, Eigen::Dynamic, 1>; 35 : 36 : /// global type for vectors of data_t 37 : template <typename data_t> 38 : using Vector_t = Eigen::Matrix<data_t, Eigen::Dynamic, 1>; 39 : 40 : /// global type for arrays of index_t of size dim 41 : template <int dim> 42 : using IndexArray_t = Eigen::Array<index_t, dim, 1>; 43 : 44 : /// global type for arrays of real_t of size dim 45 : template <int dim> 46 : using RealArray_t = Eigen::Array<real_t, dim, 1>; 47 : 48 : /// global type for arrays of bol of size dim 49 : template <int dim> 50 : using BooleanArray_t = Eigen::Array<bool, dim, 1>; 51 : 52 : /// global type for matrices of real numbers 53 : template <class data_t> 54 : using Matrix_t = Eigen::Matrix<data_t, Eigen::Dynamic, Eigen::Dynamic>; 55 : 56 : /// global type for matrices of real numbers 57 : using RealMatrix_t = Matrix_t<real_t>; 58 : 59 : /// global type alias for rays 60 : using RealRay_t = Eigen::ParametrizedLine<real_t, Eigen::Dynamic>; 61 : 62 : /// global type alias for rays 63 : template <typename data_t> 64 : using Ray_t = Eigen::ParametrizedLine<data_t, Eigen::Dynamic>; 65 : 66 : /// template global constexpr for the number pi 67 : template <typename T> 68 : constexpr auto pi = static_cast<T>(3.14159265358979323846); 69 : 70 : /// global constexpr for the number pi 71 : constexpr auto pi_t = pi<real_t>; 72 : 73 : /// various values of the different norms of the Fourier transforms 74 : enum class FFTNorm { FORWARD, ORTHO, BACKWARD }; 75 : 76 : /// base case for deducing floating point type of std::complex 77 : template <typename T> 78 : struct GetFloatingPointType { 79 : using type = T; 80 : }; 81 : 82 : /// partial specialization to derive correct floating point type 83 : template <typename T> 84 : struct GetFloatingPointType<complex<T>> { 85 : using type = T; 86 : }; 87 : 88 : /// helper typedef to facilitate usage 89 : template <typename T> 90 : using GetFloatingPointType_t = typename GetFloatingPointType<T>::type; 91 : 92 : /// Remove cv qualifiers as well as reference of given type 93 : // TODO: Replace with std::remove_cv_ref_t when C++20 available 94 : template <typename T> 95 : struct RemoveCvRef { 96 : using type = std::remove_cv_t<std::remove_reference_t<T>>; 97 : }; 98 : 99 : /// Helper to make type available 100 : template <class T> 101 : using RemoveCvRef_t = typename RemoveCvRef<T>::type; 102 : 103 : /// Predicate to check if of complex type 104 : template <typename T> 105 : constexpr bool isComplex = std::is_same<RemoveCvRef_t<T>, complex<float>>::value 106 : || std::is_same<RemoveCvRef_t<T>, complex<double>>::value; 107 : 108 : /// With C++20 this can be replaced by std::type_identity 109 : template <class T> 110 : struct SelfType { 111 : using type = T; 112 : }; 113 : template <class T> 114 : using SelfType_t = typename SelfType<T>::type; 115 : 116 : namespace axdt 117 : { 118 : /// Symmetry influences the coefficients of the underlying spherical harmonics 119 : /// even -> odd degrees will be deemed to have zero coefficients; 120 : /// regular -> all non-zero (no simplification) 121 : /// Purely odd functions make no physical sense and can hence be ignored 122 : enum class Symmetry { even, regular }; 123 : 124 : /// 3D vector representing a sampling (scattering) direction 125 : template <typename data_t> 126 : using DirVec = Eigen::Vector3<data_t>; 127 : 128 : /// The collection of selected sampling directions 129 : template <typename data_t> 130 : using DirVecList = std::vector<DirVec<data_t>>; 131 : } // namespace axdt 132 : 133 : } // namespace elsa 134 : 135 : /* 136 : * Branch prediction tuning. 137 : * the expression is expected to be true (=likely) or false (=unlikely). 138 : * 139 : * btw, this implementation was taken from the Linux kernel. 140 : */ 141 : #if defined(__GNUC__) || defined(__clang__) 142 : #define likely(x) __builtin_expect(!!(x), 1) 143 57366751 : #define unlikely(x) __builtin_expect(!!(x), 0) 144 : #else 145 : #define likely(x) (x) 146 : #define unlikely(x) (x) 147 : #endif