diff --git a/Base/Math/FourierTransform.cpp b/Base/Math/FourierTransform.cpp index 7952afc35386cc61bf27d66a1fb85a96eaab69f7..737b0c513a8b8ba9a3e8f02cb1ca0af0b2c3e894 100644 --- a/Base/Math/FourierTransform.cpp +++ b/Base/Math/FourierTransform.cpp @@ -33,10 +33,9 @@ template <typename T> std::vector<T> fftshift_1d(const std::vector<T>& src, bool return result; } -template <typename T> -std::vector<std::vector<T>> fftshift_2d(const std::vector<std::vector<T>>& src, bool inverse) +template <typename T> Field2D<T> fftshift_2d(const Field2D<T>& src, bool inverse) { - std::vector<std::vector<T>> result = src; + Field2D<T> result = src; // Centering FT around zero frequency int row_shift = (result.size() + 1) / 2; diff --git a/Base/Type/Field2D.h b/Base/Type/Field2D.h index fc73473b090bee69789436b9dfd9502091d9ef70..185ad7f0adaa2396f9259ce61bf61305f99f426d 100644 --- a/Base/Type/Field2D.h +++ b/Base/Type/Field2D.h @@ -18,12 +18,14 @@ #include <heinz/Complex.h> #include <vector> -using double2d_t = std::vector<std::vector<double>>; -using complex2d_t = std::vector<std::vector<complex_t>>; +template <typename T> using Field2D = std::vector<std::vector<T>>; + +using double2d_t = Field2D<double>; +using complex2d_t = Field2D<complex_t>; namespace FieldUtil { -template <typename C> std::vector<C> flatten(const std::vector<std::vector<C>>& src) +template <typename C> std::vector<C> flatten(const Field2D<C>& src) { std::vector<C> result; for (const auto& row : src) @@ -31,11 +33,10 @@ template <typename C> std::vector<C> flatten(const std::vector<std::vector<C>>& return result; } -template <typename C> -std::vector<std::vector<C>> reshapeTo2D(const std::vector<C>& src, size_t n_rows) +template <typename C> Field2D<C> reshapeTo2D(const std::vector<C>& src, size_t n_rows) { size_t n_cols = src.size() / n_rows; - std::vector<std::vector<C>> result(n_rows); + Field2D<C> result(n_rows); for (size_t i = 0; i < n_rows; i++) result[i].insert(result[i].end(), src.begin() + i * n_cols, src.begin() + (i + 1) * n_cols);