VTK
vtkColorTransferFunction.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkColorTransferFunction.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 =========================================================================*/
36 #ifndef vtkColorTransferFunction_h
37 #define vtkColorTransferFunction_h
38 
39 #include "vtkRenderingCoreModule.h" // For export macro
40 #include "vtkScalarsToColors.h"
41 
42 class vtkColorTransferFunctionInternals;
43 
44 #define VTK_CTF_RGB 0
45 #define VTK_CTF_HSV 1
46 #define VTK_CTF_LAB 2
47 #define VTK_CTF_DIVERGING 3
48 #define VTK_CTF_LAB_CIEDE2000 4
49 #define VTK_CTF_STEP 5
50 
51 #define VTK_CTF_LINEAR 0
52 #define VTK_CTF_LOG10 1
53 
54 class VTKRENDERINGCORE_EXPORT vtkColorTransferFunction : public vtkScalarsToColors
55 {
56 public:
59  void DeepCopy(vtkScalarsToColors* f) override;
61 
65  void PrintSelf(ostream& os, vtkIndent indent) override;
66 
70  int GetSize();
71 
73 
79  int AddRGBPoint(double x, double r, double g, double b);
80  int AddRGBPoint(double x, double r, double g, double b, double midpoint, double sharpness);
81  int AddHSVPoint(double x, double h, double s, double v);
82  int AddHSVPoint(double x, double h, double s, double v, double midpoint, double sharpness);
83  int RemovePoint(double x);
85 
87 
91  void AddRGBSegment(double x1,
92  double r1,
93  double g1,
94  double b1,
95  double x2,
96  double r2,
97  double g2,
98  double b2);
99  void AddHSVSegment(double x1,
100  double h1,
101  double s1,
102  double v1,
103  double x2,
104  double h2,
105  double s2,
106  double v2);
108 
113 
117  double* GetColor(double x) VTK_SIZEHINT(3) { return vtkScalarsToColors::GetColor(x); }
118  void GetColor(double x, double rgb[3]) override;
119 
121 
124  double GetRedValue(double x);
125  double GetGreenValue(double x);
126  double GetBlueValue(double x);
128 
130 
135  int GetNodeValue(int index, double val[6]);
136  int SetNodeValue(int index, double val[6]);
138 
142  const unsigned char* MapValue(double v) override;
143 
145 
148  double* GetRange() VTK_SIZEHINT(2) override { return this->Range; }
149  virtual void GetRange(double& arg1, double& arg2)
150  {
151  arg1 = this->Range[0];
152  arg2 = this->Range[1];
153  }
154  virtual void GetRange(double _arg[2]) { this->GetRange(_arg[0], _arg[1]); }
156 
162  int AdjustRange(double range[2]);
163 
165 
171  void GetTable(double x1, double x2, int n, double* table);
172  void GetTable(double x1, double x2, int n, float* table);
173  const unsigned char* GetTable(double x1, double x2, int n);
175 
185  void BuildFunctionFromTable(double x1, double x2, int size, double* table);
186 
188 
196  vtkSetClampMacro(Clamping, vtkTypeBool, 0, 1);
197  vtkGetMacro(Clamping, vtkTypeBool);
198  vtkBooleanMacro(Clamping, vtkTypeBool);
200 
202 
214  vtkSetClampMacro(ColorSpace, int, VTK_CTF_RGB, VTK_CTF_STEP);
215  void SetColorSpaceToRGB() { this->SetColorSpace(VTK_CTF_RGB); }
216  void SetColorSpaceToHSV() { this->SetColorSpace(VTK_CTF_HSV); }
217  void SetColorSpaceToLab() { this->SetColorSpace(VTK_CTF_LAB); }
218  void SetColorSpaceToLabCIEDE2000() { this->SetColorSpace(VTK_CTF_LAB_CIEDE2000); }
219  void SetColorSpaceToDiverging() { this->SetColorSpace(VTK_CTF_DIVERGING); }
220  void SetColorSpaceToStep() { this->SetColorSpace(VTK_CTF_STEP); }
221  vtkGetMacro(ColorSpace, int);
222  vtkSetMacro(HSVWrap, vtkTypeBool);
223  vtkGetMacro(HSVWrap, vtkTypeBool);
224  vtkBooleanMacro(HSVWrap, vtkTypeBool);
226 
228 
233  vtkSetMacro(Scale, int);
234  void SetScaleToLinear() { this->SetScale(VTK_CTF_LINEAR); }
235  void SetScaleToLog10() { this->SetScale(VTK_CTF_LOG10); }
236  vtkGetMacro(Scale, int);
238 
240 
245  vtkSetVector3Macro(NanColor, double);
246  vtkGetVector3Macro(NanColor, double);
248 
250 
254  vtkSetMacro(NanOpacity, double);
255  vtkGetMacro(NanOpacity, double);
257 
259 
264  virtual void SetNanColorRGBA(double r, double g, double b, double a)
265  {
266  this->SetNanColor(r, g, b);
267  this->SetNanOpacity(a);
268  }
269 
270  void SetNanColorRGBA(double rgba[4])
271  {
272  this->SetNanColorRGBA(rgba[0], rgba[1], rgba[2], rgba[3]);
273  }
275 
277 
281  vtkSetVector3Macro(BelowRangeColor, double);
282  vtkGetVector3Macro(BelowRangeColor, double);
284 
286 
289  vtkSetMacro(UseBelowRangeColor, vtkTypeBool);
290  vtkGetMacro(UseBelowRangeColor, vtkTypeBool);
291  vtkBooleanMacro(UseBelowRangeColor, vtkTypeBool);
293 
295 
299  vtkSetVector3Macro(AboveRangeColor, double);
300  vtkGetVector3Macro(AboveRangeColor, double);
302 
304 
307  vtkSetMacro(UseAboveRangeColor, vtkTypeBool);
308  vtkGetMacro(UseAboveRangeColor, vtkTypeBool);
309  vtkBooleanMacro(UseAboveRangeColor, vtkTypeBool);
311 
319  double* GetDataPointer();
320 
326  void FillFromDataPointer(int n, double* ptr);
327 
331  void MapScalarsThroughTable2(void* input,
332  unsigned char* output,
333  int inputDataType,
334  int numberOfValues,
335  int inputIncrement,
336  int outputIncrement) override;
337 
339 
343  vtkSetMacro(AllowDuplicateScalars, vtkTypeBool);
344  vtkGetMacro(AllowDuplicateScalars, vtkTypeBool);
345  vtkBooleanMacro(AllowDuplicateScalars, vtkTypeBool);
347 
352 
359  void GetIndexedColor(vtkIdType idx, double rgba[4]) override;
360 
365  int EstimateMinNumberOfSamples(double const& x1, double const& x2);
366 
367 protected:
370 
371  vtkColorTransferFunctionInternals* Internal;
372 
380 
385 
390 
394  int Scale;
395 
399  double NanColor[3];
400 
404  double NanOpacity;
405 
409  double BelowRangeColor[3];
410 
415 
419  double AboveRangeColor[3];
420 
425 
429  double* Function;
430 
434  double Range[2];
435 
439  unsigned char UnsignedCharRGBAValue[4];
440 
445 
447  unsigned char* Table;
448 
454 
459  void SetRange(double, double) override {}
460  void SetRange(const double rng[2]) override { this->SetRange(rng[0], rng[1]); }
461 
468 
473  bool UpdateRange();
474 
479  void MovePoint(double oldX, double newX);
480 
485 
486 private:
488  void operator=(const vtkColorTransferFunction&) = delete;
489 };
490 
491 #endif
vtkColorTransferFunction::~vtkColorTransferFunction
~vtkColorTransferFunction() override
vtkColorTransferFunction::SetColorSpaceToStep
void SetColorSpaceToStep()
Definition: vtkColorTransferFunction.h:220
vtkColorTransferFunction::GetRange
virtual void GetRange(double _arg[2])
Definition: vtkColorTransferFunction.h:154
vtkColorTransferFunction::GetColor
double * GetColor(double x)
Returns an RGB color for the specified scalar value.
Definition: vtkColorTransferFunction.h:117
vtkColorTransferFunction::BuildTime
vtkTimeStamp BuildTime
Definition: vtkColorTransferFunction.h:446
vtkColorTransferFunction::SetNanColorRGBA
void SetNanColorRGBA(double rgba[4])
Definition: vtkColorTransferFunction.h:270
vtkColorTransferFunction::GetDataPointer
double * GetDataPointer()
Returns a pointer to an array of all node values in an interleaved array with the layout [X1,...
vtkColorTransferFunction::UseBelowRangeColor
vtkTypeBool UseBelowRangeColor
Flag indicating whether below-range color should be used.
Definition: vtkColorTransferFunction.h:414
vtkColorTransferFunction::SetRange
void SetRange(double, double) override
Set the range of scalars being mapped.
Definition: vtkColorTransferFunction.h:459
vtkColorTransferFunction::AddHSVPoint
int AddHSVPoint(double x, double h, double s, double v)
vtkColorTransferFunction::AllowDuplicateScalars
vtkTypeBool AllowDuplicateScalars
If on, the same scalar value may have more than one node assigned to it.
Definition: vtkColorTransferFunction.h:444
vtkColorTransferFunction::SetRange
void SetRange(const double rng[2]) override
Definition: vtkColorTransferFunction.h:460
vtkIdType
int vtkIdType
Definition: vtkType.h:347
vtkColorTransferFunction::New
static vtkColorTransferFunction * New()
vtkColorTransferFunction::GetTable
void GetTable(double x1, double x2, int n, float *table)
vtkColorTransferFunction::vtkColorTransferFunction
vtkColorTransferFunction()
vtkColorTransferFunction::SetNanColorRGBA
virtual void SetNanColorRGBA(double r, double g, double b, double a)
Set the RGBA color to use when a NaN (not a number) is encountered.
Definition: vtkColorTransferFunction.h:264
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:36
VTK_CTF_LAB
#define VTK_CTF_LAB
Definition: vtkColorTransferFunction.h:46
vtkColorTransferFunction::GetTable
const unsigned char * GetTable(double x1, double x2, int n)
vtkColorTransferFunction::SetColorSpaceToDiverging
void SetColorSpaceToDiverging()
Definition: vtkColorTransferFunction.h:219
vtkColorTransferFunction::MovePoint
void MovePoint(double oldX, double newX)
Moves point from oldX to newX.
vtkColorTransferFunction::Internal
vtkColorTransferFunctionInternals * Internal
Definition: vtkColorTransferFunction.h:371
vtkX3D::range
@ range
Definition: vtkX3D.h:238
vtkColorTransferFunction::GetTable
void GetTable(double x1, double x2, int n, double *table)
Fills in a table of n colors mapped from values mapped with even spacing between x1 and x2,...
vtkColorTransferFunction::FillFromDataPointer
void FillFromDataPointer(int n, double *ptr)
Defines the nodes from an array ptr with the layout [X1, R1, G1, B1, X2, R2, G2, B2,...
vtkColorTransferFunction::UpdateRange
bool UpdateRange()
Returns true if the range has been changed.
vtkColorTransferFunction::Scale
int Scale
The color interpolation scale (linear or logarithmic).
Definition: vtkColorTransferFunction.h:394
vtkColorTransferFunction::GetSize
int GetSize()
How many nodes define this function?
vtkColorTransferFunction::BuildFunctionFromTable
void BuildFunctionFromTable(double x1, double x2, int size, double *table)
Construct a color transfer function from a table.
vtkColorTransferFunction::NanOpacity
double NanOpacity
The opacity to use for not-a-number.
Definition: vtkColorTransferFunction.h:404
vtkColorTransferFunction
Defines a transfer function for mapping a property to an RGB color value.
Definition: vtkColorTransferFunction.h:55
vtkColorTransferFunction::AddRGBPoint
int AddRGBPoint(double x, double r, double g, double b)
Add/Remove a point to/from the function defined in RGB or HSV Return the index of the point (0 based)...
vtkColorTransferFunction::SetColorSpaceToLab
void SetColorSpaceToLab()
Definition: vtkColorTransferFunction.h:217
vtkColorTransferFunction::AddRGBPoint
int AddRGBPoint(double x, double r, double g, double b, double midpoint, double sharpness)
vtkColorTransferFunction::GetRedValue
double GetRedValue(double x)
Get the color components individually.
VTK_CTF_LINEAR
#define VTK_CTF_LINEAR
Definition: vtkColorTransferFunction.h:51
vtkColorTransferFunction::GetIndexedColor
void GetIndexedColor(vtkIdType idx, double rgba[4]) override
Return a color given an integer index.
vtkColorTransferFunction::GetBlueValue
double GetBlueValue(double x)
VTK_CTF_LAB_CIEDE2000
#define VTK_CTF_LAB_CIEDE2000
Definition: vtkColorTransferFunction.h:48
vtkColorTransferFunction::GetNumberOfAvailableColors
vtkIdType GetNumberOfAvailableColors() override
Get the number of available colors for mapping to.
vtkColorTransferFunction::SetScaleToLog10
void SetScaleToLog10()
Definition: vtkColorTransferFunction.h:235
VTK_SIZEHINT
#define VTK_SIZEHINT(...)
Definition: vtkWrappingHints.h:42
vtkColorTransferFunction::SetColorSpaceToRGB
void SetColorSpaceToRGB()
Definition: vtkColorTransferFunction.h:215
vtkColorTransferFunction::SetScaleToLinear
void SetScaleToLinear()
Definition: vtkColorTransferFunction.h:234
vtkColorTransferFunction::AdjustRange
int AdjustRange(double range[2])
Remove all points out of the new range, and make sure there is a point at each end of that range.
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:40
vtkColorTransferFunction::AddHSVPoint
int AddHSVPoint(double x, double h, double s, double v, double midpoint, double sharpness)
vtkScalarsToColors.h
vtkColorTransferFunction::TableSize
int TableSize
Temporary storage for the size of the table.
Definition: vtkColorTransferFunction.h:453
vtkX3D::size
@ size
Definition: vtkX3D.h:253
VTK_CTF_RGB
#define VTK_CTF_RGB
Definition: vtkColorTransferFunction.h:44
vtkColorTransferFunction::UseAboveRangeColor
vtkTypeBool UseAboveRangeColor
Flag indicating whether below-range color should be used.
Definition: vtkColorTransferFunction.h:424
vtkColorTransferFunction::AddRGBSegment
void AddRGBSegment(double x1, double r1, double g1, double b1, double x2, double r2, double g2, double b2)
Add two points to the function and remove all the points between them.
vtkScalarsToColors
Superclass for mapping scalar values to colors.
Definition: vtkScalarsToColors.h:67
vtkColorTransferFunction::Table
unsigned char * Table
Definition: vtkColorTransferFunction.h:447
VTK_CTF_STEP
#define VTK_CTF_STEP
Definition: vtkColorTransferFunction.h:49
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...
vtkColorTransferFunction::RemoveAllPoints
void RemoveAllPoints()
Remove all points.
vtkColorTransferFunction::GetGreenValue
double GetGreenValue(double x)
vtkColorTransferFunction::DeepCopy
void DeepCopy(vtkScalarsToColors *f) override
Copy the contents from another object.
vtkColorTransferFunction::ColorSpace
int ColorSpace
The color space in which interpolation is performed.
Definition: vtkColorTransferFunction.h:384
vtkColorTransferFunction::GetColor
void GetColor(double x, double rgb[3]) override
Map one value through the lookup table and store the color as an RGB array of doubles between 0 and 1...
vtkColorTransferFunction::GetRange
double * GetRange() override
Returns min and max position of all function points.
Definition: vtkColorTransferFunction.h:148
vtkColorTransferFunction::Clamping
vtkTypeBool Clamping
Determines the function value outside of defined points Zero = always return 0.0 outside of defined p...
Definition: vtkColorTransferFunction.h:379
vtkColorTransferFunction::MapValue
const unsigned char * MapValue(double v) override
Map one value through the lookup table.
vtkColorTransferFunction::RemovePoint
int RemovePoint(double x)
vtkColorTransferFunction::SetColorSpaceToHSV
void SetColorSpaceToHSV()
Definition: vtkColorTransferFunction.h:216
vtkColorTransferFunction::SetNodeValue
int SetNodeValue(int index, double val[6])
vtkColorTransferFunction::GetNodeValue
int GetNodeValue(int index, double val[6])
For the node specified by index, set/get the location (X), R, G, and B values, midpoint,...
vtkColorTransferFunction::SortAndUpdateRange
void SortAndUpdateRange()
Internal method to sort the vector and update the Range whenever a node is added, edited or removed I...
vtkColorTransferFunction::MapScalarsThroughTable2
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.
vtkColorTransferFunction::EstimateMinNumberOfSamples
int EstimateMinNumberOfSamples(double const &x1, double const &x2)
Estimates the minimum size of a table such that it would correctly sample this function.
vtkColorTransferFunction::SetColorSpaceToLabCIEDE2000
void SetColorSpaceToLabCIEDE2000()
Definition: vtkColorTransferFunction.h:218
vtkColorTransferFunction::GetRange
virtual void GetRange(double &arg1, double &arg2)
Definition: vtkColorTransferFunction.h:149
VTK_CTF_LOG10
#define VTK_CTF_LOG10
Definition: vtkColorTransferFunction.h:52
vtkColorTransferFunction::Function
double * Function
Temporary array to store data from the nodes.
Definition: vtkColorTransferFunction.h:429
VTK_CTF_DIVERGING
#define VTK_CTF_DIVERGING
Definition: vtkColorTransferFunction.h:47
vtkX3D::index
@ index
Definition: vtkX3D.h:246
vtkColorTransferFunction::ShallowCopy
void ShallowCopy(vtkColorTransferFunction *f)
vtkColorTransferFunction::AddHSVSegment
void AddHSVSegment(double x1, double h1, double s1, double v1, double x2, double h2, double s2, double v2)
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69
h
VTK_CTF_HSV
#define VTK_CTF_HSV
Definition: vtkColorTransferFunction.h:45
vtkColorTransferFunction::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Print method for vtkColorTransferFunction.
vtkColorTransferFunction::HSVWrap
vtkTypeBool HSVWrap
Specify if HSV is wrap or not.
Definition: vtkColorTransferFunction.h:389
vtkColorTransferFunction::FindMinimumXDistance
double FindMinimumXDistance()
Traverses the nodes to find the minimum distance.