VTK  9.3.20240327
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
157 #ifndef vtkLookupTable_h
158 #define vtkLookupTable_h
159 
160 #include "vtkCommonCoreModule.h" // For export macro
161 #include "vtkScalarsToColors.h"
162 
163 #include "vtkUnsignedCharArray.h" // Needed for inline method
164 
165 #define VTK_RAMP_LINEAR 0
166 #define VTK_RAMP_SCURVE 1
167 #define VTK_RAMP_SQRT 2
168 #define VTK_SCALE_LINEAR 0
169 #define VTK_SCALE_LOG10 1
170 
171 VTK_ABI_NAMESPACE_BEGIN
172 class VTKCOMMONCORE_EXPORT vtkLookupTable : public vtkScalarsToColors
173 {
174 public:
176 
187 
192  static vtkLookupTable* New();
193 
195  void PrintSelf(ostream& os, vtkIndent indent) override;
196 
198 
202  vtkTypeBool IsOpaque() override;
203  vtkTypeBool IsOpaque(vtkAbstractArray* scalars, int colorMode, int component) override;
204  vtkTypeBool IsOpaque(vtkAbstractArray* scalars, int colorMode, int component,
205  vtkUnsignedCharArray* ghosts, unsigned char ghostsToSkip = 0xff) override;
207 
212  int Allocate(int sz = 256, int ext = 256);
213 
218  void Build() override;
219 
227  virtual void ForceBuild();
228 
233 
235 
247  vtkSetMacro(Ramp, int);
248  void SetRampToLinear() { this->SetRamp(VTK_RAMP_LINEAR); }
249  void SetRampToSCurve() { this->SetRamp(VTK_RAMP_SCURVE); }
250  void SetRampToSQRT() { this->SetRamp(VTK_RAMP_SQRT); }
251  vtkGetMacro(Ramp, int);
253 
255 
260  void SetScale(int scale);
261  void SetScaleToLinear() { this->SetScale(VTK_SCALE_LINEAR); }
262  void SetScaleToLog10() { this->SetScale(VTK_SCALE_LOG10); }
263  vtkGetMacro(Scale, int);
265 
267 
275  virtual void SetTableRange(const double r[2]);
276  virtual void SetTableRange(double min, double max);
277  vtkGetVectorMacro(TableRange, double, 2);
279 
281 
285  vtkSetVector2Macro(HueRange, double);
286  vtkGetVector2Macro(HueRange, double);
288 
290 
294  vtkSetVector2Macro(SaturationRange, double);
295  vtkGetVector2Macro(SaturationRange, double);
297 
299 
303  vtkSetVector2Macro(ValueRange, double);
304  vtkGetVector2Macro(ValueRange, double);
306 
308 
312  vtkSetVector2Macro(AlphaRange, double);
313  vtkGetVector2Macro(AlphaRange, double);
315 
317 
321  vtkSetVector4Macro(NanColor, double);
322  vtkGetVector4Macro(NanColor, double);
324 
329  unsigned char* GetNanColorAsUnsignedChars();
330 
334  static void GetColorAsUnsignedChars(const double colorIn[4], unsigned char colorOut[4]);
335 
337 
341  vtkSetVector4Macro(BelowRangeColor, double);
342  vtkGetVector4Macro(BelowRangeColor, double);
344 
346 
349  vtkSetMacro(UseBelowRangeColor, vtkTypeBool);
350  vtkGetMacro(UseBelowRangeColor, vtkTypeBool);
351  vtkBooleanMacro(UseBelowRangeColor, vtkTypeBool);
353 
355 
359  vtkSetVector4Macro(AboveRangeColor, double);
360  vtkGetVector4Macro(AboveRangeColor, double);
362 
364 
367  vtkSetMacro(UseAboveRangeColor, vtkTypeBool);
368  vtkGetMacro(UseAboveRangeColor, vtkTypeBool);
369  vtkBooleanMacro(UseAboveRangeColor, vtkTypeBool);
371 
375  const unsigned char* MapValue(double v) override;
376 
381  void GetColor(double v, double rgb[3]) override;
382 
387  double GetOpacity(double v) override;
388 
398  virtual vtkIdType GetIndex(double v);
399 
401 
405  vtkIdType GetNumberOfTableValues() { return this->NumberOfColors; }
407 
414  virtual void SetTableValue(vtkIdType indx, const double rgba[4]);
415 
420  virtual void SetTableValue(vtkIdType indx, double r, double g, double b, double a = 1.0);
421 
427 
432  void GetTableValue(vtkIdType indx, double rgba[4]);
433 
438  unsigned char* GetPointer(vtkIdType id) { return this->Table->GetPointer(4 * id); }
439 
450  unsigned char* WritePointer(vtkIdType id, int number);
451 
453 
457  double* GetRange() VTK_SIZEHINT(2) override { return this->GetTableRange(); }
458  void SetRange(double min, double max) override { this->SetTableRange(min, max); }
459  void SetRange(const double rng[2]) override { this->SetRange(rng[0], rng[1]); }
461 
468  static void GetLogRange(const double range[2], double log_range[2]);
469 
473  static double ApplyLogScale(double v, const double range[2], const double log_range[2]);
474 
476 
482  vtkSetClampMacro(NumberOfColors, vtkIdType, 2, VTK_ID_MAX);
483  vtkGetMacro(NumberOfColors, vtkIdType);
485 
487 
493  vtkGetObjectMacro(Table, vtkUnsignedCharArray);
495 
501  void MapScalarsThroughTable2(void* input, unsigned char* output, int inputDataType,
502  int numberOfValues, int inputIncrement, int outputFormat) override;
503 
507  void DeepCopy(vtkScalarsToColors* obj) override;
508 
513  vtkTypeBool UsingLogScale() override { return (this->GetScale() == VTK_SCALE_LOG10) ? 1 : 0; }
514 
519 
527  void GetIndexedColor(vtkIdType idx, double rgba[4]) override;
528 
529 protected:
530  vtkLookupTable(int sze = 256, int ext = 256);
531  ~vtkLookupTable() override;
532 
535  double TableRange[2];
536  double HueRange[2];
537  double SaturationRange[2];
538  double ValueRange[2];
539  double AlphaRange[2];
540  double NanColor[4];
541  double BelowRangeColor[4];
543  double AboveRangeColor[4];
545 
546  int Scale;
547  int Ramp;
550  double RGBA[4]; // used during conversion process
551  unsigned char NanColorChar[4];
552 
556 
561 
562 private:
563  vtkLookupTable(const vtkLookupTable&) = delete;
564  void operator=(const vtkLookupTable&) = delete;
565 };
566 
567 //----------------------------------------------------------------------------
568 inline unsigned char* vtkLookupTable::WritePointer(vtkIdType id, int number)
569 {
570  this->InsertTime.Modified();
571  return this->Table->WritePointer(4 * id, 4 * number);
572 }
573 
574 VTK_ABI_NAMESPACE_END
575 #endif
ValueType * WritePointer(vtkIdType valueIdx, vtkIdType numValues)
Get the address of a particular data index.
Abstract superclass for all arrays.
a simple class to control print indentation
Definition: vtkIndent.h:108
map scalar values into colors via a lookup table
void SetScaleToLinear()
Set the type of scale to use, linear or logarithmic.
vtkTypeBool IsOpaque(vtkAbstractArray *scalars, int colorMode, int component, vtkUnsignedCharArray *ghosts, unsigned char ghostsToSkip=0xff) override
Return true if all of the values defining the mapping have an opacity equal to 1.
virtual void ForceBuild()
Force the lookup table to regenerate from hue, saturation, value, and alpha min/max values.
static const vtkIdType ABOVE_RANGE_COLOR_INDEX
Constants for offsets of special colors (e.g., NanColor, BelowRangeColor, AboveRangeColor) from the m...
double GetOpacity(double v) override
Map one value through the lookup table and return the alpha value (the opacity) as a double between 0...
vtkTypeBool IsOpaque() override
Return true if all of the values defining the mapping have an opacity equal to 1.
vtkIdType GetNumberOfAvailableColors() override
Get the number of available colors for mapping to.
static vtkLookupTable * New()
Construct with range=[0,1]; and hsv ranges set up for rainbow color table (from red to blue).
static const vtkIdType NUMBER_OF_SPECIAL_COLORS
Constants for offsets of special colors (e.g., NanColor, BelowRangeColor, AboveRangeColor) from the m...
void GetIndexedColor(vtkIdType idx, double rgba[4]) override
Return a color given an integer index.
vtkTimeStamp OpaqueFlagBuildTime
void ResizeTableForSpecialColors()
Resize the LookupTable to have enough room for the out-of-range colors.
static void GetColorAsUnsignedChars(const double colorIn[4], unsigned char colorOut[4])
Given an RGBA[4] color in the [0,1] range, convert it to RGBA[4] in the [0,255] range.
virtual void SetTableValue(vtkIdType indx, const double rgba[4])
Directly load color into lookup table.
double * GetTableValue(vtkIdType indx)
Return an RGBA color value for the given index into the lookup table.
static const vtkIdType BELOW_RANGE_COLOR_INDEX
Constants for offsets of special colors (e.g., NanColor, BelowRangeColor, AboveRangeColor) from the m...
void SetNumberOfTableValues(vtkIdType number)
Specify the number of values (i.e., colors) in the lookup table.
vtkTimeStamp BuildTime
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkTimeStamp InsertTime
void DeepCopy(vtkScalarsToColors *obj) override
Copy the contents from another LookupTable.
static const vtkIdType REPEATED_LAST_COLOR_INDEX
Constants for offsets of special colors (e.g., NanColor, BelowRangeColor, AboveRangeColor) from the m...
int Allocate(int sz=256, int ext=256)
Allocate a color table of specified size.
unsigned char * GetNanColorAsUnsignedChars()
Return the NanColor as a pointer to 4 unsigned chars.
vtkTypeBool IsOpaque(vtkAbstractArray *scalars, int colorMode, int component) override
Return true if all of the values defining the mapping have an opacity equal to 1.
void BuildSpecialColors()
Copies the "special" colors into the given table.
virtual void SetTableValue(vtkIdType indx, double r, double g, double b, double a=1.0)
Directly load color into lookup table.
void MapScalarsThroughTable2(void *input, unsigned char *output, int inputDataType, int numberOfValues, int inputIncrement, int outputFormat) override
Map a set of scalars through the lookup table.
virtual vtkIdType GetIndex(double v)
Return the table index associated with a particular value.
void SetRampToLinear()
Set the shape of the table ramp to either S-curve, linear, or sqrt.
vtkTypeBool UsingLogScale() override
This should return 1 if the subclass is using log scale for mapping scalars to colors.
virtual void SetTableRange(double min, double max)
Set/Get the minimum/maximum scalar values for scalar mapping.
void SetRampToSQRT()
Set the shape of the table ramp to either S-curve, linear, or sqrt.
void SetRange(const double rng[2]) override
Sets/Gets the range of scalars which will be mapped.
vtkUnsignedCharArray * Table
void SetScaleToLog10()
Set the type of scale to use, linear or logarithmic.
double * GetRange() override
Sets/Gets the range of scalars which will be mapped.
void SetRange(double min, double max) override
Sets/Gets the range of scalars which will be mapped.
void SetRampToSCurve()
Set the shape of the table ramp to either S-curve, linear, or sqrt.
unsigned char * WritePointer(vtkIdType id, int number)
Get pointer to data.
static void GetLogRange(const double range[2], double log_range[2])
Returns the log of range in log_range.
void GetColor(double v, double rgb[3]) override
Map one value through the lookup table and return the color as an RGB[3] array of doubles between 0 a...
void SetTable(vtkUnsignedCharArray *)
Set/Get the internal table array that is used to map the scalars to colors.
const unsigned char * MapValue(double v) override
Map one value through the lookup table, returning an RBGA[4] color.
vtkLookupTable(int sze=256, int ext=256)
void SetScale(int scale)
Set the type of scale to use, linear or logarithmic.
vtkIdType GetNumberOfTableValues()
Specify the number of values (i.e., colors) in the lookup table.
unsigned char * GetPointer(vtkIdType id)
Get pointer to color table data.
void GetTableValue(vtkIdType indx, double rgba[4])
Return an RGBA color value for the given index into the lookup table.
vtkTimeStamp SpecialColorsBuildTime
static double ApplyLogScale(double v, const double range[2], const double log_range[2])
Apply log to value, with appropriate constraints.
vtkTypeBool OpaqueFlag
virtual void SetTableRange(const double r[2])
Set/Get the minimum/maximum scalar values for scalar mapping.
~vtkLookupTable() override
void Build() override
Generate lookup table from hue, saturation, value, alpha min/max values.
vtkTypeBool UseAboveRangeColor
vtkIdType NumberOfColors
vtkTypeBool UseBelowRangeColor
static const vtkIdType NAN_COLOR_INDEX
Constants for offsets of special colors (e.g., NanColor, BelowRangeColor, AboveRangeColor) from the m...
Superclass for mapping scalar values to colors.
record modification and/or execution time
Definition: vtkTimeStamp.h:44
void Modified()
Set this objects time to the current time.
dynamic, self-adjusting array of unsigned char
@ component
Definition: vtkX3D.h:175
@ scale
Definition: vtkX3D.h:229
@ range
Definition: vtkX3D.h:238
int vtkTypeBool
Definition: vtkABI.h:64
#define VTK_SCALE_LOG10
#define VTK_SCALE_LINEAR
#define VTK_RAMP_SQRT
#define VTK_RAMP_LINEAR
#define VTK_RAMP_SCURVE
int vtkIdType
Definition: vtkType.h:315
#define VTK_ID_MAX
Definition: vtkType.h:319
#define VTK_SIZEHINT(...)
#define max(a, b)