ColormapDefinition.h

Classes

ColormapDefinition -- This class defines a wrapper for a color function or look-up table. (full description)

class ColormapDefinition

Interface

Public Members
ColormapDefinition()
explicit ColormapDefinition(const String & mapName)
ColormapDefinition(const String & mapName, const Vector<Float> & reds, const Vector<Float> & greens, const Vector<Float> & blues)
void getValue(const Float t, Float & red, Float & green, Float & blue) const
void setValues(const Vector<Float> & reds, const Vector<Float> & greens, const Vector<Float> & blues)
Bool save(const String &fullPathName, const Vector<String> &synonyms, const Bool &overwrite = True) const
static Vector<String> builtinColormapNames(Bool uniqueonly = True)
Bool loadColormap(const String& name)
Bool loadBuiltinColormap(const String& name)
friend ostream & operator << (ostream & os, const ColormapDefinition& pcreh)
Private Members
Bool queryColormapTable(const Table& table, const String& name)
static void loadColormapTable()

Description

Review Status

Date Reviewed:
yyyy/mm/dd

Etymology

"ColormapDefinition" is the thing one uses to define a colormap.

Synopsis

ColormapDefinition is a class whose principal purpose is, given an input value in the range [0.0, 1.0], to return an RGB triplet corresponding to that position in the colormap. It can read definitions from and write definitions to Tables on disk, thereby providing a mechanism for using custom colormaps for display applications.

It supplies one built-in colormap Greyscale 1, which will always be available. The other colormaps are stored in AIPS++ tables. The standard colormaps ar in /aips++/data/colormaps/default.tbl. These can be deactivated by putting display.colormaps.usedefault: no in the .aipsrc file. It also supplies user defined colormaps. It looks for the complete path to the user table in .aipsrc under display.colormaps.usertable:.

ColormapDefinition is used by the Colormap class to generate color values for the ColormapManager.

Example

A ColormapDefinition corresponding to the system "rainbow" Colormap can be obtained and used as follows:
    ColormapDefinition rainbowDefinition(String("rainbow"));
    Float red, green, blue;
    for (uInt i = 0; i <= 100; i++) {
      rainbowDefinition.getValues((Float)i/100.0, red, green, blue);
      // ... do something with red, green, blue ...
    }
    
Or a new ColormapDefinition with a red ramp and green and blue fixed at 0.5 could be constructed and saved for later use as follows:
    Vector<Float> reds(40), greens(40), blues(40);
    greens = 0.5;
    blues = 0.5;
    for (uInt i = 0; i < 40; i++) {
      reds(i) = (Float)i / 39.0;
    }
    ColormapDefinition simpleRamp("redRamp", reds, greens, blues);
    Vector<String> synonyms(2);
    synonyms(0) = "RedRamp";synonyms(1) = "redramp";
    simpleRamp.save("mytable.tbl,synonyms);
    

Motivation

Needed to separate out ColormapDefinition from Colormap to give the programmer a way to over-ride the definition without having to also over-ride the shape function.

Thrown Exceptions

To Do

Member Description

ColormapDefinition()

Construct a single color (white) Colormap

explicit ColormapDefinition(const String & mapName)

Construct the known Colormap mapName, first looking for a saved Colormap having this name, then resorting to a built-in Colormap, and if that doesn't exist, throw an error

ColormapDefinition(const String & mapName, const Vector<Float> & reds, const Vector<Float> & greens, const Vector<Float> & blues)

Construct a new Colormap, using the supplied name and component vectors

void getValue(const Float t, Float & red, Float & green, Float & blue) const

Obtain the Colormap value for the "index" value 0 <= t <= 1

void setValues(const Vector<Float> & reds, const Vector<Float> & greens, const Vector<Float> & blues)

Change the Colormap values with the provided component vectors

Bool save(const String &fullPathName, const Vector<String> &synonyms, const Bool &overwrite = True) const

Write this ColormapDefinition to the named Table in the named directory (default values are obtained from the user's .aipsrc file. If overwrite is True, then an existing map of the same name in the Table will be over-written. If the named Table does not exist, it will be created.

The table format has to conform with following scheme. It must have five columns: CMAP_NAME a String RED a Float array of dim n GREEN a Float array of dim n BLUE a Float array of dim n SYNONYMS a String array of dim m

static Vector<String> builtinColormapNames(Bool uniqueonly = True)

Return the names of the built-in colormaps. If uniqueonly is True (default), only the names of the unique colormaps are returned, otherwise all colormap names are returned.

Bool loadColormap(const String& name)

Load Colormap definitions for a specified colormapname

Bool loadBuiltinColormap(const String& name)

friend ostream & operator << (ostream & os, const ColormapDefinition& pcreh)

Write a ColormapDefinition to an ostream in a simple text form.

Bool queryColormapTable(const Table& table, const String& name)

Utility function to look if a colormap name is in a Table

static void loadColormapTable()

load ColormapDefinitions from default location aips++/data/colormaps/default.tbl and/or location specified in display.colormaps.usertable