VTK  9.6.2
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_5_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 vtkDataArray;
83class vtkStringArray;
85
86class VTKCOMMONCORE_EXPORT VTK_MARSHALMANUAL vtkScalarsToColors : public vtkObject
87{
88public:
90 void PrintSelf(ostream& os, vtkIndent indent) override;
92
94
100 virtual vtkTypeBool IsOpaque(vtkAbstractArray* scalars, int colorMode, int component);
101 virtual vtkTypeBool IsOpaque(vtkAbstractArray* scalars, int colorMode, int component,
102 vtkUnsignedCharArray* ghosts, unsigned char ghostsToSkip = 0xff);
104
109 virtual void Build() {}
110
112
115 virtual double* GetRange() VTK_SIZEHINT(2);
116 virtual void SetRange(double min, double max);
117 virtual void SetRange(const double rng[2]) { this->SetRange(rng[0], rng[1]); }
119
124 virtual const unsigned char* MapValue(double v);
125
130 virtual void GetColor(double v, double rgb[3]);
131
136 double* GetColor(double v) VTK_SIZEHINT(3)
137 {
138 this->GetColor(v, this->RGB);
139 return this->RGB;
140 }
141
147 virtual double GetOpacity(double v);
148
154 double GetLuminance(double x)
155 {
156 double rgb[3];
157 this->GetColor(x, rgb);
158 return rgb[0] * 0.30 + rgb[1] * 0.59 + rgb[2] * 0.11;
159 }
160
162
168 virtual void SetAlpha(double alpha);
169 vtkGetMacro(Alpha, double);
171
173
193 vtkDataArray* scalars, int colorMode, int component, int outputFormat = VTK_RGBA);
195 vtkAbstractArray* scalars, int colorMode, int component, int outputFormat = VTK_RGBA);
197
199
204 vtkSetMacro(VectorMode, int);
205 vtkGetMacro(VectorMode, int);
210
212 {
216 };
217
219
223 vtkSetMacro(VectorComponent, int);
224 vtkGetMacro(VectorComponent, int);
226
228
235 vtkSetMacro(VectorSize, int);
236 vtkGetMacro(VectorSize, int);
238
246 void MapVectorsThroughTable(void* input, unsigned char* output, int inputDataType,
247 int numberOfValues, int inputIncrement, int outputFormat, int vectorComponent, int vectorSize);
248 void MapVectorsThroughTable(void* input, unsigned char* output, int inputDataType,
249 int numberOfValues, int inputIncrement, int outputFormat)
250 {
252 input, output, inputDataType, numberOfValues, inputIncrement, outputFormat, -1, -1);
253 }
254
263 void MapScalarsThroughTable(vtkDataArray* scalars, unsigned char* output, int outputFormat);
264 void MapScalarsThroughTable(vtkDataArray* scalars, unsigned char* output)
265 {
266 this->MapScalarsThroughTable(scalars, output, VTK_RGBA);
267 }
268 void MapScalarsThroughTable(void* input, unsigned char* output, int inputDataType,
269 int numberOfValues, int inputIncrement, int outputFormat)
270 {
272 input, output, inputDataType, numberOfValues, inputIncrement, outputFormat);
273 }
274
280 virtual void MapScalarsThroughTable2(void* input, unsigned char* output, int inputDataType,
281 int numberOfValues, int inputIncrement, int outputFormat);
282
286 virtual void DeepCopy(vtkScalarsToColors* o);
287
292 virtual vtkTypeBool UsingLogScale() { return 0; }
293
298
300
313 virtual void SetAnnotations(vtkAbstractArray* values, vtkStringArray* annotations);
315 vtkGetObjectMacro(Annotations, vtkStringArray);
317
322 virtual vtkIdType SetAnnotation(vtkVariant value, vtkStdString annotation);
323
329
334
340
346
350 virtual void GetAnnotationColor(const vtkVariant& val, double rgba[4]);
351
356
363
376 virtual void GetIndexedColor(vtkIdType i, double rgba[4]);
377
384 virtual bool RemoveAnnotation(vtkVariant value);
385
389 virtual void ResetAnnotations();
390
392
402 vtkBooleanMacro(IndexedLookup, vtkTypeBool);
404
406
411 template <typename T>
412 static unsigned char ColorToUChar(T t)
413 {
414 return static_cast<unsigned char>(t);
415 }
416 template <typename T>
417 static void ColorToUChar(T t, unsigned char* dest)
418 {
419 *dest = ColorToUChar(t);
420 }
421
422
423protected:
426
438 void MapColorsToColors(void* input, unsigned char* output, int inputDataType, int numberOfValues,
439 int numberOfComponents, int vectorSize, int outputFormat);
440
447 vtkDataArray* colors, int numComp, int numTuples);
448
453 void MapVectorsToMagnitude(void* input, double* output, int inputDataType, int numberOfValues,
454 int numberOfComponents, int vectorSize);
455
461
467
468 // Annotations of specific values.
471
472 class vtkInternalAnnotatedValueList;
473 vtkInternalAnnotatedValueList* AnnotatedValueList;
474
476
477 double Alpha;
478
479 // How to map arrays with multiple components.
483
484#if !defined(VTK_LEGACY_REMOVE)
485 VTK_DEPRECATED_IN_9_5_0("UseMagnitude is ignored and will be removed")
487#endif
488
489 unsigned char RGBABytes[4];
490
491private:
492 double RGB[3];
493 double InputRange[2];
494
495 vtkScalarsToColors(const vtkScalarsToColors&) = delete;
496 void operator=(const vtkScalarsToColors&) = delete;
497};
498
500
505template <>
506inline unsigned char vtkScalarsToColors::ColorToUChar(double t)
507{
508 double temp = (t * 255.0) + 0.5;
509 return static_cast<unsigned char>(temp);
510}
511template <>
512inline unsigned char vtkScalarsToColors::ColorToUChar(float t)
513{
514 double temp = (t * 255.0) + 0.5;
515 return static_cast<unsigned char>(temp);
516}
517
518
519VTK_ABI_NAMESPACE_END
520#endif
Abstract superclass for all arrays.
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 ...
void MapScalarsThroughTable(vtkDataArray *scalars, unsigned char *output)
void MapColorsToColors(void *input, unsigned char *output, int inputDataType, int numberOfValues, 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 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.
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 component)
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.
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 MapScalarsThroughTable(void *input, unsigned char *output, int inputDataType, int numberOfValues, int inputIncrement, int outputFormat)
void MapVectorsThroughTable(void *input, unsigned char *output, int inputDataType, int numberOfValues, int inputIncrement, int outputFormat, int vectorComponent, int vectorSize)
Map vectors through the lookup table.
virtual bool RemoveAnnotation(vtkVariant value)
Remove an existing entry from the list of annotated values.
virtual double GetOpacity(double v)
Map one value through the lookup table and return the alpha value (the opacity) as a double between 0...
void MapVectorsThroughTable(void *input, unsigned char *output, int inputDataType, int numberOfValues, int inputIncrement, int outputFormat)
~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...
virtual vtkTypeBool IsOpaque(vtkAbstractArray *scalars, int colorMode, int component, vtkUnsignedCharArray *ghosts, unsigned char ghostsToSkip=0xff)
Return true if all of the values defining the mapping have an opacity equal to 1.
virtual vtkUnsignedCharArray * MapScalars(vtkDataArray *scalars, int colorMode, int component, int outputFormat=VTK_RGBA)
Internal methods that map a data array into an unsigned char array.
void SetVectorModeToComponent()
Change mode that maps vectors by magnitude vs.
void SetVectorModeToMagnitude()
Change mode that maps vectors by magnitude vs.
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.
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 MapScalarsThroughTable2(void *input, unsigned char *output, int inputDataType, int numberOfValues, int inputIncrement, int outputFormat)
An internal method typically not used in applications.
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 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.
void MapVectorsToMagnitude(void *input, double *output, int inputDataType, int numberOfValues, int numberOfComponents, int vectorSize)
An internal method for converting vectors to magnitudes, used as a preliminary step before doing magn...
virtual vtkUnsignedCharArray * MapScalars(vtkAbstractArray *scalars, int colorMode, int component, int outputFormat=VTK_RGBA)
Internal methods that map a data array into an unsigned char array.
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.
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_5_0(reason)
#define VTK_RGBA
int vtkIdType
Definition vtkType.h:368
#define VTK_SIZEHINT(...)
#define VTK_MARSHALMANUAL
#define VTK_NEWINSTANCE
#define max(a, b)