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 =========================================================================*/
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 
84  const static vtkIdType NAN_COLOR_INDEX;
87 
92  static vtkLookupTable *New();
93 
95  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
96 
101  int IsOpaque() VTK_OVERRIDE;
102 
106  int Allocate(int sz=256, int ext=256);
107 
112  void Build() VTK_OVERRIDE;
113 
121  virtual void ForceBuild();
122 
126  void BuildSpecialColors();
127 
129 
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  void SetTableRange(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 
226  static void GetColorAsUnsignedChars(const double colorIn[4],
227  unsigned char colorOut[4]);
228 
230 
234  vtkSetVector4Macro(BelowRangeColor, double);
235  vtkGetVector4Macro(BelowRangeColor, double);
237 
239 
242  vtkSetMacro(UseBelowRangeColor, int);
243  vtkGetMacro(UseBelowRangeColor, int);
244  vtkBooleanMacro(UseBelowRangeColor, int);
246 
248 
252  vtkSetVector4Macro(AboveRangeColor, double);
253  vtkGetVector4Macro(AboveRangeColor, double);
255 
257 
260  vtkSetMacro(UseAboveRangeColor, int);
261  vtkGetMacro(UseAboveRangeColor, int);
262  vtkBooleanMacro(UseAboveRangeColor, int);
264 
268  unsigned char* MapValue(double v) VTK_OVERRIDE;
269 
274  void GetColor(double x, double rgb[3]) VTK_OVERRIDE;
275 
280  double GetOpacity(double v) VTK_OVERRIDE;
281 
290  virtual vtkIdType GetIndex(double v);
291 
293 
297  void SetNumberOfTableValues(vtkIdType number);
298  vtkIdType GetNumberOfTableValues() { return this->NumberOfColors; };
300 
307  virtual void SetTableValue(vtkIdType indx, double rgba[4]);
308 
313  virtual void SetTableValue(vtkIdType indx,
314  double r, double g, double b, double a=1.0);
315 
320  double *GetTableValue(vtkIdType id);
321 
326  void GetTableValue(vtkIdType id, double rgba[4]);
327 
332  unsigned char *GetPointer(const vtkIdType id) {
333  return this->Table->GetPointer(4*id); };
334 
345  unsigned char *WritePointer(const vtkIdType id, const int number);
346 
348 
352  double *GetRange() VTK_OVERRIDE
353  { return this->GetTableRange(); };
354  void SetRange(double min, double max) VTK_OVERRIDE
355  { this->SetTableRange(min, max); };
356  void SetRange(double rng[2]) { this->SetRange(rng[0], rng[1]); };
358 
365  static void GetLogRange(const double range[2], double log_range[2]);
366 
370  static double ApplyLogScale(double v, const double range[2],
371  const double log_range[2]);
372 
374 
380  vtkSetClampMacro(NumberOfColors,vtkIdType,2,VTK_ID_MAX);
381  vtkGetMacro(NumberOfColors,vtkIdType);
383 
385 
390  void SetTable(vtkUnsignedCharArray *);
391  vtkGetObjectMacro(Table,vtkUnsignedCharArray);
393 
399  void MapScalarsThroughTable2(void *input,
400  unsigned char *output,
401  int inputDataType,
402  int numberOfValues,
403  int inputIncrement,
404  int outputIncrement) VTK_OVERRIDE;
405 
409  void DeepCopy(vtkScalarsToColors *lut) VTK_OVERRIDE;
410 
415  int UsingLogScale() VTK_OVERRIDE
416  {
417  return (this->GetScale() == VTK_SCALE_LOG10)? 1 : 0;
418  }
419 
423  vtkIdType GetNumberOfAvailableColors() VTK_OVERRIDE;
424 
432  void GetIndexedColor(vtkIdType idx, double rgba[4]) VTK_OVERRIDE;
433 
434 protected:
435  vtkLookupTable(int sze=256, int ext=256);
436  ~vtkLookupTable() VTK_OVERRIDE;
437 
438  vtkIdType NumberOfColors;
440  double TableRange[2];
441  double HueRange[2];
442  double SaturationRange[2];
443  double ValueRange[2];
444  double AlphaRange[2];
445  double NanColor[4];
446  double BelowRangeColor[4];
447  int UseBelowRangeColor;
448  double AboveRangeColor[4];
449  int UseAboveRangeColor;
450 
451  int Scale;
452  int Ramp;
453  vtkTimeStamp InsertTime;
455  double RGBA[4]; //used during conversion process
456  unsigned char NanColorChar[4];
457 
458  int OpaqueFlag;
459  vtkTimeStamp OpaqueFlagBuildTime;
460 
464  void ResizeTableForSpecialColors();
465 
466 private:
467  vtkLookupTable(const vtkLookupTable&) VTK_DELETE_FUNCTION;
468  void operator=(const vtkLookupTable&) VTK_DELETE_FUNCTION;
469 };
470 
471 //----------------------------------------------------------------------------
472 inline unsigned char *vtkLookupTable::WritePointer(const vtkIdType id,
473  const int number)
474 {
475  this->InsertTime.Modified();
476  return this->Table->WritePointer(4*id,4*number);
477 }
478 
479 #endif
vtkTimeStamp BuildTime
record modification and/or execution time
Definition: vtkTimeStamp.h:35
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:287
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:39
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:291
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.