![]() |
Dune-Fufem 2.11-git
|
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, Color > | ColorKey |
| 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
| typedef Dune::FieldVector<CType, 3> ColorMap::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
| typedef std::map<KeyType, Color> ColorMap::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
◆ IODataFormat
Constructor & Destructor Documentation
◆ ColorMap() [1/2]
|
inline |
The default constructor
◆ ColorMap() [2/2]
|
inline |
Construction from dune-fufem colormap (.cm) File.
Constructor that builds up the ColorKey from a dune-fufem colormap file (.cm).
- Parameters
-
filename The path of the Colormap file
Member Function Documentation
◆ exportColorMap()
|
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
-
filename The path the output file shall be written to format The file formmat to use
◆ exportColorMapGraphic()
|
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
-
filename the path the output file shall be written to df The IODataFormat to use
◆ insertInColorKey()
insert keyvalues into the ColorKey
- Parameters
-
key the integer (in [0,65535]) mapped to color color the color key is mapped to
- Returns
truewhen insertion successful,falseotherwise
◆ inv_map()
|
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 will probably evaluate asdouble inv_map(const double fMin, const double fMax, const Color color)maps a color to a scalarDefinition portablepixelmap.hh:202Color map(const double fMin, const double fMax, const double fVal) constmaps a scalar to a colorDefinition portablepixelmap.hh:154
false. So inv_map() is ONLY a hopefully APPROXIMATE inverse of map().
- Parameters
-
fMin lower interval boundary for values represented by the colormap fMax upper interval boundary for values represented by the colormap color a color (best included in the ColorKey) to be inversely mapped to a scalar in [fMin,fMax]
- Returns
- the scalar mapped to
◆ map()
|
inline |
maps a scalar to a color
- Parameters
-
fMin lower interval boundary for values represented by the colormap fMax upper interval boundary for values represented by the colormap fVal scalar in [fMin,fMax] to be mapped to a color
- Returns
- the color mapped to
◆ size()
|
inline |
The documentation for this class was generated from the following file:
