kspaceFirstOrder3D-OMP  1.2
The C++ implementation of the k-wave toolbox for the time-domain simulation of acoustic wave fields in 3D
IndexMatrix.h
Go to the documentation of this file.
1 /**
2  * @file IndexMatrix.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 containing the class for 64b integer matrices.
10  *
11  * @version kspaceFirstOrder3D 2.16
12  *
13  * @date 26 July 2011, 15:16 (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 INDEX_MATRIX_H
33 #define INDEX_MATRIX_H
34 
35 
37 #include <Utils/DimensionSizes.h>
38 
39 /**
40  * @class IndexMatrix
41  * @brief The class for 64b unsigned integers (indices). It is used for linear and cuboid corners masks to get the
42  * address of sampled voxels.
43  *
44  * @details The class for 64b unsigned integers (indices). It is used for linear and cuboid corners masks to get the
45  * get the address of sampled voxels.
46  */
48 {
49  public:
50 
51  /// Default constructor not allowed.
52  IndexMatrix() = delete;
53  /**
54  * @brief Constructor.
55  * @param [in] dimensionSizes - Dimension sizes of the matrix.
56  */
57  IndexMatrix(const DimensionSizes& dimensionSizes);
58  /// Copy constructor not allowed.
59  IndexMatrix(const IndexMatrix&) = delete;
60  /// Destructor.
61  virtual ~IndexMatrix();
62 
63  /// Operator= is not allowed.
65 
66  /**
67  * @brief Read matrix from HDF5 file.
68  * @details Read matrix from HDF5 file.
69  * @param [in] file - Handle to the HDF5 file
70  * @param [in] matrixName - HDF5 dataset name to read from
71  * @throw ios::failure - If error occurred.
72  */
73  virtual void readData(Hdf5File& file,
74  MatrixName& matrixName);
75  /**
76  * @brief Write data into HDF5 file.
77  * @details Write data into HDF5 file.
78  * @param [in] file - Handle to the HDF5 file
79  * @param [in] matrixName - HDF5 dataset name to write to
80  * @param [in] compressionLevel - Compression level for the HDF5 dataset
81  * @throw ios::failure - If an error occurred.
82  */
83  virtual void writeData(Hdf5File& file,
84  MatrixName& matrixName,
85  const size_t compressionLevel);
86 
87  /**
88  * @brief operator [].
89  * @param [in] index - 1D index into the matrix.
90  * @return An element of the matrix.
91  */
92  inline size_t& operator[](const size_t& index) { return mData[index]; };
93  /**
94  * @brief operator [], constant version.
95  * @param [in] index - 1D index into the matrix.
96  * @return An element of the matrix.
97  */
98  inline const size_t& operator[](const size_t& index) const { return mData[index]; };
99 
100  /**
101  * @brief Get the top left corner of the index-th cuboid.
102  * @param [in] index - Index of the cuboid
103  * @return The top left corner
104  */
105  DimensionSizes getTopLeftCorner(const size_t& index) const;
106  /**
107  * @brief Get the top bottom right of the index-th cuboid.
108  * @param [in] index - Index of the cuboid
109  * @return The bottom right corner
110  */
111  DimensionSizes getBottomRightCorner(const size_t& index) const;
112 
113  /// Recompute indices MATALAB->C++.
114  void recomputeIndicesToCPP();
115  /// Recompute indices C++ -> MATLAB.
117 
118  /**
119  * @brief Get total number of elements in all cuboids to be able to allocate output file.
120  * @return Total sampled grid points
121  */
122  size_t getSizeOfAllCuboids() const;
123 
124  protected:
125 
126  private:
127  /// Init dimension.
128  void initDimensions(const DimensionSizes& dimensionSizes);
129  /// Number of elements to get 4MB block of data.
130  static constexpr size_t kChunkSize1D4MB = 1048576; //(4MB)
131  /// Number of elements to get 1MB block of data.
132  static constexpr size_t kChunkSize1D1MB = 262144; //(1MB)
133  /// Number of elements to get 256KB block of data.
134  static constexpr size_t kChunkSize1D256kB = 65536; //(256KB)
135 
136 };// end of IndexMatrix
137 //----------------------------------------------------------------------------------------------------------------------
138 #endif /* INDEX_MATRIX_H */
void recomputeIndicesToMatlab()
Recompute indices C++ -> MATLAB.
virtual void readData(Hdf5File &file, MatrixName &matrixName)
Read matrix from HDF5 file.
Definition: IndexMatrix.cpp:70
virtual void writeData(Hdf5File &file, MatrixName &matrixName, const size_t compressionLevel)
Write data into HDF5 file.
Definition: IndexMatrix.cpp:94
size_t * mData
Raw matrix data.
static constexpr size_t kChunkSize1D1MB
Number of elements to get 1MB block of data.
Definition: IndexMatrix.h:132
static constexpr size_t kChunkSize1D256kB
Number of elements to get 256KB block of data.
Definition: IndexMatrix.h:134
DimensionSizes getTopLeftCorner(const size_t &index) const
Get the top left corner of the index-th cuboid.
virtual ~IndexMatrix()
Destructor.
Definition: IndexMatrix.cpp:61
Class wrapping the HDF5 routines.
Definition: Hdf5File.h:490
const size_t & operator[](const size_t &index) const
operator [], constant version.
Definition: IndexMatrix.h:98
IndexMatrix & operator=(const IndexMatrix &)
Operator= is not allowed.
const std::string MatrixName
Datatype for matrix names.
Definition: MatrixNames.h:39
Structure with 4D dimension sizes (3 in space and 1 in time).
The header file containing the structure with 3D dimension sizes.
void initDimensions(const DimensionSizes &dimensionSizes)
Init dimension.
static constexpr size_t kChunkSize1D4MB
Number of elements to get 4MB block of data.
Definition: IndexMatrix.h:130
DimensionSizes getBottomRightCorner(const size_t &index) const
Get the top bottom right of the index-th cuboid.
size_t & operator[](const size_t &index)
operator [].
Definition: IndexMatrix.h:92
void recomputeIndicesToCPP()
Recompute indices MATALAB->C++.
The header file containing the base class for index matrices (based on the size_t datatype)...
IndexMatrix()=delete
Default constructor not allowed.
The class for 64b unsigned integers (indices). It is used for linear and cuboid corners masks to get ...
Definition: IndexMatrix.h:47
Abstract base class for index based matrices defining basic interface. Higher dimensional matrices st...
size_t getSizeOfAllCuboids() const
Get total number of elements in all cuboids to be able to allocate output file.