VTK  9.7.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 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
54 
55 #include "vtkUnsignedCharArray.h" // Needed for inline method
56 
57 #define VTK_RAMP_LINEAR 0
58 #define VTK_RAMP_SCURVE 1
59 #define VTK_RAMP_SQRT 2
60 #define VTK_SCALE_LINEAR 0
61 #define VTK_SCALE_LOG10 1
62 
63 VTK_ABI_NAMESPACE_BEGIN
64 class VTKCOMMONCORE_EXPORT VTK_MARSHALAUTO vtkLookupTable : public vtkScalarsToColors
65 {
66 public:
68 
76  static const vtkIdType NAN_COLOR_INDEX;
79 
84  static vtkLookupTable* New();
85 
87  void PrintSelf(ostream& os, vtkIndent indent) override;
88 
90 
94  vtkTypeBool IsOpaque() override;
95  vtkTypeBool IsOpaque(vtkAbstractArray* scalars, int colorMode, int component) override;
96  vtkTypeBool IsOpaque(vtkAbstractArray* scalars, int colorMode, int component,
97  vtkUnsignedCharArray* ghosts, unsigned char ghostsToSkip = 0xff) override;
99 
104  int Allocate(int sz = 256, int ext = 256);
105 
110  void Build() override;
111 
119  virtual void ForceBuild();
120 
124  void BuildSpecialColors();
125 
127 
139  vtkSetMacro(Ramp, int);
140  void SetRampToLinear() { this->SetRamp(VTK_RAMP_LINEAR); }
141  void SetRampToSCurve() { this->SetRamp(VTK_RAMP_SCURVE); }
142  void SetRampToSQRT() { this->SetRamp(VTK_RAMP_SQRT); }
143  vtkGetMacro(Ramp, int);
145 
147 
152  void SetScale(int scale);
153  void SetScaleToLinear() { this->SetScale(VTK_SCALE_LINEAR); }
154  void SetScaleToLog10() { this->SetScale(VTK_SCALE_LOG10); }
155  vtkGetMacro(Scale, int);
157 
159 
167  virtual void SetTableRange(const double r[2]);
168  virtual void SetTableRange(double min, double max);
169  vtkGetVectorMacro(TableRange, double, 2);
171 
173 
177  vtkSetVector2Macro(HueRange, double);
178  vtkGetVector2Macro(HueRange, double);
180 
182 
186  vtkSetVector2Macro(SaturationRange, double);
187  vtkGetVector2Macro(SaturationRange, double);
189 
191 
195  vtkSetVector2Macro(ValueRange, double);
196  vtkGetVector2Macro(ValueRange, double);
198 
200 
204  vtkSetVector2Macro(AlphaRange, double);
205  vtkGetVector2Macro(AlphaRange, double);
207 
209 
213  vtkSetVector4Macro(NanColor, double);
214  vtkGetVector4Macro(NanColor, double);
216 
221  unsigned char* GetNanColorAsUnsignedChars();
222 
226  static void GetColorAsUnsignedChars(const double colorIn[4], unsigned char colorOut[4]);
227 
229 
233  vtkSetVector4Macro(BelowRangeColor, double);
234  vtkGetVector4Macro(BelowRangeColor, double);
236 
238 
241  vtkSetMacro(UseBelowRangeColor, vtkTypeBool);
242  vtkGetMacro(UseBelowRangeColor, vtkTypeBool);
243  vtkBooleanMacro(UseBelowRangeColor, vtkTypeBool);
245 
247 
251  vtkSetVector4Macro(AboveRangeColor, double);
252  vtkGetVector4Macro(AboveRangeColor, double);
254 
256 
259  vtkSetMacro(UseAboveRangeColor, vtkTypeBool);
260  vtkGetMacro(UseAboveRangeColor, vtkTypeBool);
261  vtkBooleanMacro(UseAboveRangeColor, vtkTypeBool);
263 
267  const unsigned char* MapValue(double v) override;
268 
273  void GetColor(double v, double rgb[3]) override;
274 
279  double GetOpacity(double v) override;
280 
290  virtual vtkIdType GetIndex(double v);
291 
293 
297  void SetNumberOfTableValues(vtkIdType number);
299  vtkIdType GetNumberOfTableValues() { return this->NumberOfColors; }
301 
309  virtual void SetTableValue(vtkIdType index, const double rgba[4]);
310 
316  virtual void SetTableValue(vtkIdType index, double r, double g, double b, double a = 1.0);
317 
323  double* GetTableValue(vtkIdType index) VTK_SIZEHINT(4);
324 
330  void GetTableValue(vtkIdType index, double rgba[4]);
331 
336  unsigned char* GetPointer(vtkIdType id) { return this->Table->GetPointer(4 * id); }
337 
348  unsigned char* WritePointer(vtkIdType id, int number);
349 
351 
355  double* GetRange() VTK_SIZEHINT(2) override { return this->GetTableRange(); }
356  void SetRange(double min, double max) override { this->SetTableRange(min, max); }
357  void SetRange(const double rng[2]) override { this->SetRange(rng[0], rng[1]); }
359 
366  static void GetLogRange(const double range[2], double log_range[2]);
367 
371  static double ApplyLogScale(double v, const double range[2], const double log_range[2]);
372 
374 
380  vtkSetClampMacro(NumberOfColors, vtkIdType, 2, VTK_ID_MAX);
381  vtkGetMacro(NumberOfColors, vtkIdType);
383 
385 
390  void SetTable(vtkUnsignedCharArray*);
391  vtkGetObjectMacro(Table, vtkUnsignedCharArray);
393 
395 
400  void MapScalarsThroughTable(vtkAbstractArray* input, unsigned char* output, int numberOfTuples,
401  int numberOfComponents, int vectorComponent, int outputFormat) override;
404 
408  void DeepCopy(vtkScalarsToColors* obj) override;
409 
414  vtkTypeBool UsingLogScale() override { return (this->GetScale() == VTK_SCALE_LOG10) ? 1 : 0; }
415 
420 
428  void GetIndexedColor(vtkIdType idx, double rgba[4]) override;
429 
430 protected:
431  vtkLookupTable(int sze = 256, int ext = 256);
432  ~vtkLookupTable() override;
433 
436  double TableRange[2];
437  double HueRange[2];
438  double SaturationRange[2];
439  double ValueRange[2];
440  double AlphaRange[2];
441  double NanColor[4];
442  double BelowRangeColor[4];
444  double AboveRangeColor[4];
446 
447  int Scale;
448  int Ramp;
451  double RGBA[4]; // used during conversion process
452  unsigned char NanColorChar[4];
453 
457 
461  void ResizeTableForSpecialColors();
462 
463 private:
464  vtkLookupTable(const vtkLookupTable&) = delete;
465  void operator=(const vtkLookupTable&) = delete;
466 };
467 
468 //----------------------------------------------------------------------------
469 inline unsigned char* vtkLookupTable::WritePointer(vtkIdType id, int number)
470 {
471  this->InsertTime.Modified();
472  return this->Table->WritePointer(4 * id, 4 * number);
473 }
474 
475 VTK_ABI_NAMESPACE_END
476 #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
#define VTK_MARSHAL_EXCLUDE_REASON_IS_REDUNDANT
void Modified()
Set this objects time to the current time.
unsigned char * WritePointer(vtkIdType id, int number)
Get pointer to data.
int vtkIdType
Definition: vtkType.h:363
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
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.
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
#define VTK_MARSHALEXCLUDE(reason)
vtkUnsignedCharArray * Table
#define VTK_RAMP_LINEAR
#define VTK_ID_MAX
Definition: vtkType.h:367
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_MARSHALAUTO
#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.
void MapScalarsThroughTable(vtkDataArray *scalars, unsigned char *output, int outputFormat)
Map a set of scalars through the lookup table in a single operation.