SPH
Palette.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "gui/objects/Color.h"
8 
10 
11 class Path;
12 
13 enum class PaletteScale {
15  LINEAR,
16 
19 
21  HYBRID
22 };
23 
25 class Palette {
26 public:
27  struct Point {
28  float value;
30  };
31 
32 private:
33  Array<Point> points;
34  Interval range;
35  PaletteScale scale;
36 
37 public:
38  Palette() = default;
39 
40  Palette(const Palette& other);
41 
42  Palette(Palette&& other) = default;
43 
44  Palette& operator=(const Palette& other);
45 
46  Palette& operator=(Palette&& other) = default;
47 
52  Palette(Array<Point>&& controlPoints, const PaletteScale scale);
53 
57  Interval getInterval() const;
58 
59  void setInterval(const Interval& newRange);
60 
62  PaletteScale getScale() const;
63 
65  Rgba operator()(const float value) const;
66 
68  Palette transform(Function<Rgba(const Rgba&)> func) const;
69 
75  float relativeToPalette(const float value) const;
76 
78  float paletteToRelative(const float value) const;
79 
81  Outcome loadFromStream(std::istream& ifs);
82 
84  Outcome loadFromFile(const Path& path);
85 
87  Outcome saveToStream(std::ostream& ofs, const Size lineCnt = 256) const;
88 
90  Outcome saveToFile(const Path& path, const Size lineCnt = 256) const;
91 
92 private:
93  float linearToPalette(const float value) const;
94 
95  float paletteToLinear(const float value) const;
96 };
97 
Generic dynamically allocated resizable storage.
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
Generic wrappers of lambdas, functors and other callables.
uint32_t Size
Integral type used to index arrays (by default).
Definition: Globals.h:16
#define NAMESPACE_SPH_END
Definition: Object.h:12
Return value of function that may fail, containing either SUCCEES (true) or error message.
PaletteScale
Definition: Palette.h:13
@ HYBRID
Logarithic scale for values > 1 and < -1, linear scale on interval <-1, 1>
Quantity identifiers.
Generic dynamically allocated resizable storage.
Definition: Array.h:43
Object representing a 1D interval of real numbers.
Definition: Interval.h:17
Represents a color palette, used for mapping arbitrary number to a color.
Definition: Palette.h:25
void setInterval(const Interval &newRange)
Definition: Palette.cpp:95
Palette()=default
Palette & operator=(const Palette &other)
Definition: Palette.cpp:63
float relativeToPalette(const float value) const
Converts a relative position to an absolute position on a palette.
Definition: Palette.cpp:141
PaletteScale getScale() const
Returns the scale of the palette.
Definition: Palette.cpp:107
Palette transform(Function< Rgba(const Rgba &)> func) const
Returns the palette with colors modified by generic transform.
Definition: Palette.cpp:133
Palette(Palette &&other)=default
Outcome saveToStream(std::ostream &ofs, const Size lineCnt=256) const
Saves the palettes into given output stream.
Definition: Palette.cpp:205
float paletteToRelative(const float value) const
Inverse transform to relativeToPalette.
Definition: Palette.cpp:162
Outcome loadFromFile(const Path &path)
Loads the palette from given .csv file.
Definition: Palette.cpp:200
Outcome loadFromStream(std::istream &ifs)
Loads the palette from given input stream.
Definition: Palette.cpp:167
Palette & operator=(Palette &&other)=default
Outcome saveToFile(const Path &path, const Size lineCnt=256) const
Saves the palette to a .csv file.
Definition: Palette.cpp:221
Rgba operator()(const float value) const
Returns the color mapped to given number.
Definition: Palette.cpp:111
Interval getInterval() const
Returns the interval for which the palette is defined.
Definition: Palette.cpp:90
Object representing a path on a filesystem.
Definition: Path.h:17
Definition: Color.h:8
@ LINEAR
Constant time between consecutive output times.
@ LOGARITHMIC
Constant ratio between consecutive output times.
float value
Definition: Palette.h:28
Rgba color
Definition: Palette.h:29