VTK
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 =========================================================================*/
54 #ifndef vtkLookupTable_h
55 #define vtkLookupTable_h
56 
57 #include "vtkCommonCoreModule.h" // For export macro
58 #include "vtkScalarsToColors.h"
59 
60 #include "vtkUnsignedCharArray.h" // Needed for inline method
61 
62 #define VTK_RAMP_LINEAR 0
63 #define VTK_RAMP_SCURVE 1
64 #define VTK_RAMP_SQRT 2
65 #define VTK_SCALE_LINEAR 0
66 #define VTK_SCALE_LOG10 1
67 
68 class VTKCOMMONCORE_EXPORT vtkLookupTable : public vtkScalarsToColors
69 {
70 public:
72 
80  static const vtkIdType NAN_COLOR_INDEX;
83 
88  static vtkLookupTable *New();
89 
91  void PrintSelf(ostream& os, vtkIndent indent) override;
92 
97  int IsOpaque() override;
98 
103  int Allocate(int sz=256, int ext=256);
104 
109  void Build() override;
110 
118  virtual void ForceBuild();
119 
123  void BuildSpecialColors();
124 
126 
138  vtkSetMacro(Ramp,int);
139  void SetRampToLinear() { this->SetRamp(VTK_RAMP_LINEAR); }
140  void SetRampToSCurve() { this->SetRamp(VTK_RAMP_SCURVE); }
141  void SetRampToSQRT() { this->SetRamp(VTK_RAMP_SQRT); }
142  vtkGetMacro(Ramp,int);
144 
146 
151  void SetScale(int scale);
152  void SetScaleToLinear() { this->SetScale(VTK_SCALE_LINEAR); }
153  void SetScaleToLog10() { this->SetScale(VTK_SCALE_LOG10); }
154  vtkGetMacro(Scale,int);
156 
158 
166  virtual void SetTableRange(const double r[2]);
167  virtual void SetTableRange(double min, double max);
168  vtkGetVectorMacro(TableRange,double,2);
170 
172 
176  vtkSetVector2Macro(HueRange,double);
177  vtkGetVector2Macro(HueRange,double);
179 
181 
185  vtkSetVector2Macro(SaturationRange,double);
186  vtkGetVector2Macro(SaturationRange,double);
188 
190 
194  vtkSetVector2Macro(ValueRange,double);
195  vtkGetVector2Macro(ValueRange,double);
197 
199 
203  vtkSetVector2Macro(AlphaRange,double);
204  vtkGetVector2Macro(AlphaRange,double);
206 
208 
212  vtkSetVector4Macro(NanColor, double);
213  vtkGetVector4Macro(NanColor, double);
215 
220  unsigned char* GetNanColorAsUnsignedChars();
221 
225  static void GetColorAsUnsignedChars(const double colorIn[4],
226  unsigned char colorOut[4]);
227 
229 
233  vtkSetVector4Macro(BelowRangeColor, double);
234  vtkGetVector4Macro(BelowRangeColor, double);
236 
238 
241  vtkSetMacro(UseBelowRangeColor, vtkTypeBool);
242  vtkGetMacro(UseBelowRangeColor, vtkTypeBool);
243  vtkBooleanMacro(UseBelowRangeColor, vtkTypeBool);
245 
247 
251  vtkSetVector4Macro(AboveRangeColor, double);
252  vtkGetVector4Macro(AboveRangeColor, double);
254 
256 
259  vtkSetMacro(UseAboveRangeColor, vtkTypeBool);
260  vtkGetMacro(UseAboveRangeColor, vtkTypeBool);
261  vtkBooleanMacro(UseAboveRangeColor, vtkTypeBool);
263 
267  const unsigned char* MapValue(double v) override;
268 
273  void GetColor(double x, double rgb[3]) override;
274 
279  double GetOpacity(double v) override;
280 
290  virtual vtkIdType GetIndex(double v);
291 
293 
296  void SetNumberOfTableValues(vtkIdType number);
297  vtkIdType GetNumberOfTableValues() { return this->NumberOfColors; }
299 
306  virtual void SetTableValue(vtkIdType indx, const double rgba[4]);
307 
312  virtual void SetTableValue(vtkIdType indx,
313  double r, double g, double b, double a=1.0);
314 
319  double *GetTableValue(vtkIdType id) VTK_SIZEHINT(4);
320 
325  void GetTableValue(vtkIdType id, double rgba[4]);
326 
331  unsigned char *GetPointer(vtkIdType id) {
332  return this->Table->GetPointer(4*id); }
333 
344  unsigned char *WritePointer(vtkIdType id, int number);
345 
347 
351  double *GetRange() VTK_SIZEHINT(2) override
352  { return this->GetTableRange(); }
353  void SetRange(double min, double max) override
354  { this->SetTableRange(min, max); }
355  void SetRange(const double rng[2]) override { this->SetRange(rng[0], rng[1]); }
357 
364  static void GetLogRange(const double range[2], double log_range[2]);
365 
369  static double ApplyLogScale(double v, const double range[2],
370  const double log_range[2]);
371 
373 
379  vtkSetClampMacro(NumberOfColors,vtkIdType,2,VTK_ID_MAX);
380  vtkGetMacro(NumberOfColors,vtkIdType);
382 
384 
389  void SetTable(vtkUnsignedCharArray *);
390  vtkGetObjectMacro(Table,vtkUnsignedCharArray);
392 
398  void MapScalarsThroughTable2(void *input,
399  unsigned char *output,
400  int inputDataType,
401  int numberOfValues,
402  int inputIncrement,
403  int outputIncrement) override;
404 
408  void DeepCopy(vtkScalarsToColors *lut) override;
409 
414  int UsingLogScale() override
415  {
416  return (this->GetScale() == VTK_SCALE_LOG10) ? 1 : 0;
417  }
418 
423 
431  void GetIndexedColor(vtkIdType idx, double rgba[4]) override;
432 
433 protected:
434  vtkLookupTable(int sze=256, int ext=256);
435  ~vtkLookupTable() override;
436 
439  double TableRange[2];
440  double HueRange[2];
441  double SaturationRange[2];
442  double ValueRange[2];
443  double AlphaRange[2];
444  double NanColor[4];
445  double BelowRangeColor[4];
447  double AboveRangeColor[4];
449 
450  int Scale;
451  int Ramp;
454  double RGBA[4]; //used during conversion process
455  unsigned char NanColorChar[4];
456 
460 
464  void ResizeTableForSpecialColors();
465 
466 private:
467  vtkLookupTable(const vtkLookupTable&) = delete;
468  void operator=(const vtkLookupTable&) = delete;
469 };
470 
471 //----------------------------------------------------------------------------
472 inline unsigned char *vtkLookupTable::WritePointer(vtkIdType id,
473  int number)
474 {
475  this->InsertTime.Modified();
476  return this->Table->WritePointer(4*id, 4*number);
477 }
478 
479 #endif
void SetRampToLinear()
Set the shape of the table ramp to either S-curve, linear, or sqrt.
vtkTimeStamp InsertTime
vtkIdType NumberOfColors
vtkTimeStamp OpaqueFlagBuildTime
vtkTimeStamp SpecialColorsBuildTime
vtkTypeBool UseBelowRangeColor
record modification and/or execution time
Definition: vtkTimeStamp.h:32
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:345
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:33
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:349
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.