VTK  9.0.1
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 
92  double x1, double r1, double g1, double b1, double x2, double r2, double g2, double b2);
94  double x1, double h1, double s1, double v1, double x2, double h2, double s2, double v2);
96 
101 
105  double* GetColor(double x) VTK_SIZEHINT(3) { return vtkScalarsToColors::GetColor(x); }
106  void GetColor(double x, double rgb[3]) override;
107 
109 
112  double GetRedValue(double x);
113  double GetGreenValue(double x);
114  double GetBlueValue(double x);
116 
118 
123  int GetNodeValue(int index, double val[6]);
124  int SetNodeValue(int index, double val[6]);
126 
130  const unsigned char* MapValue(double v) override;
131 
133 
136  double* GetRange() VTK_SIZEHINT(2) override { return this->Range; }
137  virtual void GetRange(double& arg1, double& arg2)
138  {
139  arg1 = this->Range[0];
140  arg2 = this->Range[1];
141  }
142  virtual void GetRange(double _arg[2]) { this->GetRange(_arg[0], _arg[1]); }
144 
150  int AdjustRange(double range[2]);
151 
153 
159  void GetTable(double x1, double x2, int n, double* table);
160  void GetTable(double x1, double x2, int n, float* table);
161  const unsigned char* GetTable(double x1, double x2, int n);
163 
173  void BuildFunctionFromTable(double x1, double x2, int size, double* table);
174 
176 
184  vtkSetClampMacro(Clamping, vtkTypeBool, 0, 1);
185  vtkGetMacro(Clamping, vtkTypeBool);
186  vtkBooleanMacro(Clamping, vtkTypeBool);
188 
190 
202  vtkSetClampMacro(ColorSpace, int, VTK_CTF_RGB, VTK_CTF_STEP);
203  void SetColorSpaceToRGB() { this->SetColorSpace(VTK_CTF_RGB); }
204  void SetColorSpaceToHSV() { this->SetColorSpace(VTK_CTF_HSV); }
205  void SetColorSpaceToLab() { this->SetColorSpace(VTK_CTF_LAB); }
206  void SetColorSpaceToLabCIEDE2000() { this->SetColorSpace(VTK_CTF_LAB_CIEDE2000); }
207  void SetColorSpaceToDiverging() { this->SetColorSpace(VTK_CTF_DIVERGING); }
208  void SetColorSpaceToStep() { this->SetColorSpace(VTK_CTF_STEP); }
209  vtkGetMacro(ColorSpace, int);
210  vtkSetMacro(HSVWrap, vtkTypeBool);
211  vtkGetMacro(HSVWrap, vtkTypeBool);
212  vtkBooleanMacro(HSVWrap, vtkTypeBool);
214 
216 
221  vtkSetMacro(Scale, int);
222  void SetScaleToLinear() { this->SetScale(VTK_CTF_LINEAR); }
223  void SetScaleToLog10() { this->SetScale(VTK_CTF_LOG10); }
224  vtkGetMacro(Scale, int);
226 
228 
233  vtkSetVector3Macro(NanColor, double);
234  vtkGetVector3Macro(NanColor, double);
236 
238 
242  vtkSetMacro(NanOpacity, double);
243  vtkGetMacro(NanOpacity, double);
245 
247 
252  virtual void SetNanColorRGBA(double r, double g, double b, double a)
253  {
254  this->SetNanColor(r, g, b);
255  this->SetNanOpacity(a);
256  }
257 
258  void SetNanColorRGBA(double rgba[4])
259  {
260  this->SetNanColorRGBA(rgba[0], rgba[1], rgba[2], rgba[3]);
261  }
263 
265 
269  vtkSetVector3Macro(BelowRangeColor, double);
270  vtkGetVector3Macro(BelowRangeColor, double);
272 
274 
277  vtkSetMacro(UseBelowRangeColor, vtkTypeBool);
278  vtkGetMacro(UseBelowRangeColor, vtkTypeBool);
279  vtkBooleanMacro(UseBelowRangeColor, vtkTypeBool);
281 
283 
287  vtkSetVector3Macro(AboveRangeColor, double);
288  vtkGetVector3Macro(AboveRangeColor, double);
290 
292 
295  vtkSetMacro(UseAboveRangeColor, vtkTypeBool);
296  vtkGetMacro(UseAboveRangeColor, vtkTypeBool);
297  vtkBooleanMacro(UseAboveRangeColor, vtkTypeBool);
299 
307  double* GetDataPointer();
308 
314  void FillFromDataPointer(int n, double* ptr);
315 
319  void MapScalarsThroughTable2(void* input, unsigned char* output, int inputDataType,
320  int numberOfValues, int inputIncrement, int outputIncrement) override;
321 
323 
327  vtkSetMacro(AllowDuplicateScalars, vtkTypeBool);
328  vtkGetMacro(AllowDuplicateScalars, vtkTypeBool);
329  vtkBooleanMacro(AllowDuplicateScalars, vtkTypeBool);
331 
336 
343  void GetIndexedColor(vtkIdType idx, double rgba[4]) override;
344 
349  int EstimateMinNumberOfSamples(double const& x1, double const& x2);
350 
351 protected:
354 
355  vtkColorTransferFunctionInternals* Internal;
356 
364 
369 
374 
378  int Scale;
379 
383  double NanColor[3];
384 
388  double NanOpacity;
389 
393  double BelowRangeColor[3];
394 
399 
403  double AboveRangeColor[3];
404 
409 
413  double* Function;
414 
418  double Range[2];
419 
423  unsigned char UnsignedCharRGBAValue[4];
424 
429 
431  unsigned char* Table;
432 
438 
443  void SetRange(double, double) override {}
444  void SetRange(const double rng[2]) override { this->SetRange(rng[0], rng[1]); }
445 
452 
457  bool UpdateRange();
458 
463  void MovePoint(double oldX, double newX);
464 
469 
470 private:
472  void operator=(const vtkColorTransferFunction&) = delete;
473 };
474 
475 #endif
Defines a transfer function for mapping a property to an RGB color value.
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.
const unsigned char * MapValue(double v) override
Map one value through the lookup table.
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,...
int Scale
The color interpolation scale (linear or logarithmic).
void BuildFunctionFromTable(double x1, double x2, int size, double *table)
Construct a color transfer function from a table.
void DeepCopy(vtkScalarsToColors *f) override
Copy the contents from another object.
void RemoveAllPoints()
Remove all points.
void AddHSVSegment(double x1, double h1, double s1, double v1, double x2, double h2, double s2, double v2)
void SetNanColorRGBA(double rgba[4])
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.
int AddHSVPoint(double x, double h, double s, double v)
void GetTable(double x1, double x2, int n, float *table)
int RemovePoint(double x)
int TableSize
Temporary storage for the size of the table.
void PrintSelf(ostream &os, vtkIndent indent) override
Print method for vtkColorTransferFunction.
~vtkColorTransferFunction() override
int EstimateMinNumberOfSamples(double const &x1, double const &x2)
Estimates the minimum size of a table such that it would correctly sample this function.
double NanOpacity
The opacity to use for not-a-number.
const unsigned char * GetTable(double x1, double x2, int n)
double GetRedValue(double x)
Get the color components individually.
vtkIdType GetNumberOfAvailableColors() override
Get the number of available colors for mapping to.
int ColorSpace
The color space in which interpolation is performed.
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.
int AddRGBPoint(double x, double r, double g, double b, double midpoint, double sharpness)
int GetSize()
How many nodes define this function?
vtkColorTransferFunctionInternals * Internal
int AddHSVPoint(double x, double h, double s, double v, double midpoint, double sharpness)
void MovePoint(double oldX, double newX)
Moves point from oldX to newX.
int GetNodeValue(int index, double val[6])
For the node specified by index, set/get the location (X), R, G, and B values, midpoint,...
double FindMinimumXDistance()
Traverses the nodes to find the minimum distance.
double * GetColor(double x)
Returns an RGB color for the specified scalar value.
void SetRange(const double rng[2]) override
virtual void GetRange(double &arg1, double &arg2)
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)...
vtkTypeBool HSVWrap
Specify if HSV is wrap or not.
double * Function
Temporary array to store data from the nodes.
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.
int SetNodeValue(int index, double val[6])
double GetBlueValue(double x)
static vtkColorTransferFunction * New()
void ShallowCopy(vtkColorTransferFunction *f)
void FillFromDataPointer(int n, double *ptr)
Defines the nodes from an array ptr with the layout [X1, R1, G1, B1, X2, R2, G2, B2,...
vtkTypeBool UseAboveRangeColor
Flag indicating whether below-range color should be used.
vtkTypeBool UseBelowRangeColor
Flag indicating whether below-range color should be used.
double * GetDataPointer()
Returns a pointer to an array of all node values in an interleaved array with the layout [X1,...
vtkTypeBool Clamping
Determines the function value outside of defined points Zero = always return 0.0 outside of defined p...
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...
vtkTypeBool AllowDuplicateScalars
If on, the same scalar value may have more than one node assigned to it.
void SetRange(double, double) override
Set the range of scalars being mapped.
void SortAndUpdateRange()
Internal method to sort the vector and update the Range whenever a node is added, edited or removed I...
void GetIndexedColor(vtkIdType idx, double rgba[4]) override
Return a color given an integer index.
virtual void GetRange(double _arg[2])
bool UpdateRange()
Returns true if the range has been changed.
double GetGreenValue(double x)
double * GetRange() override
Returns min and max position of all function points.
vtkFrustumSelector is a vtkSelector that selects elements based on whether they are inside or interse...
a simple class to control print indentation
Definition: vtkIndent.h:34
Superclass for mapping scalar values to colors.
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...
record modification and/or execution time
Definition: vtkTimeStamp.h:33
@ range
Definition: vtkX3D.h:244
@ size
Definition: vtkX3D.h:259
@ index
Definition: vtkX3D.h:252
auto Range(IterablePtr iterable, Options &&... opts) -> typename detail::IterableTraits< typename detail::StripPointers< IterablePtr >::type >::RangeType
Generate an iterable STL proxy object for a VTK container.
Definition: vtkRange.h:85
int vtkTypeBool
Definition: vtkABI.h:69
#define VTK_CTF_DIVERGING
#define VTK_CTF_LAB_CIEDE2000
#define VTK_CTF_RGB
#define VTK_CTF_LAB
#define VTK_CTF_LINEAR
#define VTK_CTF_HSV
#define VTK_CTF_STEP
#define VTK_CTF_LOG10
int vtkIdType
Definition: vtkType.h:338
#define VTK_SIZEHINT(...)