SPH
Classes | Public Member Functions | List of all members
Palette Class Reference

Represents a color palette, used for mapping arbitrary number to a color. More...

#include <Palette.h>

Classes

struct  Point
 

Public Member Functions

 Palette ()=default
 
 Palette (const Palette &other)
 
 Palette (Palette &&other)=default
 
Paletteoperator= (const Palette &other)
 
Paletteoperator= (Palette &&other)=default
 
 Palette (Array< Point > &&controlPoints, const PaletteScale scale)
 Creates a color palette given control points and their colors. More...
 
Interval getInterval () const
 Returns the interval for which the palette is defined. More...
 
void setInterval (const Interval &newRange)
 
PaletteScale getScale () const
 Returns the scale of the palette. More...
 
Rgba operator() (const float value) const
 Returns the color mapped to given number. More...
 
Palette transform (Function< Rgba(const Rgba &)> func) const
 Returns the palette with colors modified by generic transform. More...
 
float relativeToPalette (const float value) const
 Converts a relative position to an absolute position on a palette. More...
 
float paletteToRelative (const float value) const
 Inverse transform to relativeToPalette. More...
 
Outcome loadFromStream (std::istream &ifs)
 Loads the palette from given input stream. More...
 
Outcome loadFromFile (const Path &path)
 Loads the palette from given .csv file. More...
 
Outcome saveToStream (std::ostream &ofs, const Size lineCnt=256) const
 Saves the palettes into given output stream. More...
 
Outcome saveToFile (const Path &path, const Size lineCnt=256) const
 Saves the palette to a .csv file. More...
 

Detailed Description

Represents a color palette, used for mapping arbitrary number to a color.

Definition at line 25 of file Palette.h.

Constructor & Destructor Documentation

◆ Palette() [1/4]

Palette::Palette ( )
default

◆ Palette() [2/4]

Palette::Palette ( const Palette other)

Definition at line 58 of file Palette.cpp.

◆ Palette() [3/4]

Palette::Palette ( Palette &&  other)
default

◆ Palette() [4/4]

Palette::Palette ( Array< Point > &&  controlPoints,
const PaletteScale  scale 
)

Creates a color palette given control points and their colors.

For linear and hybrid scale, controls points can be both positive or negative numbers, for logarithmic scale only positive numbers (and zero) are allowed. Control points must be passed in increasing order.

Definition at line 70 of file Palette.cpp.

Member Function Documentation

◆ getInterval()

Interval Palette::getInterval ( ) const

Returns the interval for which the palette is defined.

Values outside the interval will be mapped to the colors at the boundary of the interval.

Definition at line 90 of file Palette.cpp.

◆ getScale()

PaletteScale Palette::getScale ( ) const

Returns the scale of the palette.

Definition at line 107 of file Palette.cpp.

◆ loadFromFile()

Outcome Palette::loadFromFile ( const Path path)

Loads the palette from given .csv file.

Definition at line 200 of file Palette.cpp.

◆ loadFromStream()

Outcome Palette::loadFromStream ( std::istream &  ifs)

Loads the palette from given input stream.

Todo:
improve

Definition at line 167 of file Palette.cpp.

◆ operator()()

Rgba Palette::operator() ( const float  value) const

Returns the color mapped to given number.

Definition at line 111 of file Palette.cpp.

◆ operator=() [1/2]

Palette & Palette::operator= ( const Palette other)

Definition at line 63 of file Palette.cpp.

◆ operator=() [2/2]

Palette& Palette::operator= ( Palette &&  other)
default

◆ paletteToRelative()

float Palette::paletteToRelative ( const float  value) const

Inverse transform to relativeToPalette.

Definition at line 162 of file Palette.cpp.

◆ relativeToPalette()

float Palette::relativeToPalette ( const float  value) const

Converts a relative position to an absolute position on a palette.

The relative position is in interval <0, 1>, the absolute position is given by the control points of the palette. For linear palette, this function is simply scaling of the interval, for logarithmic and hybrid palettes it also transforms the input value by the corresponding function.

Definition at line 141 of file Palette.cpp.

◆ saveToFile()

Outcome Palette::saveToFile ( const Path path,
const Size  lineCnt = 256 
) const

Saves the palette to a .csv file.

Definition at line 221 of file Palette.cpp.

◆ saveToStream()

Outcome Palette::saveToStream ( std::ostream &  ofs,
const Size  lineCnt = 256 
) const

Saves the palettes into given output stream.

Definition at line 205 of file Palette.cpp.

◆ setInterval()

void Palette::setInterval ( const Interval newRange)

Definition at line 95 of file Palette.cpp.

◆ transform()

Palette Palette::transform ( Function< Rgba(const Rgba &)>  func) const

Returns the palette with colors modified by generic transform.

Definition at line 133 of file Palette.cpp.


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