VTK  9.2.6
vtkScalarsToColors.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkScalarsToColors.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=========================================================================*/
101#ifndef vtkScalarsToColors_h
102#define vtkScalarsToColors_h
103
104#include "vtkCommonCoreModule.h" // For export macro
105#include "vtkObject.h"
106#include "vtkVariant.h" // Set/get annotation methods require variants.
107
108class vtkAbstractArray;
109class vtkDataArray;
111class vtkAbstractArray;
112class vtkStringArray;
114
115class VTKCOMMONCORE_EXPORT vtkScalarsToColors : public vtkObject
116{
117public:
119 void PrintSelf(ostream& os, vtkIndent indent) override;
121
123
128 virtual int IsOpaque();
129 virtual int IsOpaque(vtkAbstractArray* scalars, int colorMode, int component);
130 virtual int IsOpaque(vtkAbstractArray* scalars, int colorMode, int component,
131 vtkUnsignedCharArray* ghosts, unsigned char ghostsToSkip = 0xff);
133
138 virtual void Build() {}
139
141
144 virtual double* GetRange() VTK_SIZEHINT(2);
145 virtual void SetRange(double min, double max);
146 virtual void SetRange(const double rng[2]) { this->SetRange(rng[0], rng[1]); }
148
153 virtual const unsigned char* MapValue(double v);
154
159 virtual void GetColor(double v, double rgb[3]);
160
165 double* GetColor(double v) VTK_SIZEHINT(3)
166 {
167 this->GetColor(v, this->RGB);
168 return this->RGB;
169 }
170
176 virtual double GetOpacity(double v);
177
183 double GetLuminance(double x)
184 {
185 double rgb[3];
186 this->GetColor(x, rgb);
187 return static_cast<double>(rgb[0] * 0.30 + rgb[1] * 0.59 + rgb[2] * 0.11);
188 }
189
191
197 virtual void SetAlpha(double alpha);
198 vtkGetMacro(Alpha, double);
200
202
222 vtkDataArray* scalars, int colorMode, int component, int outputFormat = VTK_RGBA);
224 vtkAbstractArray* scalars, int colorMode, int component, int outputFormat = VTK_RGBA);
226
228
233 vtkSetMacro(VectorMode, int);
234 vtkGetMacro(VectorMode, int);
239
241 {
242 MAGNITUDE = 0,
243 COMPONENT = 1,
244 RGBCOLORS = 2
245 };
246
248
252 vtkSetMacro(VectorComponent, int);
253 vtkGetMacro(VectorComponent, int);
255
257
264 vtkSetMacro(VectorSize, int);
265 vtkGetMacro(VectorSize, int);
267
275 void MapVectorsThroughTable(void* input, unsigned char* output, int inputDataType,
276 int numberOfValues, int inputIncrement, int outputFormat, int vectorComponent, int vectorSize);
277 void MapVectorsThroughTable(void* input, unsigned char* output, int inputDataType,
278 int numberOfValues, int inputIncrement, int outputFormat)
279 {
280 this->MapVectorsThroughTable(
281 input, output, inputDataType, numberOfValues, inputIncrement, outputFormat, -1, -1);
282 }
283
292 void MapScalarsThroughTable(vtkDataArray* scalars, unsigned char* output, int outputFormat);
293 void MapScalarsThroughTable(vtkDataArray* scalars, unsigned char* output)
294 {
295 this->MapScalarsThroughTable(scalars, output, VTK_RGBA);
296 }
297 void MapScalarsThroughTable(void* input, unsigned char* output, int inputDataType,
298 int numberOfValues, int inputIncrement, int outputFormat)
299 {
300 this->MapScalarsThroughTable2(
301 input, output, inputDataType, numberOfValues, inputIncrement, outputFormat);
302 }
303
309 virtual void MapScalarsThroughTable2(void* input, unsigned char* output, int inputDataType,
310 int numberOfValues, int inputIncrement, int outputFormat);
311
315 virtual void DeepCopy(vtkScalarsToColors* o);
316
321 virtual int UsingLogScale() { return 0; }
322
327
329
342 virtual void SetAnnotations(vtkAbstractArray* values, vtkStringArray* annotations);
343 vtkGetObjectMacro(AnnotatedValues, vtkAbstractArray);
344 vtkGetObjectMacro(Annotations, vtkStringArray);
346
352
358
363
368
373
377 virtual void GetAnnotationColor(const vtkVariant& val, double rgba[4]);
378
383
390
403 virtual void GetIndexedColor(vtkIdType i, double rgba[4]);
404
412
416 virtual void ResetAnnotations();
417
419
427 vtkSetMacro(IndexedLookup, vtkTypeBool);
428 vtkGetMacro(IndexedLookup, vtkTypeBool);
429 vtkBooleanMacro(IndexedLookup, vtkTypeBool);
431
433
438 template <typename T>
439 static unsigned char ColorToUChar(T t)
440 {
441 return static_cast<unsigned char>(t);
442 }
443 template <typename T>
444 static void ColorToUChar(T t, unsigned char* dest)
445 {
446 *dest = ColorToUChar(t);
447 }
449
450protected:
453
465 void MapColorsToColors(void* input, unsigned char* output, int inputDataType, int numberOfValues,
466 int numberOfComponents, int vectorSize, int outputFormat);
467
473 vtkUnsignedCharArray* ConvertToRGBA(vtkDataArray* colors, int numComp, int numTuples);
474
479 void MapVectorsToMagnitude(void* input, double* output, int inputDataType, int numberOfValues,
480 int numberOfComponents, int vectorSize);
481
487
493
494 // Annotations of specific values.
497
498 class vtkInternalAnnotatedValueList;
499 vtkInternalAnnotatedValueList* AnnotatedValueList;
500
502
503 double Alpha;
504
505 // How to map arrays with multiple components.
509
510 // Obsolete, kept so subclasses will still compile
512
513 unsigned char RGBABytes[4];
514
515private:
516 double RGB[3];
517 double InputRange[2];
518
519 vtkScalarsToColors(const vtkScalarsToColors&) = delete;
520 void operator=(const vtkScalarsToColors&) = delete;
521};
522
524
529template <>
530inline unsigned char vtkScalarsToColors::ColorToUChar(double t)
531{
532 return static_cast<unsigned char>(t * 255 + 0.5);
533}
534template <>
535inline unsigned char vtkScalarsToColors::ColorToUChar(float t)
536{
537 return static_cast<unsigned char>(t * 255 + 0.5);
538}
540
541#endif
Abstract superclass for all arrays.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:165
a simple class to control print indentation
Definition: vtkIndent.h:119
abstract base class for most VTK objects
Definition: vtkObject.h:82
Superclass for mapping scalar values 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.
virtual int IsOpaque()
Return true if all of the values defining the mapping have an opacity equal to 1.
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.
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 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 int IsOpaque(vtkAbstractArray *scalars, int colorMode, int component)
Return true if all of the values defining the mapping have an opacity equal to 1.
virtual int UsingLogScale()
This should return 1 is the subclass is using log scale for mapping scalars to colors.
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 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).
virtual int 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.
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.
Definition: vtkStdString.h:108
a vtkAbstractArray subclass for strings
dynamic, self-adjusting array of unsigned char
A atomic type representing the union of many types.
Definition: vtkVariant.h:149
@ component
Definition: vtkX3D.h:181
@ value
Definition: vtkX3D.h:226
@ alpha
Definition: vtkX3D.h:256
int vtkTypeBool
Definition: vtkABI.h:69
#define VTK_RGBA
int vtkIdType
Definition: vtkType.h:332
#define VTK_SIZEHINT(...)
#define max(a, b)