ColorMap.cpp
Go to the documentation of this file.
1 
36 
37 #include <cassert>
38 #include <cmath>
39 
40 namespace lvr2
41 {
42 
43 void ColorMap::getColor(float* color, size_t bucket, GradientType gradient )
44 {
45  assert(color);
46 
47  switch(gradient)
48  {
49  case GREY:
50  calcColorGrey(color, bucket);
51  break;
52  case JET:
53  calcColorJet(color, bucket);
54  break;
55  case HOT:
56  calcColorHot(color, bucket);
57  break;
58  case HSV:
59  calcColorHSV(color, bucket);
60  break;
61  case SHSV:
62  calcColorSHSV(color, bucket);
63  break;
64  case SIMPSONS:
65  calcColorSimpsons(color, bucket);
66  break;
67  default:
68  color[0] = 1.0;
69  color[1] = 1.0;
70  color[2] = 1.0;
71  break;
72 
73  }
74 }
75 
76 void ColorMap::calcColorSimpsons(float* color, size_t bucket)
77 {
78  color[0] = fabs( cos( bucket ) );
79  color[1] = fabs( sin( bucket * 30 ) );
80  color[2] = fabs( sin( bucket * 2 ) );
81 }
82 
83 void ColorMap::calcColorGrey(float *d, size_t i)
84 {
85  d[0] = (float)i/(float)m_numBuckets;
86  d[1] = (float)i/(float)m_numBuckets;
87  d[2] = (float)i/(float)m_numBuckets;
88 }
89 
90 void ColorMap::calcColorHSV(float *d, size_t i)
91 {
92  float t = (float)i/(float)m_numBuckets;
93  convertHSVToRGB(360.0*t, 1.0, 1.0, d[0], d[1], d[2]);
94 
95 }
96 
97 void ColorMap::calcColorSHSV(float *d, size_t i)
98 {
99  float t = (float)i/(float)m_numBuckets;
100  convertHSVToRGB(360.0*t, 1.0, 1.0, d[0], d[1], d[2]);
101 }
102 
103 void ColorMap::calcColorHot(float *d, size_t i)
104 {
105  float t = (float)i/(float)m_numBuckets;
106  if (t <= 1.0/3.0) {
107  d[1] = d[2] = 0.0; d[0] = t/(1.0/3.0);
108  } else if (t <= 2.0/3.0) {
109  d[0] = 1.0; d[2] = 0.0; d[1] = (t-(1.0/3.0))/(1.0/3.0);
110  } else {
111  d[0] = 1.0; d[1] = 1.0; d[2] = (t-(2.0/3.0))/(1.0/3.0);
112  }
113 }
114 
115 void ColorMap::calcColorJet(float *d, size_t i)
116 {
117  float t = (float)i/(float)m_numBuckets;
118  if (t <= 0.125) {
119  d[0] = d[1] = 0.0; d[2] = 0.5 + 0.5*(t/0.125);
120  } else if (t < 0.375) {
121  d[0] = 0.0; d[2] = 1.0; d[1] = (t-0.125)/0.25;
122  } else if (t < 0.625) {
123  d[1] = 1.0; d[0] = (t-0.375)/0.25;; d[2] = 1.0 - d[0];
124  } else if (t < 0.875) {
125  d[0] = 1.0; d[2] = 0.0; d[1] = 1.0 - (t-0.625)/0.25;
126  } else {
127  d[1] = d[2] = 0.0; d[2] = 1.0 - 0.5*(t/0.125);
128  }
129 }
130 
131 void ColorMap::convertHSVToRGB(float hue, float s, float v, float &r, float &g, float &b)
132 {
133  float p1, p2, p3, i, f;
134  float xh;
135 
136  if (hue == 360.0)
137  hue = 0.0;
138 
139  xh = hue / 60.; // convert hue to be in 0,6
140  i = (float)floor((double)xh); // i is greatest integer smaller than h
141  f = xh - i; // f is the fractional part of h
142  p1 = v * (1 - s);
143  p2 = v * (1 - (s * f));
144  p3 = v * (1 - (s * (1 - f)));
145 
146  switch ((int) i)
147  {
148  case 0:
149  r = v;
150  g = p3;
151  b = p1;
152  break;
153  case 1:
154  r = p2;
155  g = v;
156  b = p1;
157  break;
158  case 2:
159  r = p1;
160  g = v;
161  b = p3;
162  break;
163  case 3:
164  r = p1;
165  g = p2;
166  b = v;
167  break;
168  case 4:
169  r = p3;
170  g = p1;
171  b = v;
172  break;
173  case 5:
174  r = v;
175  g = p1;
176  b = p2;
177  break;
178  }
179 }
180 
181 } // namespace lvr2
void getColor(float *color, size_t bucket, GradientType gradient=GREY)
Returns three float values for the color of the given bucket.
Definition: ColorMap.cpp:43
void calcColorHot(float *color, size_t bucket)
Returns a color from a hot gradient.
Definition: ColorMap.cpp:103
void convertHSVToRGB(float hue, float s, float v, float &r, float &g, float &b)
Converts the given color in HSV space into RGB space.
Definition: ColorMap.cpp:131
void calcColorSHSV(float *color, size_t bucket)
Returns a color from a SHSV gradient.
Definition: ColorMap.cpp:97
GradientType
Identifies a color gradient.
Definition: ColorMap.hpp:50
void calcColorGrey(float *color, size_t bucket)
Returns a color from a gray gradient.
Definition: ColorMap.cpp:83
void calcColorJet(float *color, size_t bucket)
Returns a color from a Jet gradient.
Definition: ColorMap.cpp:115
void calcColorHSV(float *color, size_t bucket)
Returns a color from a HSV gradient.
Definition: ColorMap.cpp:90
size_t m_numBuckets
Number of colors in the color gradient.
Definition: ColorMap.hpp:150
void calcColorSimpsons(float *color, size_t bucket)
Returns a color from a Simpsons gradient.
Definition: ColorMap.cpp:76


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Mon Feb 28 2022 22:46:06