SMILX  1.01
milxColourMap.cxx
1 /*=========================================================================
2  The Software is copyright (c) Commonwealth Scientific and Industrial Research Organisation (CSIRO)
3  ABN 41 687 119 230.
4  All rights reserved.
5 
6  Licensed under the CSIRO BSD 3-Clause License
7  You may not use this file except in compliance with the License.
8  You may obtain a copy of the License in the file LICENSE.md or at
9 
10  https://stash.csiro.au/projects/SMILI/repos/smili/browse/license.txt
11 
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  See the License for the specific language governing permissions and
16  limitations under the License.
17 =========================================================================*/
18 #include "milxColourMap.h"
19 
20 namespace milx
21 {
22 
23 
24 ColourMap::ColourMap()
25 {
26  reset();
27 
28  mapRange[0] = 0;
29  mapRange[1] = 255;
30 
31  lookupTable = vtkSmartPointer<vtkLookupTable>::New();
32 }
33 
34 ColourMap::~ColourMap()
35 {
36 
37 }
38 
39 void ColourMap::reset()
40 {
41  mapFlag = RAINBOW;
42  generated = false;
43 }
44 
45 vtkSmartPointer<vtkLookupTable> ColourMap::GetOutput()
46 {
47  if(!generated)
48  GenerateData();
49 
50  return lookupTable;
51 }
52 
53 void ColourMap::GenerateData()
54 {
55  double tblRange[2] = {0, 255};
56 
57  lookupTable->SetNanColor(0.85, 0.85, 0.85, 1.0);
58  lookupTable->SetTableRange(mapRange[0], mapRange[1]);
59 // lookupTable->SetTableRange(tblRange[0], tblRange[1]);
60 
61  switch(mapFlag)
62  {
63  case JET:
64  {
65  lookupTable->SetNumberOfTableValues( 256 );
66  lookupTable->Build();
67 
68  lookupTable->SetTableValue(0, JET_ARRAY[0][0], JET_ARRAY[0][1], JET_ARRAY[0][2], 0.0); //transparent
69  for( unsigned int i=1; i<256; i++ )
70  lookupTable->SetTableValue(i, JET_ARRAY[i][0], JET_ARRAY[i][1], JET_ARRAY[i][2], 1.0);
71 
72  break;
73  }
74 
75  case RAINBOW:
76  {
77  lookupTable->SetNumberOfTableValues( 256 );
78  lookupTable->Build();
79 
80  lookupTable->SetTableValue(0, RAINBOW_ARRAY[0][0], RAINBOW_ARRAY[0][1], RAINBOW_ARRAY[0][2], 0.0); //transparent
81  for( unsigned int i=1; i<256; i++ )
82  lookupTable->SetTableValue(i, RAINBOW_ARRAY[i][0], RAINBOW_ARRAY[i][1], RAINBOW_ARRAY[i][2], 1.0);
83 
84  break;
85  }
86 
87  case VTK:
88  {
89  lookupTable->SetNumberOfColors(256);
90  lookupTable->SetHueRange(0.667, 0.0); // 0.667 for blue, and 0 for red
91  lookupTable->Build();
92 
93  break;
94  }
95 
96  case NIH:
97  {
98  lookupTable->SetNumberOfTableValues( 256 );
99  lookupTable->Build();
100 
101  lookupTable->SetTableValue(0, NIH_ARRAY[0][0], NIH_ARRAY[0][1], NIH_ARRAY[0][2], 0.0); //transparent
102  for( unsigned int i=1; i<256; i++ )
103  lookupTable->SetTableValue(i, NIH_ARRAY[i][0], NIH_ARRAY[i][1], NIH_ARRAY[i][2], 1.0);
104 
105  break;
106  }
107 
108  case NIH_FIRE:
109  {
110  lookupTable->SetNumberOfTableValues( 256 );
111  lookupTable->Build();
112 
113  lookupTable->SetTableValue(0, NIH_FIRE_ARRAY[0][0], NIH_FIRE_ARRAY[0][1], NIH_FIRE_ARRAY[0][2], 0.0); //transparent
114  for( unsigned int i=1; i<256; i++ )
115  lookupTable->SetTableValue(i, NIH_FIRE_ARRAY[i][0], NIH_FIRE_ARRAY[i][1], NIH_FIRE_ARRAY[i][2], 1.0);
116 
117  break;
118  }
119 
120  case HOT:
121  {
122  lookupTable->SetNumberOfTableValues( 256 );
123  lookupTable->Build();
124 
125  lookupTable->SetTableValue(0, HOT_ARRAY[0][0], HOT_ARRAY[0][1], HOT_ARRAY[0][2], 0.0); //transparent
126  for( unsigned int i=1; i<256; i++ )
127  lookupTable->SetTableValue(i, HOT_ARRAY[i][0], HOT_ARRAY[i][1], HOT_ARRAY[i][2], 1.0);
128 
129  /*lookupTable->SetRange( 0.0, 255.0 );
130  lookupTable->SetHueRange( 0.0, 0.1 );
131  lookupTable->SetValueRange( 0.4, 0.8 );
132  lookupTable->Build();*/
133 
134  break;
135  }
136 
137  case COOL:
138 
139  lookupTable->SetNumberOfTableValues( 256 );
140  lookupTable->Build();
141 
142  lookupTable->SetTableValue(0, COOL_ARRAY[0][0], COOL_ARRAY[0][1], COOL_ARRAY[0][2], 0.0); //transparent
143  for( unsigned int i=1; i<256; i++ )
144  lookupTable->SetTableValue(i, COOL_ARRAY[i][0], COOL_ARRAY[i][1], COOL_ARRAY[i][2], 1.0);
145 
146  break;
147 
148  case COOLWARM:
149  {
150  lookupTable->SetNumberOfTableValues( 256 );
151  lookupTable->Build();
152 
153  lookupTable->SetTableValue(0, COOLWARM_ARRAY[0][0], COOLWARM_ARRAY[0][1], COOLWARM_ARRAY[0][2], 0.0); //transparent
154  for( unsigned int i=1; i<256; i++ )
155  lookupTable->SetTableValue(i, COOLWARM_ARRAY[i][0], COOLWARM_ARRAY[i][1], COOLWARM_ARRAY[i][2], 1.0);
156 
157  break;
158  }
159 
160  case KNEE:
161  {
162  lookupTable->SetNumberOfTableValues( 256 );
163  lookupTable->Build();
164 
165  lookupTable->SetTableValue(0, KNEE_ARRAY[0][0], KNEE_ARRAY[0][1], KNEE_ARRAY[0][2], 0.0); //transparent
166  for( unsigned int i=1; i<256; i++ )
167  lookupTable->SetTableValue(i, KNEE_ARRAY[i][0], KNEE_ARRAY[i][1], KNEE_ARRAY[i][2], 1.0);
168 
169  break;
170  }
171 
172  case AAL:
173  {
174  lookupTable->SetNumberOfTableValues( 256 );
175  lookupTable->Build();
176 
177  lookupTable->SetTableValue(0, AAL_ARRAY[0][0], AAL_ARRAY[0][1], AAL_ARRAY[0][2], 0.0); //transparent
178  for( unsigned int i=1; i<256; i++ )
179  lookupTable->SetTableValue(i, AAL_ARRAY[i][0], AAL_ARRAY[i][1], AAL_ARRAY[i][2], 1.0);
180 
181  break;
182  }
183 
184  case FS:
185  {
186  lookupTable->SetNumberOfTableValues( 256 );
187  lookupTable->Build();
188 
189  lookupTable->SetTableValue(0, FS_ARRAY[0][0], FS_ARRAY[0][1], FS_ARRAY[0][2], 0.0); //transparent
190  for( unsigned int i=1; i<256; i++ )
191  lookupTable->SetTableValue(i, FS_ARRAY[i][0], FS_ARRAY[i][1], FS_ARRAY[i][2], 1.0);
192 
193  break;
194  }
195 
196 // else if (colourmap == "Muscles")
197 // {
198 // lookupTable->SetNumberOfTableValues( 256 );
199 // lookupTable->SetTableRange(0, tblRange[1]);
200 // lookupTable->Build();
201 //
202 // unsigned char *p = lookupTable->WritePointer(0, 1);
203 // for (unsigned int j=0; j<3; ++j)
204 // *p++ = static_cast<unsigned char>(Muscles[0][j]*tblRange[1]);
205 // *p++ = static_cast<unsigned char>(0);
206 // for( unsigned int i=1; i<256; i++ )
207 // {
208 // p = lookupTable->WritePointer(i, 1);
209 // for (unsigned int j=0; j<3; ++j)
210 // *p++ = static_cast<unsigned char>(Muscles[i][j]*tblRange[1]);
211 // *p++ = static_cast<unsigned char>(tblRange[1]);
212 // }
213 // }
214  case LOG_GRAY:
215 
216  lookupTable->SetHueRange(0.0, 0.0);
217  lookupTable->SetSaturationRange(0, 0);
218  lookupTable->SetNumberOfTableValues(256);
219  lookupTable->SetValueRange(0, 1);
220  lookupTable->SetScaleToLog10();
221  lookupTable->Build();
222 
223  lookupTable->SetTableValue(0, 0.0, 0.0, 0.0, 0.0); //transparent
224 
225  break;
226 
227  case GRAY:
228 
229  lookupTable->SetHueRange(0.0, 0.0);
230  lookupTable->SetSaturationRange(0, 0);
231  lookupTable->SetNumberOfTableValues(256);
232  lookupTable->SetValueRange(0.2, 1);
233  lookupTable->Build();
234 
235  lookupTable->SetTableValue(0, 0.0, 0.0, 0.0, 0.0); //transparent
236 
237  break;
238 
239  case SEISMIC:
240 
241  lookupTable->SetNumberOfTableValues(256);
242  lookupTable->Build();
243 
244  lookupTable->SetTableValue(0, SEISMIC_ARRAY[0][0], SEISMIC_ARRAY[0][1], SEISMIC_ARRAY[0][2], 0.0); //transparent
245  for( unsigned int i=1; i<256; i++ )
246  lookupTable->SetTableValue(i, SEISMIC_ARRAY[i][0], SEISMIC_ARRAY[i][1], SEISMIC_ARRAY[i][2], 1.0);
247 
248  break;
249 
250  case BONE:
251 
252  lookupTable->SetNumberOfTableValues(256);
253  lookupTable->Build();
254 
255  lookupTable->SetTableValue(0, BONE_ARRAY[0][0], BONE_ARRAY[0][1], BONE_ARRAY[0][2], 0.0); //transparent
256  for( unsigned int i=1; i<256; i++ )
257  lookupTable->SetTableValue(i, BONE_ARRAY[i][0], BONE_ARRAY[i][1], BONE_ARRAY[i][2], 1.0);
258 
259  break;
260 
261  case SPECTRAL:
262 
263  lookupTable->SetNumberOfTableValues(256);
264  lookupTable->Build();
265 
266  lookupTable->SetTableValue(0, SPECTRAL_ARRAY[0][0], SPECTRAL_ARRAY[0][1], SPECTRAL_ARRAY[0][2], 0.0); //transparent
267  for( unsigned int i=1; i<256; i++ )
268  lookupTable->SetTableValue(i, SPECTRAL_ARRAY[i][0], SPECTRAL_ARRAY[i][1], SPECTRAL_ARRAY[i][2], 1.0);
269 
270  break;
271 
272  case GNUPLOT:
273 
274  lookupTable->SetNumberOfTableValues(256);
275  lookupTable->Build();
276 
277  lookupTable->SetTableValue(0, GNUPLOT_ARRAY[0][0], GNUPLOT_ARRAY[0][1], GNUPLOT_ARRAY[0][2], 0.0); //transparent
278  for( unsigned int i=1; i<256; i++ )
279  lookupTable->SetTableValue(i, GNUPLOT_ARRAY[i][0], GNUPLOT_ARRAY[i][1], GNUPLOT_ARRAY[i][2], 1.0);
280 
281  break;
282 
283  case CUBEHELIX:
284 
285  lookupTable->SetNumberOfTableValues(256);
286  lookupTable->Build();
287 
288  lookupTable->SetTableValue(0, CUBEHELIX_ARRAY[0][0], CUBEHELIX_ARRAY[0][1], CUBEHELIX_ARRAY[0][2], 0.0); //transparent
289  for( unsigned int i=1; i<256; i++ )
290  lookupTable->SetTableValue(i, CUBEHELIX_ARRAY[i][0], CUBEHELIX_ARRAY[i][1], CUBEHELIX_ARRAY[i][2], 1.0);
291 
292  break;
293 
294  case HSV:
295 
296  lookupTable->SetNumberOfTableValues(256);
297  lookupTable->Build();
298 
299  lookupTable->SetTableValue(0, HSV_ARRAY[0][0], HSV_ARRAY[0][1], HSV_ARRAY[0][2], 0.0); //transparent
300  for( unsigned int i=1; i<256; i++ )
301  lookupTable->SetTableValue(i, HSV_ARRAY[i][0], HSV_ARRAY[i][1], HSV_ARRAY[i][2], 1.0);
302 
303  break;
304 
305  default:
306 
307  lookupTable->SetNumberOfTableValues(256);
308  lookupTable->Build();
309 
310  break;
311 
312  }
313 
314  generated = true;
315 }
316 
317 } //end namespace
vtkSmartPointer< vtkLookupTable > GetOutput()
Get the colourmap set.