VTK
vtkLookupTable.h
Go to the documentation of this file.
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 =========================================================================*/
60 #ifndef vtkLookupTable_h
61 #define vtkLookupTable_h
62 
63 #include "vtkCommonCoreModule.h" // For export macro
64 #include "vtkScalarsToColors.h"
65 
66 #include "vtkUnsignedCharArray.h" // Needed for inline method
67 
68 #define VTK_RAMP_LINEAR 0
69 #define VTK_RAMP_SCURVE 1
70 #define VTK_RAMP_SQRT 2
71 #define VTK_SCALE_LINEAR 0
72 #define VTK_SCALE_LOG10 1
73 
74 class VTKCOMMONCORE_EXPORT vtkLookupTable : public vtkScalarsToColors
75 {
76 public:
78 
86  static const vtkIdType NAN_COLOR_INDEX;
89 
94  static vtkLookupTable *New();
95 
97  void PrintSelf(ostream& os, vtkIndent indent) override;
98 
103  int IsOpaque() override;
104 
109  int Allocate(int sz=256, int ext=256);
110 
115  void Build() override;
116 
124  virtual void ForceBuild();
125 
129  void BuildSpecialColors();
130 
132 
144  vtkSetMacro(Ramp,int);
145  void SetRampToLinear() { this->SetRamp(VTK_RAMP_LINEAR); }
146  void SetRampToSCurve() { this->SetRamp(VTK_RAMP_SCURVE); }
147  void SetRampToSQRT() { this->SetRamp(VTK_RAMP_SQRT); }
148  vtkGetMacro(Ramp,int);
150 
152 
157  void SetScale(int scale);
158  void SetScaleToLinear() { this->SetScale(VTK_SCALE_LINEAR); }
159  void SetScaleToLog10() { this->SetScale(VTK_SCALE_LOG10); }
160  vtkGetMacro(Scale,int);
162 
164 
172  virtual void SetTableRange(const double r[2]);
173  virtual void SetTableRange(double min, double max);
174  vtkGetVectorMacro(TableRange,double,2);
176 
178 
182  vtkSetVector2Macro(HueRange,double);
183  vtkGetVector2Macro(HueRange,double);
185 
187 
191  vtkSetVector2Macro(SaturationRange,double);
192  vtkGetVector2Macro(SaturationRange,double);
194 
196 
200  vtkSetVector2Macro(ValueRange,double);
201  vtkGetVector2Macro(ValueRange,double);
203 
205 
209  vtkSetVector2Macro(AlphaRange,double);
210  vtkGetVector2Macro(AlphaRange,double);
212 
214 
218  vtkSetVector4Macro(NanColor, double);
219  vtkGetVector4Macro(NanColor, double);
221 
226  unsigned char* GetNanColorAsUnsignedChars();
227 
231  static void GetColorAsUnsignedChars(const double colorIn[4],
232  unsigned char colorOut[4]);
233 
235 
239  vtkSetVector4Macro(BelowRangeColor, double);
240  vtkGetVector4Macro(BelowRangeColor, double);
242 
244 
247  vtkSetMacro(UseBelowRangeColor, vtkTypeBool);
248  vtkGetMacro(UseBelowRangeColor, vtkTypeBool);
249  vtkBooleanMacro(UseBelowRangeColor, vtkTypeBool);
251 
253 
257  vtkSetVector4Macro(AboveRangeColor, double);
258  vtkGetVector4Macro(AboveRangeColor, double);
260 
262 
265  vtkSetMacro(UseAboveRangeColor, vtkTypeBool);
266  vtkGetMacro(UseAboveRangeColor, vtkTypeBool);
267  vtkBooleanMacro(UseAboveRangeColor, vtkTypeBool);
269 
273  const unsigned char* MapValue(double v) override;
274 
279  void GetColor(double x, double rgb[3]) override;
280 
285  double GetOpacity(double v) override;
286 
296  virtual vtkIdType GetIndex(double v);
297 
299 
302  void SetNumberOfTableValues(vtkIdType number);
303  vtkIdType GetNumberOfTableValues() { return this->NumberOfColors; }
305 
312  virtual void SetTableValue(vtkIdType indx, const double rgba[4]);
313 
318  virtual void SetTableValue(vtkIdType indx,
319  double r, double g, double b, double a=1.0);
320 
325  double *GetTableValue(vtkIdType id) VTK_SIZEHINT(4);
326 
331  void GetTableValue(vtkIdType id, double rgba[4]);
332 
337  unsigned char *GetPointer(vtkIdType id) {
338  return this->Table->GetPointer(4*id); }
339 
350  unsigned char *WritePointer(vtkIdType id, int number);
351 
353 
357  double *GetRange() VTK_SIZEHINT(2) override
358  { return this->GetTableRange(); }
359  void SetRange(double min, double max) override
360  { this->SetTableRange(min, max); }
361  void SetRange(const double rng[2]) override { this->SetRange(rng[0], rng[1]); }
363 
370  static void GetLogRange(const double range[2], double log_range[2]);
371 
375  static double ApplyLogScale(double v, const double range[2],
376  const double log_range[2]);
377 
379 
385  vtkSetClampMacro(NumberOfColors,vtkIdType,2,VTK_ID_MAX);
386  vtkGetMacro(NumberOfColors,vtkIdType);
388 
390 
395  void SetTable(vtkUnsignedCharArray *);
396  vtkGetObjectMacro(Table,vtkUnsignedCharArray);
398 
404  void MapScalarsThroughTable2(void *input,
405  unsigned char *output,
406  int inputDataType,
407  int numberOfValues,
408  int inputIncrement,
409  int outputIncrement) override;
410 
414  void DeepCopy(vtkScalarsToColors *lut) override;
415 
420  int UsingLogScale() override
421  {
422  return (this->GetScale() == VTK_SCALE_LOG10) ? 1 : 0;
423  }
424 
429 
437  void GetIndexedColor(vtkIdType idx, double rgba[4]) override;
438 
439 protected:
440  vtkLookupTable(int sze=256, int ext=256);
441  ~vtkLookupTable() override;
442 
445  double TableRange[2];
446  double HueRange[2];
447  double SaturationRange[2];
448  double ValueRange[2];
449  double AlphaRange[2];
450  double NanColor[4];
451  double BelowRangeColor[4];
453  double AboveRangeColor[4];
455 
456  int Scale;
457  int Ramp;
460  double RGBA[4]; //used during conversion process
461  unsigned char NanColorChar[4];
462 
466 
470  void ResizeTableForSpecialColors();
471 
472 private:
473  vtkLookupTable(const vtkLookupTable&) = delete;
474  void operator=(const vtkLookupTable&) = delete;
475 };
476 
477 //----------------------------------------------------------------------------
478 inline unsigned char *vtkLookupTable::WritePointer(vtkIdType id,
479  int number)
480 {
481  this->InsertTime.Modified();
482  return this->Table->WritePointer(4*id, 4*number);
483 }
484 
485 #endif
vtkLookupTable::NumberOfColors
vtkIdType NumberOfColors
Definition: vtkLookupTable.h:443
vtkAOSDataArrayTemplate::WritePointer
ValueType * WritePointer(vtkIdType valueIdx, vtkIdType numValues)
Get the address of a particular data index.
vtkLookupTable::OpaqueFlagBuildTime
vtkTimeStamp OpaqueFlagBuildTime
Definition: vtkLookupTable.h:464
vtkX3D::scale
Definition: vtkX3D.h:229
vtkLookupTable::UseAboveRangeColor
vtkTypeBool UseAboveRangeColor
Definition: vtkLookupTable.h:454
vtkIdType
int vtkIdType
Definition: vtkType.h:347
vtkLookupTable::NAN_COLOR_INDEX
static const vtkIdType NAN_COLOR_INDEX
Definition: vtkLookupTable.h:86
vtkLookupTable::ABOVE_RANGE_COLOR_INDEX
static const vtkIdType ABOVE_RANGE_COLOR_INDEX
Definition: vtkLookupTable.h:85
vtkLookupTable::BELOW_RANGE_COLOR_INDEX
static const vtkIdType BELOW_RANGE_COLOR_INDEX
Definition: vtkLookupTable.h:84
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:35
VTK_RAMP_LINEAR
#define VTK_RAMP_LINEAR
Definition: vtkLookupTable.h:68
vtkLookupTable::REPEATED_LAST_COLOR_INDEX
static const vtkIdType REPEATED_LAST_COLOR_INDEX
Constants for offsets of special colors (e.g., NanColor, BelowRangeColor, AboveRangeColor) from the m...
Definition: vtkLookupTable.h:83
vtkUnsignedCharArray
dynamic, self-adjusting array of unsigned char
Definition: vtkUnsignedCharArray.h:41
vtkLookupTable::InsertTime
vtkTimeStamp InsertTime
Definition: vtkLookupTable.h:458
vtkLookupTable::SetScaleToLog10
void SetScaleToLog10()
Definition: vtkLookupTable.h:159
vtkX3D::range
Definition: vtkX3D.h:238
vtkLookupTable::Scale
int Scale
Definition: vtkLookupTable.h:456
vtkScalarsToColors::Build
virtual void Build()
Perform any processing required (if any) before processing scalars.
Definition: vtkScalarsToColors.h:83
vtkLookupTable::SetRange
void SetRange(const double rng[2]) override
Definition: vtkLookupTable.h:361
vtkLookupTable::WritePointer
unsigned char * WritePointer(vtkIdType id, int number)
Get pointer to data.
Definition: vtkLookupTable.h:478
vtkLookupTable::SetRampToSCurve
void SetRampToSCurve()
Definition: vtkLookupTable.h:146
vtkScalarsToColors::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkScalarsToColors::GetIndexedColor
virtual void GetIndexedColor(vtkIdType i, double rgba[4])
Get the "indexed color" assigned to an index.
max
#define max(a, b)
Definition: vtkX3DExporterFIWriterHelper.h:31
vtkLookupTable::NUMBER_OF_SPECIAL_COLORS
static const vtkIdType NUMBER_OF_SPECIAL_COLORS
Definition: vtkLookupTable.h:87
vtkScalarsToColors::GetOpacity
virtual double GetOpacity(double v)
Map one value through the lookup table and return the alpha value (the opacity) as a double between 0...
vtkLookupTable::OpaqueFlag
int OpaqueFlag
Definition: vtkLookupTable.h:463
vtkLookupTable::SpecialColorsBuildTime
vtkTimeStamp SpecialColorsBuildTime
Definition: vtkLookupTable.h:465
VTK_SIZEHINT
#define VTK_SIZEHINT(...)
Definition: vtkWrappingHints.h:42
vtkTimeStamp::Modified
void Modified()
Set this objects time to the current time.
vtkLookupTable::Ramp
int Ramp
Definition: vtkLookupTable.h:457
vtkScalarsToColors::DeepCopy
virtual void DeepCopy(vtkScalarsToColors *o)
Copy the contents from another object.
vtkLookupTable::SetScaleToLinear
void SetScaleToLinear()
Definition: vtkLookupTable.h:158
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkScalarsToColors.h
vtkLookupTable::SetRampToSQRT
void SetRampToSQRT()
Definition: vtkLookupTable.h:147
vtkUnsignedCharArray.h
vtkScalarsToColors
Superclass for mapping scalar values to colors.
Definition: vtkScalarsToColors.h:66
vtkScalarsToColors::MapValue
virtual const unsigned char * MapValue(double v)
Map one value through the lookup table and return a color defined as an RGBA unsigned char tuple (4 b...
vtkScalarsToColors::GetColor
virtual void GetColor(double v, double rgb[3])
Map one value through the lookup table and store the color as an RGB array of doubles between 0 and 1...
vtkLookupTable::GetNumberOfTableValues
vtkIdType GetNumberOfTableValues()
Definition: vtkLookupTable.h:303
vtkLookupTable
map scalar values into colors via a lookup table
Definition: vtkLookupTable.h:74
vtkScalarsToColors::GetNumberOfAvailableColors
virtual vtkIdType GetNumberOfAvailableColors()
Get the number of available colors for mapping to.
vtkLookupTable::BuildTime
vtkTimeStamp BuildTime
Definition: vtkLookupTable.h:459
VTK_RAMP_SQRT
#define VTK_RAMP_SQRT
Definition: vtkLookupTable.h:70
VTK_ID_MAX
#define VTK_ID_MAX
Definition: vtkType.h:351
vtkLookupTable::UsingLogScale
int UsingLogScale() override
This should return 1 if the subclass is using log scale for mapping scalars to colors.
Definition: vtkLookupTable.h:420
vtkScalarsToColors::MapScalarsThroughTable2
virtual void MapScalarsThroughTable2(void *input, unsigned char *output, int inputDataType, int numberOfValues, int inputIncrement, int outputFormat)
An internal method typically not used in applications.
VTK_RAMP_SCURVE
#define VTK_RAMP_SCURVE
Definition: vtkLookupTable.h:69
vtkLookupTable::Table
vtkUnsignedCharArray * Table
Definition: vtkLookupTable.h:444
vtkScalarsToColors::New
static vtkScalarsToColors * New()
VTK_SCALE_LOG10
#define VTK_SCALE_LOG10
Definition: vtkLookupTable.h:72
vtkLookupTable::SetRampToLinear
void SetRampToLinear()
Definition: vtkLookupTable.h:145
vtkLookupTable::GetPointer
unsigned char * GetPointer(vtkIdType id)
Get pointer to color table data.
Definition: vtkLookupTable.h:337
vtkLookupTable::UseBelowRangeColor
vtkTypeBool UseBelowRangeColor
Definition: vtkLookupTable.h:452
VTK_SCALE_LINEAR
#define VTK_SCALE_LINEAR
Definition: vtkLookupTable.h:71
vtkLookupTable::GetRange
double * GetRange() override
Sets/Gets the range of scalars which will be mapped.
Definition: vtkLookupTable.h:357
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69
vtkLookupTable::SetRange
void SetRange(double min, double max) override
Definition: vtkLookupTable.h:359
vtkScalarsToColors::IsOpaque
virtual int IsOpaque()
Return true if all of the values defining the mapping have an opacity equal to 1.