VTK  9.1.0
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 =========================================================================*/
163 #ifndef vtkLookupTable_h
164 #define vtkLookupTable_h
165 
166 #include "vtkCommonCoreModule.h" // For export macro
167 #include "vtkScalarsToColors.h"
168 
169 #include "vtkUnsignedCharArray.h" // Needed for inline method
170 
171 #define VTK_RAMP_LINEAR 0
172 #define VTK_RAMP_SCURVE 1
173 #define VTK_RAMP_SQRT 2
174 #define VTK_SCALE_LINEAR 0
175 #define VTK_SCALE_LOG10 1
176 
177 class VTKCOMMONCORE_EXPORT vtkLookupTable : public vtkScalarsToColors
178 {
179 public:
181 
192 
197  static vtkLookupTable* New();
198 
200  void PrintSelf(ostream& os, vtkIndent indent) override;
201 
203 
207  int IsOpaque() override;
208  int IsOpaque(vtkAbstractArray* scalars, int colorMode, int component) override;
210 
215  int Allocate(int sz = 256, int ext = 256);
216 
221  void Build() override;
222 
230  virtual void ForceBuild();
231 
236 
238 
250  vtkSetMacro(Ramp, int);
251  void SetRampToLinear() { this->SetRamp(VTK_RAMP_LINEAR); }
252  void SetRampToSCurve() { this->SetRamp(VTK_RAMP_SCURVE); }
253  void SetRampToSQRT() { this->SetRamp(VTK_RAMP_SQRT); }
254  vtkGetMacro(Ramp, int);
256 
258 
263  void SetScale(int scale);
264  void SetScaleToLinear() { this->SetScale(VTK_SCALE_LINEAR); }
265  void SetScaleToLog10() { this->SetScale(VTK_SCALE_LOG10); }
266  vtkGetMacro(Scale, int);
268 
270 
278  virtual void SetTableRange(const double r[2]);
279  virtual void SetTableRange(double min, double max);
280  vtkGetVectorMacro(TableRange, double, 2);
282 
284 
288  vtkSetVector2Macro(HueRange, double);
289  vtkGetVector2Macro(HueRange, double);
291 
293 
297  vtkSetVector2Macro(SaturationRange, double);
298  vtkGetVector2Macro(SaturationRange, double);
300 
302 
306  vtkSetVector2Macro(ValueRange, double);
307  vtkGetVector2Macro(ValueRange, double);
309 
311 
315  vtkSetVector2Macro(AlphaRange, double);
316  vtkGetVector2Macro(AlphaRange, double);
318 
320 
324  vtkSetVector4Macro(NanColor, double);
325  vtkGetVector4Macro(NanColor, double);
327 
332  unsigned char* GetNanColorAsUnsignedChars();
333 
337  static void GetColorAsUnsignedChars(const double colorIn[4], unsigned char colorOut[4]);
338 
340 
344  vtkSetVector4Macro(BelowRangeColor, double);
345  vtkGetVector4Macro(BelowRangeColor, double);
347 
349 
352  vtkSetMacro(UseBelowRangeColor, vtkTypeBool);
353  vtkGetMacro(UseBelowRangeColor, vtkTypeBool);
354  vtkBooleanMacro(UseBelowRangeColor, vtkTypeBool);
356 
358 
362  vtkSetVector4Macro(AboveRangeColor, double);
363  vtkGetVector4Macro(AboveRangeColor, double);
365 
367 
370  vtkSetMacro(UseAboveRangeColor, vtkTypeBool);
371  vtkGetMacro(UseAboveRangeColor, vtkTypeBool);
372  vtkBooleanMacro(UseAboveRangeColor, vtkTypeBool);
374 
378  const unsigned char* MapValue(double v) override;
379 
384  void GetColor(double v, double rgb[3]) override;
385 
390  double GetOpacity(double v) override;
391 
401  virtual vtkIdType GetIndex(double v);
402 
404 
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  int UsingLogScale() override { return (this->GetScale() == VTK_SCALE_LOG10) ? 1 : 0; }
517 
522 
530  void GetIndexedColor(vtkIdType idx, double rgba[4]) override;
531 
532 protected:
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 
565 private:
566  vtkLookupTable(const vtkLookupTable&) = delete;
567  void operator=(const vtkLookupTable&) = delete;
568 };
569 
570 //----------------------------------------------------------------------------
571 inline unsigned char* vtkLookupTable::WritePointer(vtkIdType id, int number)
572 {
573  this->InsertTime.Modified();
574  return this->Table->WritePointer(4 * id, 4 * number);
575 }
576 
577 #endif
vtkLookupTable::IsOpaque
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.
vtkLookupTable::SetTableValue
virtual void SetTableValue(vtkIdType indx, const double rgba[4])
Directly load color into lookup table.
vtkLookupTable::MapScalarsThroughTable2
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.
vtkLookupTable::NumberOfColors
vtkIdType NumberOfColors
Definition: vtkLookupTable.h:536
vtkX3D::component
@ component
Definition: vtkX3D.h:181
vtkAOSDataArrayTemplate::WritePointer
ValueType * WritePointer(vtkIdType valueIdx, vtkIdType numValues)
Get the address of a particular data index.
vtkLookupTable::OpaqueFlagBuildTime
vtkTimeStamp OpaqueFlagBuildTime
Definition: vtkLookupTable.h:557
vtkX3D::scale
@ scale
Definition: vtkX3D.h:235
vtkLookupTable::UseAboveRangeColor
vtkTypeBool UseAboveRangeColor
Definition: vtkLookupTable.h:547
vtkLookupTable::GetNumberOfAvailableColors
vtkIdType GetNumberOfAvailableColors() override
Get the number of available colors for mapping to.
vtkLookupTable::DeepCopy
void DeepCopy(vtkScalarsToColors *obj) override
Copy the contents from another LookupTable.
vtkLookupTable::GetNanColorAsUnsignedChars
unsigned char * GetNanColorAsUnsignedChars()
Return the NanColor as a pointer to 4 unsigned chars.
vtkLookupTable::Build
void Build() override
Generate lookup table from hue, saturation, value, alpha min/max values.
vtkIdType
int vtkIdType
Definition: vtkType.h:332
vtkLookupTable::NAN_COLOR_INDEX
static const vtkIdType NAN_COLOR_INDEX
Constants for offsets of special colors (e.g., NanColor, BelowRangeColor, AboveRangeColor) from the m...
Definition: vtkLookupTable.h:189
vtkLookupTable::New
static vtkLookupTable * New()
Construct with range=[0,1]; and hsv ranges set up for rainbow color table (from red to blue).
vtkLookupTable::BuildSpecialColors
void BuildSpecialColors()
Copies the "special" colors into the given table.
vtkLookupTable::vtkLookupTable
vtkLookupTable(int sze=256, int ext=256)
vtkLookupTable::ABOVE_RANGE_COLOR_INDEX
static const vtkIdType ABOVE_RANGE_COLOR_INDEX
Constants for offsets of special colors (e.g., NanColor, BelowRangeColor, AboveRangeColor) from the m...
Definition: vtkLookupTable.h:188
vtkLookupTable::ResizeTableForSpecialColors
void ResizeTableForSpecialColors()
Resize the LookupTable to have enough room for the out-of-range colors.
vtkLookupTable::BELOW_RANGE_COLOR_INDEX
static const vtkIdType BELOW_RANGE_COLOR_INDEX
Constants for offsets of special colors (e.g., NanColor, BelowRangeColor, AboveRangeColor) from the m...
Definition: vtkLookupTable.h:187
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:52
VTK_RAMP_LINEAR
#define VTK_RAMP_LINEAR
Definition: vtkLookupTable.h:171
vtkLookupTable::REPEATED_LAST_COLOR_INDEX
static const vtkIdType REPEATED_LAST_COLOR_INDEX
Constants for offsets of special colors (e.g., NanColor, BelowRangeColor, AboveRangeColor) from the m...
Definition: vtkLookupTable.h:186
vtkUnsignedCharArray
dynamic, self-adjusting array of unsigned char
Definition: vtkUnsignedCharArray.h:145
vtkLookupTable::InsertTime
vtkTimeStamp InsertTime
Definition: vtkLookupTable.h:551
vtkLookupTable::GetOpacity
double GetOpacity(double v) override
Map one value through the lookup table and return the alpha value (the opacity) as a double between 0...
vtkLookupTable::SetScaleToLog10
void SetScaleToLog10()
Set the type of scale to use, linear or logarithmic.
Definition: vtkLookupTable.h:265
vtkX3D::range
@ range
Definition: vtkX3D.h:244
vtkLookupTable::GetIndexedColor
void GetIndexedColor(vtkIdType idx, double rgba[4]) override
Return a color given an integer index.
vtkLookupTable::Scale
int Scale
Definition: vtkLookupTable.h:549
vtkLookupTable::GetColorAsUnsignedChars
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.
vtkLookupTable::ApplyLogScale
static double ApplyLogScale(double v, const double range[2], const double log_range[2])
Apply log to value, with appropriate constraints.
vtkLookupTable::SetRange
void SetRange(const double rng[2]) override
Sets/Gets the range of scalars which will be mapped.
Definition: vtkLookupTable.h:462
vtkLookupTable::WritePointer
unsigned char * WritePointer(vtkIdType id, int number)
Get pointer to data.
Definition: vtkLookupTable.h:571
vtkLookupTable::SetTable
void SetTable(vtkUnsignedCharArray *)
Set/Get the internal table array that is used to map the scalars to colors.
vtkLookupTable::SetRampToSCurve
void SetRampToSCurve()
Set the shape of the table ramp to either S-curve, linear, or sqrt.
Definition: vtkLookupTable.h:252
vtkLookupTable::ForceBuild
virtual void ForceBuild()
Force the lookup table to regenerate from hue, saturation, value, and alpha min/max values.
max
#define max(a, b)
Definition: vtkX3DExporterFIWriterHelper.h:31
vtkLookupTable::NUMBER_OF_SPECIAL_COLORS
static const vtkIdType NUMBER_OF_SPECIAL_COLORS
Constants for offsets of special colors (e.g., NanColor, BelowRangeColor, AboveRangeColor) from the m...
Definition: vtkLookupTable.h:190
vtkLookupTable::OpaqueFlag
int OpaqueFlag
Definition: vtkLookupTable.h:556
vtkLookupTable::SpecialColorsBuildTime
vtkTimeStamp SpecialColorsBuildTime
Definition: vtkLookupTable.h:558
VTK_SIZEHINT
#define VTK_SIZEHINT(...)
Definition: vtkWrappingHints.h:48
vtkTimeStamp::Modified
void Modified()
Set this objects time to the current time.
vtkLookupTable::SetTableRange
virtual void SetTableRange(double min, double max)
Set/Get the minimum/maximum scalar values for scalar mapping.
vtkLookupTable::Ramp
int Ramp
Definition: vtkLookupTable.h:550
vtkLookupTable::GetColor
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...
vtkLookupTable::SetTableRange
virtual void SetTableRange(const double r[2])
Set/Get the minimum/maximum scalar values for scalar mapping.
vtkLookupTable::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkLookupTable::SetScaleToLinear
void SetScaleToLinear()
Set the type of scale to use, linear or logarithmic.
Definition: vtkLookupTable.h:264
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:113
vtkLookupTable::SetTableValue
virtual void SetTableValue(vtkIdType indx, double r, double g, double b, double a=1.0)
Directly load color into lookup table.
vtkScalarsToColors.h
vtkLookupTable::SetRampToSQRT
void SetRampToSQRT()
Set the shape of the table ramp to either S-curve, linear, or sqrt.
Definition: vtkLookupTable.h:253
vtkUnsignedCharArray.h
vtkScalarsToColors
Superclass for mapping scalar values to colors.
Definition: vtkScalarsToColors.h:109
vtkLookupTable::SetScale
void SetScale(int scale)
Set the type of scale to use, linear or logarithmic.
vtkLookupTable::GetTableValue
double * GetTableValue(vtkIdType indx)
Return an RGBA color value for the given index into the lookup table.
vtkAbstractArray
Abstract superclass for all arrays.
Definition: vtkAbstractArray.h:76
vtkLookupTable::GetNumberOfTableValues
vtkIdType GetNumberOfTableValues()
Specify the number of values (i.e., colors) in the lookup table.
Definition: vtkLookupTable.h:408
vtkLookupTable::MapValue
const unsigned char * MapValue(double v) override
Map one value through the lookup table, returning an RBGA[4] color.
vtkLookupTable
map scalar values into colors via a lookup table
Definition: vtkLookupTable.h:178
vtkLookupTable::~vtkLookupTable
~vtkLookupTable() override
vtkLookupTable::Allocate
int Allocate(int sz=256, int ext=256)
Allocate a color table of specified size.
vtkLookupTable::BuildTime
vtkTimeStamp BuildTime
Definition: vtkLookupTable.h:552
VTK_RAMP_SQRT
#define VTK_RAMP_SQRT
Definition: vtkLookupTable.h:173
VTK_ID_MAX
#define VTK_ID_MAX
Definition: vtkType.h:336
vtkLookupTable::UsingLogScale
int UsingLogScale() override
This should return 1 if the subclass is using log scale for mapping scalars to colors.
Definition: vtkLookupTable.h:516
vtkLookupTable::GetLogRange
static void GetLogRange(const double range[2], double log_range[2])
Returns the log of range in log_range.
vtkLookupTable::SetNumberOfTableValues
void SetNumberOfTableValues(vtkIdType number)
Specify the number of values (i.e., colors) in the lookup table.
vtkLookupTable::GetTableValue
void GetTableValue(vtkIdType indx, double rgba[4])
Return an RGBA color value for the given index into the lookup table.
VTK_RAMP_SCURVE
#define VTK_RAMP_SCURVE
Definition: vtkLookupTable.h:172
vtkLookupTable::Table
vtkUnsignedCharArray * Table
Definition: vtkLookupTable.h:537
VTK_SCALE_LOG10
#define VTK_SCALE_LOG10
Definition: vtkLookupTable.h:175
vtkLookupTable::SetRampToLinear
void SetRampToLinear()
Set the shape of the table ramp to either S-curve, linear, or sqrt.
Definition: vtkLookupTable.h:251
vtkLookupTable::GetPointer
unsigned char * GetPointer(vtkIdType id)
Get pointer to color table data.
Definition: vtkLookupTable.h:441
vtkLookupTable::UseBelowRangeColor
vtkTypeBool UseBelowRangeColor
Definition: vtkLookupTable.h:545
VTK_SCALE_LINEAR
#define VTK_SCALE_LINEAR
Definition: vtkLookupTable.h:174
vtkLookupTable::GetRange
double * GetRange() override
Sets/Gets the range of scalars which will be mapped.
Definition: vtkLookupTable.h:460
vtkLookupTable::GetIndex
virtual vtkIdType GetIndex(double v)
Return the table index associated with a particular value.
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69
vtkLookupTable::IsOpaque
int IsOpaque() override
Return true if all of the values defining the mapping have an opacity equal to 1.
vtkLookupTable::SetRange
void SetRange(double min, double max) override
Sets/Gets the range of scalars which will be mapped.
Definition: vtkLookupTable.h:461