VTK  9.3.0
vtkColorTransferFunction.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
30 #ifndef vtkColorTransferFunction_h
31 #define vtkColorTransferFunction_h
32 
33 #include "vtkRenderingCoreModule.h" // For export macro
34 #include "vtkScalarsToColors.h"
35 
36 VTK_ABI_NAMESPACE_BEGIN
37 class vtkColorTransferFunctionInternals;
38 class vtkDoubleArray;
39 
40 #define VTK_CTF_RGB 0
41 #define VTK_CTF_HSV 1
42 #define VTK_CTF_LAB 2
43 #define VTK_CTF_DIVERGING 3
44 #define VTK_CTF_LAB_CIEDE2000 4
45 #define VTK_CTF_STEP 5
46 
47 #define VTK_CTF_LINEAR 0
48 #define VTK_CTF_LOG10 1
49 
50 class VTKRENDERINGCORE_EXPORT vtkColorTransferFunction : public vtkScalarsToColors
51 {
52 public:
55  void DeepCopy(vtkScalarsToColors* f) override;
57 
61  void PrintSelf(ostream& os, vtkIndent indent) override;
62 
66  int GetSize();
67 
69 
75  int AddRGBPoint(double x, double r, double g, double b);
76  int AddRGBPoint(double x, double r, double g, double b, double midpoint, double sharpness);
78  int AddRGBPoints(vtkDoubleArray* x, vtkDoubleArray* rgbColors, double midpoint, double sharpness);
79  int AddHSVPoint(double x, double h, double s, double v);
80  int AddHSVPoint(double x, double h, double s, double v, double midpoint, double sharpness);
81  int RemovePoint(double x);
83 
85 
90  double x1, double r1, double g1, double b1, double x2, double r2, double g2, double b2);
92  double x1, double h1, double s1, double v1, double x2, double h2, double s2, double v2);
94 
99 
103  double* GetColor(double x) VTK_SIZEHINT(3) { return vtkScalarsToColors::GetColor(x); }
104  void GetColor(double x, double rgb[3]) override;
105 
107 
110  double GetRedValue(double x);
111  double GetGreenValue(double x);
112  double GetBlueValue(double x);
114 
116 
121  int GetNodeValue(int index, double val[6]);
122  int SetNodeValue(int index, double val[6]);
124 
128  const unsigned char* MapValue(double v) override;
129 
131 
134  double* GetRange() VTK_SIZEHINT(2) override { return this->Range; }
135  virtual void GetRange(double& arg1, double& arg2)
136  {
137  arg1 = this->Range[0];
138  arg2 = this->Range[1];
139  }
140  virtual void GetRange(double _arg[2]) { this->GetRange(_arg[0], _arg[1]); }
142 
148  int AdjustRange(double range[2]);
149 
151 
157  void GetTable(double x1, double x2, int n, double* table);
158  void GetTable(double x1, double x2, int n, float* table);
159  const unsigned char* GetTable(double x1, double x2, int n);
161 
171  void BuildFunctionFromTable(double x1, double x2, int size, double* table);
172 
174 
182  vtkSetClampMacro(Clamping, vtkTypeBool, 0, 1);
183  vtkGetMacro(Clamping, vtkTypeBool);
184  vtkBooleanMacro(Clamping, vtkTypeBool);
186 
188 
200  vtkSetClampMacro(ColorSpace, int, VTK_CTF_RGB, VTK_CTF_STEP);
201  void SetColorSpaceToRGB() { this->SetColorSpace(VTK_CTF_RGB); }
202  void SetColorSpaceToHSV() { this->SetColorSpace(VTK_CTF_HSV); }
203  void SetColorSpaceToLab() { this->SetColorSpace(VTK_CTF_LAB); }
204  void SetColorSpaceToLabCIEDE2000() { this->SetColorSpace(VTK_CTF_LAB_CIEDE2000); }
205  void SetColorSpaceToDiverging() { this->SetColorSpace(VTK_CTF_DIVERGING); }
206  void SetColorSpaceToStep() { this->SetColorSpace(VTK_CTF_STEP); }
207  vtkGetMacro(ColorSpace, int);
208  vtkSetMacro(HSVWrap, vtkTypeBool);
209  vtkGetMacro(HSVWrap, vtkTypeBool);
210  vtkBooleanMacro(HSVWrap, vtkTypeBool);
212 
214 
219  vtkSetMacro(Scale, int);
220  void SetScaleToLinear() { this->SetScale(VTK_CTF_LINEAR); }
221  void SetScaleToLog10() { this->SetScale(VTK_CTF_LOG10); }
222  vtkGetMacro(Scale, int);
224 
226 
231  vtkSetVector3Macro(NanColor, double);
232  vtkGetVector3Macro(NanColor, double);
234 
236 
240  vtkSetMacro(NanOpacity, double);
241  vtkGetMacro(NanOpacity, double);
243 
245 
250  virtual void SetNanColorRGBA(double r, double g, double b, double a)
251  {
252  this->SetNanColor(r, g, b);
253  this->SetNanOpacity(a);
254  }
255 
256  void SetNanColorRGBA(double rgba[4])
257  {
258  this->SetNanColorRGBA(rgba[0], rgba[1], rgba[2], rgba[3]);
259  }
261 
263 
267  vtkSetVector3Macro(BelowRangeColor, double);
268  vtkGetVector3Macro(BelowRangeColor, double);
270 
272 
275  vtkSetMacro(UseBelowRangeColor, vtkTypeBool);
276  vtkGetMacro(UseBelowRangeColor, vtkTypeBool);
277  vtkBooleanMacro(UseBelowRangeColor, vtkTypeBool);
279 
281 
285  vtkSetVector3Macro(AboveRangeColor, double);
286  vtkGetVector3Macro(AboveRangeColor, double);
288 
290 
293  vtkSetMacro(UseAboveRangeColor, vtkTypeBool);
294  vtkGetMacro(UseAboveRangeColor, vtkTypeBool);
295  vtkBooleanMacro(UseAboveRangeColor, vtkTypeBool);
297 
305  double* GetDataPointer();
306 
312  void FillFromDataPointer(int n, double* ptr);
313 
317  void MapScalarsThroughTable2(void* input, unsigned char* output, int inputDataType,
318  int numberOfValues, int inputIncrement, int outputIncrement) override;
319 
321 
325  vtkSetMacro(AllowDuplicateScalars, vtkTypeBool);
326  vtkGetMacro(AllowDuplicateScalars, vtkTypeBool);
327  vtkBooleanMacro(AllowDuplicateScalars, vtkTypeBool);
329 
334 
341  void GetIndexedColor(vtkIdType idx, double rgba[4]) override;
342 
347  int EstimateMinNumberOfSamples(double const& x1, double const& x2);
348 
349 protected:
352 
353  vtkColorTransferFunctionInternals* Internal;
354 
362 
367 
372 
376  int Scale;
377 
381  double NanColor[3];
382 
386  double NanOpacity;
387 
391  double BelowRangeColor[3];
392 
397 
401  double AboveRangeColor[3];
402 
407 
411  double* Function;
412 
416  double Range[2];
417 
421  unsigned char UnsignedCharRGBAValue[4];
422 
427 
429  unsigned char* Table;
430 
436 
441  void SetRange(double, double) override {}
442  void SetRange(const double rng[2]) override { this->SetRange(rng[0], rng[1]); }
443 
450 
455  bool UpdateRange();
456 
461  void MovePoint(double oldX, double newX);
462 
467 
468 private:
470  void operator=(const vtkColorTransferFunction&) = delete;
471 };
472 
473 VTK_ABI_NAMESPACE_END
474 #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)
Add two points to the function and remove all the points between them.
void SetNanColorRGBA(double rgba[4])
Set the RGBA color to use when a NaN (not a number) is encountered.
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)
Add/Remove a point to/from the function defined in RGB or HSV Return the index of the point (0 based)...
void GetTable(double x1, double x2, int n, float *table)
Fills in a table of n colors mapped from values mapped with even spacing between x1 and x2,...
int RemovePoint(double x)
Add/Remove a point to/from the function defined in RGB or HSV Return the index of the point (0 based)...
int TableSize
Temporary storage for the size of the table.
void PrintSelf(ostream &os, vtkIndent indent) override
Print method for vtkColorTransferFunction.
~vtkColorTransferFunction() override
int AddRGBPoints(vtkDoubleArray *x, vtkDoubleArray *rgbColors, double midpoint, double sharpness)
Add/Remove a point to/from the function defined in RGB or HSV Return the index of the point (0 based)...
int EstimateMinNumberOfSamples(double const &x1, double const &x2)
Estimates the minimum size of a table such that it would correctly sample this function.
void SetScaleToLog10()
Set the type of scale to use, linear or logarithmic.
double NanOpacity
The opacity to use for not-a-number.
const unsigned char * GetTable(double x1, double x2, int n)
Fills in a table of n colors mapped from values mapped with even spacing between x1 and x2,...
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.
void SetColorSpaceToHSV()
Set/Get the color space used for interpolation: RGB, HSV, CIELAB, Diverging or Step.
int AddRGBPoint(double x, double r, double g, double b, double midpoint, double sharpness)
Add/Remove a point to/from the function defined in RGB or HSV Return the index of the point (0 based)...
int AddRGBPoints(vtkDoubleArray *x, vtkDoubleArray *rgbColors)
Add/Remove a point to/from the function defined in RGB or HSV Return the index of the point (0 based)...
int GetSize()
How many nodes define this function?
void SetColorSpaceToDiverging()
Set/Get the color space used for interpolation: RGB, HSV, CIELAB, Diverging or Step.
vtkColorTransferFunctionInternals * Internal
int AddHSVPoint(double x, double h, double s, double v, double midpoint, double sharpness)
Add/Remove a point to/from the function defined in RGB or HSV Return the index of the point (0 based)...
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
Sets/Gets the range of scalars that will be mapped.
virtual void GetRange(double &arg1, double &arg2)
Returns min and max position of all function points.
void SetScaleToLinear()
Set the type of scale to use, linear or logarithmic.
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)...
void SetColorSpaceToLab()
Set/Get the color space used for interpolation: RGB, HSV, CIELAB, Diverging or Step.
vtkTypeBool HSVWrap
Specify if HSV is wrap or not.
double * Function
Temporary array to store data from the nodes.
void SetColorSpaceToStep()
Set/Get the color space used for interpolation: RGB, HSV, CIELAB, Diverging or Step.
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])
For the node specified by index, set/get the location (X), R, G, and B values, midpoint,...
double GetBlueValue(double x)
Get the color components individually.
static vtkColorTransferFunction * New()
void ShallowCopy(vtkColorTransferFunction *f)
void SetColorSpaceToLabCIEDE2000()
Set/Get the color space used for interpolation: RGB, HSV, CIELAB, Diverging or Step.
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 SetColorSpaceToRGB()
Set/Get the color space used for interpolation: RGB, HSV, CIELAB, Diverging or Step.
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])
Returns min and max position of all function points.
bool UpdateRange()
Returns true if the range has been changed.
double GetGreenValue(double x)
Get the color components individually.
double * GetRange() override
Returns min and max position of all function points.
dynamic, self-adjusting array of double
a simple class to control print indentation
Definition: vtkIndent.h:29
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...
Computes the portion of a dataset which is inside a selection.
record modification and/or execution time
Definition: vtkTimeStamp.h:25
@ range
Definition: vtkX3D.h:238
@ size
Definition: vtkX3D.h:253
@ index
Definition: vtkX3D.h:246
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:74
int vtkTypeBool
Definition: vtkABI.h:64
#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:315
#define VTK_SIZEHINT(...)