VTK  9.4.20241117
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#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
163
164#include "vtkUnsignedCharArray.h" // Needed for inline method
165
166#define VTK_RAMP_LINEAR 0
167#define VTK_RAMP_SCURVE 1
168#define VTK_RAMP_SQRT 2
169#define VTK_SCALE_LINEAR 0
170#define VTK_SCALE_LOG10 1
171
172VTK_ABI_NAMESPACE_BEGIN
173class VTKCOMMONCORE_EXPORT VTK_MARSHALAUTO vtkLookupTable : public vtkScalarsToColors
174{
175public:
177
188
194
196 void PrintSelf(ostream& os, vtkIndent indent) override;
197
199
204 vtkTypeBool IsOpaque(vtkAbstractArray* scalars, int colorMode, int component) override;
205 vtkTypeBool IsOpaque(vtkAbstractArray* scalars, int colorMode, int component,
206 vtkUnsignedCharArray* ghosts, unsigned char ghostsToSkip = 0xff) override;
208
213 int Allocate(int sz = 256, int ext = 256);
214
219 void Build() override;
220
228 virtual void ForceBuild();
229
234
236
248 vtkSetMacro(Ramp, int);
249 void SetRampToLinear() { this->SetRamp(VTK_RAMP_LINEAR); }
250 void SetRampToSCurve() { this->SetRamp(VTK_RAMP_SCURVE); }
251 void SetRampToSQRT() { this->SetRamp(VTK_RAMP_SQRT); }
252 vtkGetMacro(Ramp, int);
254
256
261 void SetScale(int scale);
262 void SetScaleToLinear() { this->SetScale(VTK_SCALE_LINEAR); }
263 void SetScaleToLog10() { this->SetScale(VTK_SCALE_LOG10); }
264 vtkGetMacro(Scale, int);
266
268
276 virtual void SetTableRange(const double r[2]);
277 virtual void SetTableRange(double min, double max);
278 vtkGetVectorMacro(TableRange, double, 2);
280
282
286 vtkSetVector2Macro(HueRange, double);
287 vtkGetVector2Macro(HueRange, double);
289
291
295 vtkSetVector2Macro(SaturationRange, double);
296 vtkGetVector2Macro(SaturationRange, double);
298
300
304 vtkSetVector2Macro(ValueRange, double);
305 vtkGetVector2Macro(ValueRange, double);
307
309
313 vtkSetVector2Macro(AlphaRange, double);
314 vtkGetVector2Macro(AlphaRange, double);
316
318
322 vtkSetVector4Macro(NanColor, double);
323 vtkGetVector4Macro(NanColor, double);
325
331
335 static void GetColorAsUnsignedChars(const double colorIn[4], unsigned char colorOut[4]);
336
338
342 vtkSetVector4Macro(BelowRangeColor, double);
343 vtkGetVector4Macro(BelowRangeColor, double);
345
347
350 vtkSetMacro(UseBelowRangeColor, vtkTypeBool);
351 vtkGetMacro(UseBelowRangeColor, vtkTypeBool);
352 vtkBooleanMacro(UseBelowRangeColor, vtkTypeBool);
354
356
360 vtkSetVector4Macro(AboveRangeColor, double);
361 vtkGetVector4Macro(AboveRangeColor, double);
363
365
368 vtkSetMacro(UseAboveRangeColor, vtkTypeBool);
369 vtkGetMacro(UseAboveRangeColor, vtkTypeBool);
370 vtkBooleanMacro(UseAboveRangeColor, vtkTypeBool);
372
376 const unsigned char* MapValue(double v) override;
377
382 void GetColor(double v, double rgb[3]) override;
383
388 double GetOpacity(double v) override;
389
399 virtual vtkIdType GetIndex(double v);
400
402
406 void SetNumberOfTableValues(vtkIdType number);
408 vtkIdType GetNumberOfTableValues() { return this->NumberOfColors; }
410
417 virtual void SetTableValue(vtkIdType indx, const double rgba[4]);
418
423 virtual void SetTableValue(vtkIdType indx, double r, double g, double b, double a = 1.0);
424
430
435 void GetTableValue(vtkIdType indx, double rgba[4]);
436
441 unsigned char* GetPointer(vtkIdType id) { return this->Table->GetPointer(4 * id); }
442
453 unsigned char* WritePointer(vtkIdType id, int number);
454
456
460 double* GetRange() VTK_SIZEHINT(2) override { return this->GetTableRange(); }
461 void SetRange(double min, double max) override { this->SetTableRange(min, max); }
462 void SetRange(const double rng[2]) override { this->SetRange(rng[0], rng[1]); }
464
471 static void GetLogRange(const double range[2], double log_range[2]);
472
476 static double ApplyLogScale(double v, const double range[2], const double log_range[2]);
477
479
485 vtkSetClampMacro(NumberOfColors, vtkIdType, 2, VTK_ID_MAX);
486 vtkGetMacro(NumberOfColors, vtkIdType);
488
490
496 vtkGetObjectMacro(Table, vtkUnsignedCharArray);
498
504 void MapScalarsThroughTable2(void* input, unsigned char* output, int inputDataType,
505 int numberOfValues, int inputIncrement, int outputFormat) override;
506
510 void DeepCopy(vtkScalarsToColors* obj) override;
511
516 vtkTypeBool UsingLogScale() override { return (this->GetScale() == VTK_SCALE_LOG10) ? 1 : 0; }
517
522
530 void GetIndexedColor(vtkIdType idx, double rgba[4]) override;
531
532protected:
533 vtkLookupTable(int sze = 256, int ext = 256);
534 ~vtkLookupTable() override;
535
538 double TableRange[2];
539 double HueRange[2];
540 double SaturationRange[2];
541 double ValueRange[2];
542 double AlphaRange[2];
543 double NanColor[4];
544 double BelowRangeColor[4];
546 double AboveRangeColor[4];
548
549 int Scale;
550 int Ramp;
553 double RGBA[4]; // used during conversion process
554 unsigned char NanColorChar[4];
555
559
564
565private:
566 vtkLookupTable(const vtkLookupTable&) = delete;
567 void operator=(const vtkLookupTable&) = delete;
568};
569
570//----------------------------------------------------------------------------
571inline unsigned char* vtkLookupTable::WritePointer(vtkIdType id, int number)
572{
573 this->InsertTime.Modified();
574 return this->Table->WritePointer(4 * id, 4 * number);
575}
576
577VTK_ABI_NAMESPACE_END
578#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 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.
static vtkLookupTable * New()
Construct with range=[0,1]; and hsv ranges set up for rainbow color table (from red to blue).
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.
static const vtkIdType BELOW_RANGE_COLOR_INDEX
Constants for offsets of special colors (e.g., NanColor, BelowRangeColor, AboveRangeColor) from the m...
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.
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.
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.
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.
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.
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.
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.
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
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: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_MARSHAL_EXCLUDE_REASON_IS_REDUNDANT
#define VTK_SIZEHINT(...)
#define VTK_MARSHALAUTO
#define VTK_MARSHALEXCLUDE(reason)
#define max(a, b)