MechSys  1.0
Computing library for simulations in continuum and discrete mechanics
/home/dorival/mechsys/lib/mpm/colormaps.h
Go to the documentation of this file.
00001 /************************************************************************
00002  * MechSys - Open Library for Mechanical Systems                        *
00003  * Copyright (C) 2005 Dorival M. Pedroso                                *
00004  *                                                                      *
00005  * This program is free software: you can redistribute it and/or modify *
00006  * it under the terms of the GNU General Public License as published by *
00007  * the Free Software Foundation, either version 3 of the License, or    *
00008  * any later version.                                                   *
00009  *                                                                      *
00010  * This program is distributed in the hope that it will be useful,      *
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the         *
00013  * GNU General Public License for more details.                         *
00014  *                                                                      *
00015  * You should have received a copy of the GNU General Public License    *
00016  * along with this program. If not, see <http://www.gnu.org/licenses/>  *
00017  ************************************************************************/
00018 
00019 /* ColorMaps - Copyright (C) 2007 Dorival de Moraes Pedroso */
00020 
00021 #ifndef MPM_COLORMAP_H
00022 #define MPM_COLORMAP_H
00023 
00024 // FLTK
00025 #include <FL/Enumerations.H> // for Fl_Color
00026 #include <FL/Fl_Choice.H>
00027 
00028 // MechSys
00029 #include <mechsys/util/colors.h>
00030 
00032 namespace ClrMap
00033 {
00034 
00035 Fl_Menu_Item Items[] =
00036 {
00037     {"BW/Paper" , 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 0, 0},
00038     {"Hot"      , 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 0, 0},
00039     {"Jet"      , 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 0, 0},
00040     {0,0,0,0,0,0,0,0,0}
00041 };
00042 
00044 struct Colour
00045 {
00046     double R;
00047     double G;
00048     double B;
00049 }; // struct Colour
00050 
00051 // Color maps
00052 const size_t BWP_NCOLORS = 9;
00053 const Colour BWP_RGB[]=
00054 {{ 0.0  , 0.0  , 0.0  },
00055  { 0.15 , 0.15 , 0.5  },
00056  { 0.3  , 0.15 , 0.75 },
00057  { 0.6  , 0.2  , 0.5  },
00058  { 1.0  , 0.25 , 0.15 },
00059  { 0.9  , 0.5  , 0.0  },
00060  { 0.9  , 0.75 , 0.1  },
00061  { 0.9  , 0.9  , 0.5  },
00062  { 1.0  , 1.0  , 1.0  }};
00063 const size_t HOT_NCOLORS = 12;
00064 const Colour HOT_RGB[]=
00065 {{ 0.25 , 0.0  , 0.0  },
00066  { 0.5  , 0.0  , 0.0  },
00067  { 0.75 , 0.0  , 0.0  },
00068  { 1.0  , 0.0  , 0.0  },
00069  { 1.0  , 0.25 , 0.0  },
00070  { 1.0  , 0.5  , 0.0  },
00071  { 1.0  , 0.75 , 0.0  },
00072  { 1.0  , 1.0  , 0.0  },
00073  { 1.0  , 1.0  , 0.25 },
00074  { 1.0  , 1.0  , 0.5  },
00075  { 1.0  , 1.0  , 0.75 },
00076  { 1.0  , 1.0  , 1.0  }};
00077 const size_t JET_NCOLORS = 12;
00078 const Colour JET_RGB[]=
00079 {{ 0.0     , 0.0     , 2.0/3.0 },
00080  { 0.0     , 0.0     , 1.0     },
00081  { 0.0     , 1.0/3.0 , 1.0     },
00082  { 0.0     , 2.0/3.0 , 1.0     },
00083  { 0.0     , 1.0     , 1.0     },
00084  { 1.0/3.0 , 1.0     , 2.0/3.0 },
00085  { 2.0/3.0 , 1.0     , 1.0/3.0 },
00086  { 1.0     , 1.0     , 0.0     },
00087  { 1.0     , 2.0/3.0 , 0.0     },
00088  { 1.0     , 1.0/3.0 , 0.0     },
00089  { 1.0     , 0.0     , 0.0     },
00090  { 2.0/3.0 , 0.0     , 0.0     }};
00091 
00092 static inline Fl_Color Color2FlColor (Colour const & C)
00093 {
00094     uchar r = static_cast<uchar>(C.R*255.0);
00095     uchar g = static_cast<uchar>(C.G*255.0);
00096     uchar b = static_cast<uchar>(C.B*255.0);
00097     return fl_rgb_color (r,g,b);
00098 }
00099 
00100 Fl_Color BWP [BWP_NCOLORS];
00101 Fl_Color HOT [HOT_NCOLORS];
00102 Fl_Color JET [JET_NCOLORS];
00103 
00104 static inline int __initialize_colormaps ()
00105 {
00106     for (size_t i=0; i<BWP_NCOLORS; ++i) BWP[i] = Color2FlColor (BWP_RGB[i]);
00107     for (size_t i=0; i<HOT_NCOLORS; ++i) HOT[i] = Color2FlColor (HOT_RGB[i]);
00108     for (size_t i=0; i<JET_NCOLORS; ++i) JET[i] = Color2FlColor (JET_RGB[i]);
00109     return 0;
00110 }
00111 
00112 int __dummy_initialize_colormaps = __initialize_colormaps ();
00113 
00114 
00115 
00116 // Auxiliary functions
00117 Array<Fl_Color> __colorset;
00118 
00119 int __init_colorset()
00120 {
00121     Vec3_t const * c = &Colors::Get("yellow_light");
00122     uchar r = static_cast<uchar>((*c)(0)*255.0);
00123     uchar g = static_cast<uchar>((*c)(1)*255.0);
00124     uchar b = static_cast<uchar>((*c)(2)*255.0);
00125     __colorset.Push (fl_rgb_color(r,g,b));
00126 
00127     c = &Colors::Get("melon");
00128     r = static_cast<uchar>((*c)(0)*255.0);
00129     g = static_cast<uchar>((*c)(1)*255.0);
00130     b = static_cast<uchar>((*c)(2)*255.0);
00131     __colorset.Push (fl_rgb_color(r,g,b));
00132 
00133     c = &Colors::Get("peacock");
00134     r = static_cast<uchar>((*c)(0)*255.0);
00135     g = static_cast<uchar>((*c)(1)*255.0);
00136     b = static_cast<uchar>((*c)(2)*255.0);
00137     __colorset.Push (fl_rgb_color(r,g,b));
00138 
00139     return 0;
00140 }
00141 
00142 int __dummy_init_colorset = __init_colorset();
00143 
00144 Fl_Color GetColor (int Tag)
00145 {
00146     if      (Tag==-1) return __colorset[0];
00147     else if (Tag==-2) return __colorset[1];
00148     else              return __colorset[2];
00149 }
00150 
00151 }; // namespace ClrMap
00152 
00153 #endif // MPM_COLORMAP_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines