3.2-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
Classes | Static Public Member Functions | List of all members
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. More...

#include <dumux/io/rasterimagereader.hh>

Description

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.

Classes

struct  Format
 A struct that holds all information of the image format. More...
 
struct  HeaderData
 A struct that contains all header data of the image. More...
 
class  Result
 The return type of the reading functions. Holds the actual pixel values and the header data. More...
 

Static Public Member Functions

static Format getFormat (const std::string &magicNumber)
 A helper function to retrieve the format data from a given magic number. 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

Change the ordering of the pixels according to Dune's convention, shifting the origin from upper left to lower left.

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

Fill a pre-defined 2D image object, e.g. std::vector<std::vector<bool>>, with the pixel values stored in a 1D container.

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

Flattens a 2D image object to a 1D container.

Parameters
imageThe 2D image to be flattened.

◆ getFormat()

static Format Dumux::NetPBMReader::getFormat ( const std::string &  magicNumber)
inlinestatic

A helper function to retrieve the format data from a given magic number.

Parameters
magicNumberThe magic number contained in the header data of the file.

◆ printInfo()

template<class T >
static void Dumux::NetPBMReader::printInfo ( const Result< T > &  result)
inlinestatic

Print the data contained in the header.

Parameters
resultThe object storing both the image's pixel values and the header data.

◆ readHeader()

static HeaderData Dumux::NetPBMReader::readHeader ( std::ifstream &  infile)
inlinestatic

Returns the header data of the image file.

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

Reads a *pbm (black and white) in ASCII or binary encoding. Returns a struct that contains both the pixel values and the header data.

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

Reads a *.pgm (grayscale) in ASCII or binary encoding. Returns a struct that contains both the pixel values and the header data.

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: