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 =========================================================================*/
60 #ifndef vtkLookupTable_h
61 #define vtkLookupTable_h
62 
63 #include "vtkCommonCoreModule.h" // For export macro
64 #include "vtkScalarsToColors.h"
65 
66 #include "vtkUnsignedCharArray.h" // Needed for inline method
67 
68 #define VTK_RAMP_LINEAR 0
69 #define VTK_RAMP_SCURVE 1
70 #define VTK_RAMP_SQRT 2
71 #define VTK_SCALE_LINEAR 0
72 #define VTK_SCALE_LOG10 1
73 
74 class VTKCOMMONCORE_EXPORT vtkLookupTable : public vtkScalarsToColors
75 {
76 public:
78 
86  static const vtkIdType NAN_COLOR_INDEX;
89 
94  static vtkLookupTable* New();
95 
97  void PrintSelf(ostream& os, vtkIndent indent) override;
98 
100 
104  int IsOpaque() override;
105  int IsOpaque(vtkAbstractArray* scalars, int colorMode, int component) override;
106  int IsOpaque(vtkAbstractArray* scalars, int colorMode, int component,
107  vtkUnsignedCharArray* ghosts, unsigned char ghostsToSkip = 0xff) override;
109 
114  int Allocate(int sz = 256, int ext = 256);
115 
120  void Build() override;
121 
129  virtual void ForceBuild();
130 
134  void BuildSpecialColors();
135 
137 
149  vtkSetMacro(Ramp, int);
150  void SetRampToLinear() { this->SetRamp(VTK_RAMP_LINEAR); }
151  void SetRampToSCurve() { this->SetRamp(VTK_RAMP_SCURVE); }
152  void SetRampToSQRT() { this->SetRamp(VTK_RAMP_SQRT); }
153  vtkGetMacro(Ramp, int);
155 
157 
162  void SetScale(int scale);
163  void SetScaleToLinear() { this->SetScale(VTK_SCALE_LINEAR); }
164  void SetScaleToLog10() { this->SetScale(VTK_SCALE_LOG10); }
165  vtkGetMacro(Scale, int);
167 
169 
177  virtual void SetTableRange(const double r[2]);
178  virtual void SetTableRange(double min, double max);
179  vtkGetVectorMacro(TableRange, double, 2);
181 
183 
187  vtkSetVector2Macro(HueRange, double);
188  vtkGetVector2Macro(HueRange, double);
190 
192 
196  vtkSetVector2Macro(SaturationRange, double);
197  vtkGetVector2Macro(SaturationRange, double);
199 
201 
205  vtkSetVector2Macro(ValueRange, double);
206  vtkGetVector2Macro(ValueRange, double);
208 
210 
214  vtkSetVector2Macro(AlphaRange, double);
215  vtkGetVector2Macro(AlphaRange, double);
217 
219 
223  vtkSetVector4Macro(NanColor, double);
224  vtkGetVector4Macro(NanColor, double);
226 
231  unsigned char* GetNanColorAsUnsignedChars();
232 
236  static void GetColorAsUnsignedChars(const double colorIn[4], unsigned char colorOut[4]);
237 
239 
243  vtkSetVector4Macro(BelowRangeColor, double);
244  vtkGetVector4Macro(BelowRangeColor, double);
246 
248 
251  vtkSetMacro(UseBelowRangeColor, vtkTypeBool);
252  vtkGetMacro(UseBelowRangeColor, vtkTypeBool);
253  vtkBooleanMacro(UseBelowRangeColor, vtkTypeBool);
255 
257 
261  vtkSetVector4Macro(AboveRangeColor, double);
262  vtkGetVector4Macro(AboveRangeColor, double);
264 
266 
269  vtkSetMacro(UseAboveRangeColor, vtkTypeBool);
270  vtkGetMacro(UseAboveRangeColor, vtkTypeBool);
271  vtkBooleanMacro(UseAboveRangeColor, vtkTypeBool);
273 
277  const unsigned char* MapValue(double v) override;
278 
283  void GetColor(double v, double rgb[3]) override;
284 
289  double GetOpacity(double v) override;
290 
300  virtual vtkIdType GetIndex(double v);
301 
303 
306  void SetNumberOfTableValues(vtkIdType number);
307  vtkIdType GetNumberOfTableValues() { return this->NumberOfColors; }
309 
316  virtual void SetTableValue(vtkIdType indx, const double rgba[4]);
317 
322  virtual void SetTableValue(vtkIdType indx, double r, double g, double b, double a = 1.0);
323 
328  double* GetTableValue(vtkIdType indx) VTK_SIZEHINT(4);
329 
334  void GetTableValue(vtkIdType indx, double rgba[4]);
335 
340  unsigned char* GetPointer(vtkIdType id) { return this->Table->GetPointer(4 * id); }
341 
352  unsigned char* WritePointer(vtkIdType id, int number);
353 
355 
359  double* GetRange() VTK_SIZEHINT(2) override { return this->GetTableRange(); }
360  void SetRange(double min, double max) override { this->SetTableRange(min, max); }
361  void SetRange(const double rng[2]) override { this->SetRange(rng[0], rng[1]); }
363 
370  static void GetLogRange(const double range[2], double log_range[2]);
371 
375  static double ApplyLogScale(double v, const double range[2], const double log_range[2]);
376 
378 
384  vtkSetClampMacro(NumberOfColors, vtkIdType, 2, VTK_ID_MAX);
385  vtkGetMacro(NumberOfColors, vtkIdType);
387 
389 
394  void SetTable(vtkUnsignedCharArray*);
395  vtkGetObjectMacro(Table, vtkUnsignedCharArray);
397 
403  void MapScalarsThroughTable2(void* input, unsigned char* output, int inputDataType,
404  int numberOfValues, int inputIncrement, int outputFormat) override;
405 
409  void DeepCopy(vtkScalarsToColors* obj) override;
410 
415  int UsingLogScale() override { return (this->GetScale() == VTK_SCALE_LOG10) ? 1 : 0; }
416 
421 
429  void GetIndexedColor(vtkIdType idx, double rgba[4]) override;
430 
431 protected:
432  vtkLookupTable(int sze = 256, int ext = 256);
433  ~vtkLookupTable() override;
434 
437  double TableRange[2];
438  double HueRange[2];
439  double SaturationRange[2];
440  double ValueRange[2];
441  double AlphaRange[2];
442  double NanColor[4];
443  double BelowRangeColor[4];
445  double AboveRangeColor[4];
447 
448  int Scale;
449  int Ramp;
452  double RGBA[4]; // used during conversion process
453  unsigned char NanColorChar[4];
454 
458 
462  void ResizeTableForSpecialColors();
463 
464 private:
465  vtkLookupTable(const vtkLookupTable&) = delete;
466  void operator=(const vtkLookupTable&) = delete;
467 };
468 
469 //----------------------------------------------------------------------------
470 inline unsigned char* vtkLookupTable::WritePointer(vtkIdType id, int number)
471 {
472  this->InsertTime.Modified();
473  return this->Table->WritePointer(4 * id, 4 * number);
474 }
475 
476 #endif
void SetRampToLinear()
Set the shape of the table ramp to either S-curve, linear, or sqrt.
vtkTimeStamp InsertTime
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:35
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
void Modified()
Set this objects time to the current time.
virtual void MapScalarsThroughTable2(void *input, unsigned char *output, int inputDataType, int numberOfValues, int inputIncrement, int outputFormat)
An internal method typically not used in applications.
unsigned char * WritePointer(vtkIdType id, int number)
Get pointer to data.
int vtkIdType
Definition: vtkType.h:332
void SetRange(double min, double max) override
Sets/Gets the range of scalars which will be mapped.
int UsingLogScale() override
This should return 1 if the subclass is using log scale for mapping scalars to colors.
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:69
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()
virtual int IsOpaque()
Return true if all of the values defining the mapping have an opacity equal to 1. ...
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:39
unsigned char * GetPointer(vtkIdType id)
Get pointer to color table data.
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...
vtkIdType GetNumberOfTableValues()
Specify the number of values (i.e., colors) in the lookup table.
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
vtkUnsignedCharArray * Table
#define VTK_RAMP_LINEAR
#define VTK_ID_MAX
Definition: vtkType.h:336
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_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.