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
vtkLookupTable::NumberOfColors
vtkIdType NumberOfColors
Definition: vtkLookupTable.h:437
vtkAOSDataArrayTemplate::WritePointer
ValueType * WritePointer(vtkIdType valueIdx, vtkIdType numValues)
Get the address of a particular data index.
vtkLookupTable::OpaqueFlagBuildTime
vtkTimeStamp OpaqueFlagBuildTime
Definition: vtkLookupTable.h:458
vtkX3D::scale
Definition: vtkX3D.h:229
vtkLookupTable::UseAboveRangeColor
vtkTypeBool UseAboveRangeColor
Definition: vtkLookupTable.h:448
vtkIdType
int vtkIdType
Definition: vtkType.h:347
vtkLookupTable::NAN_COLOR_INDEX
static const vtkIdType NAN_COLOR_INDEX
Definition: vtkLookupTable.h:80
vtkLookupTable::ABOVE_RANGE_COLOR_INDEX
static const vtkIdType ABOVE_RANGE_COLOR_INDEX
Definition: vtkLookupTable.h:79
vtkLookupTable::BELOW_RANGE_COLOR_INDEX
static const vtkIdType BELOW_RANGE_COLOR_INDEX
Definition: vtkLookupTable.h:78
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:32
VTK_RAMP_LINEAR
#define VTK_RAMP_LINEAR
Definition: vtkLookupTable.h:62
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:77
vtkUnsignedCharArray
dynamic, self-adjusting array of unsigned char
Definition: vtkUnsignedCharArray.h:35
vtkLookupTable::InsertTime
vtkTimeStamp InsertTime
Definition: vtkLookupTable.h:452
vtkLookupTable::SetScaleToLog10
void SetScaleToLog10()
Definition: vtkLookupTable.h:153
vtkX3D::range
Definition: vtkX3D.h:238
vtkLookupTable::Scale
int Scale
Definition: vtkLookupTable.h:450
vtkScalarsToColors::Build
virtual void Build()
Perform any processing required (if any) before processing scalars.
Definition: vtkScalarsToColors.h:77
vtkLookupTable::SetRange
void SetRange(const double rng[2]) override
Definition: vtkLookupTable.h:355
vtkLookupTable::WritePointer
unsigned char * WritePointer(vtkIdType id, int number)
Get pointer to data.
Definition: vtkLookupTable.h:472
vtkLookupTable::SetRampToSCurve
void SetRampToSCurve()
Definition: vtkLookupTable.h:140
vtkScalarsToColors::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkScalarsToColors::GetIndexedColor
virtual void GetIndexedColor(vtkIdType i, double rgba[4])
Get the "indexed color" assigned to an index.
max
#define max(a, b)
Definition: vtkX3DExporterFIWriterHelper.h:31
vtkLookupTable::NUMBER_OF_SPECIAL_COLORS
static const vtkIdType NUMBER_OF_SPECIAL_COLORS
Definition: vtkLookupTable.h:81
vtkScalarsToColors::GetOpacity
virtual double GetOpacity(double v)
Map one value through the lookup table and return the alpha value (the opacity) as a double between 0...
vtkLookupTable::OpaqueFlag
int OpaqueFlag
Definition: vtkLookupTable.h:457
vtkLookupTable::SpecialColorsBuildTime
vtkTimeStamp SpecialColorsBuildTime
Definition: vtkLookupTable.h:459
VTK_SIZEHINT
#define VTK_SIZEHINT(...)
Definition: vtkWrappingHints.h:42
vtkTimeStamp::Modified
void Modified()
Set this objects time to the current time.
vtkLookupTable::Ramp
int Ramp
Definition: vtkLookupTable.h:451
vtkScalarsToColors::DeepCopy
virtual void DeepCopy(vtkScalarsToColors *o)
Copy the contents from another object.
vtkLookupTable::SetScaleToLinear
void SetScaleToLinear()
Definition: vtkLookupTable.h:152
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkScalarsToColors.h
vtkLookupTable::SetRampToSQRT
void SetRampToSQRT()
Definition: vtkLookupTable.h:141
vtkUnsignedCharArray.h
vtkScalarsToColors
Superclass for mapping scalar values to colors.
Definition: vtkScalarsToColors.h:60
vtkScalarsToColors::MapValue
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...
vtkScalarsToColors::GetColor
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...
vtkLookupTable::GetNumberOfTableValues
vtkIdType GetNumberOfTableValues()
Definition: vtkLookupTable.h:297
vtkLookupTable
map scalar values into colors via a lookup table
Definition: vtkLookupTable.h:68
vtkScalarsToColors::GetNumberOfAvailableColors
virtual vtkIdType GetNumberOfAvailableColors()
Get the number of available colors for mapping to.
vtkLookupTable::BuildTime
vtkTimeStamp BuildTime
Definition: vtkLookupTable.h:453
VTK_RAMP_SQRT
#define VTK_RAMP_SQRT
Definition: vtkLookupTable.h:64
VTK_ID_MAX
#define VTK_ID_MAX
Definition: vtkType.h:351
vtkLookupTable::UsingLogScale
int UsingLogScale() override
This should return 1 if the subclass is using log scale for mapping scalars to colors.
Definition: vtkLookupTable.h:414
vtkScalarsToColors::MapScalarsThroughTable2
virtual void MapScalarsThroughTable2(void *input, unsigned char *output, int inputDataType, int numberOfValues, int inputIncrement, int outputFormat)
An internal method typically not used in applications.
VTK_RAMP_SCURVE
#define VTK_RAMP_SCURVE
Definition: vtkLookupTable.h:63
vtkLookupTable::Table
vtkUnsignedCharArray * Table
Definition: vtkLookupTable.h:438
vtkScalarsToColors::New
static vtkScalarsToColors * New()
VTK_SCALE_LOG10
#define VTK_SCALE_LOG10
Definition: vtkLookupTable.h:66
vtkLookupTable::SetRampToLinear
void SetRampToLinear()
Definition: vtkLookupTable.h:139
vtkLookupTable::GetPointer
unsigned char * GetPointer(vtkIdType id)
Get pointer to color table data.
Definition: vtkLookupTable.h:331
vtkLookupTable::UseBelowRangeColor
vtkTypeBool UseBelowRangeColor
Definition: vtkLookupTable.h:446
VTK_SCALE_LINEAR
#define VTK_SCALE_LINEAR
Definition: vtkLookupTable.h:65
vtkLookupTable::GetRange
double * GetRange() override
Sets/Gets the range of scalars which will be mapped.
Definition: vtkLookupTable.h:351
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69
vtkLookupTable::SetRange
void SetRange(double min, double max) override
Definition: vtkLookupTable.h:353
vtkScalarsToColors::IsOpaque
virtual int IsOpaque()
Return true if all of the values defining the mapping have an opacity equal to 1.