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 
78  static const vtkIdType NAN_COLOR_INDEX;
81 
86  static vtkLookupTable *New();
87 
89  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
90 
95  int IsOpaque() VTK_OVERRIDE;
96 
100  int Allocate(int sz=256, int ext=256);
101 
106  void Build() VTK_OVERRIDE;
107 
115  virtual void ForceBuild();
116 
120  void BuildSpecialColors();
121 
123 
132  vtkSetMacro(Ramp,int);
133  void SetRampToLinear() { this->SetRamp(VTK_RAMP_LINEAR); };
134  void SetRampToSCurve() { this->SetRamp(VTK_RAMP_SCURVE); };
135  void SetRampToSQRT() { this->SetRamp(VTK_RAMP_SQRT); };
136  vtkGetMacro(Ramp,int);
138 
140 
145  void SetScale(int scale);
146  void SetScaleToLinear() { this->SetScale(VTK_SCALE_LINEAR); };
147  void SetScaleToLog10() { this->SetScale(VTK_SCALE_LOG10); };
148  vtkGetMacro(Scale,int);
150 
152 
160  void SetTableRange(double r[2]);
161  virtual void SetTableRange(double min, double max);
162  vtkGetVectorMacro(TableRange,double,2);
164 
166 
170  vtkSetVector2Macro(HueRange,double);
171  vtkGetVector2Macro(HueRange,double);
173 
175 
179  vtkSetVector2Macro(SaturationRange,double);
180  vtkGetVector2Macro(SaturationRange,double);
182 
184 
188  vtkSetVector2Macro(ValueRange,double);
189  vtkGetVector2Macro(ValueRange,double);
191 
193 
197  vtkSetVector2Macro(AlphaRange,double);
198  vtkGetVector2Macro(AlphaRange,double);
200 
202 
206  vtkSetVector4Macro(NanColor, double);
207  vtkGetVector4Macro(NanColor, double);
209 
214  unsigned char* GetNanColorAsUnsignedChars();
215 
220  static void GetColorAsUnsignedChars(const double colorIn[4],
221  unsigned char colorOut[4]);
222 
224 
228  vtkSetVector4Macro(BelowRangeColor, double);
229  vtkGetVector4Macro(BelowRangeColor, double);
231 
233 
236  vtkSetMacro(UseBelowRangeColor, int);
237  vtkGetMacro(UseBelowRangeColor, int);
238  vtkBooleanMacro(UseBelowRangeColor, int);
240 
242 
246  vtkSetVector4Macro(AboveRangeColor, double);
247  vtkGetVector4Macro(AboveRangeColor, double);
249 
251 
254  vtkSetMacro(UseAboveRangeColor, int);
255  vtkGetMacro(UseAboveRangeColor, int);
256  vtkBooleanMacro(UseAboveRangeColor, int);
258 
262  unsigned char* MapValue(double v) VTK_OVERRIDE;
263 
268  void GetColor(double x, double rgb[3]) VTK_OVERRIDE;
269 
274  double GetOpacity(double v) VTK_OVERRIDE;
275 
284  virtual vtkIdType GetIndex(double v);
285 
287 
291  void SetNumberOfTableValues(vtkIdType number);
292  vtkIdType GetNumberOfTableValues() { return this->NumberOfColors; };
294 
301  virtual void SetTableValue(vtkIdType indx, double rgba[4]);
302 
307  virtual void SetTableValue(vtkIdType indx,
308  double r, double g, double b, double a=1.0);
309 
314  double *GetTableValue(vtkIdType id);
315 
320  void GetTableValue(vtkIdType id, double rgba[4]);
321 
326  unsigned char *GetPointer(const vtkIdType id) {
327  return this->Table->GetPointer(4*id); };
328 
339  unsigned char *WritePointer(const vtkIdType id, const int number);
340 
342 
346  double *GetRange() VTK_OVERRIDE
347  { return this->GetTableRange(); };
348  void SetRange(double min, double max) VTK_OVERRIDE
349  { this->SetTableRange(min, max); };
350  void SetRange(double rng[2]) { this->SetRange(rng[0], rng[1]); };
352 
359  static void GetLogRange(const double range[2], double log_range[2]);
360 
364  static double ApplyLogScale(double v, const double range[2],
365  const double log_range[2]);
366 
368 
374  vtkSetClampMacro(NumberOfColors,vtkIdType,2,VTK_ID_MAX);
375  vtkGetMacro(NumberOfColors,vtkIdType);
377 
379 
384  void SetTable(vtkUnsignedCharArray *);
385  vtkGetObjectMacro(Table,vtkUnsignedCharArray);
387 
393  void MapScalarsThroughTable2(void *input,
394  unsigned char *output,
395  int inputDataType,
396  int numberOfValues,
397  int inputIncrement,
398  int outputIncrement) VTK_OVERRIDE;
399 
403  void DeepCopy(vtkScalarsToColors *lut) VTK_OVERRIDE;
404 
409  int UsingLogScale() VTK_OVERRIDE
410  {
411  return (this->GetScale() == VTK_SCALE_LOG10)? 1 : 0;
412  }
413 
417  vtkIdType GetNumberOfAvailableColors() VTK_OVERRIDE;
418 
426  void GetIndexedColor(vtkIdType idx, double rgba[4]) VTK_OVERRIDE;
427 
428 protected:
429  vtkLookupTable(int sze=256, int ext=256);
430  ~vtkLookupTable() VTK_OVERRIDE;
431 
432  vtkIdType NumberOfColors;
434  double TableRange[2];
435  double HueRange[2];
436  double SaturationRange[2];
437  double ValueRange[2];
438  double AlphaRange[2];
439  double NanColor[4];
440  double BelowRangeColor[4];
441  int UseBelowRangeColor;
442  double AboveRangeColor[4];
443  int UseAboveRangeColor;
444 
445  int Scale;
446  int Ramp;
447  vtkTimeStamp InsertTime;
449  double RGBA[4]; //used during conversion process
450  unsigned char NanColorChar[4];
451 
452  int OpaqueFlag;
453  vtkTimeStamp OpaqueFlagBuildTime;
454  vtkTimeStamp SpecialColorsBuildTime;
455 
459  void ResizeTableForSpecialColors();
460 
461 private:
462  vtkLookupTable(const vtkLookupTable&) VTK_DELETE_FUNCTION;
463  void operator=(const vtkLookupTable&) VTK_DELETE_FUNCTION;
464 };
465 
466 //----------------------------------------------------------------------------
467 inline unsigned char *vtkLookupTable::WritePointer(const vtkIdType id,
468  const int number)
469 {
470  this->InsertTime.Modified();
471  return this->Table->WritePointer(4*id,4*number);
472 }
473 
474 #endif
vtkTimeStamp BuildTime
record modification and/or execution time
Definition: vtkTimeStamp.h:32
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.
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 is 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 unsigned char * MapValue(double v)
Map one value through the lookup table and return a color defined as a RGBA unsigned char tuple (4 by...
void SetRampToSCurve()
Set the shape of the table ramp to either linear or S-curve.
Superclass for mapping scalar values to colors.
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
a simple class to control print indentation
Definition: vtkIndent.h:33
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
static const vtkIdType NAN_COLOR_INDEX
Constants for offsets of special colors (e.g., NanColor, BelowRangeColor, AboveRangeColor) from the m...
unsigned char * GetPointer(const vtkIdType id)
Get pointer to color table data.
dynamic, self-adjusting array of unsigned char
vtkSetMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
void SetRange(double rng[2])
Sets/Gets the range of scalars which will be mapped.
#define VTK_RAMP_LINEAR
#define VTK_ID_MAX
Definition: vtkType.h:349
void SetRampToSQRT()
Set the shape of the table ramp to either linear or S-curve.
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
vtkBooleanMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
#define VTK_RAMP_SQRT
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.