Dune-Fufem 2.11-git
Loading...
Searching...
No Matches

Class to represent a color map. More...

#include <dune/fufem/functions/portablepixelmap.hh>

Public Types

enum  ColorMapFileFormat { CM }
 
enum  IODataFormat { ASCII , Bin }
 
typedef unsigned char CType
 
typedef unsigned short int KeyType
 
typedef Dune::FieldVector< CType, 3 > Color
 The type used to represent the color.
 
typedef std::map< KeyType, ColorColorKey
 The actual type of the ColorKey.
 

Public Member Functions

 ColorMap ()
 
 ColorMap (const std::string filename)
 Construction from dune-fufem colormap (.cm) File.
 
bool insertInColorKey (const KeyType key, const Color color)
 insert keyvalues into the ColorKey
 
Color map (const double fMin, const double fMax, const double fVal) const
 maps a scalar to a color
 
double inv_map (const double fMin, const double fMax, const Color color)
 maps a color to a scalar
 
void exportColorMapGraphic (const std::string filename="colormap.ppm", IODataFormat df=Bin) const
 writes a ppm-file to harddisk as an illustration of the colormap
 
void exportColorMap (std::string filename="colormap", ColorMapFileFormat format=CM)
 writes the colorkey to a file in an own format (.cm)
 
int size ()
 

Detailed Description

Class to represent a color map.

The ColorMap class represents a (not quite) invertible mapping \(\Gamma:\mathbb{R}\supset[a,b]\longrightarrow \text{RGB}\) where the interval boundaries \( a,b\) are not fixed for any instance of that class but rather have to be specified when the methods map() resp. inverse_map() are called. Internally the mapping is represented by the ColorKey which maps \(\gamma:\mathbb{N}\supset[0\ldots N]\supset D\longrightarrow\text{RGB}\). Return colors are linearly interpolated between the two adjacent keys in the ColorKey after the linear transformation \(\tau:[a,b]\ni r\mapsto\xi\in[0,N]\subset\mathbb{R}\).

A ColorMap can be created from single keys that are interpolated or from files in either an dune-fufem native (.cm) format. This file formats may also be exported. Lastly a PPM-file representing the colormap can be exported, e.g. for illustrative purposes.

  • Extract Color Type, make it a template (?) -> Allow for arbitrary number of color channels
  • Make CType variable -> Allow for larger channel width
  • unify PortablePixelMap, PortableGreyMap -> PortableArbitraryMap

Member Typedef Documentation

◆ Color

The type used to represent the color.

Presently only three dimensional color spaces are supported. Each channel is expected to contain integer values between 0 and 255.

◆ ColorKey

The actual type of the ColorKey.

The ColorKey is expected to contain \(2\leqslant n\leqslant N+1\) entries where \(0<N<65535\). There are two ways to obtain a valid ColorKey. Firstly by calling insertInColorKey() at least twice with different keys after default constructing the ColorMap or secondly by calling ColorMap(const std::string filename) on a valid dune-fufem colormap (.cm).

Attention
It is assumed that there exists a key 0. This assumption is not enforced however!

◆ CType

typedef unsigned char ColorMap::CType

◆ KeyType

typedef unsigned short int ColorMap::KeyType

Member Enumeration Documentation

◆ ColorMapFileFormat

An enum for the employed file format to read/write colormaps

Enumerator
CM 

◆ IODataFormat

An enum for the data format of exported grafix files

Enumerator
ASCII 
Bin 

Constructor & Destructor Documentation

◆ ColorMap() [1/2]

ColorMap::ColorMap ( )
inline

The default constructor

◆ ColorMap() [2/2]

ColorMap::ColorMap ( const std::string  filename)
inline

Construction from dune-fufem colormap (.cm) File.

Constructor that builds up the ColorKey from a dune-fufem colormap file (.cm).

Parameters
filenameThe path of the Colormap file

Member Function Documentation

◆ exportColorMap()

void ColorMap::exportColorMap ( std::string  filename = "colormap",
ColorMapFileFormat  format = CM 
)
inline

writes the colorkey to a file in an own format (.cm)

This method writes a file to disk which may be used to construct a ColorMap and appends an extension to filename (.cm) if none is given.

Parameters
filenameThe path the output file shall be written to
formatThe file formmat to use

◆ exportColorMapGraphic()

void ColorMap::exportColorMapGraphic ( const std::string  filename = "colormap.ppm",
IODataFormat  df = Bin 
) const
inline

writes a ppm-file to harddisk as an illustration of the colormap

This method writes a graphics file in ppm format (256x25 pixels) to harddisk illustrating the colormap.

Parameters
filenamethe path the output file shall be written to
dfThe IODataFormat to use

◆ insertInColorKey()

bool ColorMap::insertInColorKey ( const KeyType  key,
const Color  color 
)
inline

insert keyvalues into the ColorKey

Parameters
keythe integer (in [0,65535]) mapped to color
colorthe color key is mapped to
Returns
true when insertion successful, false otherwise

◆ inv_map()

double ColorMap::inv_map ( const double  fMin,
const double  fMax,
const Color  color 
)
inline

maps a color to a scalar

The method first fills in the ColorKey and then finds the key color closest to the argument in the sense of the one-norm (called keycol resp col in the following). The return value is interpolated between keycol and the next closest color to col among the predecessor and the successor of keycolor (called adj for adjacent) in the following (crude) way:

\[ \text{returnval} = \tau^{-1}\left((1-\lambda)\cdot\gamma^{-1}(keycol) + \lambda\cdot\gamma^{-1}(adj)\right)\qquad\text{, where }\lambda=\frac{\lVert col - keycol\rVert_1}{\lVert col - keycol\rVert_1+\lVert col - adj\rVert_1} \]

(for notation \(\tau, \gamma\) see above)

Warning
In order to be of any real use color is not restricted to values in the filled in ColorKey. This, however, leads to possibly highly inaccurate if not meaningless results, if color is too "far away" of the colors in the ColorKey. Also
x==inv_map(fMin,fMax,map(fMin,fMax,x))
double inv_map(const double fMin, const double fMax, const Color color)
maps a color to a scalar
Definition portablepixelmap.hh:202
Color map(const double fMin, const double fMax, const double fVal) const
maps a scalar to a color
Definition portablepixelmap.hh:154
will probably evaluate as false. So inv_map() is ONLY a hopefully APPROXIMATE inverse of map().
Parameters
fMinlower interval boundary for values represented by the colormap
fMaxupper interval boundary for values represented by the colormap
colora color (best included in the ColorKey) to be inversely mapped to a scalar in [fMin,fMax]
Returns
the scalar mapped to

◆ map()

Color ColorMap::map ( const double  fMin,
const double  fMax,
const double  fVal 
) const
inline

maps a scalar to a color

Parameters
fMinlower interval boundary for values represented by the colormap
fMaxupper interval boundary for values represented by the colormap
fValscalar in [fMin,fMax] to be mapped to a color
Returns
the color mapped to

◆ size()

int ColorMap::size ( )
inline

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