VTK  9.3.20240303
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 
66 VTK_ABI_NAMESPACE_BEGIN
67 class vtkAbstractArray;
68 class vtkDataArray;
70 class vtkAbstractArray;
71 class vtkStringArray;
73 
74 class VTKCOMMONCORE_EXPORT vtkScalarsToColors : public vtkObject
75 {
76 public:
77  vtkTypeMacro(vtkScalarsToColors, vtkObject);
78  void PrintSelf(ostream& os, vtkIndent indent) override;
80 
82 
87  virtual vtkTypeBool IsOpaque();
88  virtual vtkTypeBool IsOpaque(vtkAbstractArray* scalars, int colorMode, int component);
89  virtual vtkTypeBool IsOpaque(vtkAbstractArray* scalars, int colorMode, int component,
90  vtkUnsignedCharArray* ghosts, unsigned char ghostsToSkip = 0xff);
92 
97  virtual void Build() {}
98 
100 
103  virtual double* GetRange() VTK_SIZEHINT(2);
104  virtual void SetRange(double min, double max);
105  virtual void SetRange(const double rng[2]) { this->SetRange(rng[0], rng[1]); }
107 
112  virtual const unsigned char* MapValue(double v);
113 
118  virtual void GetColor(double v, double rgb[3]);
119 
124  double* GetColor(double v) VTK_SIZEHINT(3)
125  {
126  this->GetColor(v, this->RGB);
127  return this->RGB;
128  }
129 
135  virtual double GetOpacity(double v);
136 
142  double GetLuminance(double x)
143  {
144  double rgb[3];
145  this->GetColor(x, rgb);
146  return static_cast<double>(rgb[0] * 0.30 + rgb[1] * 0.59 + rgb[2] * 0.11);
147  }
148 
150 
156  virtual void SetAlpha(double alpha);
157  vtkGetMacro(Alpha, double);
159 
161 
181  vtkDataArray* scalars, int colorMode, int component, int outputFormat = VTK_RGBA);
183  vtkAbstractArray* scalars, int colorMode, int component, int outputFormat = VTK_RGBA);
185 
187 
192  vtkSetMacro(VectorMode, int);
193  vtkGetMacro(VectorMode, int);
198 
200  {
201  MAGNITUDE = 0,
202  COMPONENT = 1,
203  RGBCOLORS = 2
204  };
205 
207 
211  vtkSetMacro(VectorComponent, int);
212  vtkGetMacro(VectorComponent, int);
214 
216 
223  vtkSetMacro(VectorSize, int);
224  vtkGetMacro(VectorSize, int);
226 
234  void MapVectorsThroughTable(void* input, unsigned char* output, int inputDataType,
235  int numberOfValues, int inputIncrement, int outputFormat, int vectorComponent, int vectorSize);
236  void MapVectorsThroughTable(void* input, unsigned char* output, int inputDataType,
237  int numberOfValues, int inputIncrement, int outputFormat)
238  {
239  this->MapVectorsThroughTable(
240  input, output, inputDataType, numberOfValues, inputIncrement, outputFormat, -1, -1);
241  }
242 
251  void MapScalarsThroughTable(vtkDataArray* scalars, unsigned char* output, int outputFormat);
252  void MapScalarsThroughTable(vtkDataArray* scalars, unsigned char* output)
253  {
254  this->MapScalarsThroughTable(scalars, output, VTK_RGBA);
255  }
256  void MapScalarsThroughTable(void* input, unsigned char* output, int inputDataType,
257  int numberOfValues, int inputIncrement, int outputFormat)
258  {
259  this->MapScalarsThroughTable2(
260  input, output, inputDataType, numberOfValues, inputIncrement, outputFormat);
261  }
262 
268  virtual void MapScalarsThroughTable2(void* input, unsigned char* output, int inputDataType,
269  int numberOfValues, int inputIncrement, int outputFormat);
270 
274  virtual void DeepCopy(vtkScalarsToColors* o);
275 
280  virtual vtkTypeBool UsingLogScale() { return 0; }
281 
286 
288 
301  virtual void SetAnnotations(vtkAbstractArray* values, vtkStringArray* annotations);
302  vtkGetObjectMacro(AnnotatedValues, vtkAbstractArray);
303  vtkGetObjectMacro(Annotations, vtkStringArray);
305 
311 
317 
322 
328 
334 
338  virtual void GetAnnotationColor(const vtkVariant& val, double rgba[4]);
339 
344 
351 
364  virtual void GetIndexedColor(vtkIdType i, double rgba[4]);
365 
373 
377  virtual void ResetAnnotations();
378 
380 
388  vtkSetMacro(IndexedLookup, vtkTypeBool);
389  vtkGetMacro(IndexedLookup, vtkTypeBool);
390  vtkBooleanMacro(IndexedLookup, vtkTypeBool);
392 
394 
399  template <typename T>
400  static unsigned char ColorToUChar(T t)
401  {
402  return static_cast<unsigned char>(t);
403  }
404  template <typename T>
405  static void ColorToUChar(T t, unsigned char* dest)
406  {
407  *dest = ColorToUChar(t);
408  }
410 
411 protected:
414 
426  void MapColorsToColors(void* input, unsigned char* output, int inputDataType, int numberOfValues,
427  int numberOfComponents, int vectorSize, int outputFormat);
428 
435  vtkDataArray* colors, int numComp, int numTuples);
436 
441  void MapVectorsToMagnitude(void* input, double* output, int inputDataType, int numberOfValues,
442  int numberOfComponents, int vectorSize);
443 
449 
454  virtual void UpdateAnnotatedValueMap();
455 
456  // Annotations of specific values.
459 
460  class vtkInternalAnnotatedValueList;
461  vtkInternalAnnotatedValueList* AnnotatedValueList;
462 
464 
465  double Alpha;
466 
467  // How to map arrays with multiple components.
471 
472 #if !defined(VTK_LEGACY_REMOVE)
473  // Obsolete, kept so subclasses will still compile
475 #endif
476 
477  unsigned char RGBABytes[4];
478 
479 private:
480  double RGB[3];
481  double InputRange[2];
482 
483  vtkScalarsToColors(const vtkScalarsToColors&) = delete;
484  void operator=(const vtkScalarsToColors&) = delete;
485 };
486 
488 
493 template <>
494 inline unsigned char vtkScalarsToColors::ColorToUChar(double t)
495 {
496  double temp = (t * 255.0) + 0.5;
497  return static_cast<unsigned char>(temp);
498 }
499 template <>
500 inline unsigned char vtkScalarsToColors::ColorToUChar(float t)
501 {
502  double temp = (t * 255.0) + 0.5;
503  return static_cast<unsigned char>(temp);
504 }
506 
507 VTK_ABI_NAMESPACE_END
508 #endif
Abstract superclass for all arrays.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:154
a simple class to control print indentation
Definition: vtkIndent.h:108
abstract base class for most VTK objects
Definition: vtkObject.h:161
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.
static vtkScalarsToColors * New()
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.
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 vtkUnsignedCharArray * MapScalars(vtkAbstractArray *scalars, int colorMode, int component, int outputFormat=VTK_RGBA)
Internal methods that map a data array into an unsigned char array.
virtual void SetRange(const double rng[2])
Sets/Gets the range of scalars that will be mapped.
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.
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(void *input, unsigned char *output, int inputDataType, int numberOfValues, int inputIncrement, int outputFormat)
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 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 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 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 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.
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
virtual double * GetRange()
Sets/Gets the range of scalars that will be mapped.
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.
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...
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.
vtkUnsignedCharArray * ConvertToRGBA(vtkDataArray *colors, int numComp, int numTuples)
An internal method used to convert a color array to RGBA.
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:78
a vtkAbstractArray subclass for strings
dynamic, self-adjusting array of unsigned char
A type representing the union of many types.
Definition: vtkVariant.h:162
@ component
Definition: vtkX3D.h:175
@ value
Definition: vtkX3D.h:220
@ alpha
Definition: vtkX3D.h:250
int vtkTypeBool
Definition: vtkABI.h:64
#define VTK_RGBA
int vtkIdType
Definition: vtkType.h:315
#define VTK_SIZEHINT(...)
#define VTK_NEWINSTANCE
#define max(a, b)