~ubuntu-branches/ubuntu/karmic/gmsh/karmic

« back to all changes in this revision

Viewing changes to Post/ColorTable.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme, Christophe Prud'homme, Daniel Leidert
  • Date: 2008-05-18 12:46:05 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20080518124605-716xqbqeo07o497k
Tags: 2.2.0-2
[Christophe Prud'homme]
* Bug fix: "gmsh ships no .desktop", thanks to Vassilis Pandis (Closes:
  #375770). Applied the Ubuntu patch.

[Daniel Leidert]
* debian/control (Vcs-Svn): Fixed.
  (Build-Depends): Use texlive instead of tetex-bin.
* debian/gmsh.doc-base (Section): Fixed accordingly to doc-base (>= 0.8.10).
* debian/rules: Removed some variable declarations, that lead to double
  configuration and seem to be useless.
  (build/gmsh): Try to avoid multiple runs by using a stamp.
  (orig-tarball): Renamed to get-orig-source and changed to use uscan.
* debian/watch: Added.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// $Id: ColorTable.cpp,v 1.1 2007-07-09 13:54:37 geuzaine Exp $
 
1
// $Id: ColorTable.cpp,v 1.5 2008-03-20 11:44:15 geuzaine Exp $
2
2
//
3
 
// Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 
3
// Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
4
4
//
5
5
// This program is free software; you can redistribute it and/or modify
6
6
// it under the terms of the GNU General Public License as published by
28
28
// Copyright (C) 1990 - 1995 Bill Hibbard, Brian Paul, Dave Santek,
29
29
// and Andre Battaiola.
30
30
 
31
 
#include "Gmsh.h"
 
31
#include <string.h>
 
32
#include "Message.h"
32
33
#include "ColorTable.h"
33
34
#include "Context.h"
34
35
#include "Numeric.h"
35
36
 
36
37
extern Context_T CTX;
37
38
 
38
 
void ColorTable_InitParam(int number, GmshColorTable * ct)
 
39
void ColorTable_InitParam(int number, GmshColorTable *ct)
39
40
{
40
41
  ct->size = 255;
41
42
  for(int i = 0; i < COLORTABLE_NBMAX_PARAM; i++){
54
55
 
55
56
static double hot_r(double s)
56
57
{
57
 
  return s < 0. ? 0. : (s < 3./8. ? 8./3. * s : 1.);
 
58
  return s < 0. ? 0. : (s < 3. / 8. ? 8. / 3. * s : 1.);
58
59
}
59
60
 
60
61
static double hot_g(double s)
61
62
{
62
 
  return s < 3./8. ? 0. : (s < 6./8. ? 8./3. * (s - 3./8.) : 1.);
 
63
  return s < 3. / 8. ? 0. : (s < 6. / 8. ? 8. / 3. * (s - 3. / 8.) : 1.);
63
64
}
64
65
 
65
66
static double hot_b(double s)
66
67
{
67
 
  return s < 6./8. ? 0. : (s < 1. ? 8./2. * (s - 6./8.) : 1.);
 
68
  return s < 6. / 8. ? 0. : (s < 1. ? 8. / 2. * (s - 6. / 8.) : 1.);
68
69
}
69
70
 
70
71
static double cubic(double a, double b, double c, double d, double x)
109
110
      break;
110
111
    case 2: // matlab "jet"
111
112
      {
112
 
        double ii = (double)(s-bias)*128.;
113
 
        if(ii < 0) ii = 0;
114
 
        if(ii > 128) ii = 128;
115
 
        double rr = 
116
 
          ii <= 46 ? 0. : 
117
 
          ii >= 111 ? -0.03125*(ii - 111) + 1. :
118
 
          ii >= 78 ? 1. : 
119
 
          0.03125*(ii - 46);
120
 
        double gg = 
121
 
          ii <= 14 || ii >= 111 ? 0. : 
122
 
          ii >= 79 ? -0.03125*(ii - 111) : 
123
 
          ii <= 46 ? 0.03125*(ii - 14) : 
124
 
          1.;
125
 
        double bb =
126
 
          ii >= 79 ? 0. :
127
 
          ii >= 47 ? -0.03125*(ii - 79) :
128
 
          ii <= 14 ? 0.03125*(ii - 14) + 1.:
129
 
          1.;
130
 
        r = (int)(rr*255.);
131
 
        g = (int)(gg*255.);
132
 
        b = (int)(bb*255.);
 
113
        double ii = (double)(s - bias) * 128.;
 
114
        if(ii < 0) ii = 0;
 
115
        if(ii > 128) ii = 128;
 
116
        double rr = 
 
117
          ii <= 46 ? 0. : 
 
118
          ii >= 111 ? -0.03125 * (ii - 111) + 1. :
 
119
          ii >= 78 ? 1. : 
 
120
          0.03125 * (ii - 46);
 
121
        double gg = 
 
122
          ii <= 14 || ii >= 111 ? 0. : 
 
123
          ii >= 79 ? -0.03125 * (ii - 111) : 
 
124
          ii <= 46 ? 0.03125 * (ii - 14) : 
 
125
          1.;
 
126
        double bb =
 
127
          ii >= 79 ? 0. :
 
128
          ii >= 47 ? -0.03125 * (ii - 79) :
 
129
          ii <= 14 ? 0.03125 * (ii - 14) + 1.:
 
130
          1.;
 
131
        r = (int)(rr * 255.);
 
132
        g = (int)(gg * 255.);
 
133
        b = (int)(bb * 255.);
133
134
      }
134
135
      break;
135
136
    case 3: // lucie, samcef (?)
136
137
      if(s - bias <= 0.) {
137
 
        r = 0;
138
 
        g = 0;
139
 
        b = 255;
 
138
        r = 0;
 
139
        g = 0;
 
140
        b = 255;
140
141
      }
141
142
      else if(s - bias <= 0.40) {
142
 
        r = 0;
143
 
        g = (int)((s - bias) * 637.5);
144
 
        b = (int)(255. - (s - bias) * 637.5);
 
143
        r = 0;
 
144
        g = (int)((s - bias) * 637.5);
 
145
        b = (int)(255. - (s - bias) * 637.5);
145
146
      }
146
147
      else if(s - bias <= 0.60) {
147
 
        r = (int)(1275. * (s - bias - 0.4));
148
 
        g = 255;
149
 
        b = 0;
 
148
        r = (int)(1275. * (s - bias - 0.4));
 
149
        g = 255;
 
150
        b = 0;
150
151
      }
151
152
      else if(s - bias <= 1.) {
152
 
        r = 255;
153
 
        g = (int)(255. - 637.5 * (s - bias - 0.6));
154
 
        b = 0;
 
153
        r = 255;
 
154
        g = (int)(255. - 637.5 * (s - bias - 0.6));
 
155
        b = 0;
155
156
      }
156
157
      else {
157
 
        r = 255;
158
 
        g = 0;
159
 
        b = 0;
 
158
        r = 255;
 
159
        g = 0;
 
160
        b = 0;
160
161
      }
161
162
      break;
162
163
    case 4: // rainbow
163
164
      if(s - bias <= 0.) {
164
 
        r = 0;
165
 
        g = 0;
166
 
        b = 255;
 
165
        r = 0;
 
166
        g = 0;
 
167
        b = 255;
167
168
      }
168
169
      else if(s - bias <= 0.25 + curvature) {
169
 
        curvature = (curvature == -0.25) ? -0.26 : curvature;
170
 
        r = 0;
171
 
        g = (int)((s - bias) * (255. / (0.25 + curvature)));
172
 
        b = 255;
 
170
        curvature = (curvature == -0.25) ? -0.26 : curvature;
 
171
        r = 0;
 
172
        g = (int)((s - bias) * (255. / (0.25 + curvature)));
 
173
        b = 255;
173
174
      }
174
175
      else if(s - bias <= 0.50) {
175
 
        curvature = (curvature == 0.25) ? 0.26 : curvature;
176
 
        r = 0;
177
 
        g = 255;
178
 
        b = (int)(255. - (255. / (0.25 - curvature)) * (s - bias - 0.25 - curvature));
 
176
        curvature = (curvature == 0.25) ? 0.26 : curvature;
 
177
        r = 0;
 
178
        g = 255;
 
179
        b = (int)(255. - (255. / (0.25 - curvature)) * (s - bias - 0.25 - curvature));
179
180
      }
180
181
      else if(s - bias <= 0.75 - curvature) {
181
 
        curvature = (curvature == 0.25) ? 0.26 : curvature;
182
 
        r = (int)((s - bias - 0.5) * (255. / (0.25 - curvature)));
183
 
        g = 255;
184
 
        b = 0;
 
182
        curvature = (curvature == 0.25) ? 0.26 : curvature;
 
183
        r = (int)((s - bias - 0.5) * (255. / (0.25 - curvature)));
 
184
        g = 255;
 
185
        b = 0;
185
186
      }
186
187
      else if(s - bias <= 1.) {
187
 
        curvature = (curvature == -0.25) ? -0.26 : curvature;
188
 
        r = 255;
189
 
        g = (int)(255. - (255. / (0.25 + curvature)) * (s - bias - 0.75 + curvature));
190
 
        b = 0;
 
188
        curvature = (curvature == -0.25) ? -0.26 : curvature;
 
189
        r = 255;
 
190
        g = (int)(255. - (255. / (0.25 + curvature)) * (s - bias - 0.75 + curvature));
 
191
        b = 0;
191
192
      }
192
193
      else {
193
 
        r = 255;
194
 
        g = 0;
195
 
        b = 0;
 
194
        r = 255;
 
195
        g = 0;
 
196
        b = 0;
196
197
      }
197
198
      break;
198
199
    case 5: // emc2000 (rainbow with black and white)
199
200
      if(s - bias <= 0.) {
200
 
        r = 0;
201
 
        g = 0;
202
 
        b = 0;
 
201
        r = 0;
 
202
        g = 0;
 
203
        b = 0;
203
204
      }
204
205
      else if(s - bias <= 0.2) {
205
 
        r = (int)(57 * (1 - 100 * ((s - bias) - 0.1) * ((s - bias) - 0.1)));
206
 
        g = 0;
207
 
        b = (int)((s - bias) * (255. / 0.2));
 
206
        r = (int)(57 * (1 - 100 * ((s - bias) - 0.1) * ((s - bias) - 0.1)));
 
207
        g = 0;
 
208
        b = (int)((s - bias) * (255. / 0.2));
208
209
      }
209
210
      else if(s - bias <= 0.3624) {
210
 
        r = 0;
211
 
        g = (int)((s - bias - 0.2) * (255. / 0.1624));
212
 
        b = 255;
 
211
        r = 0;
 
212
        g = (int)((s - bias - 0.2) * (255. / 0.1624));
 
213
        b = 255;
213
214
      }
214
215
      else if(s - bias <= 0.50) {
215
 
        r = 0;
216
 
        g = 255;
217
 
        b = (int)(255. - (255. / 0.1376) * (s - bias - 0.3624));
 
216
        r = 0;
 
217
        g = 255;
 
218
        b = (int)(255. - (255. / 0.1376) * (s - bias - 0.3624));
218
219
      }
219
220
      else if(s - bias <= 0.6376) {
220
 
        r = (int)((s - bias - 0.5) * (255. / 0.1376));
221
 
        g = 255;
222
 
        b = 0;
 
221
        r = (int)((s - bias - 0.5) * (255. / 0.1376));
 
222
        g = 255;
 
223
        b = 0;
223
224
      }
224
225
      else if(s - bias <= 0.8) {
225
 
        r = 255;
226
 
        g = (int)(255. - (255. / 0.1624) * (s - bias - 0.6376));
227
 
        b = 0;
 
226
        r = 255;
 
227
        g = (int)(255. - (255. / 0.1624) * (s - bias - 0.6376));
 
228
        b = 0;
228
229
      }
229
230
      else if(s - bias <= 1.0) {
230
 
        r = 255;
231
 
        g = (int)((255. / 0.2) * (s - bias - 0.8));
232
 
        b = (int)(-3187.66 * (s - bias) * (s - bias) + 7012.76 * (s - bias) - 3570.61);
 
231
        r = 255;
 
232
        g = (int)((255. / 0.2) * (s - bias - 0.8));
 
233
        b = (int)(-3187.66 * (s - bias) * (s - bias) + 7012.76 * (s - bias) - 3570.61);
233
234
      }
234
235
      else {
235
 
        r = 255;
236
 
        g = 255;
237
 
        b = 255;
 
236
        r = 255;
 
237
        g = 255;
 
238
        b = 255;
238
239
      }
239
240
      break;
240
241
    case 6: // darkblue->red->yellow->white
248
249
      b = (int)(255. * hot_b(s-bias));
249
250
      break;
250
251
    case 8: // matlab "pink"
251
 
      r = (int)(255. * sqrt((2.*gray(s-bias) + hot_r(s-bias))/3.));
252
 
      g = (int)(255. * sqrt((2.*gray(s-bias) + hot_g(s-bias))/3.));
253
 
      b = (int)(255. * sqrt((2.*gray(s-bias) + hot_b(s-bias))/3.));
 
252
      r = (int)(255. * sqrt((2. * gray(s - bias) + hot_r(s - bias)) / 3.));
 
253
      g = (int)(255. * sqrt((2. * gray(s - bias) + hot_g(s - bias)) / 3.));
 
254
      b = (int)(255. * sqrt((2. * gray(s - bias) + hot_b(s - bias)) / 3.));
254
255
      break;
255
256
    case 9: // grayscale
256
257
      if(s - bias <= 0.) {
257
 
        r = g = b = 0;
 
258
        r = g = b = 0;
258
259
      }
259
260
      else if(s - bias <= 1.) {
260
 
        r = g = b = (int)(255 * (1. - curvature) * (s - bias));
 
261
        r = g = b = (int)(255 * (1. - curvature) * (s - bias));
261
262
      }
262
263
      else {
263
 
        r = g = b = (int)(255 * (1. - curvature));
 
264
        r = g = b = (int)(255 * (1. - curvature));
264
265
      }
265
266
      break;
266
267
    case 10: // all white
268
269
      break;
269
270
    case 11: // matlab "hsv"
270
271
      {
271
 
        double H = 6. * s + 1.e-10, R, G, B;
272
 
        HSV_to_RGB(H, 1., 1., &R, &G, &B);
273
 
        r = (int)(255 * R);
274
 
        g = (int)(255 * G);
275
 
        b = (int)(255 * B);
 
272
        double H = 6. * s + 1.e-10, R, G, B;
 
273
        HSV_to_RGB(H, 1., 1., &R, &G, &B);
 
274
        r = (int)(255 * R);
 
275
        g = (int)(255 * G);
 
276
        b = (int)(255 * B);
276
277
      }
277
278
      break;
278
279
    case 12: // spectrum (truncated hsv)
279
280
      {
280
 
        double H = 5. * s + 1.e-10, R, G, B;
281
 
        HSV_to_RGB(H, 1., 1., &R, &G, &B);
282
 
        r = (int)(255 * R);
283
 
        g = (int)(255 * G);
284
 
        b = (int)(255 * B);
 
281
        double H = 5. * s + 1.e-10, R, G, B;
 
282
        HSV_to_RGB(H, 1., 1., &R, &G, &B);
 
283
        r = (int)(255 * R);
 
284
        g = (int)(255 * G);
 
285
        b = (int)(255 * B);
285
286
      }
286
287
      break;
287
288
    case 13: // matlab "bone"
288
 
      r = (int)(255. * (7.*gray(s-bias) + hot_b(s-bias))/8.);
289
 
      g = (int)(255. * (7.*gray(s-bias) + hot_g(s-bias))/8.);
290
 
      b = (int)(255. * (7.*gray(s-bias) + hot_r(s-bias))/8.);
 
289
      r = (int)(255. * (7. * gray(s-bias) + hot_b(s - bias)) / 8.);
 
290
      g = (int)(255. * (7. * gray(s-bias) + hot_g(s - bias)) / 8.);
 
291
      b = (int)(255. * (7. * gray(s-bias) + hot_r(s - bias)) / 8.);
291
292
      break;
292
293
    case 14: // matlab "spring"
293
294
      r = (int)(255. * 1.);
294
 
      g = (int)(255. * gray(s-bias));
295
 
      b = (int)(255. * (1. - gray(s-bias)));
 
295
      g = (int)(255. * gray(s - bias));
 
296
      b = (int)(255. * (1. - gray(s - bias)));
296
297
      break;
297
298
    case 15: // matlab "summer"
298
 
      r = (int)(255. * gray(s-bias));
299
 
      g = (int)(255. * (0.5+gray(s-bias)/2.));
 
299
      r = (int)(255. * gray(s - bias));
 
300
      g = (int)(255. * (0.5 + gray(s - bias) / 2.));
300
301
      b = (int)(255. * 0.4);
301
302
      break;
302
303
    case 16: // matlab "autumn"
303
304
      r = (int)(255. * 1.);
304
 
      g = (int)(255. * gray(s-bias));
 
305
      g = (int)(255. * gray(s - bias));
305
306
      b = (int)(255. * 0.);
306
307
      break;
307
308
    case 17: // matlab "winter"
308
309
      r = (int)(255. * 0.);
309
 
      g = (int)(255. * gray(s-bias));
310
 
      b = (int)(255. * (0.5+(1.-gray(s-bias))/2.));
 
310
      g = (int)(255. * gray(s - bias));
 
311
      b = (int)(255. * (0.5 + (1. - gray(s - bias)) / 2.));
311
312
      break;
312
313
    case 18: // matlab "cool"
313
 
      r = (int)(255. * gray(s-bias));
314
 
      g = (int)(255. * (1.-gray(s-bias)));
 
314
      r = (int)(255. * gray(s - bias));
 
315
      g = (int)(255. * (1. - gray(s - bias)));
315
316
      b = (int)(255. * 1.);
316
317
      break;
317
318
    case 19: // matlab "copper"
318
 
      r = (int)(255. * DMIN(1., gray(s-bias) * 1.25));
319
 
      g = (int)(255. * DMIN(1., gray(s-bias) * 0.7812));
320
 
      b = (int)(255. * DMIN(1., gray(s-bias) * 0.4975));
 
319
      r = (int)(255. * DMIN(1., gray(s - bias) * 1.25));
 
320
      g = (int)(255. * DMIN(1., gray(s - bias) * 0.7812));
 
321
      b = (int)(255. * DMIN(1., gray(s - bias) * 0.4975));
321
322
      break;
322
323
    default:
323
324
      r = g = b = 0;
331
332
 
332
333
    if(ct->dpar[COLORTABLE_BETA]) {
333
334
      if(ct->dpar[COLORTABLE_BETA] > 0.0)
334
 
        gamma = 1. - ct->dpar[COLORTABLE_BETA];
 
335
        gamma = 1. - ct->dpar[COLORTABLE_BETA];
335
336
      else
336
 
        gamma = 1. / (1.001 + ct->dpar[COLORTABLE_BETA]); // beta is thresholded to [-1,1]
 
337
        gamma = 1. / (1.001 + ct->dpar[COLORTABLE_BETA]); // beta is thresholded to [-1,1]
337
338
      r = (int)(255. * pow((double)r / 255., gamma));
338
339
      g = (int)(255. * pow((double)g / 255., gamma));
339
340
      b = (int)(255. * pow((double)b / 255., gamma));
425
426
// HSV/RBG conversion routines
426
427
 
427
428
void HSV_to_RGB(double H, double S, double V, 
428
 
                double *R, double *G, double *B) 
 
429
                double *R, double *G, double *B) 
429
430
{
430
431
  if(S < 5.0e-6) {
431
432
    *R = *G = *B = V;
433
434
  else {
434
435
    int i = (int)H;  
435
436
    double f = H - (float)i;
436
 
    double p1 = V*(1.0-S);
437
 
    double p2 = V*(1.0-S*f);
438
 
    double p3 = V*(1.0-S*(1.0-f));
 
437
    double p1 = V * (1.0 - S);
 
438
    double p2 = V * (1.0 - S * f);
 
439
    double p3 = V * (1.0 - S * (1.0 - f));
439
440
    switch(i){
440
441
    case 0: *R = V;   *G = p3;  *B = p1;  break;
441
442
    case 1: *R = p2;  *G = V;   *B = p1;  break;
448
449
}
449
450
 
450
451
void RGB_to_HSV(double R, double G, double B, 
451
 
                double *H, double *S, double *V) 
 
452
                double *H, double *S, double *V) 
452
453
{
453
454
  double maxv = R > G ? R : G; if(B > maxv) maxv = B;
454
455
  *V = maxv;
455
 
  if(maxv>0){
 
456
  if(maxv > 0){
456
457
    double minv = R < G ? R : G; if(B < minv) minv = B;
457
458
    *S = 1.0 - double(minv)/maxv;
458
459
    if(maxv > minv){
459
460
      if(maxv == R){ *H = (G-B)/double(maxv-minv); if (*H<0) *H += 6.0; }
460
 
      else if(maxv == G) *H = 2.0+(B-R)/double(maxv-minv);
461
 
      else *H = 4.0+(R-G)/double(maxv-minv);
 
461
      else if(maxv == G) *H = 2.0 + (B - R) / double(maxv - minv);
 
462
      else *H = 4.0 + (R - G) / double(maxv - minv);
462
463
    }
463
464
  }
464
465
}