Fréchet View  1.6.0
A Tool for Exploring Fréchet Distance Algorithms
palette.cpp
Go to the documentation of this file.
1 
2 #include <palette.h>
3 //#include <QRandomGenerator>
4 #include <QDebug>
5 #include <random>
6 
7 using namespace frechet;
8 using namespace view;
9 
10 std::mt19937 gen; //Standard mersenne_twister_engine seeded with rd()
11 
12 std::uniform_int_distribution<> disHue(0, 360);
13 std::uniform_int_distribution<> disSat(200, 255);
14 std::uniform_int_distribution<> disLight(80, 140);
15 
17  return toColor(disHue(gen), disSat(gen), disLight(gen));
18 }
19 
20 QColor Palette::nextColor(size_t key) {
21  /* colors should look random,
22  * but still be deterministic (w.r.t. key)
23  * */
24  gen.seed(key);
25  //gen.discard(key);
26  //gen.seed(gen());
27  return randomColor();
28 }
29 
30 QColor Palette::toColor(int x, int sat, int light) {
31  return QColor::fromHsl(abs(x) % 360, sat,light);
32 }
33 
34 
36 { }
37 
38 QColor Palette::operator[](size_t key)
39 {
40  typename ColorMap::const_iterator i = map.find(key);
41  if (i==map.end()) {
42  QColor col = nextColor(key);
43  map.insert(key,col);
44  //qDebug() << "Palette: " << key << "=" << col.hslHue() << "\n";
45  return col;
46  }
47  else {
48  return *i;
49  }
50 }
51 
53  map.clear();
54 }
55 
global definitions for all algorithms.
QColor nextColor(size_t key)
get color for a component; chose a new random color, if necessary
Definition: palette.cpp:20
void clear()
remove all entries from the map
Definition: palette.cpp:52
ColorMap map
the map
Definition: palette.h:23
std::uniform_int_distribution disHue(0, 360)
QColor operator[](size_t key)
look up a color
Definition: palette.cpp:38
std::uniform_int_distribution disSat(200, 255)
static QColor toColor(int x, int sat=220, int light=200)
map an integer key to a color
Definition: palette.cpp:30
std::mt19937 gen
Definition: palette.cpp:10
Palette()
constructor; creates an empty palette
Definition: palette.cpp:35
std::uniform_int_distribution disLight(80, 140)
Number abs(const Number &x)
abs() function template for arbitrary numerical types
Definition: numeric.h:91