OpenImpala
Image-based parallel transport property solver
Loading...
Searching...
No Matches
RawReader.H
Go to the documentation of this file.
1
4#ifndef OPENIMPALA_RAW_READER_H
5#define OPENIMPALA_RAW_READER_H
6
7#include <vector>
8#include <string>
9#include <cstdint> // For fixed-width integers (e.g., uint8_t, int16_t)
10#include <stdexcept> // For standard exception classes (e.g., std::runtime_error)
11
12// AMReX Includes
13// Include necessary AMReX headers directly instead of relying on forward declarations
14// where feasible, as class definitions might change between versions (e.g., IntVect).
15#include <AMReX_Box.H> // Defines amrex::Box for representing index space
16#include <AMReX_iMultiFab.H> // Defines amrex::iMultiFab for integer multifabs
17#include <AMReX_IntVect.H> // Defines amrex::IntVect for integer vectors/indices
18
19// Forward declarations are generally discouraged for AMReX types unless strictly needed
20// to manage complex include dependencies, as their definitions can change.
21// The necessary headers are included above.
22
23namespace OpenImpala {
24
51
69class RawReader {
70public:
76 using ByteType = unsigned char;
77
83 RawReader();
84
102 explicit RawReader(const std::string& filename, int width, int height, int depth,
103 RawDataType data_type);
104
109 virtual ~RawReader() = default;
110
111 // --- Resource Management (Rule of 5/3) ---
112 // Prevent copying: Copying potentially large raw data buffers is expensive
113 // and usually undesirable. Deleted copy constructor and assignment operator.
114 RawReader(const RawReader&) = delete;
115 RawReader& operator=(const RawReader&) = delete;
116
117 // Allow moving: Efficiently transfer ownership of the internal data buffer
118 // from one RawReader instance to another. Default move constructor and
119 // assignment operator are suitable here.
120 RawReader(RawReader&&) = default;
122
140 bool readFile(const std::string& filename, int width, int height, int depth,
141 RawDataType data_type);
142
147 bool isRead() const;
148
153 int width() const;
154
159 int height() const;
160
165 int depth() const;
166
174 amrex::Box box() const;
175
180 RawDataType getDataType() const;
181
201 double getValue(int i, int j, int k) const;
202
226 void threshold(double threshold_value, int value_if_true, int value_if_false,
227 amrex::iMultiFab& mf) const;
228
244 void threshold(double threshold_value, amrex::iMultiFab& mf) const;
245
246
247private:
254 bool readRawFileInternal();
255
261 size_t getBytesPerVoxel() const;
262
268 bool isHostLittleEndian() const;
269
270
271 // --- Member Variables ---
272 std::string m_filename;
274 int m_width =
275 0;
276 int m_height =
277 0;
278 int m_depth =
279 0;
280 RawDataType m_data_type =
282
283 // Internal buffer holding the raw byte data read from the file.
284 std::vector<ByteType> m_raw_bytes;
285
286 bool m_is_read = false;
287};
288
289} // namespace OpenImpala
290
291#endif // OPENIMPALA_RAW_READER_H
amrex::Box box() const
Gets the index space (bounding box) corresponding to the dataset dimensions.
Definition RawReader.cpp:301
bool isRead() const
Checks if data has been successfully read and the reader is ready.
Definition RawReader.cpp:285
int width() const
Gets the width (X dimension) of the loaded dataset.
Definition RawReader.cpp:288
double getValue(int i, int j, int k) const
Retrieves the numerical value at a specific voxel, converting it to double.
Definition RawReader.cpp:314
bool readFile(const std::string &filename, int width, int height, int depth, RawDataType data_type)
Reads or re-reads data from the specified raw binary file.
Definition RawReader.cpp:100
void threshold(double threshold_value, int value_if_true, int value_if_false, amrex::iMultiFab &mf) const
Fills an AMReX iMultiFab based on thresholding the raw data.
Definition RawReader.cpp:436
RawReader()
Default constructor. Creates an empty reader instance.
Definition RawReader.cpp:79
virtual ~RawReader()=default
Virtual default destructor.
unsigned char ByteType
Type alias for the underlying byte storage.
Definition RawReader.H:76
RawReader(const RawReader &)=delete
int height() const
Gets the height (Y dimension) of the loaded dataset.
Definition RawReader.cpp:291
RawReader(RawReader &&)=default
int depth() const
Gets the depth (Z dimension) of the loaded dataset.
Definition RawReader.cpp:294
RawReader & operator=(RawReader &&)=default
RawReader & operator=(const RawReader &)=delete
RawDataType getDataType() const
Gets the data type and endianness specified when the file was read.
Definition RawReader.cpp:297
Definition CathodeWrite.cpp:12
RawDataType
Specifies the expected primitive data type and endianness of voxels within a raw binary data file.
Definition RawReader.H:33
@ INT32_BE
32-bit signed integer, Big Endian.
Definition RawReader.H:43
@ INT32_LE
32-bit signed integer, Little Endian.
Definition RawReader.H:42
@ UNKNOWN
Default, indicating an uninitialized or invalid type.
Definition RawReader.H:34
@ FLOAT64_LE
64-bit double-precision float (IEEE 754), Little Endian.
Definition RawReader.H:48
@ FLOAT32_BE
32-bit single-precision float (IEEE 754), Big Endian.
Definition RawReader.H:47
@ FLOAT64_BE
64-bit double-precision float (IEEE 754), Big Endian.
Definition RawReader.H:49
@ UINT16_BE
16-bit unsigned integer, Big Endian.
Definition RawReader.H:41
@ UINT32_BE
32-bit unsigned integer, Big Endian.
Definition RawReader.H:45
@ UINT32_LE
32-bit unsigned integer, Little Endian.
Definition RawReader.H:44
@ INT16_BE
16-bit signed integer, Big Endian (most significant byte first).
Definition RawReader.H:39
@ INT16_LE
Definition RawReader.H:37
@ UINT8
8-bit unsigned integer (char, byte). Endianness irrelevant.
Definition RawReader.H:35
@ INT8
8-bit signed integer (signed char). Endianness irrelevant.
Definition RawReader.H:36
@ FLOAT32_LE
32-bit single-precision float (IEEE 754), Little Endian.
Definition RawReader.H:46
@ UINT16_LE
16-bit unsigned integer, Little Endian.
Definition RawReader.H:40