From bf65d6994cdc417fcc90e81ab60b2adeb7a32770 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Fri, 24 Dec 2004 20:25:12 +0000
Subject: [PATCH] power law for the alpha channel

---
 Common/ColorTable.cpp     |  7 +++++--
 Common/ColorTable.h       |  1 +
 Common/DefaultOptions.h   |  2 ++
 Common/Options.cpp        | 18 +++++++++++++++++-
 Common/Options.h          |  1 +
 Fltk/Colorbar_Window.cpp  | 21 ++++++++++++++++-----
 doc/texinfo/opt_view.texi |  5 +++++
 7 files changed, 47 insertions(+), 8 deletions(-)

diff --git a/Common/ColorTable.cpp b/Common/ColorTable.cpp
index e39463f7dc..ec01a143ed 100644
--- a/Common/ColorTable.cpp
+++ b/Common/ColorTable.cpp
@@ -1,4 +1,4 @@
-// $Id: ColorTable.cpp,v 1.26 2004-12-24 18:12:22 geuzaine Exp $
+// $Id: ColorTable.cpp,v 1.27 2004-12-24 20:25:11 geuzaine Exp $
 //
 // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
 //
@@ -315,7 +315,10 @@ void ColorTable_Recompute(GmshColorTable * ct)
       break;
     }
 
-    a = (int)(255. * ct->dpar[COLORTABLE_ALPHA]);
+    double aa = 1.0;
+    if(ct->dpar[COLORTABLE_ALPHAPOW])
+      aa = pow(s ? s : 1.e-10, ct->dpar[COLORTABLE_ALPHAPOW]);
+    a = (int)(255. * aa * ct->dpar[COLORTABLE_ALPHA]);
 
     if(ct->dpar[COLORTABLE_BETA]) {
       if(ct->dpar[COLORTABLE_BETA] > 0.0)
diff --git a/Common/ColorTable.h b/Common/ColorTable.h
index 57357afda7..dd714b6650 100644
--- a/Common/ColorTable.h
+++ b/Common/ColorTable.h
@@ -49,6 +49,7 @@ typedef struct{
 #define COLORTABLE_BIAS      1  // offset
 #define COLORTABLE_ALPHA     2  // alpha channel value
 #define COLORTABLE_BETA      3  // beta coeff for brighten
+#define COLORTABLE_ALPHAPOW  4  // alpha channel power value
 
 void ColorTable_InitParam(int number, GmshColorTable *ct);
 void ColorTable_Recompute(GmshColorTable *ct);
diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h
index 0a4fe5be95..c59cb43acb 100644
--- a/Common/DefaultOptions.h
+++ b/Common/DefaultOptions.h
@@ -1005,6 +1005,8 @@ StringXNumber ViewOptions_Number[] = {
 
   { F|O, "ColormapAlpha" , opt_view_colormap_alpha , 1.0 ,
     "Colormap alpha channel value (used only if != 1)" },
+  { F|O, "ColormapAlphaPower" , opt_view_colormap_alpha_power , 0.0 ,
+    "Colormap alpha channel power" },
   { F|O, "ColormapBeta" , opt_view_colormap_beta , 0.0 ,
     "Colormap beta parameter (gamma = 1-beta)" },
   { F|O, "ColormapBias" , opt_view_colormap_bias , 0.0 ,
diff --git a/Common/Options.cpp b/Common/Options.cpp
index b844e4682d..c40b868110 100644
--- a/Common/Options.cpp
+++ b/Common/Options.cpp
@@ -1,4 +1,4 @@
-// $Id: Options.cpp,v 1.214 2004-12-24 04:58:20 geuzaine Exp $
+// $Id: Options.cpp,v 1.215 2004-12-24 20:25:11 geuzaine Exp $
 //
 // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
 //
@@ -5418,6 +5418,22 @@ double opt_view_colormap_alpha(OPT_ARGS_NUM)
   return v->CT.dpar[COLORTABLE_ALPHA];
 }
 
+double opt_view_colormap_alpha_power(OPT_ARGS_NUM)
+{
+  GET_VIEW(0.);
+  if(action & GMSH_SET) {
+    v->CT.dpar[COLORTABLE_ALPHAPOW] = val;
+    ColorTable_Recompute(&v->CT);
+    v->Changed = 1;
+  }
+#if defined(HAVE_FLTK)
+  if(_gui_action_valid(action, num)) {
+    WID->view_colorbar_window->redraw();
+  }
+#endif
+  return v->CT.dpar[COLORTABLE_ALPHAPOW];
+}
+
 double opt_view_colormap_beta(OPT_ARGS_NUM)
 {
   GET_VIEW(0.);
diff --git a/Common/Options.h b/Common/Options.h
index c06cc08822..2aa227d09f 100644
--- a/Common/Options.h
+++ b/Common/Options.h
@@ -484,6 +484,7 @@ double opt_view_saturate_values(OPT_ARGS_NUM);
 double opt_view_max_recursion_level(OPT_ARGS_NUM);
 double opt_view_target_error(OPT_ARGS_NUM);
 double opt_view_colormap_alpha(OPT_ARGS_NUM);
+double opt_view_colormap_alpha_power(OPT_ARGS_NUM);
 double opt_view_colormap_beta(OPT_ARGS_NUM);
 double opt_view_colormap_bias(OPT_ARGS_NUM);
 double opt_view_colormap_curvature(OPT_ARGS_NUM);
diff --git a/Fltk/Colorbar_Window.cpp b/Fltk/Colorbar_Window.cpp
index ec60e07f78..f9aeb51832 100644
--- a/Fltk/Colorbar_Window.cpp
+++ b/Fltk/Colorbar_Window.cpp
@@ -1,4 +1,4 @@
-// $Id: Colorbar_Window.cpp,v 1.42 2004-12-24 18:12:22 geuzaine Exp $
+// $Id: Colorbar_Window.cpp,v 1.43 2004-12-24 20:25:11 geuzaine Exp $
 //
 // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
 //
@@ -223,7 +223,7 @@ void Colorbar_Window::redraw_range(int a, int b)
   // print colortable mode and help
   fl_font(FL_HELVETICA, font_height);
   fl_color(fl_contrast(FL_BLACK, color_bg));
-  int xx0 = 10, xx1 = 12 * font_height, yy0 = 10;
+  int xx0 = 8, xx1 = 12 * font_height, yy0 = 8;
   if(help_flag) {
     i = 0;
     fl_draw("0, 1, 2, 3, ...", xx0, yy0 + (i + 1) * font_height);
@@ -244,7 +244,7 @@ void Colorbar_Window::redraw_range(int a, int b)
     fl_draw("Ctrl+mouse1", xx0, yy0 + (i + 1) * font_height);
     fl_draw("draw alpha channel", xx1, yy0 + (i + 1) * font_height);
     i++;
-    fl_draw("c, p, r", xx0, yy0 + (i + 1) * font_height);
+    fl_draw("Ctrl+c, Ctrl+v, r", xx0, yy0 + (i + 1) * font_height);
     fl_draw("copy, paste or reset colormap", xx1, yy0 + (i + 1) * font_height);
     i++;
     fl_draw("m", xx0, yy0 + (i + 1) * font_height);
@@ -262,6 +262,9 @@ void Colorbar_Window::redraw_range(int a, int b)
     fl_draw("a, Ctrl+a", xx0, yy0 + (i + 1) * font_height);
     fl_draw("increase or decrease alpha", xx1, yy0 + (i + 1) * font_height);
     i++;
+    fl_draw("p, Ctrl+p", xx0, yy0 + (i + 1) * font_height);
+    fl_draw("modify alpha channel power law", xx1, yy0 + (i + 1) * font_height);
+    i++;
     fl_draw("b, Ctrl+b", xx0, yy0 + (i + 1) * font_height);
     fl_draw("increase or decrease gamma", xx1, yy0 + (i + 1) * font_height);
     i++;
@@ -443,10 +446,10 @@ int Colorbar_Window::handle(int event)
       ColorTable_InitParam(19, ct);
       compute = 1;
     }
-    else if(Fl::test_shortcut('c')) {
+    else if(Fl::test_shortcut(FL_CTRL + 'c')) {
       ColorTable_Copy(ct);
     }
-    else if(Fl::test_shortcut('p')) {
+    else if(Fl::test_shortcut(FL_CTRL + 'v')) {
       ColorTable_Paste(ct);
       draw();
       *viewchanged = 1;
@@ -498,6 +501,14 @@ int Colorbar_Window::handle(int event)
         ct->dpar[COLORTABLE_ALPHA] = 1.0;
       compute = 1;
     }
+    else if(Fl::test_shortcut('p')) {
+      ct->dpar[COLORTABLE_ALPHAPOW] += 0.05;
+      compute = 1;
+    }
+    else if(Fl::test_shortcut(FL_CTRL + 'p')) {
+      ct->dpar[COLORTABLE_ALPHAPOW] -= 0.05;
+      compute = 1;
+    }
     else if(Fl::test_shortcut(FL_Left)) {
       ct->dpar[COLORTABLE_BIAS] -= 0.05;
       compute = 1;
diff --git a/doc/texinfo/opt_view.texi b/doc/texinfo/opt_view.texi
index f414ec0249..2c42ae2791 100644
--- a/doc/texinfo/opt_view.texi
+++ b/doc/texinfo/opt_view.texi
@@ -89,6 +89,11 @@ Colormap alpha channel value (used only if != 1)@*
 Default value: @code{1}@*
 Saved in: @code{General.OptionsFileName}
 
+@item View.ColormapAlphaPower
+Colormap alpha channel power@*
+Default value: @code{0}@*
+Saved in: @code{General.OptionsFileName}
+
 @item View.ColormapBeta
 Colormap beta parameter (gamma = 1-beta)@*
 Default value: @code{0}@*
-- 
GitLab