kspaceFirstOrder3D-OMP  1.2
The C++ implementation of the k-wave toolbox for the time-domain simulation of acoustic wave fields in 3D
ComplexMatrix.h
Go to the documentation of this file.
1 /**
2  * @file ComplexMatrix.h
3  *
4  * @author Jiri Jaros \n
5  * Faculty of Information Technology \n
6  * Brno University of Technology \n
7  * jarosjir@fit.vutbr.cz
8  *
9  * @brief The header file with the class for complex matrices.
10  *
11  * @version kspaceFirstOrder3D 2.16
12  *
13  * @date 11 July 2011, 14:02 (created) \n
14  * 04 September 2017, 11:02 (revised)
15  *
16  * @copyright Copyright (C) 2017 Jiri Jaros and Bradley Treeby.
17  *
18  * This file is part of the C++ extension of the [k-Wave Toolbox](http://www.k-wave.org).
19  *
20  * This file is part of the k-Wave. k-Wave is free software: you can redistribute it and/or modify it under the terms
21  * of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the
22  * License, or (at your option) any later version.
23  *
24  * k-Wave is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
25  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
26  * more details.
27  *
28  * You should have received a copy of the GNU Lesser General Public License along with k-Wave.
29  * If not, see [http://www.gnu.org/licenses/](http://www.gnu.org/licenses/).
30  */
31 
32 #ifndef COMPLEX_MATRIX_H
33 #define COMPLEX_MATRIX_H
34 
35 #include <complex>
36 
39 
40 #include <Utils/DimensionSizes.h>
41 
42 /// Datatype for complex single precision numbers.
43 using FloatComplex = std::complex<float>;
44 
45 
46 /**
47  * @class ComplexMatrix
48  * @brief The class for complex matrices.
49  * @details The class for complex matrices.
50  */
52 {
53  public:
54 
55  /// Default constructor not allowed.
56  ComplexMatrix() = delete;
57  /**
58  * @brief Constructor.
59  * @param [in] dimensionSizes - Dimension sizes of the matrix.
60  */
61  ComplexMatrix(const DimensionSizes& dimensionSizes);
62  /// Copy constructor not allowed.
63  ComplexMatrix(const ComplexMatrix&) = delete;
64  /// Destructor.
65  virtual ~ComplexMatrix();
66 
67  /// Operator= is not allowed.
69 
70  /**
71  * @brief Read matrix from HDF5 file.
72  * @details Read matrix from HDF5 file.
73  * @param [in] file - Handle to the HDF5 file.
74  * @param [in] matrixName - HDF5 dataset name to read from.
75  * @throw ios::failure - If error occurred.
76  */
77  virtual void readData(Hdf5File& file,
78  MatrixName& matrixName);
79 
80  /**
81  * @brief Write data into HDF5 file.
82  * @details Write data into HDF5 file.
83  * @param [in] file - Handle to the HDF5 file
84  * @param [in] matrixName - HDF5 dataset name to write to.
85  * @param [in] compressionLevel - Compression level for the HDF5 dataset.
86  * @throw ios::failure - If an error occurred.
87  */
88  virtual void writeData(Hdf5File& file,
89  MatrixName& matrixName,
90  const size_t compressionLevel);
91 
92  /**
93  * @brief Get raw complex data out of the class (for direct kernel access).
94  * @return Mutable matrix data
95  */
97  {
98  return reinterpret_cast<FloatComplex*> (mData);
99  };
100 
101  /**
102  * @brief Get raw complex data out of the class (for direct kernel access).
103  * @return Imutable matrix data
104  */
105  virtual const FloatComplex* getComplexData() const
106  {
107  return reinterpret_cast<FloatComplex*> (mData);
108  };
109 
110  /**
111  * @brief Operator [].
112  * @param [in] index - 1D index into the matrix.
113  * @return An element of the matrix.
114  */
115  inline FloatComplex& operator[](const size_t& index)
116  {
117  return reinterpret_cast<FloatComplex*>(mData)[index];
118  };
119  /**
120  * @brief Operator [], constant version.
121  * @param [in] index - 1D index into the matrix.
122  * @return An element of the matrix.
123  */
124  inline const FloatComplex& operator[](const size_t& index) const
125  {
126  return reinterpret_cast<FloatComplex*> (mData)[index];
127  };
128 
129  /**
130  * @brief Get element from 3D matrix.
131  * @details Get element from 3D matrix.
132  * @param [in] x - x dimension
133  * @param [in] y - y dimension
134  * @param [in] z - z dimension
135  * @return a complex element of the class
136  */
137  inline FloatComplex& GetElementFrom3D(const size_t x,
138  const size_t y,
139  const size_t z)
140  {
141  return reinterpret_cast<FloatComplex*> (mData)[z * (mSlabSize>>1) + y * (mRowSize>>1) + x];
142  };
143 
144  /**
145  * @brief Get element from 3D matrix, constant version.
146  * @details Get element from 3D matrix, constant version.
147  * @param [in] x - x dimension
148  * @param [in] y - y dimension
149  * @param [in] z - z dimension
150  * @return a complex element of the class
151  */
152  inline const FloatComplex& GetElementFrom3D(const size_t x,
153  const size_t y,
154  const size_t z) const
155  {
156  return reinterpret_cast<FloatComplex*> (mData)[z * (mSlabSize >> 1) + y * (mRowSize >> 1) + x];
157  };
158 
159  protected:
160 
161  private:
162  /**
163  * @brief Initialize dimension sizes
164  * @param [in] dimensionSizes - Dimension sizes of the matrix.
165  */
166  void initDimensions(const DimensionSizes& dimensionSizes);
167 
168 };// end of ComplexMatrix
169 //----------------------------------------------------------------------------------------------------------------------
170 
171 #endif /* COMPLEX_MATRIX_H */
size_t mRowSize
Size of a 1D row in X dimension.
virtual ~ComplexMatrix()
Destructor.
FloatComplex & operator[](const size_t &index)
Operator [].
const FloatComplex & operator[](const size_t &index) const
Operator [], constant version.
The header file containing the class for real matrices.
std::complex< float > FloatComplex
Datatype for complex single precision numbers.
Definition: ComplexMatrix.h:43
float * mData
Raw matrix data.
virtual void writeData(Hdf5File &file, MatrixName &matrixName, const size_t compressionLevel)
Write data into HDF5 file.
Class wrapping the HDF5 routines.
Definition: Hdf5File.h:490
The class for complex matrices.
Definition: ComplexMatrix.h:51
void initDimensions(const DimensionSizes &dimensionSizes)
Initialize dimension sizes.
const std::string MatrixName
Datatype for matrix names.
Definition: MatrixNames.h:39
Structure with 4D dimension sizes (3 in space and 1 in time).
virtual FloatComplex * getComplexData()
Get raw complex data out of the class (for direct kernel access).
Definition: ComplexMatrix.h:96
The header file containing the structure with 3D dimension sizes.
virtual const FloatComplex * getComplexData() const
Get raw complex data out of the class (for direct kernel access).
virtual void readData(Hdf5File &file, MatrixName &matrixName)
Read matrix from HDF5 file.
The header file containing the base class for single precisions floating point numbers (floats)...
const FloatComplex & GetElementFrom3D(const size_t x, const size_t y, const size_t z) const
Get element from 3D matrix, constant version.
size_t mSlabSize
Size of a XY slab.
ComplexMatrix()=delete
Default constructor not allowed.
ComplexMatrix & operator=(const ComplexMatrix &)
Operator= is not allowed.
FloatComplex & GetElementFrom3D(const size_t x, const size_t y, const size_t z)
Get element from 3D matrix.
Abstract base class for float based matrices defining basic interface. Higher dimensional matrices st...