OpenImpala
Image-based parallel transport property solver
Loading...
Searching...
No Matches
OpenImpala::TiffReader Class Reference

Reads 3D image data from single/multi-directory TIFFs or file sequences. Performs parallel, chunked reading directly into AMReX iMultiFab. More...

#include <TiffReader.H>

Public Member Functions

int bitsPerSample () const
 Get bits per sample (e.g., 8, 16, 32). Requires metadata to be read.
amrex::Box box () const
 Returns the index space Box covering the entire image domain [0, w-1]x[0, h-1]x[0, d-1].
int depth () const
 Get depth (Z-dimension) in pixels/voxels. Requires metadata to be read.
uint16_t getFillOrder () const
 Get TIFF FillOrder tag value (e.g., 1=MSB->LSB, 2=LSB->MSB). Requires metadata to be read.
int height () const
 Get height (Y-dimension) in pixels/voxels. Requires metadata to be read.
bool isRead () const
 Check if metadata has been successfully read and broadcast.
TiffReader & operator= (const TiffReader &)=delete
TiffReader & operator= (TiffReader &&)=default
bool readFile (const std::string &filename)
 Reads metadata from a single (potentially multi-directory) TIFF file.
bool readFileSequence (const std::string &base_pattern, int num_files, int start_index=0, int digits=1, const std::string &suffix=".tif")
 Reads metadata from the first file of a TIFF sequence.
int sampleFormat () const
 Get sample format (e.g., SAMPLEFORMAT_UINT, SAMPLEFORMAT_INT, SAMPLEFORMAT_IEEEFP from tiff.h). Requires metadata to be read.
int samplesPerPixel () const
 Get samples per pixel (e.g., 1 for grayscale, 3 for RGB). Requires metadata to be read.
void threshold (double raw_threshold, amrex::iMultiFab &mf) const
 Reads data chunk-by-chunk into an iMultiFab based on thresholding (output 1/0).
void threshold (double raw_threshold, int value_if_true, int value_if_false, amrex::iMultiFab &mf) const
 Reads data chunk-by-chunk into an iMultiFab based on thresholding with custom output values.
 TiffReader ()
 Default constructor. Creates an empty reader. Use readFile() or readFileSequence().
 TiffReader (const std::string &base_pattern, int num_files, int start_index=0, int digits=1, const std::string &suffix=".tif")
 Constructs a TiffReader, reads metadata from the first file of a sequence.
 TiffReader (const std::string &filename)
 Constructs a TiffReader, reads metadata from a single (potentially multi-directory) TIFF file.
 TiffReader (const TiffReader &)=delete
 TiffReader (TiffReader &&)=default
int width () const
 Get width (X-dimension) in pixels/voxels. Requires metadata to be read.
virtual ~TiffReader ()=default
 Virtual default destructor.

Detailed Description

Reads 3D image data from single/multi-directory TIFFs or file sequences. Performs parallel, chunked reading directly into AMReX iMultiFab.

This class uses libtiff to read TIFF files (single stack files or sequences representing Z-slices). It is designed for parallel environments (MPI+OpenMP) and large datasets that may exceed single-node memory.

Metadata (dimensions, data type) is read first by rank 0 and broadcast. Data reading is performed by the threshold methods, driven by the distribution of the target iMultiFab. Each MPI rank reads only the necessary strips or tiles for its owned boxes directly from the file(s). Supports Striped and Tiled TIFF formats.

Warning
Assumes serial libtiff calls internally. While reading is distributed across ranks via MFIter, concurrent libtiff calls from different threads within a rank to the SAME file handle might require a thread-safe libtiff build or external locking (current implementation uses per-thread handles for sequences, avoiding this issue there).
Assumes PLANARCONFIG_CONTIG. Multi-sample data is read, but only the first sample is used during thresholding.
Copy operations disabled.

Constructor & Destructor Documentation

◆ TiffReader() [1/5]

OpenImpala::TiffReader::TiffReader ( )

Default constructor. Creates an empty reader. Use readFile() or readFileSequence().

◆ TiffReader() [2/5]

OpenImpala::TiffReader::TiffReader ( const std::string & filename)
explicit

Constructs a TiffReader, reads metadata from a single (potentially multi-directory) TIFF file.

Reads dimensions and data type info on rank 0 and broadcasts. Does NOT read pixel data. Throws on error.

Parameters
filenamePath to the TIFF file.
Exceptions
std::runtime_erroron file open or metadata read errors.

◆ TiffReader() [3/5]

OpenImpala::TiffReader::TiffReader ( const std::string & base_pattern,
int num_files,
int start_index = 0,
int digits = 1,
const std::string & suffix = ".tif" )

Constructs a TiffReader, reads metadata from the first file of a sequence.

Reads dimensions and data type info from the first file on rank 0 and broadcasts. Does NOT read pixel data. Throws on error.

Parameters
base_patternBase filename pattern (e.g., "path/slice_").
num_filesTotal number of files in the sequence (determines Z dimension).
start_indexThe starting number for the sequence (e.g., 0 or 1).
digitsThe number of digits used for the sequence number padding (e.g., 4 for "0001").
suffixFile extension including dot (e.g., ".tif").
Exceptions
std::runtime_erroron file open/metadata read errors or inconsistent metadata.

◆ ~TiffReader()

virtual OpenImpala::TiffReader::~TiffReader ( )
virtualdefault

Virtual default destructor.

◆ TiffReader() [4/5]

OpenImpala::TiffReader::TiffReader ( const TiffReader & )
delete

◆ TiffReader() [5/5]

OpenImpala::TiffReader::TiffReader ( TiffReader && )
default

Member Function Documentation

◆ bitsPerSample()

int OpenImpala::TiffReader::bitsPerSample ( ) const

Get bits per sample (e.g., 8, 16, 32). Requires metadata to be read.

◆ box()

amrex::Box OpenImpala::TiffReader::box ( ) const

Returns the index space Box covering the entire image domain [0, w-1]x[0, h-1]x[0, d-1].

◆ depth()

int OpenImpala::TiffReader::depth ( ) const

Get depth (Z-dimension) in pixels/voxels. Requires metadata to be read.

◆ getFillOrder()

uint16_t OpenImpala::TiffReader::getFillOrder ( ) const
inline

Get TIFF FillOrder tag value (e.g., 1=MSB->LSB, 2=LSB->MSB). Requires metadata to be read.

◆ height()

int OpenImpala::TiffReader::height ( ) const

Get height (Y-dimension) in pixels/voxels. Requires metadata to be read.

◆ isRead()

bool OpenImpala::TiffReader::isRead ( ) const
inline

Check if metadata has been successfully read and broadcast.

◆ operator=() [1/2]

TiffReader & OpenImpala::TiffReader::operator= ( const TiffReader & )
delete

◆ operator=() [2/2]

TiffReader & OpenImpala::TiffReader::operator= ( TiffReader && )
default

◆ readFile()

bool OpenImpala::TiffReader::readFile ( const std::string & filename)

Reads metadata from a single (potentially multi-directory) TIFF file.

Clears existing metadata. Rank 0 opens file, reads dimensions/type, validates, determines depth, and broadcasts info to all ranks. Does NOT read pixel data.

Parameters
filenamePath to the TIFF file.
Returns
true on success (metadata broadcast), false otherwise. Aborts on critical errors.

◆ readFileSequence()

bool OpenImpala::TiffReader::readFileSequence ( const std::string & base_pattern,
int num_files,
int start_index = 0,
int digits = 1,
const std::string & suffix = ".tif" )

Reads metadata from the first file of a TIFF sequence.

Clears existing metadata. Rank 0 opens first file, reads dimensions/type, validates, sets depth from num_files, and broadcasts info (including sequence params) to all ranks. Does NOT read pixel data.

Parameters
base_patternBase filename pattern (e.g., "path/slice_").
num_filesTotal number of files in the sequence (determines Z dimension).
start_indexThe starting number for the sequence (e.g., 0 or 1).
digitsThe number of digits used for the sequence number padding (e.g., 4 for "0001").
suffixFile extension including dot (e.g., ".tif").
Returns
true on success (metadata broadcast), false otherwise. Aborts on critical errors.

◆ sampleFormat()

int OpenImpala::TiffReader::sampleFormat ( ) const

Get sample format (e.g., SAMPLEFORMAT_UINT, SAMPLEFORMAT_INT, SAMPLEFORMAT_IEEEFP from tiff.h). Requires metadata to be read.

◆ samplesPerPixel()

int OpenImpala::TiffReader::samplesPerPixel ( ) const

Get samples per pixel (e.g., 1 for grayscale, 3 for RGB). Requires metadata to be read.

◆ threshold() [1/2]

void OpenImpala::TiffReader::threshold ( double raw_threshold,
amrex::iMultiFab & mf ) const

Reads data chunk-by-chunk into an iMultiFab based on thresholding (output 1/0).

Performs distributed reading. Iterates through the patches (MFIter) of the output iMultiFab mf. For each patch, reads the corresponding strips or tiles from the TIFF file(s) and fills the patch's FArrayBox based on the threshold. Sets output cells to 1 if native_value > raw_threshold, else 0. Requires metadata to have been read successfully first via readFile() or readFileSequence(). Handles conversion from native TIFF type to double for comparison. Uses first sample if SPP

1.

Parameters
raw_thresholdThe threshold value (compared against data converted to double).
mfOutput amrex::iMultiFab reference to fill (must be defined and distributed).
Exceptions
std::runtime_erroron read errors or if metadata not ready.

◆ threshold() [2/2]

void OpenImpala::TiffReader::threshold ( double raw_threshold,
int value_if_true,
int value_if_false,
amrex::iMultiFab & mf ) const

Reads data chunk-by-chunk into an iMultiFab based on thresholding with custom output values.

Performs distributed reading. Iterates through the patches (MFIter) of the output iMultiFab mf. For each patch, reads the corresponding strips or tiles from the TIFF file(s) and fills the patch's FArrayBox based on the threshold. Sets output cells to value_if_true if native_value > raw_threshold, else value_if_false. Requires metadata to have been read successfully first via readFile() or readFileSequence(). Handles conversion from native TIFF type to double for comparison. Uses first sample if SPP > 1.

Parameters
raw_thresholdThe threshold value (compared against data converted to double).
value_if_trueInteger value if condition is true.
value_if_falseInteger value if condition is false.
mfOutput amrex::iMultiFab reference to fill (must be defined and distributed).
Exceptions
std::runtime_erroron read errors or if metadata not ready.

◆ width()

int OpenImpala::TiffReader::width ( ) const

Get width (X-dimension) in pixels/voxels. Requires metadata to be read.


The documentation for this class was generated from the following files: