vtk-dicom  0.8.17
vtkLookupTable.h
1  /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkLookupTable.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
54 #ifndef vtkLookupTable_h
55 #define vtkLookupTable_h
56 
57 #include "vtkCommonCoreModule.h" // For export macro
58 #include "vtkScalarsToColors.h"
59 
60 #include "vtkUnsignedCharArray.h" // Needed for inline method
61 
62 #define VTK_RAMP_LINEAR 0
63 #define VTK_RAMP_SCURVE 1
64 #define VTK_RAMP_SQRT 2
65 #define VTK_SCALE_LINEAR 0
66 #define VTK_SCALE_LOG10 1
67 
68 class VTKCOMMONCORE_EXPORT vtkLookupTable : public vtkScalarsToColors
69 {
70 public:
72 
76  const static vtkIdType BELOW_RANGE_COLOR_INDEX;
77  const static vtkIdType ABOVE_RANGE_COLOR_INDEX;
78  const static vtkIdType NAN_COLOR_INDEX;
79  const static vtkIdType NUMBER_OF_SPECIAL_COLORS;
81 
86  static vtkLookupTable *New();
87 
88  vtkTypeMacro(vtkLookupTable,vtkScalarsToColors);
89  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
90 
95  int IsOpaque() VTK_OVERRIDE;
96 
100  int Allocate(int sz=256, int ext=256);
101 
106  void Build() VTK_OVERRIDE;
107 
115  virtual void ForceBuild();
116 
120  void BuildSpecialColors();
121 
123 
132  vtkSetMacro(Ramp,int);
133  void SetRampToLinear() { this->SetRamp(VTK_RAMP_LINEAR); };
134  void SetRampToSCurve() { this->SetRamp(VTK_RAMP_SCURVE); };
135  void SetRampToSQRT() { this->SetRamp(VTK_RAMP_SQRT); };
136  vtkGetMacro(Ramp,int);
138 
140 
145  void SetScale(int scale);
146  void SetScaleToLinear() { this->SetScale(VTK_SCALE_LINEAR); };
147  void SetScaleToLog10() { this->SetScale(VTK_SCALE_LOG10); };
148  vtkGetMacro(Scale,int);
150 
152 
160  void SetTableRange(double r[2]);
161  virtual void SetTableRange(double min, double max);
162  vtkGetVectorMacro(TableRange,double,2);
164 
166 
170  vtkSetVector2Macro(HueRange,double);
171  vtkGetVector2Macro(HueRange,double);
173 
175 
179  vtkSetVector2Macro(SaturationRange,double);
180  vtkGetVector2Macro(SaturationRange,double);
182 
184 
188  vtkSetVector2Macro(ValueRange,double);
189  vtkGetVector2Macro(ValueRange,double);
191 
193 
197  vtkSetVector2Macro(AlphaRange,double);
198  vtkGetVector2Macro(AlphaRange,double);
200 
202 
206  vtkSetVector4Macro(NanColor, double);
207  vtkGetVector4Macro(NanColor, double);
209 
214  unsigned char* GetNanColorAsUnsignedChars();
215 
220  static void GetColorAsUnsignedChars(const double colorIn[4],
221  unsigned char colorOut[4]);
222 
224 
228  vtkSetVector4Macro(BelowRangeColor, double);
229  vtkGetVector4Macro(BelowRangeColor, double);
231 
233 
236  vtkSetMacro(UseBelowRangeColor, int);
237  vtkGetMacro(UseBelowRangeColor, int);
238  vtkBooleanMacro(UseBelowRangeColor, int);
240 
242 
246  vtkSetVector4Macro(AboveRangeColor, double);
247  vtkGetVector4Macro(AboveRangeColor, double);
249 
251 
254  vtkSetMacro(UseAboveRangeColor, int);
255  vtkGetMacro(UseAboveRangeColor, int);
256  vtkBooleanMacro(UseAboveRangeColor, int);
258 
262  unsigned char* MapValue(double v) VTK_OVERRIDE;
263 
268  void GetColor(double x, double rgb[3]) VTK_OVERRIDE;
269 
274  double GetOpacity(double v) VTK_OVERRIDE;
275 
284  virtual vtkIdType GetIndex(double v);
285 
287 
291  void SetNumberOfTableValues(vtkIdType number);
292  vtkIdType GetNumberOfTableValues() { return this->NumberOfColors; };
294 
301  virtual void SetTableValue(vtkIdType indx, double rgba[4]);
302 
307  virtual void SetTableValue(vtkIdType indx,
308  double r, double g, double b, double a=1.0);
309 
314  double *GetTableValue(vtkIdType id);
315 
320  void GetTableValue(vtkIdType id, double rgba[4]);
321 
326  unsigned char *GetPointer(const vtkIdType id) {
327  return this->Table->GetPointer(4*id); };
328 
339  unsigned char *WritePointer(const vtkIdType id, const int number);
340 
342 
346  double *GetRange() VTK_OVERRIDE
347  { return this->GetTableRange(); };
348  void SetRange(double min, double max) VTK_OVERRIDE
349  { this->SetTableRange(min, max); };
350  void SetRange(double rng[2]) { this->SetRange(rng[0], rng[1]); };
352 
359  static void GetLogRange(const double range[2], double log_range[2]);
360 
364  static double ApplyLogScale(double v, const double range[2],
365  const double log_range[2]);
366 
368 
374  vtkSetClampMacro(NumberOfColors,vtkIdType,2,VTK_ID_MAX);
375  vtkGetMacro(NumberOfColors,vtkIdType);
377 
379 
384  void SetTable(vtkUnsignedCharArray *);
385  vtkGetObjectMacro(Table,vtkUnsignedCharArray);
387 
393  void MapScalarsThroughTable2(void *input,
394  unsigned char *output,
395  int inputDataType,
396  int numberOfValues,
397  int inputIncrement,
398  int outputIncrement) VTK_OVERRIDE;
399 
403  void DeepCopy(vtkScalarsToColors *lut) VTK_OVERRIDE;
404 
409  int UsingLogScale() VTK_OVERRIDE
410  {
411  return (this->GetScale() == VTK_SCALE_LOG10)? 1 : 0;
412  }
413 
417  vtkIdType GetNumberOfAvailableColors() VTK_OVERRIDE;
418 
426  void GetIndexedColor(vtkIdType idx, double rgba[4]) VTK_OVERRIDE;
427 
428 protected:
429  vtkLookupTable(int sze=256, int ext=256);
430  ~vtkLookupTable() VTK_OVERRIDE;
431 
432  vtkIdType NumberOfColors;
433  vtkUnsignedCharArray *Table;
434  double TableRange[2];
435  double HueRange[2];
436  double SaturationRange[2];
437  double ValueRange[2];
438  double AlphaRange[2];
439  double NanColor[4];
440  double BelowRangeColor[4];
441  int UseBelowRangeColor;
442  double AboveRangeColor[4];
443  int UseAboveRangeColor;
444 
445  int Scale;
446  int Ramp;
447  vtkTimeStamp InsertTime;
448  vtkTimeStamp BuildTime;
449  double RGBA[4]; //used during conversion process
450  unsigned char NanColorChar[4];
451 
452  int OpaqueFlag;
453  vtkTimeStamp OpaqueFlagBuildTime;
454 
458  void ResizeTableForSpecialColors();
459 
460 private:
461  vtkLookupTable(const vtkLookupTable&) VTK_DELETE_FUNCTION;
462  void operator=(const vtkLookupTable&) VTK_DELETE_FUNCTION;
463 };
464 
465 //----------------------------------------------------------------------------
466 inline unsigned char *vtkLookupTable::WritePointer(const vtkIdType id,
467  const int number)
468 {
469  this->InsertTime.Modified();
470  return this->Table->WritePointer(4*id,4*number);
471 }
472 
473 #endif
map scalar values into colors via a lookup table
Definition: vtkLookupTable.h:69
static vtkLookupTable * New()
int UsingLogScale() VTK_OVERRIDE
Definition: vtkLookupTable.h:409
static void GetColorAsUnsignedChars(const double colorIn[4], unsigned char colorOut[4])
static const vtkIdType BELOW_RANGE_COLOR_INDEX
Definition: vtkLookupTable.h:76
void SetNumberOfTableValues(vtkIdType number)
unsigned char * GetPointer(const vtkIdType id)
Definition: vtkLookupTable.h:326
unsigned char * WritePointer(const vtkIdType id, const int number)
Definition: vtkLookupTable.h:466
unsigned char * GetNanColorAsUnsignedChars()
void MapScalarsThroughTable2(void *input, unsigned char *output, int inputDataType, int numberOfValues, int inputIncrement, int outputIncrement) VTK_OVERRIDE
double GetOpacity(double v) VTK_OVERRIDE
virtual void SetTableValue(vtkIdType indx, double r, double g, double b, double a=1.0)
void GetTableValue(vtkIdType id, double rgba[4])
void DeepCopy(vtkScalarsToColors *lut) VTK_OVERRIDE
virtual vtkIdType GetIndex(double v)
void SetTableRange(double r[2])
double * GetRange() VTK_OVERRIDE
Definition: vtkLookupTable.h:346
static void GetLogRange(const double range[2], double log_range[2])
void SetTable(vtkUnsignedCharArray *)
void GetColor(double x, double rgb[3]) VTK_OVERRIDE
virtual void SetTableValue(vtkIdType indx, double rgba[4])
void SetScale(int scale)
static double ApplyLogScale(double v, const double range[2], const double log_range[2])
double * GetTableValue(vtkIdType id)
vtkIdType GetNumberOfAvailableColors() VTK_OVERRIDE
unsigned char * MapValue(double v) VTK_OVERRIDE
int IsOpaque() VTK_OVERRIDE