version 3.10-dev
Dumux::NetPBMReader Class Reference

A simple reader class for the Netpbm format (https://en.wikipedia.org/wiki/Netpbm_format). So far, only black and white (*.pbm) and grayscale (*pgm) images are supported.

#include <dumux/io/rasterimagereader.hh>

Static Public Member Functions

static Format getFormat (const std::vector< std::string_view > &firstLineTokes)
 A helper function to retrieve the format from tokens of the file's first line. More...
 
static Result< bool > readPBM (const std::string &fileName, const bool useDuneGridOrdering=true)
 Reads a *pbm (black and white) in ASCII or binary encoding. Returns a struct that contains both the pixel values and the header data. More...
 
template<class ValueType = std::uint8_t>
static Result< ValueType > readPGM (const std::string &fileName, const bool useDuneGridOrdering=true)
 Reads a *.pgm (grayscale) in ASCII or binary encoding. Returns a struct that contains both the pixel values and the header data. More...
 
static HeaderData readHeader (std::ifstream &infile)
 Returns the header data of the image file. More...
 
template<class T >
static void applyDuneGridOrdering (Result< T > &result)
 Change the ordering of the pixels according to Dune's convention, shifting the origin from upper left to lower left. More...
 
template<class T >
static void printInfo (const Result< T > &result)
 Print the data contained in the header. More...
 
template<class Image , class T >
static void fillImage (Image &image, const Result< T > &result)
 Fill a pre-defined 2D image object, e.g. std::vector<std::vector<bool>>, with the pixel values stored in a 1D container. More...
 
template<class Image >
static auto flattenImageToVector (const Image &image)
 Flattens a 2D image object to a 1D container. More...
 

Member Function Documentation

◆ applyDuneGridOrdering()

template<class T >
static void Dumux::NetPBMReader::applyDuneGridOrdering ( Result< T > &  result)
inlinestatic
Parameters
resultThe image's pixel values ordered from top to bottom.

◆ fillImage()

template<class Image , class T >
static void Dumux::NetPBMReader::fillImage ( Image &  image,
const Result< T > &  result 
)
inlinestatic
Parameters
imageThe 2D image to be filled with values. Needs to have to correct dimensions (nCols x nRows).
resultThe image's pixel values stored in a 1D container.

◆ flattenImageToVector()

template<class Image >
static auto Dumux::NetPBMReader::flattenImageToVector ( const Image &  image)
inlinestatic
Parameters
imageThe 2D image to be flattened.

◆ getFormat()

static Format Dumux::NetPBMReader::getFormat ( const std::vector< std::string_view > &  firstLineTokes)
inlinestatic
Parameters
firstLineTokesThe tokens extracted from the first line of the file

◆ printInfo()

template<class T >
static void Dumux::NetPBMReader::printInfo ( const Result< T > &  result)
inlinestatic
Parameters
resultThe object storing both the image's pixel values and the header data.

◆ readHeader()

static HeaderData Dumux::NetPBMReader::readHeader ( std::ifstream &  infile)
inlinestatic
Parameters
infileThe input stream used to process the image file.

◆ readPBM()

static Result< bool > Dumux::NetPBMReader::readPBM ( const std::string &  fileName,
const bool  useDuneGridOrdering = true 
)
inlinestatic
Parameters
fileNameThe file name (*.pbm).
useDuneGridOrderingIf set true, the ordering of the pixels will be changed according to Dune's convention, shifting the origin from upper left to lower left.

◆ readPGM()

template<class ValueType = std::uint8_t>
static Result< ValueType > Dumux::NetPBMReader::readPGM ( const std::string &  fileName,
const bool  useDuneGridOrdering = true 
)
inlinestatic
Template Parameters
ValueTypeThe value type representing the pixel data. By default, std::uint8_t (0-255) is used. Since this type is often defined as unsigned char, some conversion issues during I/O may occur. Hence the type may be changed, e.g., to std::size_t.
Parameters
fileNameThe file name (*.pbm).
useDuneGridOrderingIf set true, the ordering of the pixels will be changed according to Dune's convention, shifting the origin from upper left to lower left.

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