VTK  9.3.1
vtkLookupTable.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
48 #ifndef vtkLookupTable_h
49 #define vtkLookupTable_h
50 
51 #include "vtkCommonCoreModule.h" // For export macro
52 #include "vtkScalarsToColors.h"
53 
54 #include "vtkUnsignedCharArray.h" // Needed for inline method
55 
56 #define VTK_RAMP_LINEAR 0
57 #define VTK_RAMP_SCURVE 1
58 #define VTK_RAMP_SQRT 2
59 #define VTK_SCALE_LINEAR 0
60 #define VTK_SCALE_LOG10 1
61 
62 VTK_ABI_NAMESPACE_BEGIN
63 class VTKCOMMONCORE_EXPORT vtkLookupTable : public vtkScalarsToColors
64 {
65 public:
67 
75  static const vtkIdType NAN_COLOR_INDEX;
78 
83  static vtkLookupTable* New();
84 
86  void PrintSelf(ostream& os, vtkIndent indent) override;
87 
89 
93  vtkTypeBool IsOpaque() override;
94  vtkTypeBool IsOpaque(vtkAbstractArray* scalars, int colorMode, int component) override;
95  vtkTypeBool IsOpaque(vtkAbstractArray* scalars, int colorMode, int component,
96  vtkUnsignedCharArray* ghosts, unsigned char ghostsToSkip = 0xff) override;
98 
103  int Allocate(int sz = 256, int ext = 256);
104 
109  void Build() override;
110 
118  virtual void ForceBuild();
119 
123  void BuildSpecialColors();
124 
126 
138  vtkSetMacro(Ramp, int);
139  void SetRampToLinear() { this->SetRamp(VTK_RAMP_LINEAR); }
140  void SetRampToSCurve() { this->SetRamp(VTK_RAMP_SCURVE); }
141  void SetRampToSQRT() { this->SetRamp(VTK_RAMP_SQRT); }
142  vtkGetMacro(Ramp, int);
144 
146 
151  void SetScale(int scale);
152  void SetScaleToLinear() { this->SetScale(VTK_SCALE_LINEAR); }
153  void SetScaleToLog10() { this->SetScale(VTK_SCALE_LOG10); }
154  vtkGetMacro(Scale, int);
156 
158 
166  virtual void SetTableRange(const double r[2]);
167  virtual void SetTableRange(double min, double max);
168  vtkGetVectorMacro(TableRange, double, 2);
170 
172 
176  vtkSetVector2Macro(HueRange, double);
177  vtkGetVector2Macro(HueRange, double);
179 
181 
185  vtkSetVector2Macro(SaturationRange, double);
186  vtkGetVector2Macro(SaturationRange, double);
188 
190 
194  vtkSetVector2Macro(ValueRange, double);
195  vtkGetVector2Macro(ValueRange, double);
197 
199 
203  vtkSetVector2Macro(AlphaRange, double);
204  vtkGetVector2Macro(AlphaRange, double);
206 
208 
212  vtkSetVector4Macro(NanColor, double);
213  vtkGetVector4Macro(NanColor, double);
215 
220  unsigned char* GetNanColorAsUnsignedChars();
221 
225  static void GetColorAsUnsignedChars(const double colorIn[4], unsigned char colorOut[4]);
226 
228 
232  vtkSetVector4Macro(BelowRangeColor, double);
233  vtkGetVector4Macro(BelowRangeColor, double);
235 
237 
240  vtkSetMacro(UseBelowRangeColor, vtkTypeBool);
241  vtkGetMacro(UseBelowRangeColor, vtkTypeBool);
242  vtkBooleanMacro(UseBelowRangeColor, vtkTypeBool);
244 
246 
250  vtkSetVector4Macro(AboveRangeColor, double);
251  vtkGetVector4Macro(AboveRangeColor, double);
253 
255 
258  vtkSetMacro(UseAboveRangeColor, vtkTypeBool);
259  vtkGetMacro(UseAboveRangeColor, vtkTypeBool);
260  vtkBooleanMacro(UseAboveRangeColor, vtkTypeBool);
262 
266  const unsigned char* MapValue(double v) override;
267 
272  void GetColor(double v, double rgb[3]) override;
273 
278  double GetOpacity(double v) override;
279 
289  virtual vtkIdType GetIndex(double v);
290 
292 
295  void SetNumberOfTableValues(vtkIdType number);
296  vtkIdType GetNumberOfTableValues() { return this->NumberOfColors; }
298 
305  virtual void SetTableValue(vtkIdType indx, const double rgba[4]);
306 
311  virtual void SetTableValue(vtkIdType indx, double r, double g, double b, double a = 1.0);
312 
317  double* GetTableValue(vtkIdType indx) VTK_SIZEHINT(4);
318 
323  void GetTableValue(vtkIdType indx, double rgba[4]);
324 
329  unsigned char* GetPointer(vtkIdType id) { return this->Table->GetPointer(4 * id); }
330 
341  unsigned char* WritePointer(vtkIdType id, int number);
342 
344 
348  double* GetRange() VTK_SIZEHINT(2) override { return this->GetTableRange(); }
349  void SetRange(double min, double max) override { this->SetTableRange(min, max); }
350  void SetRange(const double rng[2]) override { 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], const double log_range[2]);
365 
367 
373  vtkSetClampMacro(NumberOfColors, vtkIdType, 2, VTK_ID_MAX);
374  vtkGetMacro(NumberOfColors, vtkIdType);
376 
378 
383  void SetTable(vtkUnsignedCharArray*);
384  vtkGetObjectMacro(Table, vtkUnsignedCharArray);
386 
392  void MapScalarsThroughTable2(void* input, unsigned char* output, int inputDataType,
393  int numberOfValues, int inputIncrement, int outputFormat) override;
394 
398  void DeepCopy(vtkScalarsToColors* obj) override;
399 
404  vtkTypeBool UsingLogScale() override { return (this->GetScale() == VTK_SCALE_LOG10) ? 1 : 0; }
405 
410 
418  void GetIndexedColor(vtkIdType idx, double rgba[4]) override;
419 
420 protected:
421  vtkLookupTable(int sze = 256, int ext = 256);
422  ~vtkLookupTable() override;
423 
426  double TableRange[2];
427  double HueRange[2];
428  double SaturationRange[2];
429  double ValueRange[2];
430  double AlphaRange[2];
431  double NanColor[4];
432  double BelowRangeColor[4];
434  double AboveRangeColor[4];
436 
437  int Scale;
438  int Ramp;
441  double RGBA[4]; // used during conversion process
442  unsigned char NanColorChar[4];
443 
447 
451  void ResizeTableForSpecialColors();
452 
453 private:
454  vtkLookupTable(const vtkLookupTable&) = delete;
455  void operator=(const vtkLookupTable&) = delete;
456 };
457 
458 //----------------------------------------------------------------------------
459 inline unsigned char* vtkLookupTable::WritePointer(vtkIdType id, int number)
460 {
461  this->InsertTime.Modified();
462  return this->Table->WritePointer(4 * id, 4 * number);
463 }
464 
465 VTK_ABI_NAMESPACE_END
466 #endif
void SetRampToLinear()
Set the shape of the table ramp to either S-curve, linear, or sqrt.
vtkTimeStamp InsertTime
virtual vtkTypeBool IsOpaque()
Return true if all of the values defining the mapping have an opacity equal to 1. ...
ValueType * WritePointer(vtkIdType valueIdx, vtkIdType numValues)
Get the address of a particular data index.
vtkIdType NumberOfColors
vtkTimeStamp OpaqueFlagBuildTime
Abstract superclass for all arrays.
vtkTimeStamp SpecialColorsBuildTime
vtkTypeBool UseBelowRangeColor
record modification and/or execution time
Definition: vtkTimeStamp.h:24
static const vtkIdType REPEATED_LAST_COLOR_INDEX
Constants for offsets of special colors (e.g., NanColor, BelowRangeColor, AboveRangeColor) from the m...
map scalar values into colors via a lookup table
void Modified()
Set this objects time to the current time.
virtual void MapScalarsThroughTable2(void *input, unsigned char *output, int inputDataType, int numberOfValues, int inputIncrement, int outputFormat)
An internal method typically not used in applications.
unsigned char * WritePointer(vtkIdType id, int number)
Get pointer to data.
int vtkIdType
Definition: vtkType.h:315
void SetRange(double min, double max) override
Sets/Gets the range of scalars which will be mapped.
static const vtkIdType NUMBER_OF_SPECIAL_COLORS
Constants for offsets of special colors (e.g., NanColor, BelowRangeColor, AboveRangeColor) from the m...
double * GetRange() override
Sets/Gets the range of scalars which will be mapped.
void SetScaleToLog10()
Set the type of scale to use, linear or logarithmic.
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...
void SetRampToSCurve()
Set the shape of the table ramp to either S-curve, linear, or sqrt.
int vtkTypeBool
Definition: vtkABI.h:64
Superclass for mapping scalar values to colors.
vtkTypeBool UseAboveRangeColor
virtual double GetOpacity(double v)
Map one value through the lookup table and return the alpha value (the opacity) as a double between 0...
static vtkScalarsToColors * New()
void SetScaleToLinear()
Set the type of scale to use, linear or logarithmic.
#define VTK_SCALE_LOG10
void SetRange(const double rng[2]) override
Sets/Gets the range of scalars which will be mapped.
a simple class to control print indentation
Definition: vtkIndent.h:28
unsigned char * GetPointer(vtkIdType id)
Get pointer to color table data.
vtkTypeBool OpaqueFlag
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...
vtkTypeBool UsingLogScale() override
This should return 1 if the subclass is using log scale for mapping scalars to colors.
vtkIdType GetNumberOfTableValues()
Specify the number of values (i.e., colors) in the lookup table.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
#define VTK_RAMP_SCURVE
#define VTK_SIZEHINT(...)
static const vtkIdType NAN_COLOR_INDEX
Constants for offsets of special colors (e.g., NanColor, BelowRangeColor, AboveRangeColor) from the m...
dynamic, self-adjusting array of unsigned char
vtkUnsignedCharArray * Table
#define VTK_RAMP_LINEAR
#define VTK_ID_MAX
Definition: vtkType.h:319
virtual void GetIndexedColor(vtkIdType i, double rgba[4])
Get the "indexed color" assigned to an index.
void SetRampToSQRT()
Set the shape of the table ramp to either S-curve, linear, or sqrt.
virtual void Build()
Perform any processing required (if any) before processing scalars.
static const vtkIdType BELOW_RANGE_COLOR_INDEX
Constants for offsets of special colors (e.g., NanColor, BelowRangeColor, AboveRangeColor) from the m...
#define VTK_SCALE_LINEAR
#define VTK_RAMP_SQRT
vtkTimeStamp BuildTime
virtual void DeepCopy(vtkScalarsToColors *o)
Copy the contents from another object.
static const vtkIdType ABOVE_RANGE_COLOR_INDEX
Constants for offsets of special colors (e.g., NanColor, BelowRangeColor, AboveRangeColor) from the m...
#define max(a, b)
virtual vtkIdType GetNumberOfAvailableColors()
Get the number of available colors for mapping to.