F
Ich habe nun die hsv2rgb-Funktion in meinen Kennfeld-Viewer eingebaut. Leider funktioniert das Ganze nicht so, wie ich mir das dachte. Meine Annahme war die:
Hue (Farbton): von 0°-360°
-> Mein Kennfeld geht in y-Richtung von Koordinate 0.0 - 1000.0. Dazu habe ich mir eine Funktion geschrieben, die mir den Grad-Wert 0-360 in die entsprechende Höhe skaliert (0-1000).
Saturation (Sättigung): 0.0 - 1.0
-> den Wert lasse ich Konstant auf 1.0
Value (Helligkeit): 0 - 255
-> wird ebenfalls auf 255 gelassen
Tja, was kommt dabei raus: Jedenfalls kein toller regenborgenartiger Farbverlauf , sondern harte Übergänge zw. Gelb, Türkis, Pink. Das Ganze sieht also total Asche aus. Was mache ich da falsch?
Hier nochmal die hsv2rgb-Funktion aus dem obigen Link:
// h: 0° - 360° (hue - Farbton)
// s: 0.0 - 1.0 (saturation - Sättigung)
// v: 0 - 255 (value - Helligkeit)
void hsv2rgb(float h, float s, float v, float &r, float &g, float &b)
{
if (s == 0.0) r = g = b = v;
else
{
if (h == 360.0) h = 0.0;
h /= 60.0;
int i = (int)(h);
double f = h - i;
double p = v * (1 - s);
double q = v * (1 - (s * f));
double t = v * (1 - (s * (1 - f)));
switch (i)
{
case 0: {r = (float)v; g = (float)t; b = (float)p; break;}
case 1: {r = (float)q; g = (float)v; b = (float)p; break;}
case 2: {r = (float)p; g = (float)v; b = (float)t; break;}
case 3: {r = (float)p; g = (float)q; b = (float)v; break;}
case 4: {r = (float)t; g = (float)p; b = (float)v; break;}
case 5: {r = (float)v; g = (float)p; b = (float)q; break;}
}
}
}
und hier nochmal mein Aufruf:
// fHeigth: 0.0 - 1000.0
void __fastcall TfrmMDI::SetVertexColor(float fHeigth)
{
float r, g, b;
switch (GPref.GraficColorMode)
{
case ColGradient : { r = fHeigth/MAXGRIDSIZE;
b = 1 - r;
g = 1.0;
break; }
case ColHeightlines : { r = cos(fHeigth);
g = sin(fHeigth/MAXGRIDSIZE);
b = 1.0;
break; }
case ColColorCircle : { hsv2rgb(EvalKR(fHeigth, 0.0, 360.0), 1.0, 255.0, r, g, b);
break; }
}
glColor3f(r, g, b);
}
float __fastcall TfrmMDI::EvalKR(int iCoord, float fRealMin, float fRealMax)
{
// Min/Max im Bild-Koordinatensystem
float fPya = 0.0;
float fPye = MAXGRIDSIZE; // 1000.0
float fCoord = float(iCoord);
// Bild-Koordinaten in reelle umrechnen
return (((fCoord - fPya) / (fPye - fPya)) * (fRealMax - fRealMin)) + fRealMin;
}