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
74class VTKCOMMONCORE_EXPORT vtkLookupTable : public vtkScalarsToColors
75{
76public:
78
87
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
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
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
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
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
424
432 void GetIndexedColor(vtkIdType idx, double rgba[4]) VTK_OVERRIDE;
433
434protected:
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
466private:
467 vtkLookupTable(const vtkLookupTable&) VTK_DELETE_FUNCTION;
468 void operator=(const vtkLookupTable&) VTK_DELETE_FUNCTION;
469};
470
471//----------------------------------------------------------------------------
472inline 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
a simple class to control print indentation
Definition: vtkIndent.h:40
map scalar values into colors via a lookup table
void SetScaleToLinear()
static const vtkIdType ABOVE_RANGE_COLOR_INDEX
double GetOpacity(double v) override
Map one value through the lookup table and return the alpha value (the opacity) as a double between 0...
vtkIdType GetNumberOfAvailableColors() override
Get the number of available colors for mapping to.
static const vtkIdType NUMBER_OF_SPECIAL_COLORS
int UsingLogScale() override
This should return 1 is the subclass is using log scale for mapping scalars to colors.
void DeepCopy(vtkScalarsToColors *lut) override
Copy the contents from another LookupTable.
static vtkLookupTable * New()
Construct with range=[0,1]; and hsv ranges set up for rainbow color table (from red to blue).
static void GetColorAsUnsignedChars(const double colorIn[4], unsigned char colorOut[4])
Cast a double color in a type T color.
void GetColor(double x, double rgb[3]) override
Map one value through the lookup table and return the color as an RGB array of doubles between 0 and ...
void MapScalarsThroughTable2(void *input, unsigned char *output, int inputDataType, int numberOfValues, int inputIncrement, int outputIncrement) override
map a set of scalars through the lookup table
static const vtkIdType BELOW_RANGE_COLOR_INDEX
Constants for offsets of special colors (e.g., NanColor, BelowRangeColor, AboveRangeColor) from the m...
void SetNumberOfTableValues(vtkIdType number)
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.
virtual void SetTableValue(vtkIdType indx, double r, double g, double b, double a=1.0)
Directly load color into lookup table.
void GetTableValue(vtkIdType id, double rgba[4])
Return a rgba color value for the given index into the lookup table.
unsigned char * GetPointer(const vtkIdType id)
Get pointer to color table data.
double * GetTableValue(vtkIdType id)
Return a rgba color value for the given index into the lookup table.
virtual vtkIdType GetIndex(double v)
Return the table index associated with a particular value.
unsigned char * MapValue(double v) override
Map one value through the lookup table.
virtual void SetTableRange(double min, double max)
void SetTableRange(double r[2])
Set/Get the minimum/maximum scalar values for scalar mapping.
void SetScaleToLog10()
void SetRange(double rng[2])
void SetRange(double min, double max) override
void SetRampToSCurve()
static void GetLogRange(const double range[2], double log_range[2])
Returns the log of range in log_range.
void SetTable(vtkUnsignedCharArray *)
Set/Get the internal table array that is used to map the scalars to colors.
virtual void SetTableValue(vtkIdType indx, double rgba[4])
Directly load color into lookup table.
void SetScale(int scale)
Set the type of scale to use, linear or logarithmic.
vtkIdType GetNumberOfTableValues()
static double ApplyLogScale(double v, const double range[2], const double log_range[2])
Apply log to value, with appropriate constraints.
unsigned char * GetNanColorAsUnsignedChars()
Return the NanColor as a pointer to 4 unsigned chars.
double * GetRange() override
Sets/Gets the range of scalars which will be mapped.
int IsOpaque() override
Return true if all of the values defining the mapping have an opacity equal to 1.
static const vtkIdType NAN_COLOR_INDEX
Superclass for mapping scalar values to colors.
record modification and/or execution time
Definition: vtkTimeStamp.h:36
void Modified()
Set this objects time to the current time.
dynamic, self-adjusting array of unsigned char
@ scale
Definition: vtkX3D.h:229
@ range
Definition: vtkX3D.h:238
#define VTK_SCALE_LOG10
#define VTK_SCALE_LINEAR
#define VTK_RAMP_SQRT
#define VTK_RAMP_LINEAR
#define VTK_RAMP_SCURVE
vtkSetMacro(IgnoreDriverBugs, bool)
Updates the extensions string.
vtkTimeStamp BuildTime
Updates the extensions string.
vtkBooleanMacro(IgnoreDriverBugs, bool)
Updates the extensions string.
int vtkIdType
Definition: vtkType.h:287
#define VTK_ID_MAX
Definition: vtkType.h:291
#define max(a, b)