VTK  9.3.20240425
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
59#ifndef vtkScalarsToColors_h
60#define vtkScalarsToColors_h
61
62#include "vtkCommonCoreModule.h" // For export macro
63#include "vtkObject.h"
64#include "vtkVariant.h" // Set/get annotation methods require variants.
65#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
66
67VTK_ABI_NAMESPACE_BEGIN
69class vtkDataArray;
72class vtkStringArray;
74
75class VTKCOMMONCORE_EXPORT VTK_MARSHALAUTO vtkScalarsToColors : public vtkObject
76{
77public:
79 void PrintSelf(ostream& os, vtkIndent indent) override;
81
83
89 virtual vtkTypeBool IsOpaque(vtkAbstractArray* scalars, int colorMode, int component);
90 virtual vtkTypeBool IsOpaque(vtkAbstractArray* scalars, int colorMode, int component,
91 vtkUnsignedCharArray* ghosts, unsigned char ghostsToSkip = 0xff);
93
98 virtual void Build() {}
99
101
104 virtual double* GetRange() VTK_SIZEHINT(2);
105 virtual void SetRange(double min, double max);
106 virtual void SetRange(const double rng[2]) { this->SetRange(rng[0], rng[1]); }
108
113 virtual const unsigned char* MapValue(double v);
114
119 virtual void GetColor(double v, double rgb[3]);
120
125 double* GetColor(double v) VTK_SIZEHINT(3)
126 {
127 this->GetColor(v, this->RGB);
128 return this->RGB;
129 }
130
136 virtual double GetOpacity(double v);
137
143 double GetLuminance(double x)
144 {
145 double rgb[3];
146 this->GetColor(x, rgb);
147 return static_cast<double>(rgb[0] * 0.30 + rgb[1] * 0.59 + rgb[2] * 0.11);
148 }
149
151
157 virtual void SetAlpha(double alpha);
158 vtkGetMacro(Alpha, double);
160
162
182 vtkDataArray* scalars, int colorMode, int component, int outputFormat = VTK_RGBA);
184 vtkAbstractArray* scalars, int colorMode, int component, int outputFormat = VTK_RGBA);
186
188
193 vtkSetMacro(VectorMode, int);
194 vtkGetMacro(VectorMode, int);
199
201 {
202 MAGNITUDE = 0,
203 COMPONENT = 1,
204 RGBCOLORS = 2
205 };
206
208
212 vtkSetMacro(VectorComponent, int);
213 vtkGetMacro(VectorComponent, int);
215
217
224 vtkSetMacro(VectorSize, int);
225 vtkGetMacro(VectorSize, int);
227
235 void MapVectorsThroughTable(void* input, unsigned char* output, int inputDataType,
236 int numberOfValues, int inputIncrement, int outputFormat, int vectorComponent, int vectorSize);
237 void MapVectorsThroughTable(void* input, unsigned char* output, int inputDataType,
238 int numberOfValues, int inputIncrement, int outputFormat)
239 {
240 this->MapVectorsThroughTable(
241 input, output, inputDataType, numberOfValues, inputIncrement, outputFormat, -1, -1);
242 }
243
252 void MapScalarsThroughTable(vtkDataArray* scalars, unsigned char* output, int outputFormat);
253 void MapScalarsThroughTable(vtkDataArray* scalars, unsigned char* output)
254 {
255 this->MapScalarsThroughTable(scalars, output, VTK_RGBA);
256 }
257 void MapScalarsThroughTable(void* input, unsigned char* output, int inputDataType,
258 int numberOfValues, int inputIncrement, int outputFormat)
259 {
260 this->MapScalarsThroughTable2(
261 input, output, inputDataType, numberOfValues, inputIncrement, outputFormat);
262 }
263
269 virtual void MapScalarsThroughTable2(void* input, unsigned char* output, int inputDataType,
270 int numberOfValues, int inputIncrement, int outputFormat);
271
275 virtual void DeepCopy(vtkScalarsToColors* o);
276
281 virtual vtkTypeBool UsingLogScale() { return 0; }
282
287
289
302 virtual void SetAnnotations(vtkAbstractArray* values, vtkStringArray* annotations);
303 vtkGetObjectMacro(AnnotatedValues, vtkAbstractArray);
304 vtkGetObjectMacro(Annotations, vtkStringArray);
306
311 virtual vtkIdType SetAnnotation(vtkVariant value, vtkStdString annotation);
312
318
323
329
335
339 virtual void GetAnnotationColor(const vtkVariant& val, double rgba[4]);
340
345
352
365 virtual void GetIndexedColor(vtkIdType i, double rgba[4]);
366
373 virtual bool RemoveAnnotation(vtkVariant value);
374
378 virtual void ResetAnnotations();
379
381
389 vtkSetMacro(IndexedLookup, vtkTypeBool);
390 vtkGetMacro(IndexedLookup, vtkTypeBool);
391 vtkBooleanMacro(IndexedLookup, vtkTypeBool);
393
395
400 template <typename T>
401 static unsigned char ColorToUChar(T t)
402 {
403 return static_cast<unsigned char>(t);
404 }
405 template <typename T>
406 static void ColorToUChar(T t, unsigned char* dest)
407 {
408 *dest = ColorToUChar(t);
409 }
411
412protected:
415
427 void MapColorsToColors(void* input, unsigned char* output, int inputDataType, int numberOfValues,
428 int numberOfComponents, int vectorSize, int outputFormat);
429
436 vtkDataArray* colors, int numComp, int numTuples);
437
442 void MapVectorsToMagnitude(void* input, double* output, int inputDataType, int numberOfValues,
443 int numberOfComponents, int vectorSize);
444
450
456
457 // Annotations of specific values.
460
461 class vtkInternalAnnotatedValueList;
462 vtkInternalAnnotatedValueList* AnnotatedValueList;
463
465
466 double Alpha;
467
468 // How to map arrays with multiple components.
472
473#if !defined(VTK_LEGACY_REMOVE)
474 // Obsolete, kept so subclasses will still compile
476#endif
477
478 unsigned char RGBABytes[4];
479
480private:
481 double RGB[3];
482 double InputRange[2];
483
484 vtkScalarsToColors(const vtkScalarsToColors&) = delete;
485 void operator=(const vtkScalarsToColors&) = delete;
486};
487
489
494template <>
495inline unsigned char vtkScalarsToColors::ColorToUChar(double t)
496{
497 double temp = (t * 255.0) + 0.5;
498 return static_cast<unsigned char>(temp);
499}
500template <>
501inline unsigned char vtkScalarsToColors::ColorToUChar(float t)
502{
503 double temp = (t * 255.0) + 0.5;
504 return static_cast<unsigned char>(temp);
505}
507
508VTK_ABI_NAMESPACE_END
509#endif
Abstract superclass for all arrays.
abstract superclass for arrays of numeric data
a simple class to control print indentation
Definition vtkIndent.h:108
abstract base class for most VTK objects
Definition vtkObject.h:162
Superclass for mapping scalar values to colors.
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.
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.
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 VTK_RGBA
int vtkIdType
Definition vtkType.h:315
#define VTK_SIZEHINT(...)
#define VTK_MARSHALAUTO
#define VTK_NEWINSTANCE
#define max(a, b)