changeset 20761:47cec845dd5a

Set default colormap to viridis * libinterp/corefcn/graphics.cc(jet_colormap): rename as "viridis_colormap" * libinterp/corefcn/graphics.in.h: use new static function viridis_colormap to initialize the property "colormap"
author Carlo de Falco <carlo.defalco@polimi.it>
date Thu, 26 Nov 2015 13:35:06 +0100
parents 15eefcabcb31
children 0ad449bc8848
files libinterp/corefcn/graphics.cc libinterp/corefcn/graphics.in.h
diffstat 2 files changed, 79 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/graphics.cc	Wed Nov 25 16:20:34 2015 -0800
+++ b/libinterp/corefcn/graphics.cc	Thu Nov 26 13:35:06 2015 +0100
@@ -134,48 +134,88 @@
 }
 
 static Matrix
-jet_colormap (void)
-{
+viridis_colormap (void)
+{
+  // The values below have been produced by viridis (64)(:)
+  // It would be nice to be able to feval the
+  // viridis function but since there is a static property object that includes
+  // a colormap_property object, we need to initialize this before main is
+  // even called, so calling an interpreted function is not possible.
+
+  const double cmapv[] = {
+    2.67004010000000e-01, 2.72651720952381e-01, 2.77106307619048e-01,
+    2.80356151428571e-01, 2.82390045238095e-01, 2.83204606666667e-01,
+    2.82809341428571e-01, 2.81230763333333e-01, 2.78516153333333e-01,
+    2.74735528571429e-01, 2.69981791904762e-01, 2.64368580952381e-01,
+    2.58026184285714e-01, 2.51098684761905e-01, 2.43732853333333e-01,
+    2.36073294285714e-01, 2.28263191428571e-01, 2.20424955714286e-01,
+    2.12666598571429e-01, 2.05079113809524e-01, 1.97721880952381e-01,
+    1.90631350000000e-01, 1.83819438571429e-01, 1.77272360952381e-01,
+    1.70957518571429e-01, 1.64832915714286e-01, 1.58845368095238e-01,
+    1.52951235714286e-01, 1.47131626666667e-01, 1.41402210952381e-01,
+    1.35832975714286e-01, 1.30582113809524e-01, 1.25898377619048e-01,
+    1.22163105714286e-01, 1.19872409523810e-01, 1.19626570000000e-01,
+    1.22045948571429e-01, 1.27667691904762e-01, 1.36834947142857e-01,
+    1.49643331428571e-01, 1.65967274285714e-01, 1.85538397142857e-01,
+    2.08030450000000e-01, 2.33127309523809e-01, 2.60531475238095e-01,
+    2.90000730000000e-01, 3.21329971428571e-01, 3.54355250000000e-01,
+    3.88930322857143e-01, 4.24933143333333e-01, 4.62246770476190e-01,
+    5.00753620000000e-01, 5.40336957142857e-01, 5.80861172380952e-01,
+    6.22170772857143e-01, 6.64087320476191e-01, 7.06403823333333e-01,
+    7.48885251428571e-01, 7.91273132857143e-01, 8.33302102380952e-01,
+    8.74717527142857e-01, 9.15296319047619e-01, 9.54839555238095e-01,
+    9.93247890000000e-01, 4.87433000000000e-03, 2.58456800000000e-02,
+    5.09139004761905e-02, 7.42014957142857e-02, 9.59536042857143e-02,
+    1.16893314761905e-01, 1.37350195714286e-01, 1.57479940000000e-01,
+    1.77347967619048e-01, 1.96969168571429e-01, 2.16330337619048e-01,
+    2.35404660952381e-01, 2.54161735714286e-01, 2.72573219047619e-01,
+    2.90619516666667e-01, 3.08291041428571e-01, 3.25586450952381e-01,
+    3.42517215238095e-01, 3.59102207142857e-01, 3.75366067142857e-01,
+    3.91340913333333e-01, 4.07061480000000e-01, 4.22563764285714e-01,
+    4.37885543809524e-01, 4.53062984285714e-01, 4.68129543809524e-01,
+    4.83117059523810e-01, 4.98052961428571e-01, 5.12959473333333e-01,
+    5.27854311428571e-01, 5.42750087142857e-01, 5.57652481904762e-01,
+    5.72563073333333e-01, 5.87476284285714e-01, 6.02382410952381e-01,
+    6.17265840000000e-01, 6.32106955714286e-01, 6.46881817142857e-01,
+    6.61562926190476e-01, 6.76119717142857e-01, 6.90518987142857e-01,
+    7.04725181904762e-01, 7.18700950000000e-01, 7.32406441904762e-01,
+    7.45802021904762e-01, 7.58846480000000e-01, 7.71497934761905e-01,
+    7.83714033809524e-01, 7.95453081428571e-01, 8.06673890000000e-01,
+    8.17337565714286e-01, 8.27409135714286e-01, 8.36858167619048e-01,
+    8.45663399523809e-01, 8.53815582857143e-01, 8.61321019047619e-01,
+    8.68206316666667e-01, 8.74522215714286e-01, 8.80346158571429e-01,
+    8.85780083333333e-01, 8.90945338571429e-01, 8.95973498571429e-01,
+    9.01005800000000e-01, 9.06156570000000e-01, 3.29415190000000e-01,
+    3.53367293333333e-01, 3.76236064761905e-01, 3.97901482857143e-01,
+    4.18250757142857e-01, 4.37178920000000e-01, 4.54595888571429e-01,
+    4.70433883333333e-01, 4.84653865714286e-01, 4.97250492857143e-01,
+    5.08254501428571e-01, 5.17731949047619e-01, 5.25780221428571e-01,
+    5.32522206190476e-01, 5.38097133333333e-01, 5.42651800000000e-01,
+    5.46335411904762e-01, 5.49287148571429e-01, 5.51635008571429e-01,
+    5.53493173333333e-01, 5.54953478571429e-01, 5.56089070000000e-01,
+    5.56952166666667e-01, 5.57576145714286e-01, 5.57974025714286e-01,
+    5.58142745238095e-01, 5.58058673809524e-01, 5.57684744285714e-01,
+    5.56973310000000e-01, 5.55864478571429e-01, 5.54288677142857e-01,
+    5.52175699047619e-01, 5.49445382857143e-01, 5.46023368571429e-01,
+    5.41830633809524e-01, 5.36795616666667e-01, 5.30847985714286e-01,
+    5.23924198571429e-01, 5.15966779523810e-01, 5.06924262857143e-01,
+    4.96751861428571e-01, 4.85412122857143e-01, 4.72873300000000e-01,
+    4.59105875238095e-01, 4.44095883333333e-01, 4.27825852857143e-01,
+    4.10292713809524e-01, 3.91487632857143e-01, 3.71420688571429e-01,
+    3.50098750000000e-01, 3.27544678571429e-01, 3.03798967142857e-01,
+    2.78916748571429e-01, 2.53000856190476e-01, 2.26223670000000e-01,
+    1.98879439523810e-01, 1.71494930000000e-01, 1.45037631428572e-01,
+    1.21291048571429e-01, 1.03326155238095e-01, 9.53507900000000e-02,
+    1.00469958095238e-01, 1.17876387142857e-01, 1.43936200000000e-01};
+
+  // It would be nice if Matrix had a ctor allowing to do the
+  // following without a copy 
   Matrix cmap (64, 3, 0.0);
-
-  // Produce X in the same manner as linspace so that
-  // jet_colormap and jet.m produce *exactly* the same result.
-  double delta = 1.0 / 63.0;
-
-  for (octave_idx_type i = 0; i < 64; i++)
-    {
-      // This is the jet colormap.  It would be nice to be able to feval the
-      // jet function but since there is a static property object that includes
-      // a colormap_property object, we need to initialize this before main is
-      // even called, so calling an interpreted function is not possible.
-
-      double x = i*delta;
-
-      if (x >= 3.0/8.0 && x < 5.0/8.0)
-        cmap(i,0) = 4.0 * x - 3.0/2.0;
-      else if (x >= 5.0/8.0 && x < 7.0/8.0)
-        cmap(i,0) = 1.0;
-      else if (x >= 7.0/8.0)
-        cmap(i,0) = -4.0 * x + 9.0/2.0;
-
-      if (x >= 1.0/8.0 && x < 3.0/8.0)
-        cmap(i,1) = 4.0 * x - 1.0/2.0;
-      else if (x >= 3.0/8.0 && x < 5.0/8.0)
-        cmap(i,1) = 1.0;
-      else if (x >= 5.0/8.0 && x < 7.0/8.0)
-        cmap(i,1) = -4.0 * x + 7.0/2.0;
-
-      if (x < 1.0/8.0)
-        cmap(i,2) = 4.0 * x + 1.0/2.0;
-      else if (x >= 1.0/8.0 && x < 3.0/8.0)
-        cmap(i,2) = 1.0;
-      else if (x >= 3.0/8.0 && x < 5.0/8.0)
-        cmap(i,2) = -4.0 * x + 5.0/2.0;
-    }
-
+  std::copy (cmapv, cmapv + (64*3), cmap.fortran_vec ());
   return cmap;
 }
 
+
 static double
 default_screendepth (void)
 {
--- a/libinterp/corefcn/graphics.in.h	Wed Nov 25 16:20:34 2015 -0800
+++ b/libinterp/corefcn/graphics.in.h	Thu Nov 26 13:35:06 2015 +0100
@@ -3434,7 +3434,7 @@
       callback_property buttondownfcn , Matrix ()
       callback_property closerequestfcn , "closereq"
       color_property color , color_property (color_values (1, 1, 1), radio_values ("none"))
-      array_property colormap , jet_colormap ()
+      array_property colormap , viridis_colormap ()
       handle_property currentaxes S , graphics_handle ()
       string_property currentcharacter r , ""
       handle_property currentobject r , graphics_handle ()