cgv
cgv::data::data_format Class Reference

#include <data_format.h>

Inheritance diagram for cgv::data::data_format:
cgv::data::component_format cgv::data::packing_info cgv::render::texture

Public Member Functions

 data_format ()
 construct an undefined data format
 
 data_format (const std::string &description)
 construct from description string, see set_data_format for docu More...
 
bool set_data_format (const std::string &description)
 set the data format from a description string More...
 
 data_format (unsigned int _width, TypeId _component_type, const std::string &_component_name_list, unsigned int align=1, unsigned int d0=0, unsigned int d1=0, unsigned int d2=0, unsigned int d3=0)
 construct a 1d data format from width and the information needed to construct a component info
 
 data_format (unsigned int _width, TypeId _component_type, ComponentFormat _cf, unsigned int align=1, unsigned int d0=0, unsigned int d1=0, unsigned int d2=0, unsigned int d3=0)
 construct a 1d data format from width and the information needed to construct a component info
 
 data_format (unsigned int _width, unsigned int _height, TypeId _component_type, const std::string &_component_name_list, unsigned int align=1, unsigned int d0=0, unsigned int d1=0, unsigned int d2=0, unsigned int d3=0)
 construct a 2d data format from width and height
 
 data_format (unsigned int _width, unsigned int _height, TypeId _component_type, ComponentFormat _cf, unsigned int align=1, unsigned int d0=0, unsigned int d1=0, unsigned int d2=0, unsigned int d3=0)
 construct a 2d data format from width and height
 
 data_format (unsigned int _width, unsigned int _height, unsigned int _depth, TypeId _component_type, const std::string &_component_name_list, unsigned int align=1, unsigned int d0=0, unsigned int d1=0, unsigned int d2=0, unsigned int d3=0)
 construct a 3d data format from width, height and depth
 
 data_format (unsigned int _width, unsigned int _height, unsigned int _depth, TypeId _component_type, ComponentFormat _cf, unsigned int align=1, unsigned int d0=0, unsigned int d1=0, unsigned int d2=0, unsigned int d3=0)
 construct a 3d data format from width, height and depth
 
 data_format (unsigned int _width, unsigned int _height, unsigned int _depth, unsigned int _count, TypeId _component_type, const std::string &_component_name_list, unsigned int align=1, unsigned int d0=0, unsigned int d1=0, unsigned int d2=0, unsigned int d3=0)
 construct a 4d data format from width, height, depth and count
 
 data_format (unsigned int _width, unsigned int _height, unsigned int _depth, unsigned int _count, TypeId _component_type, ComponentFormat _cf, unsigned int align=1, unsigned int d0=0, unsigned int d1=0, unsigned int d2=0, unsigned int d3=0)
 construct a 4d data format from width, height, depth and count
 
void set_dimensions (unsigned _d0, unsigned _d1=-1, unsigned _d2=-1, unsigned _d3=-1)
 set the dimensions to the given values
 
unsigned int get_nr_dimensions () const
 return the number of dimensions of the data set More...
 
void set_nr_dimensions (unsigned int _d)
 set the number of dimensions of the data set More...
 
unsigned int get_resolution (unsigned int i) const
 return the resolution in the i-th dimension, or 0 if not defined More...
 
unsigned int get_width () const
 return the resolution in the first dimension, or 1 if not defined More...
 
unsigned int get_height () const
 return the resolution in the second dimension, or 1 if not defined More...
 
unsigned int get_depth () const
 return the resolution in the third dimension, or 1 if not defined More...
 
unsigned int get_nr_time_steps () const
 return the resolution in the highest dimension, or 1 if not defined More...
 
size_t get_nr_entries () const
 return the total number of data entries
 
size_t get_nr_bytes () const
 return the total number of bytes necessary to store the data
 
void set_resolution (unsigned int i, unsigned int resolution)
 set the resolution in the i-th dimension, add dimensions if necessary More...
 
void set_width (unsigned int _width)
 set the resolution in the first dimension, add dimensions if necessary More...
 
void set_height (unsigned int _height)
 set the resolution in the second dimension, add dimensions if necessary More...
 
void set_depth (unsigned int _depth)
 set the resolution in the third dimension, add dimensions if necessary More...
 
void set_nr_time_steps (unsigned int _nr_time_steps)
 set the resolution in the last dimension, add dimensions if necessary More...
 
unsigned int get_entry_alignment () const
 return the alignment of entries
 
unsigned int get_alignment (unsigned int i) const
 return the alignment of a given dimension More...
 
void set_entry_alignment (unsigned int _a)
 set the alignment of entries
 
void set_alignment (unsigned int i, unsigned int _a)
 set the alignment of a given dimension More...
 
unsigned int get_layout_dimension (unsigned int dim) const
 return the layout dimension of a given dimension
 
void get_layout_dimension (unsigned int dim, unsigned int layout_dim)
 set the layout dimension of a given dimension, add dimensions if necessary More...
 
const component_formatget_component_format () const
 return the component_format info by simple conversion of the this pointer
 
void set_component_format (const component_format &cf)
 set component_format by simply assigning to a converted this pointer
 
bool operator== (const data_format &df) const
 comparison between component formats
 
bool operator!= (const data_format &df) const
 comparison between component formats
 
bool set_component_format (const std::string &description)
 set the component format from a description string More...
 
void set_component_format (ComponentFormat _cf)
 set the component names from a standard component format More...
 
void set_components (const std::string &_components)
 comma separated list of component descriptors, for example "R,G,B"
 
void set_integer_interpretation (ComponentIntegerInterpretation cii)
 set the integer interpretation
 
ComponentIntegerInterpretation get_integer_interpretation () const
 return current integer interpretation
 
template<typename T >
get (int ci, const void *ptr) const
 constant access to the i-th component stored at the given location
 
template<typename T >
bool set (int ci, void *ptr, const T &v) const
 write access to the i-th component, return whether write was successful
 
bool empty () const
 return whether the component format is defined
 
void clear ()
 clear the component format
 
const packing_infoget_packing_info () const
 return the packing info by simple conversion of the this pointer
 
void set_packing_info (const packing_info &pi)
 set packing info by simply assigning to a converted this pointer
 
unsigned int get_nr_components () const
 return the number of components More...
 
unsigned int get_component_index (const std::string &name) const
 return the index of a component given by name or -1 if not found
 
std::string get_component_name (unsigned int i) const
 return the name of the component with index i
 
ComponentFormat get_standard_component_format () const
 return whether the component format is one of the standard formats
 
void set_component_names (const std::string &_component_name_list)
 set component names from a comma or colon separated list of names
 
TypeId get_component_type () const
 return the component type
 
void set_component_type (TypeId _type_id)
 set the component type
 
unsigned int get_entry_size () const
 return the size of one entry of components in bytes More...
 
bool operator== (const component_format &cf) const
 comparison between component formats
 
bool operator== (const packing_info &pi) const
 equal comparison
 
bool operator!= (const component_format &cf) const
 comparison between component formats
 
bool operator!= (const packing_info &pi) const
 unequal comparison
 
unsigned int get_bit_depth (unsigned int ci) const
 return the bit depth of the ci-th component
 
void set_bit_depth (unsigned int ci, unsigned int depth)
 set the bit depth of the ci-th component
 
bool is_packing () const
 return whether packing is enabled
 
void set_packing (bool enable=true)
 set the packing flag
 
unsigned int get_component_alignment () const
 return the component alignment in bits in the packed case and in bytes in the unpacked case
 
void set_component_alignment (unsigned int a)
 set the component alignment in bits in the packed case and in bytes in the unpacked case
 
int get_signed (unsigned int ci, const void *ptr) const
 return the ci-th component of the data entry pointed to by the given pointer of a signed packed component
 
unsigned int get_unsigned (unsigned int ci, const void *ptr) const
 return the ci-th component of the data entry pointed to by the given pointer of an unsigned packed component
 
bool set_signed (unsigned int ci, void *ptr, int v) const
 set the ci-th component of the data entry pointed to by the given pointer of a signed packed component
 
bool set_unsigned (unsigned int ci, void *ptr, unsigned int v) const
 set the ci-th component of the data entry pointed to by the given pointer of an unsigned packed component
 

Static Public Member Functions

static const std::string & get_last_error ()
 returns an error string after parsing of description string has failed
 
static unsigned int align (unsigned int v, unsigned int a)
 return the next integer larger or equal to v which is dividable by a
 

Protected Member Functions

void extract_components ()
 extract components from component string More...
 

Protected Attributes

std::vector< dimension_info > dimensions
 store for each dimension resolution and alignment in a dimension_info struct
 
TypeId component_type
 store the type id of the component type
 
ComponentIntegerInterpretation component_interpretation
 interpretation of integer typed components
 
std::string component_string
 store all component names in one string separated with 0-chars
 
std::vector< unsigned short > component_positions
 store the position of each component in the component string
 

Static Protected Attributes

static std::string last_error
 store the last error that appeared during parsing of a description
 

Friends

FRIEND_MEMBER_API std::ostream & operator<< (std::ostream &os, const data_format &df)
 define stream out operator More...
 

Detailed Description

A data_format describes a multidimensional data block of data entries. It inherits the information stored in component info which describes which components each data entry has. The data_format adds information about the dimensionality and the alignment and resolution in each dimension.

Constructor & Destructor Documentation

◆ data_format()

cgv::data::data_format::data_format ( const std::string &  description)
explicit

construct from description string, see set_data_format for docu

construct from description string

Member Function Documentation

◆ extract_components()

void cgv::data::component_format::extract_components ( )
protectedinherited

extract components from component string

extract component_positions from component string

◆ get_alignment()

unsigned int cgv::data::data_format::get_alignment ( unsigned int  i) const

return the alignment of a given dimension

return the alignment of a given dimension, where the alignment of the last dimension is always 1 and cannot be changed. This method also returns 1 if i is out of the range of valid dimensions.

◆ get_depth()

unsigned int cgv::data::data_format::get_depth ( ) const

return the resolution in the third dimension, or 1 if not defined

return the number of entries in the third dimension

◆ get_entry_size()

unsigned int cgv::data::component_format::get_entry_size ( ) const
inherited

return the size of one entry of components in bytes

return the size of one entry of component_positions in bytes

◆ get_height()

unsigned int cgv::data::data_format::get_height ( ) const

return the resolution in the second dimension, or 1 if not defined

return the number of entries in the second dimension

◆ get_layout_dimension()

void cgv::data::data_format::get_layout_dimension ( unsigned int  dim,
unsigned int  layout_dim 
)

set the layout dimension of a given dimension, add dimensions if necessary

set the layout dimension of a given dimension

◆ get_nr_components()

unsigned int cgv::data::component_format::get_nr_components ( ) const
inherited

return the number of components

return the number of component_positions

◆ get_nr_dimensions()

unsigned int cgv::data::data_format::get_nr_dimensions ( ) const

return the number of dimensions of the data set

return the dimension of the data set

◆ get_nr_time_steps()

unsigned int cgv::data::data_format::get_nr_time_steps ( ) const

return the resolution in the highest dimension, or 1 if not defined

return the number of entries in the last dimension

◆ get_resolution()

unsigned int cgv::data::data_format::get_resolution ( unsigned int  i) const

return the resolution in the i-th dimension, or 0 if not defined

return the number of data entries in the given dimension

◆ get_width()

unsigned int cgv::data::data_format::get_width ( ) const

return the resolution in the first dimension, or 1 if not defined

return the number of entries in the first dimension

◆ set_alignment()

void cgv::data::data_format::set_alignment ( unsigned int  i,
unsigned int  _a 
)

set the alignment of a given dimension

set the alignment of a given dimension, add dimensions if necessary. The alignment of the last dimension is always 1 and cannot be set.

◆ set_component_format() [1/2]

void cgv::data::component_format::set_component_format ( ComponentFormat  _cf)
inherited

set the component names from a standard component format

set the component names from a given component format

◆ set_component_format() [2/2]

bool cgv::data::component_format::set_component_format ( const std::string &  description)
inherited

set the component format from a description string

set component format from description string, which has the following syntax. If a parse error arises, return false and set the static last_error member, which can be queried with get_last_error():

component_format <- [type] [attributes] '[' component [',' component]* ']'

component <- component_name [attributes]

attributes <- [':' bit_depth]['|' alignment]

type <- "undef" | "bool" | 
                "int8"  | "int16"  | "int32"  | "int64"  | "uint8"  | "uint16"  | "uint32"  | "uint64" |
                "sint8" | "sint16" | "sint32" | "sint64" |                                                // same as int* types but in snorm interpretation
                "_int8" | "_int16" | "_int32" | "_int64" | "_uint8" | "_uint16" | "_uint32" | "_uint64" | // same as [u]int* but in integer interpretation
                "flt16" | "flt32"  | "flt64"  | "string"

component_name : string ... name of component, i.e. "R", "Cb", "px", ...

bit_depth : unsigned int ... number of bits used to represent a component

alignment : unsigned int ... number of bits to which a component is aligned

Some examples of valid component format description strings:

  • "uint8:3|4[R,G,B,A]" ... four components represented as unsigned integers with no more than 8 bits. Actually, each component is stored with 3 bits and aligned to a bit index which is a multiple of 4
  • "uint8[R:5,G:6,B:5]" ... three components packed into 16 bits with 5 bits for R, 6 for G and 5 for B.
  • "sint8[R,G]" ... two component format of type int8 in snorm interpretation,
  • "_uint16[R]" ... one component format of type uint16 in integer interpretation,
  • "flt32[px,py]" ... two components of 32 bit floats
  • "[D]" ... one depth component without specified type, which defaults to "undef" and implies that the default depth format should be used.

◆ set_data_format()

bool cgv::data::data_format::set_data_format ( const std::string &  description)

set the data format from a description string

Set data format from description string, which adds information to the description string of the component format and has the following syntax. For the definition of the token component_format in the syntax definition refer to the docu of component_format::set_component_format(). If a parse error arises, return false and set the static last_error member, which can be queried with get_last_error().

Syntax definition:

data_format <- component_format['|' alignment_in_bytes] '(' dimension_info (',' dimension_info)* ')'

dimension_info <- resolution [':' layout_dimension]['|' alignment_in_bytes]

- resolution : unsigned int ... number of entries in specified dimension

- layout_dimension : unsigned int ... index of dimension in memory layout, which defaults
                                    to the specified dimension
- alignment_in_bytes : unsigned int ... alignment in the memory layout for entries with index zero
                                        in the specified dimension

In the standard memory layout of for example an image, the entries are arranged line by line, i.e. first the entries of the first line are stored from left to right, followed by the entries of the second line and so on. To change this order of the layout, one can specify for each dimension in the data format a layout dimension which defaults to the dimension index, i.e. if the layout dimensions of all dimensions correspond to the dimension index, the memory layout is starting with the 0-th dimension. To store an image in a columns first memory layout, the layout dimensions would be 1 and 0 for dimensions 0 and 1.

Some examples of valid data format description strings:

  • "uint8[R,G,B](127|8,256)" ... 127x256 RGB-image, where each line is aligned to multiples of 8
  • "uint8[R,G,B](127:1,256:0)" ... 127x256 RGB-image stored in column major memory layout
  • "uint16[L:12,A:12]|4(32,32,32)" ... 32x32x32 12-Bit Luminance Alpha Volume, where each entry is aligned to 4 bytes

◆ set_depth()

void cgv::data::data_format::set_depth ( unsigned int  _depth)

set the resolution in the third dimension, add dimensions if necessary

set the number of entries in the third dimension

◆ set_height()

void cgv::data::data_format::set_height ( unsigned int  _height)

set the resolution in the second dimension, add dimensions if necessary

set the number of entries in the second dimension

◆ set_nr_dimensions()

void cgv::data::data_format::set_nr_dimensions ( unsigned int  _d)

set the number of dimensions of the data set

set the dimension of the data set

◆ set_nr_time_steps()

void cgv::data::data_format::set_nr_time_steps ( unsigned int  _nr_time_steps)

set the resolution in the last dimension, add dimensions if necessary

set the number of entries in the last dimension

◆ set_resolution()

void cgv::data::data_format::set_resolution ( unsigned int  i,
unsigned int  resolution 
)

set the resolution in the i-th dimension, add dimensions if necessary

set the number of data entries in the given dimension

◆ set_width()

void cgv::data::data_format::set_width ( unsigned int  _width)

set the resolution in the first dimension, add dimensions if necessary

set the number of entries in the first dimension

Friends And Related Function Documentation

◆ operator<<

FRIEND_MEMBER_API std::ostream& operator<< ( std::ostream &  os,
const data_format df 
)
friend

define stream out operator

stream out operator writes the data format in the syntax of description strings as defined in the docu of set_data_format().


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