GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
vtkLookupTableManager.cxx
Go to the documentation of this file.
1 /*=========================================================================
2 
3 Program: vtkINRIA3D
4 Module: $Id: vtkLookupTableManager.cxx 842 2008-05-20 16:57:09Z ntoussaint $
5 Language: C++
6 Author: $Author: arnaudgelas $
7 Date: $Date: 2009-07-31 14:33:39 -0400 (Fri, 31 Jul 2009) $
8 Version: $Revision: 490 $
9 
10 Copyright (c) 2007 INRIA - Asclepios Project. All rights reserved.
11 
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 
18 /*========================================================================
19  Copyright (c) INRIA - ASCLEPIOS Project (http://www-sop.inria.fr/asclepios).
20  All rights reserved.
21 
22  Redistribution and use in source and binary forms, with or without
23  modification, are permitted provided that the following conditions are met:
24 
25  * Redistributions of source code must retain the above copyright notice,
26  this list of conditions and the following disclaimer.
27 
28  * Redistributions in binary form must reproduce the above copyright notice,
29  this list of conditions and the following disclaimer in the documentation
30  and/or other materials provided with the distribution.
31 
32  * Neither the name of INRIA or ASCLEPIOS, nor the names of any contributors
33  may be used to endorse or promote products derived from this software
34  without specific prior written permission.
35 
36  * Modified source versions must be plainly marked as such, and must not be
37  misrepresented as being the original software.
38 
39  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
40  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
42  ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
43  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
44  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
45  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
46  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
47  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
48  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49  =========================================================================*/
50 
51 /*=========================================================================
52  Modifications were made by the GoFigure Dev. Team.
53  while at Megason Lab, Systems biology, Harvard Medical school, 2009-11
54 
55  Copyright (c) 2009-11, President and Fellows of Harvard College.
56  All rights reserved.
57 
58  Redistribution and use in source and binary forms, with or without
59  modification, are permitted provided that the following conditions are met:
60 
61  Redistributions of source code must retain the above copyright notice,
62  this list of conditions and the following disclaimer.
63  Redistributions in binary form must reproduce the above copyright notice,
64  this list of conditions and the following disclaimer in the documentation
65  and/or other materials provided with the distribution.
66  Neither the name of the President and Fellows of Harvard College
67  nor the names of its contributors may be used to endorse or promote
68  products derived from this software without specific prior written
69  permission.
70 
71  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
72  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
73  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
74  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
75  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
76  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
77  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
78  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
79  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
80  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
81  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
82 
83  =========================================================================*/
84 
85 #include "vtkLookupTableManager.h"
86 #include <vtkObjectFactory.h>
87 
88 vtkCxxRevisionMacro(vtkLookupTableManager, "$Revision: 490 $");
90 
91 #include "lut/Spectrum.h"
92 #include "lut/HotMetal.h"
93 #include "lut/GEColor.h"
94 #include "lut/Flow.h"
95 #include "lut/LONI.h"
96 #include "lut/LONI2.h"
97 #include "lut/Asymmetry.h"
98 #include "lut/Random.h"
99 
100 #include <time.h>
101 
103 {
104 }
105 
107 {
108 }
109 
111 {
112  std::vector< std::string > v_lutNames;
113  v_lutNames.push_back("B/W");
114  v_lutNames.push_back("B/W Inverse");
115  v_lutNames.push_back("Spectrum");
116  v_lutNames.push_back("HotMetal");
117  v_lutNames.push_back("GEColor");
118  v_lutNames.push_back("Flow");
119  v_lutNames.push_back("LONI");
120  v_lutNames.push_back("LONI2");
121  v_lutNames.push_back("Asymmetry");
122  v_lutNames.push_back("P-Value");
123  v_lutNames.push_back("ROI");
124  v_lutNames.push_back("Random");
125 
126  return v_lutNames;
127 }
128 
129 vtkLookupTable * vtkLookupTableManager::GetLookupTable(const int & iIndex)
130 {
131  vtkLookupTable *lut = 0;
132 
133  switch ( iIndex )
134  {
135  case LUT_BW:
137  break;
138 
139  case LUT_BWINV:
141  break;
142 
143  case LUT_SPECTTUM:
145  break;
146 
147  case LUT_HOTMETAL:
149  break;
150 
151  case LUT_GECOLORS:
153  break;
154 
155  case LUT_FLOW:
157  break;
158 
159  case LUT_LONI:
161  break;
162 
163  case LUT_LONI2:
165  break;
166 
167  case LUT_ASYMETRY:
169  break;
170 
171  case LUT_PVALUE:
173  break;
174 
175  case LUT_ROI:
177  break;
178 
179  case LUT_RANDOM:
181  break;
182 
183  default:
184  std::cout << "Unknown Lookup Table" << std::endl;
185  break;
186  }
187 
188  return lut;
189 }
190 
192 {
193  vtkLookupTable *bwLut = vtkLookupTable::New();
194 
195  bwLut->SetTableRange (0, 1);
196  bwLut->SetSaturationRange (0, 0);
197  bwLut->SetHueRange (0, 0);
198  bwLut->SetValueRange (0, 1);
199  bwLut->Build();
200 
201  return bwLut;
202 }
203 
205 {
206  vtkLookupTable *bwLut = vtkLookupTable::New();
207 
208  bwLut->SetTableRange (0, 1);
209  bwLut->SetSaturationRange (0, 0);
210  bwLut->SetHueRange (0, 0);
211  bwLut->SetValueRange (1, 0);
212  bwLut->Build();
213 
214  return bwLut;
215 }
216 
218 {
219  vtkLookupTable *lut = vtkLookupTable::New();
220 
221  lut->SetNumberOfTableValues(256);
222  lut->Build();
223 
224  for ( int i = 0; i < 256; i++ )
225  {
226  lut->SetTableValue(i, (double)Spectrum[i] / 255.0, (double)Spectrum[256 + i] / 255.0,
227  (double)Spectrum[256 * 2 + i] / 255.0, 1.0);
228  }
229 
230  return lut;
231 }
232 
234 {
235  vtkLookupTable *lut = vtkLookupTable::New();
236 
237  lut->SetNumberOfTableValues(256);
238  lut->Build();
239 
240  for ( int i = 0; i < 256; i++ )
241  {
242  lut->SetTableValue(i, (double)HotMetal[i] / 255.0, (double)HotMetal[256 + i] / 255.0,
243  (double)HotMetal[256 * 2 + i] / 255.0, 1.0);
244  }
245 
246  return lut;
247 }
248 
250 {
251  vtkLookupTable *lut = vtkLookupTable::New();
252 
253  lut->SetNumberOfTableValues(256);
254  lut->Build();
255 
256  for ( int i = 0; i < 256; i++ )
257  {
258  lut->SetTableValue(i,
259  (double)GEColor[i] / 255.0,
260  (double)GEColor[256 + i] / 255.0,
261  (double)GEColor[256 * 2 + i] / 255.0,
262  1.0);
263  }
264 
265  return lut;
266 }
267 
269 {
270  vtkLookupTable *lut = vtkLookupTable::New();
271 
272  lut->SetNumberOfTableValues(256);
273  lut->Build();
274 
275  for ( int i = 0; i < 256; i++ )
276  {
277  lut->SetTableValue(i,
278  (double)Flow[i] / 255.0,
279  (double)Flow[256 + i] / 255.0,
280  (double)Flow[256 * 2 + i] / 255.0,
281  1.0);
282  }
283 
284  return lut;
285 }
286 
288 {
289  vtkLookupTable *lut = vtkLookupTable::New();
290 
291  lut->SetNumberOfTableValues(203);
292  lut->Build();
293 
294  for ( int i = 0; i < 203; i++ )
295  {
296  lut->SetTableValue(i, (double)LONI[i][0], (double)LONI[i][1], (double)LONI[i][2], 1.0);
297  }
298 
299  return lut;
300 }
301 
303 {
304  vtkLookupTable *lut = vtkLookupTable::New();
305 
306  lut->SetNumberOfTableValues(120);
307  lut->Build();
308 
309  for ( int i = 0; i < 120; i++ )
310  {
311  lut->SetTableValue(i, (double)LONI2[i][0], (double)LONI2[i][1], (double)LONI2[i][2], 1.0);
312  }
313 
314  return lut;
315 }
316 
318 {
319  vtkLookupTable *lut = vtkLookupTable::New();
320 
321  lut->SetNumberOfTableValues(256);
322  lut->Build();
323 
324  for ( int i = 0; i < 256; i++ )
325  {
326  lut->SetTableValue(i, (double)AsymmetryLUT[i][0], (double)AsymmetryLUT[i][1], (double)AsymmetryLUT[i][2], 1.0);
327  }
328 
329  return lut;
330 }
331 
333 {
334  vtkLookupTable *lut = vtkLookupTable::New();
335 
336  lut->SetTableRange (0, 1);
337  lut->SetSaturationRange (1.0, 1.5);
338  lut->SetHueRange (0.666, 0.8333);
339  //lut->SetHueRange (0.666, 0.0);
340  lut->SetValueRange (0.5, 1.0);
341  lut->Build();
342 
343  return lut;
344 }
345 
347 {
348  vtkLookupTable *lut = vtkLookupTable::New();
349 
350  lut->SetNumberOfTableValues (256);
351  lut->SetTableValue (0, 0.0, 0.0, 0.0, 0.0); // erase color
352 
353  lut->SetTableValue (1, 1.0, 0.0, 0.0, 0.5);
354  lut->SetTableValue (2, 0.0, 1.0, 0.0, 0.5);
355  lut->SetTableValue (3, 0.0, 0.0, 1.0, 0.5);
356  lut->SetTableValue (4, 1.0, 1.0, 0.0, 0.5);
357  lut->SetTableValue (5, 0.0, 1.0, 1.0, 0.5);
358  lut->SetTableValue (6, 1.0, 0.0, 1.0, 0.5);
359 
360  lut->SetTableValue (7, 1.0, 0.5, 0.0, 0.5);
361  lut->SetTableValue (8, 0.0, 1.0, 0.5, 0.5);
362  lut->SetTableValue (9, 0.5, 0.0, 1.0, 0.5);
363  lut->SetTableValue (10, 1.0, 1.0, 0.5, 0.5);
364  lut->SetTableValue (11, 0.5, 1.0, 1.0, 0.5);
365  lut->SetTableValue (12, 1.0, 0.5, 1.0, 0.5);
366 
367  // Fill the rest of the labels with color ramps, code taken from SNAP
368 // for (int i = 13; i < 256; i++)
369 // {
370 // if (i < 85)
371 // {
372 // lut->SetTableValue (i, ((84.0-i)/85.0 * 200.0 + 50.0)/255.0, (i/85.0 *
373 // 200.0 + 50.0)/255.0, 0, 0.5);
374 // }
375 // else if (i < 170)
376 // {
377 // lut->SetTableValue (i, 0, ((169.0-i)/85.0 * 200.0 + 50)/255.0,
378 // ((i-85)/85.0 * 200.0 + 50)/255.0, 0.5);
379 // }
380 // else
381 // {
382 // lut->SetTableValue (i, ((i-170)/85.0 * 200.0 + 50)/255.0, 0.0,
383 // ((255.0-i)/85.0 * 200.0 + 50)/255.0, 0.5);
384 // }
385 // }
386 
387  // Fill the rest with random colors
388 
389 // for (int i = 13; i < 256; i++)
390 // {
391 // srand (clock());
392 
393 // // put a random color
394 // int i1 = 1 + (int) (100.0 * ((double)rand() / (RAND_MAX + 1.0)));
395 // int i2 = 1 + (int) (100.0 * ((double)rand() / (RAND_MAX + 1.0)));
396 // int i3 = 1 + (int) (100.0 * ((double)rand() / (RAND_MAX + 1.0)));
397 // double rand_1 = (double)(i1)/(100.0);
398 // double rand_2 = (double)(i2)/(100.0);
399 // double rand_3 = (double)(i3)/(100.0);
400 // double r = rand_1, g = rand_2, b = rand_3;
401 // if (i1 < 33)
402 // r = 1;
403 // else if (i1 < 66)
404 // g = 1;
405 // else if (i1 < 100)
406 // b = 1;
407 
408 // lut->SetTableValue (i, r, g, b, 0.5);
409 // }
410 
411  for ( int i = 12; i < 256; i++ )
412  {
413  if ( i % 12 == 0 ) { lut->SetTableValue (i, 1.0, 0.0, 0.0, 0.5); }
414  else if ( i % 12 == 1 )
415  {
416  lut->SetTableValue (i, 0.0, 1.0, 0.0, 0.5);
417  }
418  else if ( i % 12 == 2 )
419  {
420  lut->SetTableValue (i, 0.0, 0.0, 1.0, 0.5);
421  }
422  else if ( i % 12 == 3 )
423  {
424  lut->SetTableValue (i, 1.0, 1.0, 0.0, 0.5);
425  }
426  else if ( i % 12 == 4 )
427  {
428  lut->SetTableValue (i, 0.0, 1.0, 1.0, 0.5);
429  }
430  else if ( i % 12 == 5 )
431  {
432  lut->SetTableValue (i, 1.0, 0.0, 1.0, 0.5);
433  }
434  else if ( i % 12 == 6 )
435  {
436  lut->SetTableValue (i, 1.0, 0.5, 0.0, 0.5);
437  }
438  else if ( i % 12 == 7 )
439  {
440  lut->SetTableValue (i, 0.0, 1.0, 0.5, 0.5);
441  }
442  else if ( i % 12 == 8 )
443  {
444  lut->SetTableValue (i, 0.5, 0.0, 1.0, 0.5);
445  }
446  else if ( i % 12 == 9 )
447  {
448  lut->SetTableValue (i, 1.0, 1.0, 0.5, 0.5);
449  }
450  else if ( i % 12 == 10 )
451  {
452  lut->SetTableValue (i, 0.5, 1.0, 1.0, 0.5);
453  }
454  else if ( i % 12 == 11 )
455  {
456  lut->SetTableValue (i, 1.0, 0.5, 1.0, 0.5);
457  }
458  }
459 
460  return lut;
461 }
462 
464 {
465  vtkLookupTable *lut = vtkLookupTable::New();
466 
467  lut->SetNumberOfTableValues(30);
468  lut->Build();
469 
470  int k = 0;
471  int r, g, b;
472 
473  for ( int i = 0; i < 30; i++ )
474  {
475  r = RandomColors[k++];
476  g = RandomColors[k++];
477  b = RandomColors[k++];
478  lut->SetTableValue(i,
479  static_cast< double >( r ) / 255.,
480  static_cast< double >( g ) / 255.,
481  static_cast< double >( b ) / 255.,
482  1.0);
483  }
484 
485  return lut;
486 }
487 
488 vtkLookupTable *
490 {
491  vtkLookupTable *lut = vtkLookupTable::New();
492 
493  lut->SetTableRange (0., 1.);
494  if ( ( iHSV[0] >= 0. ) && ( iHSV[0] <= 1. ) )
495  {
496  lut->SetHueRange (iHSV[0], iHSV[0]);
497  }
498  else
499  {
500  std::cout << "iHSV[0] < 0 or > 1" << std::endl;
501  return NULL;
502  }
503 
504  if ( ( iHSV[1] >= 0. ) && ( iHSV[1] <= 1. ) )
505  {
506  lut->SetSaturationRange (iHSV[1], iHSV[1]);
507  }
508  else
509  {
510  std::cout << "iHSV[1] < 0 or > 1" << std::endl;
511  return NULL;
512  }
513 
514  if ( ( iHSV[2] >= 0. ) && ( iHSV[2] <= 1. ) )
515  {
516  lut->SetValueRange (0., iHSV[2]);
517  }
518  else
519  {
520  std::cout << "iHSV[2] < 0 or > 1" << std::endl;
521  return NULL;
522  }
523 
524  lut->Build();
525 
526  return lut;
527 }
static vtkLookupTable * GetPValueLookupTable(void)
Get the PValue lookup table.
static vtkLookupTable * GetLookupTable(const int &iIndex)
Get the indexed lookup table.
static vtkLookupTable * GetFlowLookupTable(void)
Get the Spectrum lookup table.
static vtkLookupTable * GetGEColorLookupTable(void)
Get the GE Color lookup table.
static vtkLookupTable * GetRandomLookupTable()
Get the Random lookup table.
static vtkLookupTable * GetHSVBasedLookupTable(double iRGB[3])
Get one HSV based lookup table.
static vtkLookupTable * GetLONI2LookupTable(void)
Get the LONI2 lookup table.
static const int Flow[3 *256]
Definition: Flow.h:54
static vtkLookupTable * GetROILookupTable(void)
Get the ROI lookup table.
static const double LONI2[120][3]
Definition: LONI2.h:54
static vtkLookupTable * GetBWLookupTable(void)
Get the BW lookup table.
Define and manage all the lookup tables available in GoFigure2.
static vtkLookupTable * GetHotMetalLookupTable(void)
Get the Hot Metal lookup table.
static const double LONI[203][3]
Definition: LONI.h:54
static const int Spectrum[256 *3]
Definition: Spectrum.h:54
static const int HotMetal[256 *3]
Definition: HotMetal.h:54
static const int RandomColors[90]
Definition: Random.h:44
static vtkLookupTable * GetLONILookupTable(void)
Get the LONI lookup table.
vtkCxxRevisionMacro(vtkLookupTableManager,"$Revision: 490 $")
static const double AsymmetryLUT[256][3]
Definition: Asymmetry.h:54
static const int GEColor[3 *256]
Definition: GEColor.h:54
vtkStandardNewMacro(vtkLookupTableManager)
static vtkLookupTable * GetBWInverseLookupTable(void)
Get the BWInverse lookup table.
static vtkLookupTable * GetSpectrumLookupTable(void)
Get the Spectrum lookup table.
static vtkLookupTable * GetAsymmetryLookupTable(void)
Get the Asymmetry lookup table.
static std::vector< std::string > GetAvailableLookupTables(void)
Get the available lookup table.