VTK  9.6.20260625
vtkScalarsToColors.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
68
69#ifndef vtkScalarsToColors_h
70#define vtkScalarsToColors_h
71
72#include "vtkCommonCoreModule.h" // For export macro
73#include "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_7_0
74#include "vtkObject.h"
75#include "vtkVariant.h" // Set/get annotation methods require variants.
76#include "vtkWrappingHints.h" // For VTK_MARSHALMANUAL
77
78VTK_ABI_NAMESPACE_BEGIN
80class vtkBitArray;
81class vtkDataArray;
82class vtkStringArray;
84
85class VTKCOMMONCORE_EXPORT VTK_MARSHALMANUAL vtkScalarsToColors : public vtkObject
86{
87public:
89 void PrintSelf(ostream& os, vtkIndent indent) override;
91
93
99 virtual vtkTypeBool IsOpaque(vtkAbstractArray* scalars, int colorMode, int vectorComponent);
100 virtual vtkTypeBool IsOpaque(vtkAbstractArray* scalars, int colorMode, int vectorComponent,
101 vtkUnsignedCharArray* ghosts, unsigned char ghostsToSkip = 0xff);
103
108 virtual void Build() {}
109
111
114 virtual double* GetRange() VTK_SIZEHINT(2);
115 virtual void SetRange(double min, double max);
116 virtual void SetRange(const double rng[2]) { this->SetRange(rng[0], rng[1]); }
118
123 virtual const unsigned char* MapValue(double v);
124
129 virtual void GetColor(double v, double rgb[3]);
130
135 double* GetColor(double v) VTK_SIZEHINT(3)
136 {
137 this->GetColor(v, this->RGB);
138 return this->RGB;
139 }
140
146 virtual double GetOpacity(double v);
147
153 double GetLuminance(double x)
154 {
155 double rgb[3];
156 this->GetColor(x, rgb);
157 return rgb[0] * 0.30 + rgb[1] * 0.59 + rgb[2] * 0.11;
158 }
159
161
167 virtual void SetAlpha(double alpha);
168 vtkGetMacro(Alpha, double);
170
172
192 vtkDataArray* scalars, int colorMode, int vectorComponent, int outputFormat = VTK_RGBA);
194 vtkAbstractArray* scalars, int colorMode, int vectorComponent, int outputFormat = VTK_RGBA);
196
198
203 vtkSetMacro(VectorMode, int);
204 vtkGetMacro(VectorMode, int);
209
211 {
215 };
216
218
222 vtkSetMacro(VectorComponent, int);
223 vtkGetMacro(VectorComponent, int);
225
227
234 vtkSetMacro(VectorSize, int);
235 vtkGetMacro(VectorSize, int);
237
239
246 void MapVectorsThroughTable(VTK_FUTURE_CONST void* input, unsigned char* output,
247 int inputDataType, int numberOfTuples, int numberOfComponents, int outputFormat,
248 int vectorComponent, int vectorSize);
249 void MapVectorsThroughTable(VTK_FUTURE_CONST void* input, unsigned char* output,
250 int inputDataType, int numberOfTuples, int numberOfComponents, int outputFormat)
251 {
253 input, output, inputDataType, numberOfTuples, numberOfComponents, outputFormat, -1, -1);
254 }
255 void MapVectorsThroughTable(vtkDataArray* input, unsigned char* output, int numberOfTuples,
256 int numberOfComponents, int vectorComponent, int vectorSize, int outputFormat);
257 void MapVectorsThroughTable(vtkDataArray* input, unsigned char* output, int numberOfTuples,
258 int numberOfComponents, int outputFormat)
259 {
261 input, output, numberOfTuples, numberOfComponents, -1, -1, outputFormat);
262 }
263
264
266
274 void MapScalarsThroughTable(vtkDataArray* scalars, unsigned char* output, int outputFormat);
275 void MapScalarsThroughTable(vtkDataArray* scalars, unsigned char* output)
276 {
277 this->MapScalarsThroughTable(scalars, output, VTK_RGBA);
278 }
279
280
282
287 virtual void MapScalarsThroughTable(vtkAbstractArray* input, unsigned char* output,
288 int numberOfTuples, int numberOfComponents, int vectorComponent, int outputFormat);
289 void MapScalarsThroughTable(VTK_FUTURE_CONST void* input, unsigned char* output,
290 int inputDataType, int numberOfTuples, int numberOfComponents, int outputFormat);
291 VTK_DEPRECATED_IN_9_7_0("Use the MapScalarsThroughTable overload instead")
292 virtual void MapScalarsThroughTable2(VTK_FUTURE_CONST void* input, unsigned char* output,
293 int inputDataType, int numberOfTuples, int numberOfComponents, int outputFormat);
295
299 virtual void DeepCopy(vtkScalarsToColors* o);
300
305 virtual vtkTypeBool UsingLogScale() { return 0; }
306
311
313
326 virtual void SetAnnotations(vtkAbstractArray* values, vtkStringArray* annotations);
328 vtkGetObjectMacro(Annotations, vtkStringArray);
330
335 virtual vtkIdType SetAnnotation(vtkVariant value, vtkStdString annotation);
336
342
347
353
359
363 virtual void GetAnnotationColor(const vtkVariant& val, double rgba[4]);
364
369
376
389 virtual void GetIndexedColor(vtkIdType i, double rgba[4]);
390
397 virtual bool RemoveAnnotation(vtkVariant value);
398
402 virtual void ResetAnnotations();
403
405
415 vtkBooleanMacro(IndexedLookup, vtkTypeBool);
417
419
424 template <typename T>
425 static unsigned char ColorToUChar(T t)
426 {
427 return static_cast<unsigned char>(t);
428 }
429 template <typename T>
430 static void ColorToUChar(T t, unsigned char* dest)
431 {
432 *dest = ColorToUChar(t);
433 }
434
435
436protected:
439
445 vtkBitArray* colors, int numComp, vtkIdType numTuples);
446
448
459 VTK_DEPRECATED_IN_9_7_0("Use the overload taking vtkDataArray* instead")
460 void MapColorsToColors(VTK_FUTURE_CONST void* input, unsigned char* output, int inputDataType,
461 int numberOfTuples, int numberOfComponents, int vectorSize, int outputFormat);
462 void MapColorsToColors(vtkDataArray* input, unsigned char* output, int numberOfTuples,
463 int numberOfComponents, int vectorComponent, int vectorSize, int outputFormat);
465
472 vtkDataArray* colors, int numComp, int numTuples);
473
475
479 VTK_DEPRECATED_IN_9_7_0("Use the overload taking vtkDataArray* instead")
480 void MapVectorsToMagnitude(VTK_FUTURE_CONST void* input, double* output, int inputDataType,
481 int numberOfTuples, int numberOfComponents, int vectorSize);
482 void MapVectorsToMagnitude(vtkDataArray* input, double* output, int numberOfTuples,
483 int numberOfComponents, int vectorComponent, int vectorSize);
485
491
497
498 // Annotations of specific values.
501
502 class vtkInternalAnnotatedValueList;
503 vtkInternalAnnotatedValueList* AnnotatedValueList;
504
506
507 double Alpha;
508
509 // How to map arrays with multiple components.
513
514 unsigned char RGBABytes[4];
515
516private:
517 double RGB[3];
518 double InputRange[2];
519
520 vtkScalarsToColors(const vtkScalarsToColors&) = delete;
521 void operator=(const vtkScalarsToColors&) = delete;
522};
523
525
530template <>
531inline unsigned char vtkScalarsToColors::ColorToUChar(double t)
532{
533 double temp = (t * 255.0) + 0.5;
534 return static_cast<unsigned char>(temp);
535}
536template <>
537inline unsigned char vtkScalarsToColors::ColorToUChar(float t)
538{
539 double temp = (t * 255.0) + 0.5;
540 return static_cast<unsigned char>(temp);
541}
542
543
544VTK_ABI_NAMESPACE_END
545#endif
Abstract superclass for all arrays.
dynamic, self-adjusting array of bits
Definition vtkBitArray.h:33
a simple class to control print indentation
Definition vtkIndent.h:108
virtual vtkTypeBool UsingLogScale()
This should return 1 if the subclass is using log scale for mapping scalars to colors.
double * GetColor(double v)
Map one value through the lookup table and return the color as an RGB array of doubles between 0 and ...
virtual vtkUnsignedCharArray * MapScalars(vtkDataArray *scalars, int colorMode, int vectorComponent, int outputFormat=VTK_RGBA)
Internal methods that map a data array into an unsigned char array.
void MapVectorsThroughTable(vtkDataArray *input, unsigned char *output, int numberOfTuples, int numberOfComponents, int outputFormat)
Map vectors through the lookup table.
void MapScalarsThroughTable(vtkDataArray *scalars, unsigned char *output)
Map a set of scalars through the lookup table in a single operation.
void MapVectorsToMagnitude(VTK_FUTURE_CONST void *input, double *output, int inputDataType, int numberOfTuples, int numberOfComponents, int vectorSize)
An internal method for converting vectors to magnitudes, used as a preliminary step before doing magn...
virtual void DeepCopy(vtkScalarsToColors *o)
Copy the contents from another object.
vtkVariant GetAnnotatedValue(vtkIdType idx)
Return the annotated value at a particular index in the list of annotations.
void MapScalarsThroughTable(VTK_FUTURE_CONST void *input, unsigned char *output, int inputDataType, int numberOfTuples, int numberOfComponents, int outputFormat)
An internal method typically not used in applications.
virtual void SetRange(double min, double max)
Sets/Gets the range of scalars that will be mapped.
void MapScalarsThroughTable(vtkDataArray *scalars, unsigned char *output, int outputFormat)
Map a set of scalars through the lookup table in a single operation.
virtual void UpdateAnnotatedValueMap()
Update the map from annotated values to indices in the array of annotations.
virtual vtkTypeBool IsOpaque(vtkAbstractArray *scalars, int colorMode, int vectorComponent)
Return true if all of the values defining the mapping have an opacity equal to 1.
vtkUnsignedCharArray * ConvertToRGBA(vtkDataArray *colors, int numComp, int numTuples)
An internal method used to convert a color array to RGBA.
virtual void SetAlpha(double alpha)
Specify an additional opacity (alpha) value to blend with.
double GetLuminance(double x)
Map one value through the lookup table and return the luminance 0.3*red + 0.59*green + 0....
virtual void SetRange(const double rng[2])
Sets/Gets the range of scalars that will be mapped.
static vtkScalarsToColors * New()
virtual void GetIndexedColor(vtkIdType i, double rgba[4])
Get the "indexed color" assigned to an index.
virtual vtkIdType SetAnnotation(vtkStdString value, vtkStdString annotation)
This variant of SetAnnotation accepts the value as a string so ParaView can treat annotations as stri...
virtual vtkTypeBool IsOpaque()
Return true if all of the values defining the mapping have an opacity equal to 1.
void MapVectorsThroughTable(vtkDataArray *input, unsigned char *output, int numberOfTuples, int numberOfComponents, int vectorComponent, int vectorSize, int outputFormat)
Map vectors through the lookup table.
virtual vtkIdType GetNumberOfAvailableColors()
Get the number of available colors for mapping to.
static void ColorToUChar(T t, unsigned char *dest)
Converts a color from numeric type T to uchar.
void MapVectorsThroughTable(VTK_FUTURE_CONST void *input, unsigned char *output, int inputDataType, int numberOfTuples, int numberOfComponents, int outputFormat)
Map vectors through the lookup table.
virtual bool RemoveAnnotation(vtkVariant value)
Remove an existing entry from the list of annotated values.
virtual void MapScalarsThroughTable2(VTK_FUTURE_CONST void *input, unsigned char *output, int inputDataType, int numberOfTuples, int numberOfComponents, int outputFormat)
An internal method typically not used in applications.
virtual double GetOpacity(double v)
Map one value through the lookup table and return the alpha value (the opacity) as a double between 0...
~vtkScalarsToColors() override
virtual void ResetAnnotations()
Remove all existing values and their annotations.
virtual const unsigned char * MapValue(double v)
Map one value through the lookup table and return a color defined as an RGBA unsigned char tuple (4 b...
void SetVectorModeToComponent()
Change mode that maps vectors by magnitude vs.
void SetVectorModeToMagnitude()
Change mode that maps vectors by magnitude vs.
void MapColorsToColors(VTK_FUTURE_CONST void *input, unsigned char *output, int inputDataType, int numberOfTuples, int numberOfComponents, int vectorSize, int outputFormat)
An internal method that assumes that the input already has the right colors, and only remaps the rang...
virtual void MapScalarsThroughTable(vtkAbstractArray *input, unsigned char *output, int numberOfTuples, int numberOfComponents, int vectorComponent, int outputFormat)
An internal method typically not used in applications.
vtkIdType GetAnnotatedValueIndexInternal(const vtkVariant &val)
Look up an index into the array of annotations given a value.
virtual void SetAnnotations(vtkAbstractArray *values, vtkStringArray *annotations)
Set a list of discrete values, either as a categorical set of values (when IndexedLookup is true) or ...
static unsigned char ColorToUChar(T t)
Converts a color from numeric type T to uchar.
void MapVectorsThroughTable(VTK_FUTURE_CONST void *input, unsigned char *output, int inputDataType, int numberOfTuples, int numberOfComponents, int outputFormat, int vectorComponent, int vectorSize)
Map vectors through the lookup table.
virtual vtkUnsignedCharArray * MapScalars(vtkAbstractArray *scalars, int colorMode, int vectorComponent, int outputFormat=VTK_RGBA)
Internal methods that map a data array into an unsigned char array.
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 GetNumberOfAnnotatedValues()
Return the annotated value at a particular index in the list of annotations.
virtual void Build()
Perform any processing required (if any) before processing scalars.
virtual vtkIdType SetAnnotation(vtkVariant value, vtkStdString annotation)
Add a new entry (or change an existing entry) to the list of annotated values.
virtual vtkTypeBool IsOpaque(vtkAbstractArray *scalars, int colorMode, int vectorComponent, vtkUnsignedCharArray *ghosts, unsigned char ghostsToSkip=0xff)
Return true if all of the values defining the mapping have an opacity equal to 1.
virtual void GetAnnotationColor(const vtkVariant &val, double rgba[4])
Obtain the color associated with a particular annotated value (or NanColor if unmatched).
vtkInternalAnnotatedValueList * AnnotatedValueList
vtkAbstractArray * AnnotatedValues
virtual vtkIdType CheckForAnnotatedValue(vtkVariant value)
Allocate annotation arrays if needed, then return the index of the given value or -1 if not present.
virtual double * GetRange()
Sets/Gets the range of scalars that will be mapped.
static vtkSmartPointer< vtkUnsignedCharArray > UnpackBits(vtkBitArray *colors, int numComp, vtkIdType numTuples)
An internal method to unpack bit arrays (vtkBitArray) into vtkUnsignedCharArray with 1 component.
vtkIdType GetAnnotatedValueIndex(vtkVariant val)
Return the index of the given value in the list of annotated values (or -1 if not present).
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
unsigned char RGBABytes[4]
vtkStringArray * Annotations
void SetVectorModeToRGBColors()
Change mode that maps vectors by magnitude vs.
vtkStdString GetAnnotation(vtkIdType idx)
Return the annotation at a particular index in the list of annotations.
Hold a reference to a vtkObjectBase instance.
Wrapper around std::string to keep symbols short.
a vtkAbstractArray subclass for strings
dynamic, self-adjusting array of unsigned char
A type representing the union of many types.
Definition vtkVariant.h:162
int vtkTypeBool
Definition vtkABI.h:64
#define vtkDataArray
#define VTK_DEPRECATED_IN_9_7_0(reason)
#define VTK_RGBA
int vtkIdType
Definition vtkType.h:363
#define VTK_SIZEHINT(...)
#define VTK_MARSHALMANUAL
#define VTK_NEWINSTANCE
#define max(a, b)