VTK  9.2.6
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=========================================================================*/
69#ifndef vtkLookupTable_h
70#define vtkLookupTable_h
71
72#include "vtkCommonCoreModule.h" // For export macro
73#include "vtkScalarsToColors.h"
74
75#include "vtkUnsignedCharArray.h" // Needed for inline method
76
77#define VTK_RAMP_LINEAR 0
78#define VTK_RAMP_SCURVE 1
79#define VTK_RAMP_SQRT 2
80#define VTK_SCALE_LINEAR 0
81#define VTK_SCALE_LOG10 1
82
83class VTKCOMMONCORE_EXPORT vtkLookupTable : public vtkScalarsToColors
84{
85public:
87
98
104
106 void PrintSelf(ostream& os, vtkIndent indent) override;
107
109
113 int IsOpaque() override;
114 int IsOpaque(vtkAbstractArray* scalars, int colorMode, int component) override;
115 int IsOpaque(vtkAbstractArray* scalars, int colorMode, int component,
116 vtkUnsignedCharArray* ghosts, unsigned char ghostsToSkip = 0xff) override;
118
123 int Allocate(int sz = 256, int ext = 256);
124
129 void Build() override;
130
138 virtual void ForceBuild();
139
144
146
158 vtkSetMacro(Ramp, int);
159 void SetRampToLinear() { this->SetRamp(VTK_RAMP_LINEAR); }
160 void SetRampToSCurve() { this->SetRamp(VTK_RAMP_SCURVE); }
161 void SetRampToSQRT() { this->SetRamp(VTK_RAMP_SQRT); }
162 vtkGetMacro(Ramp, int);
164
166
171 void SetScale(int scale);
172 void SetScaleToLinear() { this->SetScale(VTK_SCALE_LINEAR); }
173 void SetScaleToLog10() { this->SetScale(VTK_SCALE_LOG10); }
174 vtkGetMacro(Scale, int);
176
178
186 virtual void SetTableRange(const double r[2]);
187 virtual void SetTableRange(double min, double max);
188 vtkGetVectorMacro(TableRange, double, 2);
190
192
196 vtkSetVector2Macro(HueRange, double);
197 vtkGetVector2Macro(HueRange, double);
199
201
205 vtkSetVector2Macro(SaturationRange, double);
206 vtkGetVector2Macro(SaturationRange, double);
208
210
214 vtkSetVector2Macro(ValueRange, double);
215 vtkGetVector2Macro(ValueRange, double);
217
219
223 vtkSetVector2Macro(AlphaRange, double);
224 vtkGetVector2Macro(AlphaRange, double);
226
228
232 vtkSetVector4Macro(NanColor, double);
233 vtkGetVector4Macro(NanColor, double);
235
241
245 static void GetColorAsUnsignedChars(const double colorIn[4], unsigned char colorOut[4]);
246
248
252 vtkSetVector4Macro(BelowRangeColor, double);
253 vtkGetVector4Macro(BelowRangeColor, double);
255
257
260 vtkSetMacro(UseBelowRangeColor, vtkTypeBool);
261 vtkGetMacro(UseBelowRangeColor, vtkTypeBool);
262 vtkBooleanMacro(UseBelowRangeColor, vtkTypeBool);
264
266
270 vtkSetVector4Macro(AboveRangeColor, double);
271 vtkGetVector4Macro(AboveRangeColor, double);
273
275
278 vtkSetMacro(UseAboveRangeColor, vtkTypeBool);
279 vtkGetMacro(UseAboveRangeColor, vtkTypeBool);
280 vtkBooleanMacro(UseAboveRangeColor, vtkTypeBool);
282
286 const unsigned char* MapValue(double v) override;
287
292 void GetColor(double v, double rgb[3]) override;
293
298 double GetOpacity(double v) override;
299
309 virtual vtkIdType GetIndex(double v);
310
312
316 vtkIdType GetNumberOfTableValues() { return this->NumberOfColors; }
318
325 virtual void SetTableValue(vtkIdType indx, const double rgba[4]);
326
331 virtual void SetTableValue(vtkIdType indx, double r, double g, double b, double a = 1.0);
332
338
343 void GetTableValue(vtkIdType indx, double rgba[4]);
344
349 unsigned char* GetPointer(vtkIdType id) { return this->Table->GetPointer(4 * id); }
350
361 unsigned char* WritePointer(vtkIdType id, int number);
362
364
368 double* GetRange() VTK_SIZEHINT(2) override { return this->GetTableRange(); }
369 void SetRange(double min, double max) override { this->SetTableRange(min, max); }
370 void SetRange(const double rng[2]) override { this->SetRange(rng[0], rng[1]); }
372
379 static void GetLogRange(const double range[2], double log_range[2]);
380
384 static double ApplyLogScale(double v, const double range[2], const double log_range[2]);
385
387
393 vtkSetClampMacro(NumberOfColors, vtkIdType, 2, VTK_ID_MAX);
394 vtkGetMacro(NumberOfColors, vtkIdType);
396
398
404 vtkGetObjectMacro(Table, vtkUnsignedCharArray);
406
412 void MapScalarsThroughTable2(void* input, unsigned char* output, int inputDataType,
413 int numberOfValues, int inputIncrement, int outputFormat) override;
414
418 void DeepCopy(vtkScalarsToColors* obj) override;
419
424 int UsingLogScale() override { return (this->GetScale() == VTK_SCALE_LOG10) ? 1 : 0; }
425
430
438 void GetIndexedColor(vtkIdType idx, double rgba[4]) override;
439
440protected:
441 vtkLookupTable(int sze = 256, int ext = 256);
442 ~vtkLookupTable() override;
443
446 double TableRange[2];
447 double HueRange[2];
448 double SaturationRange[2];
449 double ValueRange[2];
450 double AlphaRange[2];
451 double NanColor[4];
452 double BelowRangeColor[4];
454 double AboveRangeColor[4];
456
457 int Scale;
458 int Ramp;
461 double RGBA[4]; // used during conversion process
462 unsigned char NanColorChar[4];
463
467
472
473private:
474 vtkLookupTable(const vtkLookupTable&) = delete;
475 void operator=(const vtkLookupTable&) = delete;
476};
477
478//----------------------------------------------------------------------------
479inline unsigned char* vtkLookupTable::WritePointer(vtkIdType id, int number)
480{
481 this->InsertTime.Modified();
482 return this->Table->WritePointer(4 * id, 4 * number);
483}
484
485#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:49
map scalar values into colors via a lookup table
void SetScaleToLinear()
Set the type of scale to use, linear or logarithmic.
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...
vtkIdType GetNumberOfAvailableColors() override
Get the number of available colors for mapping to.
static const vtkIdType NUMBER_OF_SPECIAL_COLORS
Constants for offsets of special colors (e.g., NanColor, BelowRangeColor, AboveRangeColor) from the m...
int UsingLogScale() override
This should return 1 if the subclass is using log scale for mapping scalars to colors.
void GetIndexedColor(vtkIdType idx, double rgba[4]) override
Return a color given an integer index.
static vtkLookupTable * New()
Construct with range=[0,1]; and hsv ranges set up for rainbow color table (from red to blue).
vtkTimeStamp OpaqueFlagBuildTime
int 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 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.
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.
double * GetTableValue(vtkIdType indx)
Return an RGBA color value for the given index into the lookup table.
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.
const unsigned char * MapValue(double v) override
Map one value through the lookup table, returning an RBGA[4] color.
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.
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.
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.
int 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.
vtkLookupTable(int sze=256, int ext=256)
unsigned char * GetPointer(vtkIdType id)
Get pointer to color table data.
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.
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.
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.
unsigned char * GetNanColorAsUnsignedChars()
Return the NanColor as a pointer to 4 unsigned chars.
vtkTypeBool UseAboveRangeColor
double * GetRange() override
Sets/Gets the range of scalars which will be mapped.
vtkIdType NumberOfColors
vtkTypeBool UseBelowRangeColor
int IsOpaque() override
Return true if all of the values defining the mapping have an opacity equal to 1.
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
void Modified()
Set this objects time to the current time.
dynamic, self-adjusting array of unsigned char
int vtkTypeBool
Definition vtkABI.h:69
#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:332
#define VTK_ID_MAX
Definition vtkType.h:336
#define VTK_SIZEHINT(...)
#define max(a, b)