Loading...
Searching...
No Matches
Public Types | Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Palette Class Reference

#include <Palette.h>

Inheritance diagram for Palette:
Inheritance graph
[legend]
Collaboration diagram for Palette:
Collaboration graph
[legend]

Public Types

typedef std::map< std::string, PaletteEntry > spec_t
 Some kind of identity key for the palette, typically filename to avoid reloading.
 
- Public Types inherited from ImageCodeMap< PaletteEntry >
typedef std::map< double, PaletteEntry > cont_t
 
typedef cont_t::key_type key_t
 
typedef cont_t::value_type entry_t
 
typedef drain::LookUp< typename cont_t::const_iterator > lookup_t
 LOOK-UP table is an array of pointers to the actual Palette.
 
typedef std::list< entry_t > list_t
 

Public Member Functions

 Palette ()
 Basic constructor.
 
 Palette (std::initializer_list< std::pair< Variable, PaletteEntry > > inits)
 Constructor supporting initialisation.
 
const value_type & getEntryByCode (const std::string &code, bool lenient=true) const
 
key_type getValueByCode (const std::string &code, bool lenient=true) const
 Shorthand invoking fgetEntryByCode for retrieving the code.
 
void reset ()
 
void addEntry (double min, double red=0.0, double green=0.0, double blue=0.0, const std::string &id="", const std::string &label="")
 Add one color. Deprecating; brace-enclosed initialization more preferable.
 
void load (const std::string &filename, bool flexible=false)
 Loads a palette from text file.
 
void loadTXT (std::istream &ifstr)
 Loads a palette from a text file.
 
void loadJSON (std::istream &ifstr)
 Loads a palette from a json file. Under revision; support may be dropped later.
 
void write (const std::string &filename) const
 
void exportTXT (std::ostream &ostr, char separator='\t', char separator2=0) const
 
void exportJSON (drain::JSONtree &json) const
 
void exportFMT (std::ostream &ostr, const std::string &format) const
 
void exportSVGLegend (TreeSVG &svg, bool up=true) const
 Returns a legend as an SVG graphic.
 
void exportSLD (TreeSLD &sld) const
 Export as SLD structure supported by GeoServer.
 
const ChannelGeometry & getChannels () const
 Export palette such.
 
void refine (size_t n=0)
 Extend palette to contain n entries ("colors") by adding intermediate entries.
 
- Public Member Functions inherited from ImageCodeMap< PaletteEntry >
 ImageCodeMap ()
 Default constructor.
 
 ImageCodeMap (std::initializer_list< entry_t > l)
 
 ImageCodeMap (const cont_t &map)
 Copy constructor //.
 
lookup_t & createLookUp (const std::type_info &type, const ValueScaling &scaling) const
 Creates a vector of 256 or 65535 entries for fast retrieval.
 
cont_t::const_iterator retrieve (double d) const
 
cont_t::iterator retrieve (double d)
 

Public Attributes

std::string title
 Name of the palette. In reading files, the first comment line (without the prefix '#') is copied to this. Legend shows the title on top.
 
spec_t specialCodes
 
size_t refinement
 void updateDictionary();
 
std::string comment
 
- Public Attributes inherited from ImageCodeMap< PaletteEntry >
lookup_t lookUp
 
char separator
 

Static Public Attributes

static const SprinterLayout cppLayout2
 

Protected Member Functions

void update () const
 Container for special codes ??
 
void importJSON (const drain::JSONtree &json)
 Creates a palette from json object.
 

Protected Attributes

ChannelGeometry channels
 

Detailed Description

A map of RGB colours, with optional transparency (alpha) values, and with Dictionary support.

Member Typedef Documentation

◆ spec_t

typedef std::map<std::string,PaletteEntry> spec_t

Some kind of identity key for the palette, typically filename to avoid reloading.

Certain intensities (before scaling with gain and offset) may require special treatment.

Constructor & Destructor Documentation

◆ Palette()

Palette ( std::initializer_list< std::pair< Variable, PaletteEntry > >  inits)

Constructor supporting initialisation.

Colorizes an image of 1 channel to an image of N channels by using a palette image as a lookup table.

Having Variable as key type allows mixing numeric codes and alphabetic (special) codes.

Treats an RGB truecolor image of N pixels as as a palette of N colors.

Member Function Documentation

◆ exportSLD()

void exportSLD ( TreeSLD &  sld) const

Export as SLD structure supported by GeoServer.

If the quantity is an integer, do not apply decimal notation.

GeoServer extends the <ColorMap> element to allow two attributes: type and extended.

The <ColorMap> type attribute specifies the kind of ColorMap to use. There are three different types of ColorMaps that can be specified: ramp, intervals and values.

type="ramp" is the default ColorMap type. It specifies that colors should be interpolated for values between the color map entries.

type="values" means that only pixels with the specified entry quantity values are rendered. Pixels with other values are not rendered. Using the example set of color map entries:

type="intervals" value means that each interval defined by two entries is rendered using the color of the first (lowest-value) entry. No color interpolation is applied across the intervals.

The 'extended' attribute specifies whether the color map gradient uses 256 (8-bit) or 65536 (16-bit) colors. The value false (the default) specifies that the color scale is calculated using 8-bit color, and true specifies using 16-bit color.

https://docs.geoserver.org/latest/en/user/styling/sld/reference/rastersymbolizer.html#type

<ColorMapEntry> elements can also have opacity and label attributes. The opacity attribute overrides the global <Opacity> value. The label attribute is used to provide text for legends.

https://docs.geoserver.org/latest/en/user/styling/sld/reference/rastersymbolizer.html#colormap

The simplest <ColorMap> has two color map entries. One specifyies a color for the “bottom” of the dataset, and the other specifyies a color for the “top” of the dataset. Pixels with values equal to or less than the minimum value are rendered with the bottom color (and opacity). Pixels with values equal to or great than the maximum value are rendered with the top color and opacity. The colors for values in between are automatically interpolated, making creating color gradients easy.

◆ getChannels()

const ChannelGeometry & getChannels ( ) const
inline

Export palette such.

void exportCPP(std::ostream & ostr, bool flat=true) const; Creates a palette from json object

Parameters
json- JSON structure combining optional metadata and compulsory entries section.

◆ getEntryByCode()

const Palette::value_type & getEntryByCode ( const std::string &  code,
bool  lenient = true 
) const

Given code (class index or similar marker), returns the (threshold) value, ie. index of the palette entry.

Argument code is matched against palette entries with tests in the following order:

exact string match (if \c lenient=true , testing stops here )

\c palette.code starts with \c code

\c palette.code end with \c code

\c palette.code contains with \c code

If a matching code is not found, std::runtime_exeption is thrown.

Parameters
code
lenient- if false, only exact string match tested, else substring match accepted

getImgLog().setVerbosity(20);

◆ load()

void load ( const std::string &  filename,
bool  flexible = false 
)

Loads a palette from text file.

Parameters
flexible- if true, try also directory appended with ./palette, basename palette-(string) and extensions txt,json

◆ loadTXT()

void loadTXT ( std::istream &  ifstr)

Loads a palette from a text file.

First label in the file will be the title

◆ refine()

void refine ( size_t  n = 0)

Extend palette to contain n entries ("colors") by adding intermediate entries.

Number of colors.

New number of entries between two current entries.

Member Data Documentation

◆ refinement

size_t refinement

void updateDictionary();

Request for future refinement, ie. refine() call upon next load(). It is upto applications to use this.


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