VTK  9.0.1
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 =========================================================================*/
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 
80  static const vtkIdType NAN_COLOR_INDEX;
83 
88  static vtkLookupTable* New();
89 
91  void PrintSelf(ostream& os, vtkIndent indent) override;
92 
94 
98  int IsOpaque() override;
99  int IsOpaque(vtkAbstractArray* scalars, int colorMode, int component) override;
101 
106  int Allocate(int sz = 256, int ext = 256);
107 
112  void Build() override;
113 
121  virtual void ForceBuild();
122 
126  void BuildSpecialColors();
127 
129 
141  vtkSetMacro(Ramp, int);
142  void SetRampToLinear() { this->SetRamp(VTK_RAMP_LINEAR); }
143  void SetRampToSCurve() { this->SetRamp(VTK_RAMP_SCURVE); }
144  void SetRampToSQRT() { this->SetRamp(VTK_RAMP_SQRT); }
145  vtkGetMacro(Ramp, int);
147 
149 
154  void SetScale(int scale);
155  void SetScaleToLinear() { this->SetScale(VTK_SCALE_LINEAR); }
156  void SetScaleToLog10() { this->SetScale(VTK_SCALE_LOG10); }
157  vtkGetMacro(Scale, int);
159 
161 
169  virtual void SetTableRange(const double r[2]);
170  virtual void SetTableRange(double min, double max);
171  vtkGetVectorMacro(TableRange, double, 2);
173 
175 
179  vtkSetVector2Macro(HueRange, double);
180  vtkGetVector2Macro(HueRange, double);
182 
184 
188  vtkSetVector2Macro(SaturationRange, double);
189  vtkGetVector2Macro(SaturationRange, double);
191 
193 
197  vtkSetVector2Macro(ValueRange, double);
198  vtkGetVector2Macro(ValueRange, double);
200 
202 
206  vtkSetVector2Macro(AlphaRange, double);
207  vtkGetVector2Macro(AlphaRange, double);
209 
211 
215  vtkSetVector4Macro(NanColor, double);
216  vtkGetVector4Macro(NanColor, double);
218 
223  unsigned char* GetNanColorAsUnsignedChars();
224 
228  static void GetColorAsUnsignedChars(const double colorIn[4], unsigned char colorOut[4]);
229 
231 
235  vtkSetVector4Macro(BelowRangeColor, double);
236  vtkGetVector4Macro(BelowRangeColor, double);
238 
240 
243  vtkSetMacro(UseBelowRangeColor, vtkTypeBool);
244  vtkGetMacro(UseBelowRangeColor, vtkTypeBool);
245  vtkBooleanMacro(UseBelowRangeColor, vtkTypeBool);
247 
249 
253  vtkSetVector4Macro(AboveRangeColor, double);
254  vtkGetVector4Macro(AboveRangeColor, double);
256 
258 
261  vtkSetMacro(UseAboveRangeColor, vtkTypeBool);
262  vtkGetMacro(UseAboveRangeColor, vtkTypeBool);
263  vtkBooleanMacro(UseAboveRangeColor, vtkTypeBool);
265 
269  const unsigned char* MapValue(double v) override;
270 
275  void GetColor(double x, double rgb[3]) override;
276 
281  double GetOpacity(double v) override;
282 
292  virtual vtkIdType GetIndex(double v);
293 
295 
298  void SetNumberOfTableValues(vtkIdType number);
299  vtkIdType GetNumberOfTableValues() { return this->NumberOfColors; }
301 
308  virtual void SetTableValue(vtkIdType indx, const double rgba[4]);
309 
314  virtual void SetTableValue(vtkIdType indx, double r, double g, double b, double a = 1.0);
315 
320  double* GetTableValue(vtkIdType id) VTK_SIZEHINT(4);
321 
326  void GetTableValue(vtkIdType id, double rgba[4]);
327 
332  unsigned char* GetPointer(vtkIdType id) { return this->Table->GetPointer(4 * id); }
333 
344  unsigned char* WritePointer(vtkIdType id, int number);
345 
347 
351  double* GetRange() VTK_SIZEHINT(2) override { return this->GetTableRange(); }
352  void SetRange(double min, double max) override { this->SetTableRange(min, max); }
353  void SetRange(const double rng[2]) override { this->SetRange(rng[0], rng[1]); }
355 
362  static void GetLogRange(const double range[2], double log_range[2]);
363 
367  static double ApplyLogScale(double v, const double range[2], const double log_range[2]);
368 
370 
376  vtkSetClampMacro(NumberOfColors, vtkIdType, 2, VTK_ID_MAX);
377  vtkGetMacro(NumberOfColors, vtkIdType);
379 
381 
386  void SetTable(vtkUnsignedCharArray*);
387  vtkGetObjectMacro(Table, vtkUnsignedCharArray);
389 
395  void MapScalarsThroughTable2(void* input, unsigned char* output, int inputDataType,
396  int numberOfValues, int inputIncrement, int outputIncrement) override;
397 
401  void DeepCopy(vtkScalarsToColors* lut) override;
402 
407  int UsingLogScale() override { return (this->GetScale() == VTK_SCALE_LOG10) ? 1 : 0; }
408 
413 
421  void GetIndexedColor(vtkIdType idx, double rgba[4]) override;
422 
423 protected:
424  vtkLookupTable(int sze = 256, int ext = 256);
425  ~vtkLookupTable() override;
426 
429  double TableRange[2];
430  double HueRange[2];
431  double SaturationRange[2];
432  double ValueRange[2];
433  double AlphaRange[2];
434  double NanColor[4];
435  double BelowRangeColor[4];
437  double AboveRangeColor[4];
439 
440  int Scale;
441  int Ramp;
444  double RGBA[4]; // used during conversion process
445  unsigned char NanColorChar[4];
446 
450 
454  void ResizeTableForSpecialColors();
455 
456 private:
457  vtkLookupTable(const vtkLookupTable&) = delete;
458  void operator=(const vtkLookupTable&) = delete;
459 };
460 
461 //----------------------------------------------------------------------------
462 inline unsigned char* vtkLookupTable::WritePointer(vtkIdType id, int number)
463 {
464  this->InsertTime.Modified();
465  return this->Table->WritePointer(4 * id, 4 * number);
466 }
467 
468 #endif
vtkLookupTable::NumberOfColors
vtkIdType NumberOfColors
Definition: vtkLookupTable.h:427
vtkX3D::component
@ component
Definition: vtkX3D.h:181
vtkAOSDataArrayTemplate::WritePointer
ValueType * WritePointer(vtkIdType valueIdx, vtkIdType numValues)
Get the address of a particular data index.
vtkLookupTable::OpaqueFlagBuildTime
vtkTimeStamp OpaqueFlagBuildTime
Definition: vtkLookupTable.h:448
vtkX3D::scale
@ scale
Definition: vtkX3D.h:235
vtkLookupTable::UseAboveRangeColor
vtkTypeBool UseAboveRangeColor
Definition: vtkLookupTable.h:438
vtkIdType
int vtkIdType
Definition: vtkType.h:338
vtkLookupTable::NAN_COLOR_INDEX
static const vtkIdType NAN_COLOR_INDEX
Definition: vtkLookupTable.h:80
vtkLookupTable::ABOVE_RANGE_COLOR_INDEX
static const vtkIdType ABOVE_RANGE_COLOR_INDEX
Definition: vtkLookupTable.h:79
vtkLookupTable::BELOW_RANGE_COLOR_INDEX
static const vtkIdType BELOW_RANGE_COLOR_INDEX
Definition: vtkLookupTable.h:78
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:32
VTK_RAMP_LINEAR
#define VTK_RAMP_LINEAR
Definition: vtkLookupTable.h:62
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:77
vtkUnsignedCharArray
dynamic, self-adjusting array of unsigned char
Definition: vtkUnsignedCharArray.h:35
vtkLookupTable::InsertTime
vtkTimeStamp InsertTime
Definition: vtkLookupTable.h:442
vtkLookupTable::SetScaleToLog10
void SetScaleToLog10()
Definition: vtkLookupTable.h:156
vtkX3D::range
@ range
Definition: vtkX3D.h:244
vtkLookupTable::Scale
int Scale
Definition: vtkLookupTable.h:440
vtkScalarsToColors::Build
virtual void Build()
Perform any processing required (if any) before processing scalars.
Definition: vtkScalarsToColors.h:80
vtkLookupTable::SetRange
void SetRange(const double rng[2]) override
Definition: vtkLookupTable.h:353
vtkLookupTable::WritePointer
unsigned char * WritePointer(vtkIdType id, int number)
Get pointer to data.
Definition: vtkLookupTable.h:462
vtkLookupTable::SetRampToSCurve
void SetRampToSCurve()
Definition: vtkLookupTable.h:143
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:81
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:447
vtkLookupTable::SpecialColorsBuildTime
vtkTimeStamp SpecialColorsBuildTime
Definition: vtkLookupTable.h:449
VTK_SIZEHINT
#define VTK_SIZEHINT(...)
Definition: vtkWrappingHints.h:45
vtkTimeStamp::Modified
void Modified()
Set this objects time to the current time.
vtkLookupTable::Ramp
int Ramp
Definition: vtkLookupTable.h:441
vtkScalarsToColors::DeepCopy
virtual void DeepCopy(vtkScalarsToColors *o)
Copy the contents from another object.
vtkLookupTable::SetScaleToLinear
void SetScaleToLinear()
Definition: vtkLookupTable.h:155
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkScalarsToColors.h
vtkLookupTable::SetRampToSQRT
void SetRampToSQRT()
Definition: vtkLookupTable.h:144
vtkUnsignedCharArray.h
vtkScalarsToColors
Superclass for mapping scalar values to colors.
Definition: vtkScalarsToColors.h:59
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...
vtkAbstractArray
Abstract superclass for all arrays.
Definition: vtkAbstractArray.h:75
vtkLookupTable::GetNumberOfTableValues
vtkIdType GetNumberOfTableValues()
Definition: vtkLookupTable.h:299
vtkLookupTable
map scalar values into colors via a lookup table
Definition: vtkLookupTable.h:68
vtkScalarsToColors::GetNumberOfAvailableColors
virtual vtkIdType GetNumberOfAvailableColors()
Get the number of available colors for mapping to.
vtkLookupTable::BuildTime
vtkTimeStamp BuildTime
Definition: vtkLookupTable.h:443
VTK_RAMP_SQRT
#define VTK_RAMP_SQRT
Definition: vtkLookupTable.h:64
VTK_ID_MAX
#define VTK_ID_MAX
Definition: vtkType.h:342
vtkLookupTable::UsingLogScale
int UsingLogScale() override
This should return 1 if the subclass is using log scale for mapping scalars to colors.
Definition: vtkLookupTable.h:407
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:63
vtkLookupTable::Table
vtkUnsignedCharArray * Table
Definition: vtkLookupTable.h:428
vtkScalarsToColors::New
static vtkScalarsToColors * New()
VTK_SCALE_LOG10
#define VTK_SCALE_LOG10
Definition: vtkLookupTable.h:66
vtkLookupTable::SetRampToLinear
void SetRampToLinear()
Definition: vtkLookupTable.h:142
vtkLookupTable::GetPointer
unsigned char * GetPointer(vtkIdType id)
Get pointer to color table data.
Definition: vtkLookupTable.h:332
vtkLookupTable::UseBelowRangeColor
vtkTypeBool UseBelowRangeColor
Definition: vtkLookupTable.h:436
VTK_SCALE_LINEAR
#define VTK_SCALE_LINEAR
Definition: vtkLookupTable.h:65
vtkLookupTable::GetRange
double * GetRange() override
Sets/Gets the range of scalars which will be mapped.
Definition: vtkLookupTable.h:351
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69
vtkLookupTable::SetRange
void SetRange(double min, double max) override
Definition: vtkLookupTable.h:352
vtkScalarsToColors::IsOpaque
virtual int IsOpaque()
Return true if all of the values defining the mapping have an opacity equal to 1.