Reads and provides access to data from raw binary files where metadata (dimensions, data type, endianness) is provided externally.
More...
|
| amrex::Box | box () const |
| | Gets the index space (bounding box) corresponding to the dataset dimensions.
|
| int | depth () const |
| | Gets the depth (Z dimension) of the loaded dataset.
|
| RawDataType | getDataType () const |
| | Gets the data type and endianness specified when the file was read.
|
| double | getValue (int i, int j, int k) const |
| | Retrieves the numerical value at a specific voxel, converting it to double.
|
| int | height () const |
| | Gets the height (Y dimension) of the loaded dataset.
|
| bool | isRead () const |
| | Checks if data has been successfully read and the reader is ready.
|
| RawReader & | operator= (const RawReader &)=delete |
| RawReader & | operator= (RawReader &&)=default |
| | RawReader () |
| | Default constructor. Creates an empty reader instance.
|
| | RawReader (const RawReader &)=delete |
| | RawReader (const std::string &filename, int width, int height, int depth, RawDataType data_type) |
| | Constructs a RawReader and immediately attempts to read the specified file.
|
| | RawReader (RawReader &&)=default |
| 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.
|
| void | threshold (double threshold_value, amrex::iMultiFab &mf) const |
| | Fills an AMReX iMultiFab based on thresholding the raw data (outputting 1 or 0).
|
| 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.
|
| int | width () const |
| | Gets the width (X dimension) of the loaded dataset.
|
| virtual | ~RawReader ()=default |
| | Virtual default destructor.
|
Reads and provides access to data from raw binary files where metadata (dimensions, data type, endianness) is provided externally.
This class handles reading a flat binary file containing voxel data. It assumes a simple, contiguous layout corresponding to standard C/Fortran XYZ array ordering (where the Z index varies slowest). The caller is required to supply the correct dimensions (width, height, depth) and the primitive data type (including endianness for multi-byte types) present in the file via the constructor or the readFile method.
The entire file content is read into an internal byte buffer (m_raw_bytes). Voxel values are interpreted and reconstructed from this byte buffer on demand (e.g., when getValue or threshold is called), handling potential byte swapping between the file's endianness and the host machine's endianness if they differ.
| OpenImpala::RawReader::RawReader |
( |
const std::string & | filename, |
|
|
int | width, |
|
|
int | height, |
|
|
int | depth, |
|
|
RawDataType | data_type ) |
|
explicit |
Constructs a RawReader and immediately attempts to read the specified file.
Reads the raw binary file specified by filename, interpreting the data according to the provided width, height, depth, and data_type. Throws a std::runtime_error if any part of the reading process fails (e.g., file cannot be opened, file size doesn't match expected dimensions and data type, or a read error occurs).
- Parameters
-
| filename | Path to the input .raw binary file. |
| width | Width (X dimension) of the dataset in voxels. Must be > 0. |
| height | Height (Y dimension) of the dataset in voxels. Must be > 0. |
| depth | Depth (Z dimension) of the dataset in voxels. Must be > 0. |
| data_type | The data type and endianness of the voxels stored in the file. Must not be RawDataType::UNKNOWN. |
- Exceptions
-
| std::runtime_error | If reading or validation fails. |
| double OpenImpala::RawReader::getValue |
( |
int | i, |
|
|
int | j, |
|
|
int | k ) const |
Retrieves the numerical value at a specific voxel, converting it to double.
Accesses the raw bytes corresponding to the voxel at logical coordinates (i, j, k), reconstructs the original numerical value based on the m_data_type (performing byte swapping if the file's endianness differs from the host machine's), and then casts the result to double. Assumes standard XYZ layout where the k index (depth) varies slowest.
- Parameters
-
| i | X-index (must be 0 <= i < width). |
| j | Y-index (must be 0 <= j < height). |
| k | Z-index (must be 0 <= k < depth). |
- Returns
- The voxel's numerical value converted to double.
- Exceptions
-
| std::out_of_range | If the provided indices (i, j, k) are outside the valid dataset dimensions [0..width-1, 0..height-1, 0..depth-1]. |
| std::runtime_error | If the reader is not in a valid state (isRead() is false), if the stored m_data_type is UNKNOWN, or if an internal error occurs during value reconstruction. |
| void OpenImpala::RawReader::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.
Iterates through the cells defined by the valid boxes of the input mf. For each cell (i, j, k) that falls within the bounds of the loaded raw dataset [0..width-1, 0..height-1, 0..depth-1], this function retrieves the corresponding voxel value using getValue(i, j, k). It then compares this value against threshold_value.
- If getValue(i, j, k) > threshold_value, the cell in mf is set to value_if_true.
- Otherwise (including if the cell is outside the raw data bounds), the cell in mf is set to value_if_false.
- Parameters
-
| threshold_value | The value to compare against. The comparison is strictly greater than (>). |
| value_if_true | The integer value to write to mf for cells exceeding the threshold. |
| value_if_false | The integer value to write to mf for cells not exceeding the threshold or outside the bounds of the raw data. |
| [out] | mf | The amrex::iMultiFab to be filled. It must be defined (allocated) and is expected to have exactly one component (nComp() == 1). The operation is performed in parallel using OpenMP if available. |
- Exceptions
-
| std::runtime_error | If the reader is not in a valid state (isRead() is false) or if mf.nComp() != 1. |