Skip to content
Snippets Groups Projects
Commit e6335baf authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

add matlab colormaps: hsv, bone, spring, summer, autumn, winter, cool, copper
parent 19b9328e
No related branches found
No related tags found
No related merge requests found
// $Id: ColorTable.cpp,v 1.25 2004-12-24 04:58:20 geuzaine Exp $
// $Id: ColorTable.cpp,v 1.26 2004-12-24 18:12:22 geuzaine Exp $
//
// Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
//
......@@ -31,6 +31,7 @@
#include "Gmsh.h"
#include "ColorTable.h"
#include "Context.h"
#include "Numeric.h"
extern Context_T CTX;
......@@ -97,6 +98,9 @@ void ColorTable_Recompute(GmshColorTable * ct)
s = 1.0 - s;
switch (ct->ipar[COLORTABLE_NUMBER]) {
case 0: // all black
r = g = b = 0;
break;
case 1: // vis5d
t = (curvature + 1.4) * (s - (1. + bias) / 2.);
r = (int)(128.0 + 127.0 * atan(7.0 * t) / 1.57);
......@@ -128,7 +132,7 @@ void ColorTable_Recompute(GmshColorTable * ct)
b = (int)(bb*255.);
}
break;
case 3: // samcef
case 3: // lucie, samcef (?)
if(s - bias <= 0.) {
r = 0;
g = 0;
......@@ -171,8 +175,7 @@ void ColorTable_Recompute(GmshColorTable * ct)
curvature = (curvature == 0.25) ? 0.26 : curvature;
r = 0;
g = 255;
b =
(int)(255. - (255. / (0.25 - curvature)) * (s - bias - 0.25 - curvature));
b = (int)(255. - (255. / (0.25 - curvature)) * (s - bias - 0.25 - curvature));
}
else if(s - bias <= 0.75 - curvature) {
curvature = (curvature == 0.25) ? 0.26 : curvature;
......@@ -183,8 +186,7 @@ void ColorTable_Recompute(GmshColorTable * ct)
else if(s - bias <= 1.) {
curvature = (curvature == -0.25) ? -0.26 : curvature;
r = 255;
g =
(int)(255. - (255. / (0.25 + curvature)) * (s - bias - 0.75 + curvature));
g = (int)(255. - (255. / (0.25 + curvature)) * (s - bias - 0.75 + curvature));
b = 0;
}
else {
......@@ -261,7 +263,53 @@ void ColorTable_Recompute(GmshColorTable * ct)
r = g = b = (int)(255 * (1. - curvature));
}
break;
case 0: // all black
case 10: // all white
r = g = b = 255;
break;
case 11: // matlab "hsv"
{
double H = 6. * s + 1.e-10, R, G, B;
HSV_to_RGB(H, 1., 1., &R, &G, &B);
r = (int)(255 * R);
g = (int)(255 * G);
b = (int)(255 * B);
}
break;
case 12: // matlab "bone"
r = (int)(255. * (7.*gray(s-bias) + hot_b(s-bias))/8.);
g = (int)(255. * (7.*gray(s-bias) + hot_g(s-bias))/8.);
b = (int)(255. * (7.*gray(s-bias) + hot_r(s-bias))/8.);
break;
case 13: // matlab "spring"
r = (int)(255. * 1.);
g = (int)(255. * gray(s-bias));
b = (int)(255. * (1. - gray(s-bias)));
break;
case 14: // matlab "summer"
r = (int)(255. * gray(s-bias));
g = (int)(255. * (0.5+gray(s-bias)/2.));
b = (int)(255. * 0.4);
break;
case 15: // matlab "autumn"
r = (int)(255. * 1.);
g = (int)(255. * gray(s-bias));
b = (int)(255. * 0.);
break;
case 16: // matlab "winter"
r = (int)(255. * 0.);
g = (int)(255. * gray(s-bias));
b = (int)(255. * (0.5+(1.-gray(s-bias))/2.));
break;
case 17: // matlab "cool"
r = (int)(255. * gray(s-bias));
g = (int)(255. * (1.-gray(s-bias)));
b = (int)(255. * 1.);
break;
case 18: // matlab "copper"
r = (int)(255. * DMIN(1., gray(s-bias) * 1.25));
g = (int)(255. * DMIN(1., gray(s-bias) * 0.7812));
b = (int)(255. * DMIN(1., gray(s-bias) * 0.4975));
break;
default:
r = g = b = 0;
break;
......@@ -362,3 +410,64 @@ int ColorTable_IsAlpha(GmshColorTable * ct)
return 0;
}
// HSV/RBG conversion routines
#define UNDEFINED 0
// rgb on [0, 1], sv returned on [0, 1] and h on [0, 6].
// Exception: h is returned UNDEFINED if S==0.
#define RETURN_HSV(h,s,v) {*H=h; *S=s; *V=v; return;}
void RGB_to_HSV(double R, double G, double B,
double *H, double *S, double *V)
{
double v, x, f;
int i;
x = DMIN(DMIN(R, G), B);
v = DMAX(DMAX(R, G), B);
if(v == x)
RETURN_HSV(UNDEFINED, 0, v);
f = (R == x) ? G - B : ((G == x) ? B - R : R - G);
i = (R == x) ? 3 : ((G == x) ? 5 : 1);
RETURN_HSV(i - f / (v - x), (v - x) / v, v);
}
// h given on [0, 6] or UNDEFINED. s and v given on [0, 1].
// rgb each returned on [0, 1].
#define RETURN_RGB(r,g,b) {*R=r; *G=g; *B=b; return;}
void HSV_to_RGB(double H, double S, double V,
double *R, double *G, double *B)
{
double m, n, f;
int i;
if(H == UNDEFINED)
RETURN_RGB(V, V, V);
i = (int)floor(H);
f = H - i;
if(!(i & 1))
f = 1 - f; // if i is even
m = V * (1 - S);
n = V * (1 - S * f);
switch (i) {
case 6:
case 0:
RETURN_RGB(V, n, m);
case 1:
RETURN_RGB(n, V, m);
case 2:
RETURN_RGB(m, V, n);
case 3:
RETURN_RGB(m, n, V);
case 4:
RETURN_RGB(n, m, V);
case 5:
RETURN_RGB(V, m, n);
}
}
......@@ -58,4 +58,9 @@ void ColorTable_Print(GmshColorTable *ct, FILE *fp) ;
int ColorTable_IsAlpha(GmshColorTable *ct) ;
int ColorTable_Diff(GmshColorTable *ct1, GmshColorTable *ct2);
void RGB_to_HSV(double R, double G, double B,
double *H, double *S, double *V);
void HSV_to_RGB(double H, double S, double V,
double *R, double *G, double *B);
#endif
# $Id: Makefile,v 1.68 2004-12-09 02:57:03 geuzaine Exp $
# $Id: Makefile,v 1.69 2004-12-24 18:12:22 geuzaine Exp $
#
# Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
#
......@@ -102,7 +102,7 @@ CommandLine.o: CommandLine.cpp Gmsh.h Message.h ../DataStr/Malloc.h \
Timer.o: Timer.cpp
ColorTable.o: ColorTable.cpp Gmsh.h Message.h ../DataStr/Malloc.h \
../DataStr/List.h ../DataStr/Tree.h ../DataStr/avl.h ../DataStr/Tools.h \
ColorTable.h Context.h
ColorTable.h Context.h ../Numeric/Numeric.h
Visibility.o: Visibility.cpp Gmsh.h Message.h ../DataStr/Malloc.h \
../DataStr/List.h ../DataStr/Tree.h ../DataStr/avl.h ../DataStr/Tools.h \
../Geo/Geo.h ../Geo/CAD.h ../Mesh/Mesh.h ../Mesh/Vertex.h \
......
// $Id: Colorbar_Window.cpp,v 1.41 2004-12-24 05:32:53 geuzaine Exp $
// $Id: Colorbar_Window.cpp,v 1.42 2004-12-24 18:12:22 geuzaine Exp $
//
// Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
//
......@@ -26,7 +26,6 @@
#include "Gmsh.h"
#include "GmshUI.h"
#include "Numeric.h"
#include "GUI.h"
#include "ColorTable.h"
#include "Colorbar_Window.h"
......@@ -34,7 +33,6 @@
extern Context_T CTX;
#define UNDEFINED 0
#define EPS 1.e-10
// This file defines the Colorbar_Window class (subclass of Fl_Window)
......@@ -54,65 +52,6 @@ Colorbar_Window::Colorbar_Window(int x, int y, int w, int h, const char *l)
minval = maxval = 0.0;
}
// rgb on [0, 1], sv returned on [0, 1] and h on [0, 6].
// Exception: h is returned UNDEFINED if S==0.
#define RETURN_HSV(h,s,v) {*H=h; *S=s; *V=v; return;}
static void RGB_to_HSV(double R, double G, double B,
double *H, double *S, double *V)
{
double v, x, f;
int i;
x = DMIN(DMIN(R, G), B);
v = DMAX(DMAX(R, G), B);
if(v == x)
RETURN_HSV(UNDEFINED, 0, v);
f = (R == x) ? G - B : ((G == x) ? B - R : R - G);
i = (R == x) ? 3 : ((G == x) ? 5 : 1);
RETURN_HSV(i - f / (v - x), (v - x) / v, v);
}
// h given on [0, 6] or UNDEFINED. s and v given on [0, 1].
// rgb each returned on [0, 1].
#define RETURN_RGB(r,g,b) {*R=r; *G=g; *B=b; return;}
static void HSV_to_RGB(double H, double S, double V,
double *R, double *G, double *B)
{
double m, n, f;
int i;
if(H == UNDEFINED)
RETURN_RGB(V, V, V);
i = (int)floor(H);
f = H - i;
if(!(i & 1))
f = 1 - f; // if i is even
m = V * (1 - S);
n = V * (1 - S * f);
switch (i) {
case 6:
case 0:
RETURN_RGB(V, n, m);
case 1:
RETURN_RGB(n, V, m);
case 2:
RETURN_RGB(m, V, n);
case 3:
RETURN_RGB(m, n, V);
case 4:
RETURN_RGB(n, m, V);
case 5:
RETURN_RGB(V, m, n);
}
}
// Convert window X coordinate to color table index
int Colorbar_Window::x_to_index(int x)
......@@ -287,7 +226,10 @@ void Colorbar_Window::redraw_range(int a, int b)
int xx0 = 10, xx1 = 12 * font_height, yy0 = 10;
if(help_flag) {
i = 0;
fl_draw("0, 1, 2, ..., 9", xx0, yy0 + (i + 1) * font_height);
fl_draw("0, 1, 2, 3, ...", xx0, yy0 + (i + 1) * font_height);
fl_draw("select predefined colormap", xx1, yy0 + (i + 1) * font_height);
i++;
fl_draw("Ctrl+0, Ctrl+1, ...", xx0, yy0 + (i + 1) * font_height);
fl_draw("select predefined colormap", xx1, yy0 + (i + 1) * font_height);
i++;
fl_draw("mouse1", xx0, yy0 + (i + 1) * font_height);
......@@ -461,6 +403,46 @@ int Colorbar_Window::handle(int event)
ColorTable_InitParam(9, ct);
compute = 1;
}
else if(Fl::test_shortcut(FL_CTRL + '0')) {
ColorTable_InitParam(10, ct);
compute = 1;
}
else if(Fl::test_shortcut(FL_CTRL + '1')) {
ColorTable_InitParam(11, ct);
compute = 1;
}
else if(Fl::test_shortcut(FL_CTRL + '2')) {
ColorTable_InitParam(12, ct);
compute = 1;
}
else if(Fl::test_shortcut(FL_CTRL + '3')) {
ColorTable_InitParam(13, ct);
compute = 1;
}
else if(Fl::test_shortcut(FL_CTRL + '4')) {
ColorTable_InitParam(14, ct);
compute = 1;
}
else if(Fl::test_shortcut(FL_CTRL + '5')) {
ColorTable_InitParam(15, ct);
compute = 1;
}
else if(Fl::test_shortcut(FL_CTRL + '6')) {
ColorTable_InitParam(16, ct);
compute = 1;
}
else if(Fl::test_shortcut(FL_CTRL + '7')) {
ColorTable_InitParam(17, ct);
compute = 1;
}
else if(Fl::test_shortcut(FL_CTRL + '8')) {
ColorTable_InitParam(18, ct);
compute = 1;
}
else if(Fl::test_shortcut(FL_CTRL + '9')) {
ColorTable_InitParam(19, ct);
compute = 1;
}
else if(Fl::test_shortcut('c')) {
ColorTable_Copy(ct);
}
......
# $Id: Makefile,v 1.61 2004-12-06 04:59:08 geuzaine Exp $
# $Id: Makefile,v 1.62 2004-12-24 18:12:22 geuzaine Exp $
#
# Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
#
......@@ -136,9 +136,9 @@ Opengl_Window.o: Opengl_Window.cpp ../Common/Gmsh.h ../Common/Message.h \
Colorbar_Window.o: Colorbar_Window.cpp ../Common/Gmsh.h \
../Common/Message.h ../DataStr/Malloc.h ../DataStr/List.h \
../DataStr/Tree.h ../DataStr/avl.h ../DataStr/Tools.h \
../Common/GmshUI.h ../Numeric/Numeric.h GUI.h Opengl_Window.h \
../Mesh/Mesh.h ../Mesh/Vertex.h ../Mesh/Element.h ../Mesh/Simplex.h \
../Mesh/Face.h ../Mesh/Edge.h ../Geo/ExtrudeParams.h ../Mesh/STL.h \
../Common/GmshUI.h GUI.h Opengl_Window.h ../Mesh/Mesh.h \
../Mesh/Vertex.h ../Mesh/Element.h ../Mesh/Simplex.h ../Mesh/Face.h \
../Mesh/Edge.h ../Geo/ExtrudeParams.h ../Mesh/STL.h \
../Common/VertexArray.h ../Common/SmoothNormals.h ../Mesh/Metric.h \
../Mesh/Matrix.h Colorbar_Window.h ../Common/ColorTable.h File_Picker.h \
../Common/Context.h
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment