Pixel data types module
#include "diplib.h"
dip::DataType struct

DataType objects are used to indicate what the data type of an image is.

It is a simple enumeration type, but with some added member functions that can be used to query the data type. A series of constant expressions (dip::DT_XXX) have been defined that should be used when specifying a data type, there is never a need to call the constructors to this class explicitly. It is possible to call DataType member functions on these constants:

dip::DT_BIN.SizeOf();

See Pixel data types for more information about image sample data types.

Constructors, destructors, assignment and conversion operators

DataType() constexpr
The default data type is single-precision Float (dip::DT_SFLOAT).
template<typename T>
DataType(T ) explicit constexpr
Get the data type value of any expression, as long as that expression is of one of the known data types
DataType(dip::String const& name) explicit
A string can be cast to a data type. See Pixel data types for recognized strings.

Aliases

using Classes = dip::detail::Options
Specifies a collection of data types. more...

Functions

auto IsA(dip::DataType::Classes cls) const -> bool constexpr
Returns true if the data type is of the given class.
auto IsBinary() const -> bool constexpr
Returns true if the data type is binary.
auto IsComplex() const -> bool constexpr
Returns true if the data type is complex.
auto IsFlex() const -> bool constexpr
Returns true if the data type is one of the “flex” types (floating point or complex).
auto IsFlexBin() const -> bool constexpr
Returns true if the data type is floating point, complex or binary.
auto IsFloat() const -> bool constexpr
Returns true if the data type is a floating point type.
auto IsInRange(dip::sint value) const -> bool
Returns true if the integer value is within the range representable by the data type.
auto IsInRange(dip::uint value) const -> bool
Returns true if the integer value is within the range representable by the data type.
auto IsInteger() const -> bool constexpr
Returns true if the data type is an integer type.
auto IsReal() const -> bool constexpr
Returns true if the data type is real (floating point or integer).
auto IsSigned() const -> bool constexpr
Returns true if the data type is a signed type (signed integer, floating point or complex)
auto IsSInt() const -> bool constexpr
Returns true if the data type is a signed integer type.
auto IsUInt() const -> bool constexpr
Returns true if the data type is an unsigned integer type.
auto IsUnsigned() const -> bool constexpr
Returns true if the data type is an unsigned type (binary or unsigned integer).
auto Name() const -> char const*
Returns a C-style string constant with a representation of the data type name. See Pixel data types for returned strings.
auto Real() const -> dip::DataType
Returns the real data type corresponding to a complex data type
auto SizeOf() const -> dip::uint
Returns the size in bytes of the data type.
static auto SuggestAbs(dip::DataType type) -> dip::DataType
Returns a suitable type that can hold samples of type abs(type). See Pixel data types.
static auto SuggestArithmetic(dip::DataType type1, dip::DataType type2) -> dip::DataType
Returns a suitable floating-point, complex or binary type (“FlexBin”) that can hold the result of an arithmetic computation performed with the two data types. more...
static auto SuggestComplex(dip::DataType type) -> dip::DataType
Returns a suitable complex type that can hold the samples of type. See Pixel data types.
static auto SuggestDouble(dip::DataType type) -> dip::DataType
Returns a suitable double precision floating-point type (real or complex) that can hold large sums of type. See Pixel data types.
static auto SuggestDyadicOperation(dip::DataType type1, dip::DataType type2) -> dip::DataType
Returns a suitable type that can hold any samples of the two data types. more...
static auto SuggestFlex(dip::DataType type) -> dip::DataType
Returns a suitable floating-point or complex type that can hold the samples of type. See Pixel data types.
static auto SuggestFlexBin(dip::DataType type) -> dip::DataType
Returns a suitable floating-point, complex or binary type that can hold the samples of type. See Pixel data types.
static auto SuggestFloat(dip::DataType type) -> dip::DataType
Returns a suitable floating-point type that can hold the samples of type. See Pixel data types.
static auto SuggestInteger(dip::DataType type) -> dip::DataType
Returns an integer type that is most suitable to hold samples of type. See Pixel data types.
static auto SuggestReal(dip::DataType type) -> dip::DataType
Returns a suitable real type that can hold the samples of type. See Pixel data types.
static auto SuggestSigned(dip::DataType type) -> dip::DataType
Returns a signed type that is most suitable to hold samples of type. See Pixel data types.
void swap(dip::DataType& other) noexcept
Swaps the values of this and other

Operators

auto operator Classes() const -> dip::DataType::Classes constexpr
Implicit conversion to dip::DataType::Classes options class.
auto operator int() const -> int constexpr
DataType objects implicitly convert to the enumeration integer.
auto operator==(dip::DataType other) const -> bool
DataType objects can be compared.

Alias documentation

using Classes = dip::detail::Options

Specifies a collection of data types.

Valid values are:

Classes constant DT_BIN DT_UINT8 DT_SINT8 DT_UINT16 DT_SINT16 DT_UINT32 DT_SINT32 DT_UINT64 DT_SINT64 DT_SFLOAT DT_DFLOAT DT_SCOMPLEX DT_DCOMPLEX
Class_Bin
Class_UInt8
Class_SInt8
Class_UInt16
Class_SInt16
Class_UInt32
Class_SInt32
Class_UInt64
Class_SInt64
Class_SFloat
Class_DFloat
Class_SComplex
Class_DComplex
Class_Binary
Class_UInt
Class_SInt
Class_Integer
Class_IntOrBin
Class_Float
Class_Complex
Class_Flex
Class_FlexBin
Class_Unsigned
Class_Signed
Class_Real
Class_SignedReal
Class_NonBinary
Class_NonComplex
Class_All

Note that you can add these constants together, for example dip::DataType::Class_UInt8 + dip::DataType::Class_UInt16.

It is possible to see if an image is of a type within a collection using the Contains method of dip::DataType::Classes with a dip::DataType as argument:

if( dip::DataType::Class_Flex.Contains( image.DataType() )) { ... }

But more convenient is to use the dip::DataType::IsA method:

if( image.DataType().IsA( dip::DataType::Class_Flex )) { ... }

This is equivalent to using one of the test functions, if defined for the specific group:

if( image.DataType().IsFlex() ) { ... }

The following combination of classes cover all data types, and are non-intersecting:

  • Class_Unsigned and Class_Signed
  • Class_Complex and Class_NonComplex
  • Class_Binary and Class_NonBinary
  • Class_FlexBin and Class_Integer
  • Class_Flex and Class_IntOrBin
  • Class_Binary, Class_Real and Class_Complex
  • Class_Binary, Class_Integer, Class_Float and Class_Complex

using dip::DataTypeArray = dip::DimensionArray

An array to hold data types

Function documentation

DataType( ) constexpr

The default data type is single-precision Float (dip::DT_SFLOAT).

template<typename T>
DataType( T ) explicit constexpr

Get the data type value of any expression, as long as that expression is of one of the known data types

DataType( dip::String const& name) explicit

A string can be cast to a data type. See Pixel data types for recognized strings.

void swap( dip::DataType& other) noexcept

Swaps the values of this and other

char const* Name( ) const

Returns a C-style string constant with a representation of the data type name. See Pixel data types for returned strings.

dip::uint SizeOf( ) const

Returns the size in bytes of the data type.

bool IsInRange( dip::sint value) const

Returns true if the integer value is within the range representable by the data type.

bool IsInRange( dip::uint value) const

Returns true if the integer value is within the range representable by the data type.

dip::DataType Real( ) const

Returns the real data type corresponding to a complex data type

bool IsA( dip::DataType::Classes cls) const constexpr

Returns true if the data type is of the given class.

bool IsBinary( ) const constexpr

Returns true if the data type is binary.

bool IsUInt( ) const constexpr

Returns true if the data type is an unsigned integer type.

bool IsSInt( ) const constexpr

Returns true if the data type is a signed integer type.

bool IsInteger( ) const constexpr

Returns true if the data type is an integer type.

bool IsFloat( ) const constexpr

Returns true if the data type is a floating point type.

bool IsReal( ) const constexpr

Returns true if the data type is real (floating point or integer).

bool IsFlex( ) const constexpr

Returns true if the data type is one of the “flex” types (floating point or complex).

bool IsFlexBin( ) const constexpr

Returns true if the data type is floating point, complex or binary.

bool IsComplex( ) const constexpr

Returns true if the data type is complex.

bool IsUnsigned( ) const constexpr

Returns true if the data type is an unsigned type (binary or unsigned integer).

bool IsSigned( ) const constexpr

Returns true if the data type is a signed type (signed integer, floating point or complex)

static dip::DataType SuggestInteger( dip::DataType type)

Returns an integer type that is most suitable to hold samples of type. See Pixel data types.

static dip::DataType SuggestSigned( dip::DataType type)

Returns a signed type that is most suitable to hold samples of type. See Pixel data types.

static dip::DataType SuggestFloat( dip::DataType type)

Returns a suitable floating-point type that can hold the samples of type. See Pixel data types.

static dip::DataType SuggestDouble( dip::DataType type)

Returns a suitable double precision floating-point type (real or complex) that can hold large sums of type. See Pixel data types.

static dip::DataType SuggestComplex( dip::DataType type)

Returns a suitable complex type that can hold the samples of type. See Pixel data types.

static dip::DataType SuggestFlex( dip::DataType type)

Returns a suitable floating-point or complex type that can hold the samples of type. See Pixel data types.

static dip::DataType SuggestFlexBin( dip::DataType type)

Returns a suitable floating-point, complex or binary type that can hold the samples of type. See Pixel data types.

static dip::DataType SuggestAbs( dip::DataType type)

Returns a suitable type that can hold samples of type abs(type). See Pixel data types.

static dip::DataType SuggestReal( dip::DataType type)

Returns a suitable real type that can hold the samples of type. See Pixel data types.

static dip::DataType SuggestArithmetic( dip::DataType type1, dip::DataType type2)

Returns a suitable floating-point, complex or binary type (“FlexBin”) that can hold the result of an arithmetic computation performed with the two data types.

The output value given type1 and type2 is as follows. First the two arguments are promoted using dip::DataType::SuggestFlexBin (which converts 8 and 16-bit integers to DT_SFLOAT and 32 and 64-bit integers to DT_DFLOAT), and the resulting two types are looked up in this table (note that the order of the two inputs is irrelevant, and the table is symmetric):

  DT_BIN DT_SFLOAT DT_DFLOAT DT_SCOMPLEX DT_DCOMPLEX
DT_BIN DT_BIN DT_SFLOAT DT_DFLOAT DT_SCOMPLEX DT_DCOMPLEX
DT_SFLOAT DT_SFLOAT DT_SFLOAT DT_DFLOAT DT_SCOMPLEX DT_DCOMPLEX
DT_DFLOAT DT_DFLOAT DT_DFLOAT DT_DFLOAT DT_DCOMPLEX DT_DCOMPLEX
DT_SCOMPLEX DT_SCOMPLEX DT_SCOMPLEX DT_DCOMPLEX DT_SCOMPLEX DT_DCOMPLEX
DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX

static dip::DataType SuggestDyadicOperation( dip::DataType type1, dip::DataType type2)

Returns a suitable type that can hold any samples of the two data types.

The output value given type1 and type2 is as follows (note that the order of the two inputs is irrelevant, and the table is symmetric):

  DT_BIN DT_UINT8 DT_SINT8 DT_UINT16 DT_SINT16 DT_UINT32 DT_SINT32 DT_UINT64 DT_SINT64 DT_SFLOAT DT_DFLOAT DT_SCOMPLEX DT_DCOMPLEX
DT_BIN DT_BIN DT_UINT8 DT_SINT8 DT_UINT16 DT_SINT16 DT_UINT32 DT_SINT32 DT_UINT64 DT_SINT64 DT_SFLOAT DT_DFLOAT DT_SCOMPLEX DT_DCOMPLEX
DT_UINT8 DT_UINT8 DT_UINT8 DT_SINT16 DT_UINT16 DT_SINT16 DT_UINT32 DT_SINT32 DT_UINT64 DT_SINT64 DT_SFLOAT DT_DFLOAT DT_SCOMPLEX DT_DCOMPLEX
DT_SINT8 DT_SINT8 DT_SINT16 DT_SINT8 DT_SINT32 DT_SINT16 DT_SINT64 DT_SINT32 DT_SINT64 DT_SINT64 DT_SFLOAT DT_DFLOAT DT_SCOMPLEX DT_DCOMPLEX
DT_UINT16 DT_UINT16 DT_UINT16 DT_SINT32 DT_UINT16 DT_SINT32 DT_UINT32 DT_SINT32 DT_UINT64 DT_SINT64 DT_SFLOAT DT_DFLOAT DT_SCOMPLEX DT_DCOMPLEX
DT_SINT16 DT_SINT16 DT_SINT16 DT_SINT16 DT_SINT32 DT_SINT16 DT_SINT64 DT_SINT32 DT_SINT64 DT_SINT64 DT_SFLOAT DT_DFLOAT DT_SCOMPLEX DT_DCOMPLEX
DT_UINT32 DT_UINT32 DT_UINT32 DT_SINT64 DT_UINT32 DT_SINT64 DT_UINT32 DT_SINT64 DT_UINT64 DT_SINT64 DT_DFLOAT DT_DFLOAT DT_DCOMPLEX DT_DCOMPLEX
DT_SINT32 DT_SINT32 DT_SINT32 DT_SINT32 DT_SINT32 DT_SINT32 DT_SINT64 DT_SINT32 DT_SINT64 DT_SINT64 DT_DFLOAT DT_DFLOAT DT_DCOMPLEX DT_DCOMPLEX
DT_UINT64 DT_UINT64 DT_UINT64 DT_SINT64 DT_UINT64 DT_SINT64 DT_UINT64 DT_SINT64 DT_UINT64 DT_SINT64 DT_DFLOAT DT_DFLOAT DT_DCOMPLEX DT_DCOMPLEX
DT_SINT64 DT_SINT64 DT_SINT64 DT_SINT64 DT_SINT64 DT_SINT64 DT_SINT64 DT_SINT64 DT_SINT64 DT_SINT64 DT_DFLOAT DT_DFLOAT DT_DCOMPLEX DT_DCOMPLEX
DT_SFLOAT DT_SFLOAT DT_SFLOAT DT_SFLOAT DT_SFLOAT DT_SFLOAT DT_DFLOAT DT_DFLOAT DT_DFLOAT DT_DFLOAT DT_SFLOAT DT_DFLOAT DT_SCOMPLEX DT_DCOMPLEX
DT_DFLOAT DT_DFLOAT DT_DFLOAT DT_DFLOAT DT_DFLOAT DT_DFLOAT DT_DFLOAT DT_DFLOAT DT_DFLOAT DT_DFLOAT DT_DFLOAT DT_DFLOAT DT_DCOMPLEX DT_DCOMPLEX
DT_SCOMPLEX DT_SCOMPLEX DT_SCOMPLEX DT_SCOMPLEX DT_SCOMPLEX DT_SCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_SCOMPLEX DT_DCOMPLEX DT_SCOMPLEX DT_DCOMPLEX
DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX

int operator int( ) const constexpr

DataType objects implicitly convert to the enumeration integer.

bool operator==( dip::DataType other) const

DataType objects can be compared.

dip::DataType::Classes operator Classes( ) const constexpr

Implicit conversion to dip::DataType::Classes options class.

std::ostream& dip::operator<<( std::ostream& os, dip::DataType type)

You can output a dip::DataType to std::cout or any other stream. The result of type.Name() is written.